From 94eac19888398e91d436cf31867ba9d3397e1d1a Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 2 Jun 2021 11:35:28 -0500 Subject: [PATCH] Pre-release refactors (#289) * refactor: expose `astro/components` as component entrypoint * refactor: remove `extensions` from all configs * test: fix snowpack tests * docs: update config doc --- docs/config.md | 40 ++++------- docs/markdown.md | 6 +- examples/astro-markdown/astro.config.mjs | 7 -- examples/astro-markdown/src/pages/index.astro | 2 +- examples/doc/astro.config.mjs | 6 +- examples/doc/src/pages/index.astro | 2 +- examples/portfolio/astro.config.mjs | 6 +- examples/remote-markdown/astro.config.mjs | 5 -- examples/remote-markdown/docs/dev.md | 48 ------------- examples/remote-markdown/package.json | 17 ----- .../remote-markdown/src/components/Yell.jsx | 10 --- .../remote-markdown/src/layouts/main.astro | 14 ---- .../remote-markdown/src/pages/index.astro | 72 ------------------- examples/remote-markdown/src/pages/test.astro | 6 -- examples/snowpack/astro.config.mjs | 15 ++-- packages/astro/components/index.js | 2 + packages/astro/package.json | 1 + packages/astro/src/frontend/500.astro | 2 +- .../test/fixtures/astro-expr/astro.config.mjs | 9 ++- .../fixtures/astro-fallback/astro.config.mjs | 8 +-- .../astro-markdown/src/pages/code.astro | 2 +- .../astro-markdown/src/pages/complex.astro | 2 +- .../astro-markdown/src/pages/external.astro | 4 +- .../astro-markdown/src/pages/post.astro | 2 +- .../fixtures/config-path/config/my-config.mjs | 8 +-- .../fixtures/plain-markdown/astro.config.mjs | 6 +- 26 files changed, 55 insertions(+), 247 deletions(-) delete mode 100644 examples/astro-markdown/astro.config.mjs delete mode 100644 examples/remote-markdown/astro.config.mjs delete mode 100644 examples/remote-markdown/docs/dev.md delete mode 100644 examples/remote-markdown/package.json delete mode 100644 examples/remote-markdown/src/components/Yell.jsx delete mode 100644 examples/remote-markdown/src/layouts/main.astro delete mode 100644 examples/remote-markdown/src/pages/index.astro delete mode 100644 examples/remote-markdown/src/pages/test.astro create mode 100644 packages/astro/components/index.js diff --git a/docs/config.md b/docs/config.md index 7474109ccf8c..dbbe311a2697 100644 --- a/docs/config.md +++ b/docs/config.md @@ -4,34 +4,24 @@ To configure Astro, add an `astro.config.mjs` file in the root of your project. ```js export default { - /** Where to resolve all URLs relative to. Useful if you have a monorepo project. */ - projectRoot: '.', - /** Path to your site’s pages (routes) */ - pages: './src/pages', - /** When running `astro build`, path to final static output */ - dist: './dist', - /** A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that don’t need processing. */ - public: './public', - /** Extension-specific handlings */ - extensions: { - /** Set this to "preact" or "react" to determine what *.jsx files should load */ - '.jsx': 'react', - }, - /** Options specific to `astro build` */ + projectRoot: '.', // Where to resolve all URLs relative to. Useful if you have a monorepo project. + pages: './src/pages', // Path to Astro components, pages, and data + dist: './dist', // When running `astro build`, path to final static output + public: './public', // A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that don’t need processing. buildOptions: { - /** Your public domain, e.g.: https://my-site.dev/. Used to generate sitemaps and canonical URLs. */ - site: '', - /** Generate sitemap (set to "false" to disable) */ - sitemap: true, + // site: '', // Your public domain, e.g.: https://my-site.dev/. Used to generate sitemaps and canonical URLs. + sitemap: true, // Generate sitemap (set to "false" to disable) }, - /** Options for the development server run with `astro dev`. */ devOptions: { - /** The port to run the dev server on. */ - port: 3000, - /** Path to tailwind.config.js if used, e.g. './tailwind.config.js' */ - tailwindConfig: undefined, + port: 3000, // The port to run the dev server on. + // tailwindConfig: '', // Path to tailwind.config.js if used, e.g. './tailwind.config.js' }, - /** default array of rendering packages inserted into runtime */ - renderers: ['@astrojs/renderer-preact', '@astrojs/renderer-react', '@astrojs/renderer-svelte', '@astrojs/renderer-vue'], + // component renderers which are enabled by default + renderers: [ + '@astrojs/renderer-svelte', + '@astrojs/renderer-vue', + '@astrojs/renderer-react', + '@astrojs/renderer-preact' + ], }; ``` diff --git a/docs/markdown.md b/docs/markdown.md index c20124096d1b..822efb1ef554 100644 --- a/docs/markdown.md +++ b/docs/markdown.md @@ -58,7 +58,7 @@ Astro exposes a special `Markdown` component for `.astro` files which enables ma --- // For now, this import _must_ be named "Markdown" and _must not_ be wrapped with a custom component // We're working on easing these restrictions! -import Markdown from 'astro/components/Markdown.astro'; +import { Markdown } from 'astro/components'; import Layout from '../layouts/main.astro'; import MyFancyCodePreview from '../components/MyFancyCodePreview.tsx'; @@ -101,7 +101,7 @@ If you have Markdown in a remote source, you may pass it directly to the Markdow ```jsx --- -import Markdown from 'astro/components/Markdown.astro'; +import { Markdown } from 'astro/components'; const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text()); --- @@ -115,7 +115,7 @@ Some times you might want to combine dynamic markdown with static markdown. You ```jsx --- -import Markdown from 'astro/components/Markdown.astro'; +import { Markdown } from 'astro/components'; const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text()); --- diff --git a/examples/astro-markdown/astro.config.mjs b/examples/astro-markdown/astro.config.mjs deleted file mode 100644 index a66babaf3e79..000000000000 --- a/examples/astro-markdown/astro.config.mjs +++ /dev/null @@ -1,7 +0,0 @@ -export default { - extensions: { - '.jsx': 'react', - '.tsx': 'preact', - }, - public: './public' -}; diff --git a/examples/astro-markdown/src/pages/index.astro b/examples/astro-markdown/src/pages/index.astro index b46f3698fb23..666e0557f7d1 100644 --- a/examples/astro-markdown/src/pages/index.astro +++ b/examples/astro-markdown/src/pages/index.astro @@ -1,5 +1,5 @@ --- -import Markdown from 'astro/components/Markdown.astro'; +import { Markdown } from 'astro/components'; import Layout from '../layouts/main.astro'; import ReactCounter from '../components/ReactCounter.jsx'; import PreactCounter from '../components/PreactCounter.tsx'; diff --git a/examples/doc/astro.config.mjs b/examples/doc/astro.config.mjs index 9ba6c58c949b..d97e2804d747 100644 --- a/examples/doc/astro.config.mjs +++ b/examples/doc/astro.config.mjs @@ -1,5 +1,5 @@ export default { - extensions: { - '.tsx': 'preact' - } + renderers: [ + '@astrojs/renderer-preact' + ] }; diff --git a/examples/doc/src/pages/index.astro b/examples/doc/src/pages/index.astro index fe00e15a8671..75ca0da4f913 100644 --- a/examples/doc/src/pages/index.astro +++ b/examples/doc/src/pages/index.astro @@ -1,5 +1,5 @@ --- -import Markdown from 'astro/components/Markdown.astro'; +import { Markdown } from 'astro/components'; import Layout from '../layouts/Main.astro'; --- diff --git a/examples/portfolio/astro.config.mjs b/examples/portfolio/astro.config.mjs index f50751cfdce6..d97e2804d747 100644 --- a/examples/portfolio/astro.config.mjs +++ b/examples/portfolio/astro.config.mjs @@ -1,5 +1,5 @@ export default { - extensions: { - '.jsx': 'preact', - }, + renderers: [ + '@astrojs/renderer-preact' + ] }; diff --git a/examples/remote-markdown/astro.config.mjs b/examples/remote-markdown/astro.config.mjs deleted file mode 100644 index c7bfe91b0c64..000000000000 --- a/examples/remote-markdown/astro.config.mjs +++ /dev/null @@ -1,5 +0,0 @@ -export default { - extensions: { - '.jsx': 'preact' - } -} diff --git a/examples/remote-markdown/docs/dev.md b/examples/remote-markdown/docs/dev.md deleted file mode 100644 index d9223cbbde15..000000000000 --- a/examples/remote-markdown/docs/dev.md +++ /dev/null @@ -1,48 +0,0 @@ -# Development Server - -The development server comes as part of the Astro CLI. Start the server with: - -```shell -astro dev -``` - -In your project root. You can specify an alternative - -## Special routes - -The dev server will serve the following special routes: - -### /400 - -This is a custom **400** status code page. You can add this route by adding a page component to your `src/pages` folder: - -``` -├── src/ -│ ├── components/ -│ └── pages/ -│ └── 400.astro -``` - -For any URL you visit that doesn't have a corresponding page, the `400.astro` file will be used. - -### /500 - -This is a custom **500** status code page. You can add this route by adding a page component to your `src/pages` folder: - -```astro -├── src/ │ ├── components/ │ └── pages/ │ └── 500.astro -``` - -This page is used any time an error occurs in the dev server. - -The 500 page will receive an `error` query parameter which you can access with: - -``` ---- -const error = Astro.request.url.searchParams.get('error'); ---- - -{error} -``` - -A default error page is included with Astro so you will get pretty error messages even without adding a custom 500 page. diff --git a/examples/remote-markdown/package.json b/examples/remote-markdown/package.json deleted file mode 100644 index 1c0524bf1185..000000000000 --- a/examples/remote-markdown/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "@example/remote-markdown", - "version": "0.0.1", - "private": true, - "scripts": { - "start": "astro dev", - "build": "astro build", - "astro-dev": "nodemon --delay 0.5 -w ../../packages/astro/dist -x '../../packages/astro/astro.mjs dev'" - }, - "devDependencies": { - "astro": "0.12.0-next.1", - "nodemon": "^2.0.7" - }, - "snowpack": { - "workspaceRoot": "../.." - } -} diff --git a/examples/remote-markdown/src/components/Yell.jsx b/examples/remote-markdown/src/components/Yell.jsx deleted file mode 100644 index 366d88a9524e..000000000000 --- a/examples/remote-markdown/src/components/Yell.jsx +++ /dev/null @@ -1,10 +0,0 @@ -import { h, Fragment } from 'preact'; - -export default function Yell({ children }) { - return ( - children - .filter((v) => typeof v === 'string') - .join('') - .toUpperCase() + '!' - ); -} diff --git a/examples/remote-markdown/src/layouts/main.astro b/examples/remote-markdown/src/layouts/main.astro deleted file mode 100644 index 37fcc0ee7f4e..000000000000 --- a/examples/remote-markdown/src/layouts/main.astro +++ /dev/null @@ -1,14 +0,0 @@ ---- -export let content; ---- - - - - {content.title} - - - - -
{JSON.stringify(content)}
- - diff --git a/examples/remote-markdown/src/pages/index.astro b/examples/remote-markdown/src/pages/index.astro deleted file mode 100644 index 402780065d46..000000000000 --- a/examples/remote-markdown/src/pages/index.astro +++ /dev/null @@ -1,72 +0,0 @@ ---- -import Markdown from 'astro/components/Markdown.astro'; -import Yell from '../components/Yell.jsx'; -const title = 'INTERPOLATED'; -const quietTest = 'interpolated'; -const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text()); ---- - - - -# Hello world! - - - - - # Hello indent! - - - - -# Hello {title}! - - - - - - # I cannot! - -
- # ahhhh -
- - {quietTest} - - Dope - - `nice` - - ``` - plain fence - ``` - - ```html - don't
me
bro - ``` - - ```js - Astro.fetchContent() - ``` - - ### cool stuff? - ```astro - {'can\'t interpolate'} - {} - {title} - - Do I break? - ``` -
- - -{content} - - - - {content} - - - - - {content} - diff --git a/examples/remote-markdown/src/pages/test.astro b/examples/remote-markdown/src/pages/test.astro deleted file mode 100644 index d0a050f35029..000000000000 --- a/examples/remote-markdown/src/pages/test.astro +++ /dev/null @@ -1,6 +0,0 @@ ---- -import Markdown from 'astro/components/Markdown.astro'; -const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text()); ---- - - diff --git a/examples/snowpack/astro.config.mjs b/examples/snowpack/astro.config.mjs index eedfc34db3f5..15bc31b47309 100644 --- a/examples/snowpack/astro.config.mjs +++ b/examples/snowpack/astro.config.mjs @@ -3,14 +3,9 @@ export default { pages: './src/pages', dist: './dist', public: './public', - extensions: { - '.jsx': 'preact', - }, - snowpack: { - optimize: { - bundle: false, - minify: true, - target: 'es2018', - }, - }, + renderers: [ + '@astrojs/renderer-vue', + '@astrojs/renderer-svelte', + '@astrojs/renderer-preact' + ] }; diff --git a/packages/astro/components/index.js b/packages/astro/components/index.js new file mode 100644 index 000000000000..a6673415ed0e --- /dev/null +++ b/packages/astro/components/index.js @@ -0,0 +1,2 @@ +export { default as Markdown } from './Markdown.astro'; +export { default as Prism } from './Prism.astro'; diff --git a/packages/astro/package.json b/packages/astro/package.json index 237f72a8d106..36266a05ff0f 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -9,6 +9,7 @@ ".": "./astro.mjs", "./package.json": "./package.json", "./snowpack-plugin": "./snowpack-plugin.cjs", + "./components": "./components/index.js", "./components/*": "./components/*", "./runtime/svelte": "./dist/frontend/runtime/svelte.js", "./dist/frontend/markdown.js": "./dist/frontend/markdown.js" diff --git a/packages/astro/src/frontend/500.astro b/packages/astro/src/frontend/500.astro index 01fab8bea6f8..4ffd7ac88272 100644 --- a/packages/astro/src/frontend/500.astro +++ b/packages/astro/src/frontend/500.astro @@ -1,5 +1,5 @@ --- -import Prism from 'astro/components/Prism.astro'; +import { Prism } from 'astro/components'; let title = 'Uh oh...'; const error = Astro.request.url.searchParams.get('error'); diff --git a/packages/astro/test/fixtures/astro-expr/astro.config.mjs b/packages/astro/test/fixtures/astro-expr/astro.config.mjs index 80d0860c3a73..6c6bb575d5a4 100644 --- a/packages/astro/test/fixtures/astro-expr/astro.config.mjs +++ b/packages/astro/test/fixtures/astro-expr/astro.config.mjs @@ -1,6 +1,5 @@ - export default { - extensions: { - '.jsx': 'preact' - } -} \ No newline at end of file + renderers: [ + '@astrojs/renderer-preact' + ] +} diff --git a/packages/astro/test/fixtures/astro-fallback/astro.config.mjs b/packages/astro/test/fixtures/astro-fallback/astro.config.mjs index f50751cfdce6..6c6bb575d5a4 100644 --- a/packages/astro/test/fixtures/astro-fallback/astro.config.mjs +++ b/packages/astro/test/fixtures/astro-fallback/astro.config.mjs @@ -1,5 +1,5 @@ export default { - extensions: { - '.jsx': 'preact', - }, -}; + renderers: [ + '@astrojs/renderer-preact' + ] +} diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/code.astro b/packages/astro/test/fixtures/astro-markdown/src/pages/code.astro index 16a1158c9b04..19aa90e1884d 100644 --- a/packages/astro/test/fixtures/astro-markdown/src/pages/code.astro +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/code.astro @@ -1,5 +1,5 @@ --- -import Markdown from 'astro/components/Markdown.astro'; +import { Markdown } from 'astro/components'; export const title = 'My Blog Post'; export const description = 'This is a post about some stuff.'; --- diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/complex.astro b/packages/astro/test/fixtures/astro-markdown/src/pages/complex.astro index aa9a872eb86e..4d470f48d714 100644 --- a/packages/astro/test/fixtures/astro-markdown/src/pages/complex.astro +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/complex.astro @@ -1,5 +1,5 @@ --- -import Markdown from 'astro/components/Markdown.astro'; +import { Markdown } from 'astro/components'; import Layout from '../layouts/content.astro'; import Hello from '../components/Hello.jsx'; import Counter from '../components/Counter.jsx'; diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/external.astro b/packages/astro/test/fixtures/astro-markdown/src/pages/external.astro index a39209d4a212..0b7e5911ad87 100644 --- a/packages/astro/test/fixtures/astro-markdown/src/pages/external.astro +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/external.astro @@ -1,5 +1,5 @@ --- -import Markdown from 'astro/components/Markdown.astro'; +import { Markdown } from 'astro/components'; import Hello from '../components/Hello.jsx'; const outer = `# Outer`; @@ -12,4 +12,4 @@ const inner = `## Inner`; # Nested - \ No newline at end of file + diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/post.astro b/packages/astro/test/fixtures/astro-markdown/src/pages/post.astro index 05e740c0441b..b8cffd8c42f3 100644 --- a/packages/astro/test/fixtures/astro-markdown/src/pages/post.astro +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/post.astro @@ -1,5 +1,5 @@ --- -import Markdown from 'astro/components/Markdown.astro'; +import { Markdown } from 'astro/components'; import Layout from '../layouts/content.astro'; import Example from '../components/Example.jsx'; diff --git a/packages/astro/test/fixtures/config-path/config/my-config.mjs b/packages/astro/test/fixtures/config-path/config/my-config.mjs index f50751cfdce6..6c6bb575d5a4 100644 --- a/packages/astro/test/fixtures/config-path/config/my-config.mjs +++ b/packages/astro/test/fixtures/config-path/config/my-config.mjs @@ -1,5 +1,5 @@ export default { - extensions: { - '.jsx': 'preact', - }, -}; + renderers: [ + '@astrojs/renderer-preact' + ] +} diff --git a/packages/astro/test/fixtures/plain-markdown/astro.config.mjs b/packages/astro/test/fixtures/plain-markdown/astro.config.mjs index c8631c5039f8..d940a67c98ce 100644 --- a/packages/astro/test/fixtures/plain-markdown/astro.config.mjs +++ b/packages/astro/test/fixtures/plain-markdown/astro.config.mjs @@ -1,7 +1,7 @@ export default { - extensions: { - '.jsx': 'preact', - }, + renderers: [ + '@astrojs/renderer-preact' + ], buildOptions: { sitemap: false, },