Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDX support #3706

Merged
merged 52 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
bbd5715
feat: first pass at MDX support
natemoo-re Jun 17, 2022
22f5bc8
fix: move built-in JSX renderer to come first
natemoo-re Jun 24, 2022
6457c5e
chore: remove jsx example
natemoo-re Jun 24, 2022
3597733
chore: update lockfile
natemoo-re Jun 24, 2022
174371e
chore: cleanup example
natemoo-re Jun 24, 2022
cab0932
fix: missing deps
natemoo-re Jun 24, 2022
8c61415
refactor: move component render logic to `renderPage`
natemoo-re Jun 24, 2022
62fc89e
chore: update HMR script
natemoo-re Jun 24, 2022
298a8de
chore: update MDX example
natemoo-re Jun 24, 2022
6cf0281
refactor: prefer unshit
natemoo-re Jun 27, 2022
77c7376
refactor: remove TODO comment
natemoo-re Jun 27, 2022
42bcd83
fix: remove duplicate identifier
natemoo-re Jun 27, 2022
6c3fe53
refactor: cleanup mdx entrypoint
natemoo-re Jun 27, 2022
7224371
fix: better html handling
natemoo-re Jun 27, 2022
08da23f
fix: add tsconfig to mdx package
natemoo-re Jun 27, 2022
f68bb49
chore: update lockfile
natemoo-re Jun 28, 2022
7d702aa
fix: do not sort plugins unless mdx is enabled
natemoo-re Jun 28, 2022
c7755de
chore: update compiler
natemoo-re Jun 28, 2022
c7a356f
fix(hmr): maybe render head for non-Astro pages
natemoo-re Jun 28, 2022
dd645fd
fix: set initial pageExtensions
natemoo-re Jun 28, 2022
a001657
refactor: cleanup addPageExtension
natemoo-re Jun 29, 2022
b053d51
refactor: remove addPageExtensions from types
natemoo-re Jun 29, 2022
134663a
refactor: expose HookParameters type
natemoo-re Jun 29, 2022
3ce2dca
fix: only default to astro for MDX
natemoo-re Jun 29, 2022
35f90d8
test: pick up jsx support in test fixtures
natemoo-re Jun 29, 2022
7e75c34
refactor: simplify mdx entrypoint
natemoo-re Jun 29, 2022
04ef4e0
test: add basic MDX tests
natemoo-re Jun 29, 2022
94d25f5
test(e2e): add mdx + framework tests
natemoo-re Jun 29, 2022
a2f930f
chore: update lockfile
natemoo-re Jun 29, 2022
1f1bf98
test(e2e): fix preact mdx e2e test
natemoo-re Jun 29, 2022
57bb98a
fix(mdx): disable .md support
natemoo-re Jun 29, 2022
50d4433
test(e2e): fix vue-component test missing mdx
natemoo-re Jun 29, 2022
0afb921
test(e2e): fix solid component needing import
natemoo-re Jun 29, 2022
c942516
fix: allow `client:only="solid"` as an alias to `solid-js`
natemoo-re Jun 29, 2022
42b3623
chore: move to with-mdx example
natemoo-re Jun 29, 2022
909f2c6
chore: update MDX readme
natemoo-re Jun 29, 2022
7086ae4
chore: update example readme
natemoo-re Jun 29, 2022
9cb9bdb
chore: bump astro version
natemoo-re Jun 29, 2022
1601fd2
chore: update lockfile
natemoo-re Jun 29, 2022
bbb6bfe
Update mod.d.ts
natemoo-re Jun 29, 2022
03ec6d6
feat: support `export const components` in MDX pages
natemoo-re Jun 29, 2022
6ba2fb5
chore: update mdx example
natemoo-re Jun 29, 2022
93098dc
fix: update jsx-runtime with better slot support
natemoo-re Jun 29, 2022
8ab03ac
refactor: remove object style support
natemoo-re Jun 30, 2022
15714a2
chore: cleanup package exports
natemoo-re Jun 30, 2022
bb57148
chore: add todo comment
natemoo-re Jun 30, 2022
04440d0
refactor: improve isPage function, move to utils
natemoo-re Jun 30, 2022
4e4581d
refactor: dry up manual HMR updates
natemoo-re Jun 30, 2022
aa56d34
chore: add dev tests for MDX
natemoo-re Jun 30, 2022
b68c4a9
chore: prefer set to array
natemoo-re Jun 30, 2022
fc5e187
chore: add changesets
natemoo-re Jun 30, 2022
bfb72ff
fix(hmr): flip public/private route
natemoo-re Jun 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/selfish-beers-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Internal changes needed to support `@astrojs/mdx`
5 changes: 5 additions & 0 deletions .changeset/shaggy-gifts-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---

