hmx ☞ astro (#22)

This changes all hmx files to astro files and updates all code to not reference hmx any more.
This commit is contained in:
Matthew Phillips 2021-03-24 11:45:38 -04:00 committed by GitHub
parent 5c1cd5b1da
commit 3c24faa8ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 129 additions and 127 deletions

View file

@ -1,7 +1,7 @@
export default { export default {
projectRoot: '.', projectRoot: '.',
hmxRoot: './astro', astroRoot: './astro',
dist: './_site', dist: './_site',
extensions: { extensions: {
'.jsx': 'preact' '.jsx': 'preact'

View file

@ -1,6 +1,6 @@
--- ---
import Banner from '../components/Banner.hmx'; import Banner from '../components/Banner.astro';
import Nav from '../components/Nav.hmx'; import Nav from '../components/Nav.astro';
export function setup({ context }) { export function setup({ context }) {
return { return {
context: { context: {

View file

@ -1,8 +1,8 @@
--- ---
import Menu from '../components/Menu.hmx'; import Menu from '../components/Menu.astro';
import Subnav from '../components/Subnav.hmx'; import Subnav from '../components/Subnav.astro';
export const layout = 'layouts/base.hmx'; export const layout = 'layouts/base.astro';
export function setup({ context }) { export function setup({ context }) {
return {}; return {};
} }

View file

@ -1,8 +1,8 @@
--- ---
import Subnav from '../components/Subnav.hmx'; import Subnav from '../components/Subnav.astro';
import Menu from '../components/Menu.hmx'; import Menu from '../components/Menu.astro';
export const layout = 'layouts/base.hmx'; export const layout = 'layouts/base.astro';
export function setup({ context }) { export function setup({ context }) {
return { return {
context: { context: {

View file

@ -1,6 +1,6 @@
--- ---
import Menu from '../components/Menu.hmx'; import Menu from '../components/Menu.astro';
export const layout = 'layouts/base.hmx'; export const layout = 'layouts/base.astro';
export function setup({ context }) { export function setup({ context }) {
return {}; return {};
} }

View file

@ -1,6 +1,6 @@
--- ---
import { format as formatDate, parseISO } from 'date-fns'; import { format as formatDate, parseISO } from 'date-fns';
export const layout = 'layouts/base.hmx'; export const layout = 'layouts/base.astro';
export function setup({ context }) { export function setup({ context }) {
return {}; return {};
} }

View file

@ -1,5 +1,5 @@
--- ---
export const layout = 'layouts/main.hmx'; export const layout = 'layouts/main.astro';
export function setup({ context }) { export function setup({ context }) {
return { return {

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: The Build Pipeline title: The Build Pipeline
description: Snowpack Build creates a production-ready website with or without a bundler description: Snowpack Build creates a production-ready website with or without a bundler
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: The Dev Server title: The Dev Server
description: Snowpack's dev server is fast because it only rebuilds the files you change. Powered by ESM (ES modules). description: Snowpack's dev server is fast because it only rebuilds the files you change. Powered by ESM (ES modules).
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: HMR + Fast Refresh title: HMR + Fast Refresh
description: Snowpack's ESM-powered unbundled development means near-instant single file builds that only take 10-25ms to load and update in the browser. description: Snowpack's ESM-powered unbundled development means near-instant single file builds that only take 10-25ms to load and update in the browser.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: How Snowpack Works title: How Snowpack Works
description: Snowpack serves your application unbundled during development. Each file is built only once and is cached until it changes. description: Snowpack serves your application unbundled during development. Each file is built only once and is cached until it changes.
--- ---

View file

@ -1,7 +1,7 @@
--- ---
import Card from '../components/Card.jsx'; import Card from '../components/Card.jsx';
export const layout = 'layouts/main.hmx'; export const layout = 'layouts/main.astro';
// mocked for now, to be added later // mocked for now, to be added later
// 1. import {paginate} from 'magicthing'; // 1. import {paginate} from 'magicthing';

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: 'Babel' title: 'Babel'
tags: communityGuide tags: communityGuide
published: true published: true

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: The Snowpack Guide to connecting your favorite tools title: The Snowpack Guide to connecting your favorite tools
description: 'How do you use your favorite tools in Snowpack? This Guide will help you get started' description: 'How do you use your favorite tools in Snowpack? This Guide will help you get started'
published: true published: true

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Hot Module Replacement (HMR) title: Hot Module Replacement (HMR)
description: Enable Snowpack's Hot Module Replacement (HMR) on your development server. description: Enable Snowpack's Hot Module Replacement (HMR) on your development server.
published: false published: false

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: SSL Certificates title: SSL Certificates
description: How to use HTTPs during development and generate SSL certifcates for your Snowpack build. description: How to use HTTPs during development and generate SSL certifcates for your Snowpack build.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: 'Jest' title: 'Jest'
tags: communityGuide tags: communityGuide
img: '/img/logos/jest.svg' img: '/img/logos/jest.svg'

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Optimize & Bundle for Production title: Optimize & Bundle for Production
published: true published: true
description: How to optimize your Snowpack build for production, with or without a bundler. description: How to optimize your Snowpack build for production, with or without a bundler.

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Creating Your Own Plugin title: Creating Your Own Plugin
description: Learn the basics of our Plugin API through working examples. description: Learn the basics of our Plugin API through working examples.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: 'PostCSS' title: 'PostCSS'
tags: communityGuide tags: communityGuide
published: true published: true

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Preact title: Preact
tags: communityGuide tags: communityGuide
img: '/img/logos/preact.svg' img: '/img/logos/preact.svg'

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: React + babel-plugin-import-global title: React + babel-plugin-import-global
published: false published: false
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: React + Loadable Components title: React + Loadable Components
published: false published: false
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Routing title: Routing
published: true published: true
description: This guide will walk you through some common routing scenarios and how to configure the routes option to support them in development. description: This guide will walk you through some common routing scenarios and how to configure the routes option to support them in development.

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: 'Sass' title: 'Sass'
tags: communityGuide tags: communityGuide
published: true published: true

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Server-Side Rendering (SSR) title: Server-Side Rendering (SSR)
description: This guide will walk you through three different options for setting up Snowpack with your own custom server. description: This guide will walk you through three different options for setting up Snowpack with your own custom server.
published: true published: true

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Streaming Imports title: Streaming Imports
published: true published: true
stream: Fetch your npm dependencies on-demand from a remote ESM CDN. stream: Fetch your npm dependencies on-demand from a remote ESM CDN.

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: 'Tailwind CSS' title: 'Tailwind CSS'
tags: communityGuide tags: communityGuide
published: true published: true

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Testing title: Testing
published: true published: true
description: How to choose and use a JavaScript test runner for your Snowpack site. description: How to choose and use a JavaScript test runner for your Snowpack site.

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Snowpack Upgrade Guide title: Snowpack Upgrade Guide
published: true published: true
description: How to upgrade to Snowpack v3 from older versions of Snowpack. description: How to upgrade to Snowpack v3 from older versions of Snowpack.

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Vue title: Vue
tags: communityGuide tags: communityGuide
img: '/img/logos/vue.png' img: '/img/logos/vue.png'

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: 'WASM' title: 'WASM'
tags: communityGuide tags: communityGuide
published: true published: true

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: '@web/test-runner' title: '@web/test-runner'
tags: communityGuide tags: communityGuide
img: '/img/logos/modern-web.svg' img: '/img/logos/modern-web.svg'

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: 'Web Workers' title: 'Web Workers'
tags: communityGuide tags: communityGuide
published: true published: true

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Workbox title: Workbox
tags: communityGuide tags: communityGuide
description: The Workbox CLI integrates well with Snowpack. description: The Workbox CLI integrates well with Snowpack.

View file

@ -1,8 +1,8 @@
--- ---
import Menu from '../components/Menu.hmx'; import Menu from '../components/Menu.astro';
import Hero from '../components/Hero.hmx'; import Hero from '../components/Hero.astro';
export const layout = 'layouts/base.hmx'; export const layout = 'layouts/base.astro';
export function setup({ context }) { export function setup({ context }) {
return {}; return {};
} }

View file

@ -4,7 +4,7 @@
import NewsAssets from '../components/NewsAssets.svelte'; import NewsAssets from '../components/NewsAssets.svelte';
import NewsTitle from '../components/NewsTitle.vue'; import NewsTitle from '../components/NewsTitle.vue';
export const layout = 'layouts/main.hmx'; export const layout = 'layouts/main.astro';
import news from '../data/news.json'; import news from '../data/news.json';
import users from '../data/users.json'; import users from '../data/users.json';

View file

@ -3,7 +3,7 @@
import users from '../data/users.json'; import users from '../data/users.json';
import PluginSearchPage from '../components/PluginSearchPage.jsx'; import PluginSearchPage from '../components/PluginSearchPage.jsx';
export const layout = 'layouts/main.hmx'; export const layout = 'layouts/main.astro';
export function setup({ context }) { export function setup({ context }) {
return { return {

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/post.hmx layout: layouts/post.astro
bannerVideo: '/img/extra-space-4.mp4' bannerVideo: '/img/extra-space-4.mp4'
permalink: '/posts/2020-05-26-snowpack-2-0-release/' permalink: '/posts/2020-05-26-snowpack-2-0-release/'
title: Snowpack v2.0 title: Snowpack v2.0

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/post.hmx layout: layouts/post.astro
title: Snowpack 2.7 title: Snowpack 2.7
description: 'A new plugin API plus smaller, faster production builds.' description: 'A new plugin API plus smaller, faster production builds.'
tagline: v2.7.0 release post tagline: v2.7.0 release post

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/post.hmx layout: layouts/post.astro
title: 'Snowpack v3.0 Release Candidate' title: 'Snowpack v3.0 Release Candidate'
tagline: New features to change the way you build for the web. tagline: New features to change the way you build for the web.
description: 'New features to change the way you build for the web. Snowpack v3.0 will release on January 6th, 2021 (the one-year anniversary of its original launch post). This is our biggest release yet with some serious new features, including a new way to load npm packages on-demand that lets you skip the `npm install` step entirely.' description: 'New features to change the way you build for the web. Snowpack v3.0 will release on January 6th, 2021 (the one-year anniversary of its original launch post). This is our biggest release yet with some serious new features, including a new way to load npm packages on-demand that lets you skip the `npm install` step entirely.'

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/post.hmx layout: layouts/post.astro
title: 'Snowpack v3.0' title: 'Snowpack v3.0'
description: Snowpack v3.0 is here! Our biggest release yet with some serious new features, including pre-bundled streaming imports, built-in bundling & optimizations, new JavaScript APIs, and more.' description: Snowpack v3.0 is here! Our biggest release yet with some serious new features, including pre-bundled streaming imports, built-in bundling & optimizations, new JavaScript APIs, and more.'
date: 2021-01-13 date: 2021-01-13

View file

@ -1,11 +1,11 @@
--- ---
import Subnav from '../components/Subnav.hmx'; import Subnav from '../components/Subnav.astro';
import { content as Menu } from '../components/Menu.hmx'; import { content as Menu } from '../components/Menu.astro';
// import contentful from 'skypack:contentful'; // import contentful from 'skypack:contentful';
export default async function ({ params }) { export default async function ({ params }) {
const entry = await contentful.getEntry(params.slug); const entry = await contentful.getEntry(params.slug);
return { title: entry.fields.title, description: entry.fields.description, layout: 'layouts/base.hmx', props: { entry } }; return { title: entry.fields.title, description: entry.fields.description, layout: 'layouts/base.astro', props: { entry } };
} }
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Command Line API title: Command Line API
description: The Snowpack Command Line tool's API, commands, and flags. description: The Snowpack Command Line tool's API, commands, and flags.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Common Error Details title: Common Error Details
description: How to troubleshoot common issues and error messagesm, plus our resources for getting help. description: How to troubleshoot common issues and error messagesm, plus our resources for getting help.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: snowpack.config.js title: snowpack.config.js
description: The Snowpack configuration API reference. description: The Snowpack configuration API reference.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Environment Variables title: Environment Variables
description: Using environment variables with Snowpack description: Using environment variables with Snowpack
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Hot Module Replacement (HMR) API title: Hot Module Replacement (HMR) API
description: Snowpack implements HMR via the esm-hmr spec, an attempted standard for ESM-based Hot Module Replacement (HMR). description: Snowpack implements HMR via the esm-hmr spec, an attempted standard for ESM-based Hot Module Replacement (HMR).
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: JavaScript API title: JavaScript API
description: Snowpack's JavaScript API is for anyone who wants to integrate with some custom build pipeline or server-side rendering engine. description: Snowpack's JavaScript API is for anyone who wants to integrate with some custom build pipeline or server-side rendering engine.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Plugin API title: Plugin API
description: The Snowpack Plugin API and how to use it. description: The Snowpack Plugin API and how to use it.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Supported Files title: Supported Files
description: Snowpack ships with built-in support for many file types including json, js, ts, jsx, css, css modules, and images. description: Snowpack ships with built-in support for many file types including json, js, ts, jsx, css, css modules, and images.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: 'Starting a New Project' title: 'Starting a New Project'
description: This guide shows you how to set up Snowpack from scratch in a Node.js project. Along the way learn key concepts of Snowpack and unbundled development. description: This guide shows you how to set up Snowpack from scratch in a Node.js project. Along the way learn key concepts of Snowpack and unbundled development.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: Quick Start title: Quick Start
description: A very basic guide for developers who want to run Snowpack as quickly as possible. description: A very basic guide for developers who want to run Snowpack as quickly as possible.
--- ---

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content-with-cover.hmx layout: layouts/content-with-cover.astro
title: 'Getting Started with React' title: 'Getting Started with React'
description: 'Get started with this in-depth tutorial on how to build React applications and websites with Snowpack and developer tools like React Fast Refresh' description: 'Get started with this in-depth tutorial on how to build React applications and websites with Snowpack and developer tools like React Fast Refresh'
date: 2020-12-01 date: 2020-12-01

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content-with-cover.hmx layout: layouts/content-with-cover.astro
title: 'Getting Started with Svelte' title: 'Getting Started with Svelte'
description: 'Get started with this in-depth tutorial on how to build Svelte applications and websites with Snowpack' description: 'Get started with this in-depth tutorial on how to build Svelte applications and websites with Snowpack'
date: 2020-12-01 date: 2020-12-01

View file

@ -5,10 +5,10 @@ const transformPromise = import('./lib/transform2.js');
module.exports = function (snowpackConfig, { resolve, extensions } = {}) { module.exports = function (snowpackConfig, { resolve, extensions } = {}) {
return { return {
name: 'snowpack-hmx', name: 'snowpack-astro',
knownEntrypoints: ['deepmerge'], knownEntrypoints: ['deepmerge'],
resolve: { resolve: {
input: ['.hmx', '.md'], input: ['.astro', '.md'],
output: ['.js'], output: ['.js'],
}, },
async load({ filePath }) { async load({ filePath }) {

View file

@ -1,16 +1,16 @@
export interface AstroConfigRaw { export interface AstroConfigRaw {
dist: string; dist: string;
projectRoot: string; projectRoot: string;
hmxRoot: string; astroRoot: string;
jsx?: string; jsx?: string;
} }
export type ValidExtensionPlugins = 'hmx' | 'react' | 'preact' | 'svelte' | 'vue'; export type ValidExtensionPlugins = 'astro' | 'react' | 'preact' | 'svelte' | 'vue';
export interface AstroConfig { export interface AstroConfig {
dist: string; dist: string;
projectRoot: URL; projectRoot: URL;
hmxRoot: URL; astroRoot: URL;
extensions?: Record<string, ValidExtensionPlugins> extensions?: Record<string, ValidExtensionPlugins>
} }

View file

@ -25,7 +25,7 @@ interface CodeGenOptions {
} }
function internalImport(internalPath: string) { function internalImport(internalPath: string) {
return `/__hmx_internal__/${internalPath}`; return `/_astro_internal/${internalPath}`;
} }
function getAttributes(attrs: Attribute[]): Record<string, string> { function getAttributes(attrs: Attribute[]): Record<string, string> {
@ -96,7 +96,7 @@ interface ComponentInfo {
} }
const defaultExtensions: Readonly<Record<string, ValidExtensionPlugins>> = { const defaultExtensions: Readonly<Record<string, ValidExtensionPlugins>> = {
'.hmx': 'hmx', '.astro': 'astro',
'.jsx': 'react', '.jsx': 'react',
'.vue': 'vue', '.vue': 'vue',
'.svelte': 'svelte' '.svelte': 'svelte'
@ -117,9 +117,9 @@ function getComponentWrapper(_name: string, { type, url }: ComponentInfo, compil
} }
switch (plugin) { switch (plugin) {
case 'hmx': { case 'astro': {
if (kind) { if (kind) {
throw new Error(`HMX does not support :${kind}`); throw new Error(`Astro does not support :${kind}`);
} }
return { return {
wrapper: name, wrapper: name,

View file

@ -1,3 +1,3 @@
# `hmx/compiler` # `astro/compiler`
This directory is a fork of `svelte/compiler`. It is meant to stay as close to the original source as possible, so that upstream changes are easy to integrate. Everything svelte-specific and unrelated to parsing (compiler, preprocess, etc) has been removed. This directory is a fork of `svelte/compiler`. It is meant to stay as close to the original source as possible, so that upstream changes are easy to integrate. Everything svelte-specific and unrelated to parsing (compiler, preprocess, etc) has been removed.

View file

@ -226,7 +226,7 @@ export default function parse(template: string, options: ParserOptions = {}): As
parser.error( parser.error(
{ {
code: 'duplicate-style', code: 'duplicate-style',
message: 'You can only have one <style> tag per HMX file', message: 'You can only have one <style> tag per Astro file',
}, },
parser.css[1].start parser.css[1].start
); );
@ -234,15 +234,15 @@ export default function parse(template: string, options: ParserOptions = {}): As
// const instance_scripts = parser.js.filter((script) => script.context === 'default'); // const instance_scripts = parser.js.filter((script) => script.context === 'default');
// const module_scripts = parser.js.filter((script) => script.context === 'module'); // const module_scripts = parser.js.filter((script) => script.context === 'module');
const hmx_scripts = parser.js.filter((script) => script.context === 'setup'); const astro_scripts = parser.js.filter((script) => script.context === 'setup');
if (hmx_scripts.length > 1) { if (astro_scripts.length > 1) {
parser.error( parser.error(
{ {
code: 'invalid-script', code: 'invalid-script',
message: 'A component can only have one frontmatter (---) script', message: 'A component can only have one frontmatter (---) script',
}, },
hmx_scripts[1].start astro_scripts[1].start
); );
} }
@ -260,6 +260,6 @@ export default function parse(template: string, options: ParserOptions = {}): As
html: parser.html, html: parser.html,
css: parser.css[0], css: parser.css[0],
// instance: instance_scripts[0], // instance: instance_scripts[0],
module: hmx_scripts[0], module: astro_scripts[0],
}; };
} }

View file

@ -17,6 +17,6 @@ export async function loadConfig(rawRoot: string | undefined): Promise<AstroConf
const astroConfig: AstroConfig = (await import(astroConfigPath)).default; const astroConfig: AstroConfig = (await import(astroConfigPath)).default;
astroConfig.projectRoot = new URL(astroConfig.projectRoot + '/', fileProtocolRoot); astroConfig.projectRoot = new URL(astroConfig.projectRoot + '/', fileProtocolRoot);
astroConfig.hmxRoot = new URL(astroConfig.hmxRoot + '/', fileProtocolRoot); astroConfig.astroRoot = new URL(astroConfig.astroRoot + '/', fileProtocolRoot);
return astroConfig; return astroConfig;
} }

View file

@ -53,7 +53,7 @@ export default async function (astroConfig: AstroConfig) {
break; break;
} }
default: { default: {
error(logging, 'executing hmx', result.error); error(logging, 'executing astro', result.error);
break; break;
} }
} }

View file

@ -1,7 +1,7 @@
export type HProps = Record<string, string> | null | undefined; export type HProps = Record<string, string> | null | undefined;
export type HChild = string | undefined | (() => string); export type HChild = string | undefined | (() => string);
export type HMXComponent = (props: HProps, ...children: Array<HChild>) => string; export type AstroComponent = (props: HProps, ...children: Array<HChild>) => string;
export type HTag = string | HMXComponent; export type HTag = string | AstroComponent;
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']); const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
@ -41,7 +41,7 @@ function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
export async function h(tag: HTag, attrs: HProps, ...pChildren: Array<Promise<HChild>>) { export async function h(tag: HTag, attrs: HProps, ...pChildren: Array<Promise<HChild>>) {
const children = await Promise.all(pChildren.flat(Infinity)); const children = await Promise.all(pChildren.flat(Infinity));
if (typeof tag === 'function') { if (typeof tag === 'function') {
// We assume it's an hmx component // We assume it's an astro component
return tag(attrs, ...children); return tag(attrs, ...children);
} }

View file

@ -19,8 +19,8 @@ async function* allPages(root: URL): AsyncGenerator<URL, void, unknown> {
} }
export default async function (astroConfig: AstroConfig) { export default async function (astroConfig: AstroConfig) {
const { projectRoot, hmxRoot } = astroConfig; const { projectRoot, astroRoot } = astroConfig;
const pageRoot = new URL('./pages/', hmxRoot); const pageRoot = new URL('./pages/', astroRoot);
const dist = new URL(astroConfig.dist + '/', projectRoot); const dist = new URL(astroConfig.dist + '/', projectRoot);
const configPath = new URL('./snowpack.config.js', projectRoot).pathname; const configPath = new URL('./snowpack.config.js', projectRoot).pathname;
@ -39,11 +39,11 @@ export default async function (astroConfig: AstroConfig) {
const runtime = snowpack.getServerRuntime(); const runtime = snowpack.getServerRuntime();
for await (const filepath of allPages(pageRoot)) { for await (const filepath of allPages(pageRoot)) {
const rel = pathRelative(hmxRoot.pathname, filepath.pathname); // pages/index.hmx const rel = pathRelative(astroRoot.pathname, filepath.pathname); // pages/index.astro
const pagePath = `/_hmx/${rel.replace(/\.(hmx|md)/, '.js')}`; const pagePath = `/_astro/${rel.replace(/\.(astro|md)/, '.js')}`;
try { try {
const outPath = new URL('./' + rel.replace(/\.(hmx|md)/, '.html'), dist); const outPath = new URL('./' + rel.replace(/\.(astro|md)/, '.html'), dist);
const outFolder = new URL('./', outPath); const outFolder = new URL('./', outPath);
const mod = await runtime.importModule(pagePath); const mod = await runtime.importModule(pagePath);
const html = await mod.exports.default({}); const html = await mod.exports.default({});

View file

@ -28,18 +28,18 @@ export type LoadResult = LoadResultSuccess | LoadResultNotFound | LoadResultErro
async function load(config: RuntimeConfig, rawPathname: string | undefined): Promise<LoadResult> { async function load(config: RuntimeConfig, rawPathname: string | undefined): Promise<LoadResult> {
const { logging, snowpack, snowpackRuntime } = config; const { logging, snowpack, snowpackRuntime } = config;
const { hmxRoot } = config.astroConfig; const { astroRoot } = config.astroConfig;
const fullurl = new URL(rawPathname || '/', 'https://example.org/'); const fullurl = new URL(rawPathname || '/', 'https://example.org/');
const reqPath = decodeURI(fullurl.pathname); const reqPath = decodeURI(fullurl.pathname);
const selectedPage = reqPath.substr(1) || 'index'; const selectedPage = reqPath.substr(1) || 'index';
info(logging, 'access', reqPath); info(logging, 'access', reqPath);
const selectedPageLoc = new URL(`./pages/${selectedPage}.hmx`, hmxRoot); const selectedPageLoc = new URL(`./pages/${selectedPage}.astro`, astroRoot);
const selectedPageMdLoc = new URL(`./pages/${selectedPage}.md`, hmxRoot); const selectedPageMdLoc = new URL(`./pages/${selectedPage}.md`, astroRoot);
const selectedPageUrl = `/_hmx/pages/${selectedPage}.js`; const selectedPageUrl = `/_astro/pages/${selectedPage}.js`;
// Non-hmx pages (file resources) // Non-Astro pages (file resources)
if (!existsSync(selectedPageLoc) && !existsSync(selectedPageMdLoc)) { if (!existsSync(selectedPageLoc) && !existsSync(selectedPageMdLoc)) {
try { try {
const result = await snowpack.loadUrl(reqPath); const result = await snowpack.loadUrl(reqPath);
@ -96,19 +96,19 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro
} }
export async function createRuntime(astroConfig: AstroConfig, logging: LogOptions) { export async function createRuntime(astroConfig: AstroConfig, logging: LogOptions) {
const { projectRoot, hmxRoot, extensions } = astroConfig; const { projectRoot, astroRoot, extensions } = astroConfig;
const internalPath = new URL('./frontend/', import.meta.url); const internalPath = new URL('./frontend/', import.meta.url);
// Workaround for SKY-251 // Workaround for SKY-251
const hmxPlugOptions: { const astroPlugOptions: {
resolve?: (s: string) => string; resolve?: (s: string) => string;
extensions?: Record<string, string> extensions?: Record<string, string>
} = { extensions }; } = { extensions };
if (existsSync(new URL('./package-lock.json', projectRoot))) { if (existsSync(new URL('./package-lock.json', projectRoot))) {
const pkgLockStr = await readFile(new URL('./package-lock.json', projectRoot), 'utf-8'); const pkgLockStr = await readFile(new URL('./package-lock.json', projectRoot), 'utf-8');
const pkgLock = JSON.parse(pkgLockStr); const pkgLock = JSON.parse(pkgLockStr);
hmxPlugOptions.resolve = (pkgName: string) => { astroPlugOptions.resolve = (pkgName: string) => {
const ver = pkgLock.dependencies[pkgName].version; const ver = pkgLock.dependencies[pkgName].version;
return `/_snowpack/pkg/${pkgName}.v${ver}.js`; return `/_snowpack/pkg/${pkgName}.v${ver}.js`;
}; };
@ -117,10 +117,10 @@ export async function createRuntime(astroConfig: AstroConfig, logging: LogOption
const snowpackConfig = await loadConfiguration({ const snowpackConfig = await loadConfiguration({
root: projectRoot.pathname, root: projectRoot.pathname,
mount: { mount: {
[hmxRoot.pathname]: '/_hmx', [astroRoot.pathname]: '/_astro',
[internalPath.pathname]: '/__hmx_internal__', [internalPath.pathname]: '/_astro_internal',
}, },
plugins: [[new URL('../snowpack-plugin.cjs', import.meta.url).pathname, hmxPlugOptions]], plugins: [[new URL('../snowpack-plugin.cjs', import.meta.url).pathname, astroPlugOptions]],
devOptions: { devOptions: {
open: 'none', open: 'none',
output: 'stream', output: 'stream',

View file

@ -24,16 +24,16 @@ const defaultCompileOptions: CompileOptions = {
}; };
function internalImport(internalPath: string) { function internalImport(internalPath: string) {
return `/__hmx_internal__/${internalPath}`; return `/_astro_internal/${internalPath}`;
} }
interface ConvertHmxOptions { interface ConvertAstroOptions {
compileOptions: CompileOptions; compileOptions: CompileOptions;
filename: string; filename: string;
fileID: string; fileID: string;
} }
async function convertHmxToJsx(template: string, opts: ConvertHmxOptions): Promise<TransformResult> { async function convertAstroToJsx(template: string, opts: ConvertAstroOptions): Promise<TransformResult> {
const { filename } = opts; const { filename } = opts;
// 1. Parse // 1. Parse
@ -90,17 +90,19 @@ async function convertMdToJsx(
const convertOptions = { compileOptions, filename, fileID }; const convertOptions = { compileOptions, filename, fileID };
return convertHmxToJsx(raw, convertOptions); return convertAstroToJsx(raw, convertOptions);
} }
type SupportedExtensions = '.astro' | '.md';
async function transformFromSource( async function transformFromSource(
contents: string, contents: string,
{ compileOptions, filename, projectRoot }: { compileOptions: CompileOptions; filename: string; projectRoot: string } { compileOptions, filename, projectRoot }: { compileOptions: CompileOptions; filename: string; projectRoot: string }
): Promise<TransformResult> { ): Promise<TransformResult> {
const fileID = path.relative(projectRoot, filename); const fileID = path.relative(projectRoot, filename);
switch (path.extname(filename)) { switch (path.extname(filename) as SupportedExtensions) {
case '.hmx': case '.astro':
return convertHmxToJsx(contents, { compileOptions, filename, fileID }); return convertAstroToJsx(contents, { compileOptions, filename, fileID });
case '.md': case '.md':
return convertMdToJsx(contents, { compileOptions, filename, fileID }); return convertMdToJsx(contents, { compileOptions, filename, fileID });
default: default:
@ -125,7 +127,7 @@ export async function compileComponent(
// <script astro></script> // <script astro></script>
${sourceJsx.script} ${sourceJsx.script}
// \`__render()\`: Render the contents of the HMX module. "<slot:*>" elements are not // \`__render()\`: Render the contents of the Astro module. "<slot:*>" elements are not
// included (see below). // included (see below).
import { h, Fragment } from '${internalImport('h.js')}'; import { h, Fragment } from '${internalImport('h.js')}';
export function __slothead(children, context) { return h(Fragment, null, ${headItemJsx}); } export function __slothead(children, context) { return h(Fragment, null, ${headItemJsx}); }
@ -135,7 +137,7 @@ export default __render;
if (headItemJsx) { if (headItemJsx) {
modJsx += ` modJsx += `
// \`__renderPage()\`: Render the contents of the HMX module as a page. This is a special flow, // \`__renderPage()\`: Render the contents of the Astro module as a page. This is a special flow,
// triggered by loading a component directly by URL. // triggered by loading a component directly by URL.
// If the page exports a defined "layout", then load + render those first. "context", "astro:head", // If the page exports a defined "layout", then load + render those first. "context", "astro:head",
// and "slot:body" should all inherit from parent layouts, merging together in the correct order. // and "slot:body" should all inherit from parent layouts, merging together in the correct order.
@ -149,7 +151,7 @@ export async function __renderPage({request, children}) {
// find all layouts, going up the layout chain. // find all layouts, going up the layout chain.
if (currentChild.layout) { if (currentChild.layout) {
const layoutComponent = (await import('/_hmx/layouts/' + layout.replace(/.*layouts\\//, "").replace(/\.hmx$/, '.js'))); const layoutComponent = (await import('/_astro/layouts/' + layout.replace(/.*layouts\\//, "").replace(/\.astro$/, '.js')));
return layoutComponent.__renderPage({ return layoutComponent.__renderPage({
request, request,
children: [currentChild, ...children], children: [currentChild, ...children],

View file

@ -9,8 +9,8 @@ let runtime;
Basics.before(async () => { Basics.before(async () => {
const astroConfig = { const astroConfig = {
projectRoot: new URL('./fixtures/hmx-basic/', import.meta.url), projectRoot: new URL('./fixtures/astro-basic/', import.meta.url),
hmxRoot: new URL('./fixtures/hmx-basic/astro/', import.meta.url), hmxRoot: new URL('./fixtures/astro-basic/astro/', import.meta.url),
dist: './_site' dist: './_site'
}; };
@ -26,7 +26,7 @@ Basics.after(async () => {
await runtime && runtime.shutdown(); await runtime && runtime.shutdown();
}); });
Basics('Can load hmx page', async () => { Basics('Can load page', async () => {
const result = await runtime.load('/'); const result = await runtime.load('/');
assert.equal(result.statusCode, 200); assert.equal(result.statusCode, 200);

View file

@ -4,12 +4,12 @@ import { createRuntime } from '../lib/runtime.js';
import { loadConfig } from '../lib/config.js'; import { loadConfig } from '../lib/config.js';
import { doc } from './test-utils.js'; import { doc } from './test-utils.js';
const HMXMD = suite('HMX Markdown'); const Markdown = suite('Astro Markdown');
let runtime, setupError; let runtime, setupError;
HMXMD.before(async () => { Markdown.before(async () => {
const astroConfig = await loadConfig(new URL('./fixtures/hmx-markdown', import.meta.url).pathname); const astroConfig = await loadConfig(new URL('./fixtures/astro-markdown', import.meta.url).pathname);
const logging = { const logging = {
level: 'error', level: 'error',
@ -24,15 +24,15 @@ HMXMD.before(async () => {
} }
}); });
HMXMD.after(async () => { Markdown.after(async () => {
runtime && runtime.shutdown(); runtime && runtime.shutdown();
}); });
HMXMD('No errors creating a runtime', () => { Markdown('No errors creating a runtime', () => {
assert.equal(setupError, undefined); assert.equal(setupError, undefined);
}); });
HMXMD('Can load markdown pages with hmx', async () => { Markdown('Can load markdown pages with hmx', async () => {
const result = await runtime.load('/post'); const result = await runtime.load('/post');
assert.equal(result.statusCode, 200); assert.equal(result.statusCode, 200);
@ -42,4 +42,4 @@ HMXMD('Can load markdown pages with hmx', async () => {
assert.ok($('#test').length, 'There is a div added via a component from markdown'); assert.ok($('#test').length, 'There is a div added via a component from markdown');
}); });
HMXMD.run(); Markdown.run();

View file

@ -1,6 +1,6 @@
export default { export default {
projectRoot: '.', projectRoot: '.',
hmxRoot: './astro', astroRoot: './astro',
dist: './_site' dist: './_site'
} }

View file

@ -1,7 +1,7 @@
export default { export default {
projectRoot: '.', projectRoot: '.',
hmxRoot: './astro', astroRoot: './astro',
dist: './_site', dist: './_site',
extensions: { extensions: {
'.jsx': 'preact' '.jsx': 'preact'

View file

@ -1,5 +1,5 @@
--- ---
layout: layouts/content.hmx layout: layouts/content.astro
title: My Blog Post title: My Blog Post
description: This is a post about some stuff. description: This is a post about some stuff.
import: import:

View file

@ -1,7 +1,7 @@
export default { export default {
projectRoot: '.', projectRoot: '.',
hmxRoot: './astro', astroRoot: './astro',
dist: './_site' dist: './_site'
// No extensions needed, React is the default. // No extensions needed, React is the default.
} }

View file

@ -32,7 +32,7 @@ React('No error creating the runtime', () => {
assert.equal(setupError, undefined); assert.equal(setupError, undefined);
}); });
React('Can load hmx page', async () => { React('Can load page', async () => {
const result = await runtime.load('/'); const result = await runtime.load('/');
assert.equal(result.statusCode, 200); assert.equal(result.statusCode, 200);

View file

@ -52,7 +52,7 @@ async function* allPageFiles(root) {
async function* allPages(root) { async function* allPages(root) {
for await (let fileURL of allPageFiles(root)) { for await (let fileURL of allPageFiles(root)) {
let bare = fileURL.pathname.replace(/\.(hmx|md)$/, '').replace(/index$/, ''); let bare = fileURL.pathname.replace(/\.(astro|md)$/, '').replace(/index$/, '');
yield '/' + pathRelative(root.pathname, bare); yield '/' + pathRelative(root.pathname, bare);
} }