Initial release! 🎉
19 changes: 19 additions & 0 deletions examples/with-mdx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# build output
dist/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store
2 changes: 2 additions & 0 deletions examples/with-mdx/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Expose Astro dependencies for `pnpm` users
shamefully-hoist=true
6 changes: 6 additions & 0 deletions examples/with-mdx/.stackblitzrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"startCommand": "npm start",
"env": {
"ENABLE_CJS_IMPORTS": true
}
}
4 changes: 4 additions & 0 deletions examples/with-mdx/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recommendations": ["astro-build.astro-vscode"],
"unwantedRecommendations": []
}
11 changes: 11 additions & 0 deletions examples/with-mdx/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "./node_modules/.bin/astro dev",
"name": "Development server",
"request": "launch",
"type": "node-terminal"
}
]
}
9 changes: 9 additions & 0 deletions examples/with-mdx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Astro Example: MDX

```
npm init astro -- --template with-mdx
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/with-mdx)

This example showcases using [`@astrojs/mdx`](https://www.npmjs.com/package/@astrojs/mdx) to author content using [MDX](https://mdxjs.com/).
11 changes: 11 additions & 0 deletions examples/with-mdx/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import preact from '@astrojs/preact';

// https://astro.build/config
export default defineConfig({
integrations: [
mdx(),
preact()
]
});
17 changes: 17 additions & 0 deletions examples/with-mdx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@example/with-mdx",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview"
},
"devDependencies": {
"@astrojs/mdx": "^0.0.1",
"@astrojs/preact": "^0.2.0",
"astro": "^1.0.0-beta.58",
"preact": "^10.6.5"
}
}
Binary file added examples/with-mdx/public/favicon.ico
Binary file not shown.
11 changes: 11 additions & 0 deletions examples/with-mdx/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"infiniteLoopProtection": true,
"hardReloadOnChange": false,
"view": "browser",
"template": "node",
"container": {
"port": 3000,
"startScript": "start",
"node": "14"
}
}
18 changes: 18 additions & 0 deletions examples/with-mdx/src/components/Counter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useState } from 'preact/hooks';

export default function Counter({ children }) {
const [count, setCount] = useState(0);
const add = () => setCount((i) => i + 1);
const subtract = () => setCount((i) => i - 1);

return (
<>
<div class="counter">
<button onClick={subtract}>-</button>
<pre>{count}</pre>
<button onClick={add}>+</button>
</div>
<div class="counter-message">{children}</div>
</>
);
}
7 changes: 7 additions & 0 deletions examples/with-mdx/src/components/Title.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1><slot /></h1>

<style>
h1 {
color: red;
}
</style>
19 changes: 19 additions & 0 deletions examples/with-mdx/src/pages/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Counter from '../components/Counter.jsx'
import Title from '../components/Title.astro'
export const components = { h1: Title }

# Hello world!

export const authors = [
{name: 'Jane', email: '[email protected]'},
{name: 'John', twitter: '@john2002'}
]
export const published = new Date('2022-02-01')

Written by: {new Intl.ListFormat('en').format(authors.map(d => d.name))}.

Published on: {new Intl.DateTimeFormat('en', {dateStyle: 'long'}).format(published)}.

<Counter client:idle>
## Counter
</Counter>
15 changes: 15 additions & 0 deletions examples/with-mdx/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
// Enable top-level await, and other modern ESM features.
"target": "ESNext",
"module": "ESNext",
// Enable node-style module resolution, for things like npm package imports.
"moduleResolution": "node",
// Enable JSON imports.
"resolveJsonModule": true,
// Enable stricter transpilation for better output.
"isolatedModules": true,
// Add type definitions for our Vite runtime.
"types": ["vite/client"]
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": [
"rollup",
"@babel/core",
"@babel/plugin-transform-react-jsx",
"vite"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineConfig } from 'astro/config';
import preact from '@astrojs/preact';
import mdx from '@astrojs/mdx';

// https://astro.build/config
export default defineConfig({
integrations: [preact()],
integrations: [preact(), mdx()],
});
1 change: 1 addition & 0 deletions packages/astro/e2e/fixtures/preact-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"@astrojs/preact": "workspace:*",
"@astrojs/mdx": "workspace:*",
"astro": "workspace:*",
"preact": "^10.7.3"
}
Expand Down
29 changes: 29 additions & 0 deletions packages/astro/e2e/fixtures/preact-component/src/pages/mdx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import Counter from '../components/Counter.jsx';
import PreactComponent from '../components/JSXComponent.jsx';

export const someProps = {
count: 0,
};

<Counter id="server-only" {...someProps}>
# Hello, server!
</Counter>

<Counter id="client-idle" {...someProps} client:idle>
# Hello, client:idle!
</Counter>

<Counter id="client-load" {...someProps} client:load>
# Hello, client:load!
</Counter>

<Counter id="client-visible" {...someProps} client:visible>
# Hello, client:visible!
</Counter>

<Counter id="client-media" {...someProps} client:media="(max-width: 50em)">
# Hello, client:media!
</Counter>

<PreactComponent id="client-only" client:only="preact" />
3 changes: 2 additions & 1 deletion packages/astro/e2e/fixtures/react-component/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineConfig } from 'astro/config';
import react from '@astrojs/react';
import mdx from '@astrojs/mdx';

// https://astro.build/config
export default defineConfig({
integrations: [react()],
integrations: [react(), mdx()],
});
1 change: 1 addition & 0 deletions packages/astro/e2e/fixtures/react-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@astrojs/react": "workspace:*",
"astro": "workspace:*",
"@astrojs/mdx": "workspace:*",
"react": "^18.1.0",
"react-dom": "^18.1.0"
}
Expand Down
28 changes: 28 additions & 0 deletions packages/astro/e2e/fixtures/react-component/src/pages/mdx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Counter from '../components/Counter.jsx';
import ReactComponent from '../components/JSXComponent.jsx';

export const someProps = {
count: 0,
};

<Counter id="server-only" {...someProps}>
# Hello, server!
</Counter>

<Counter id="client-idle" {...someProps} client:idle>
# Hello, client:idle!
</Counter>

<Counter id="client-load" {...someProps} client:load>
# Hello, client:load!
</Counter>

<Counter id="client-visible" {...someProps} client:visible>
# Hello, client:visible!
</Counter>

<Counter id="client-media" {...someProps} client:media="(max-width: 50em)">
# Hello, client:media!
</Counter>

<ReactComponent id="client-only" client:only="react" />
3 changes: 2 additions & 1 deletion packages/astro/e2e/fixtures/solid-component/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import solid from '@astrojs/solid-js';

// https://astro.build/config
export default defineConfig({
integrations: [solid()],
integrations: [solid(), mdx()],
});
3 changes: 2 additions & 1 deletion packages/astro/e2e/fixtures/solid-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"private": true,
"dependencies": {
"@astrojs/solid-js": "workspace:*",
"astro": "workspace:*"
"astro": "workspace:*",
"@astrojs/mdx": "workspace:*"
},
"devDependencies": {
"solid-js": "^1.4.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'solid-js';
bholmesdev marked this conversation as resolved.
Show resolved Hide resolved

export default function SolidComponent({ id }) {
return (
<div id={id}>Framework client:only component</div>
Expand Down
28 changes: 28 additions & 0 deletions packages/astro/e2e/fixtures/solid-component/src/pages/mdx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Counter from '../components/Counter.jsx';
import SolidComponent from '../components/SolidComponent.jsx';

export const someProps = {
count: 0,
};

<Counter id="server-only" {...someProps}>
# Hello, server!
</Counter>

<Counter id="client-idle" {...someProps} client:idle>
# Hello, client:idle!
</Counter>

<Counter id="client-load" {...someProps} client:load>
# Hello, client:load!
</Counter>

<Counter id="client-visible" {...someProps} client:visible>
# Hello, client:visible!
</Counter>

<Counter id="client-media" {...someProps} client:media="(max-width: 50em)">
# Hello, client:media!
</Counter>

<SolidComponent id="client-only" client:only="solid" />
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineConfig } from 'astro/config';
import svelte from '@astrojs/svelte';
import mdx from '@astrojs/mdx';

// https://astro.build/config
export default defineConfig({
integrations: [svelte()],
integrations: [svelte(), mdx()],
});
1 change: 1 addition & 0 deletions packages/astro/e2e/fixtures/svelte-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@astrojs/svelte": "workspace:*",
"astro": "workspace:*",
"@astrojs/mdx": "workspace:*",
"svelte": "^3.48.0"
}
}
28 changes: 28 additions & 0 deletions packages/astro/e2e/fixtures/svelte-component/src/pages/mdx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Counter from '../components/Counter.svelte';
import SvelteComponent from '../components/SvelteComponent.svelte';

export const someProps = {
count: 0,
};

<Counter id="server-only" {...someProps}>
# Hello, server!
</Counter>

<Counter id="client-idle" {...someProps} client:idle>
# Hello, client:idle!
</Counter>

<Counter id="client-load" {...someProps} client:load>
# Hello, client:load!
</Counter>

<Counter id="client-visible" {...someProps} client:visible>
# Hello, client:visible!
</Counter>

<Counter id="client-media" {...someProps} client:media="(max-width: 50em)">
# Hello, client:media!
</Counter>

<SvelteComponent id="client-only" client:only="svelte" />
Loading