diff options
-rw-r--r-- | .changeset/mighty-stingrays-press.md | 63 | ||||
-rw-r--r-- | examples/server-islands/package.json | 2 | ||||
-rw-r--r-- | examples/starlog/package.json | 2 | ||||
-rw-r--r-- | packages/astro/CHANGELOG.md | 17 | ||||
-rw-r--r-- | packages/astro/package.json | 2 | ||||
-rw-r--r-- | packages/astro/src/cli/info/index.ts | 34 | ||||
-rw-r--r-- | packages/astro/test/fixtures/get-static-paths-pages/src/pages/archive/[...slug]/[...page].astro | 37 | ||||
-rw-r--r-- | packages/astro/test/get-static-paths-pages.test.js | 8 | ||||
-rw-r--r-- | packages/integrations/mdx/CHANGELOG.md | 6 | ||||
-rw-r--r-- | packages/integrations/mdx/src/rehype-optimize-static.ts | 10 | ||||
-rw-r--r-- | packages/integrations/mdx/test/fixtures/mdx-optimize/astro.config.mjs | 40 | ||||
-rw-r--r-- | packages/integrations/mdx/test/mdx-optimize.test.js | 11 | ||||
-rw-r--r-- | pnpm-lock.yaml | 6 |
13 files changed, 149 insertions, 89 deletions
diff --git a/.changeset/mighty-stingrays-press.md b/.changeset/mighty-stingrays-press.md deleted file mode 100644 index 12c353dcd..000000000 --- a/.changeset/mighty-stingrays-press.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -'astro': patch ---- - -Adds support for Zod discriminated unions on Action form inputs. This allows forms with different inputs to be submitted to the same action, using a given input to decide which object should be used for validation. - -This example accepts either a `create` or `update` form submission, and uses the `type` field to determine which object to validate against. - -```ts -import { defineAction } from 'astro:actions'; -import { z } from 'astro:schema'; - -export const server = { - changeUser: defineAction({ - accept: 'form', - input: z.discriminatedUnion('type', [ - z.object({ - type: z.literal('create'), - name: z.string(), - email: z.string().email(), - }), - z.object({ - type: z.literal('update'), - id: z.number(), - name: z.string(), - email: z.string().email(), - }), - ]), - async handler(input) { - if (input.type === 'create') { - // input is { type: 'create', name: string, email: string } - } else { - // input is { type: 'update', id: number, name: string, email: string } - } - }, - }), -} -``` - -The corresponding `create` and `update` forms may look like this: - -```astro ---- -import { actions } from 'astro:actions'; ---- - -<!--Create--> -<form action={actions.changeUser} method="POST"> - <input type="hidden" name="type" value="create" /> - <input type="text" name="name" required /> - <input type="email" name="email" required /> - <button type="submit">Create User</button> -</form> - -<!--Update--> -<form action={actions.changeUser} method="POST"> - <input type="hidden" name="type" value="update" /> - <input type="hidden" name="id" value="user-123" /> - <input type="text" name="name" required /> - <input type="email" name="email" required /> - <button type="submit">Update User</button> -</form> -``` diff --git a/examples/server-islands/package.json b/examples/server-islands/package.json index 84a43a672..72a7938ea 100644 --- a/examples/server-islands/package.json +++ b/examples/server-islands/package.json @@ -18,7 +18,7 @@ "@types/react": "^18.3.5", "@types/react-dom": "^18.3.0", "astro": "^5.0.0-alpha.7", - "postcss": "^8.4.43", + "postcss": "^8.4.45", "react": "^18.3.1", "react-dom": "^18.3.1", "tailwindcss": "^3.4.10" diff --git a/examples/starlog/package.json b/examples/starlog/package.json index ec255e51c..3f32742c9 100644 --- a/examples/starlog/package.json +++ b/examples/starlog/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "astro": "^5.0.0-alpha.7", - "sass": "^1.77.8", + "sass": "^1.78.0", "sharp": "^0.33.3" } } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index 038cd15a3..88d68cb4a 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -137,6 +137,20 @@ - [#11974](https://github.com/withastro/astro/pull/11974) [`60211de`](https://github.com/withastro/astro/commit/60211defbfb2992ba17d1369e71c146d8928b09a) Thanks [@ascorbic](https://github.com/ascorbic)! - Exports the `RenderResult` type +## 4.15.6 + +### Patch Changes + +- [#11993](https://github.com/withastro/astro/pull/11993) [`ffba5d7`](https://github.com/withastro/astro/commit/ffba5d716edcdfc42899afaa4188b7a4cd0c91eb) Thanks [@matthewp](https://github.com/matthewp)! - Fix getStaticPaths regression + + This reverts a previous change meant to remove a dependency, to fix a regression with multiple nested spread routes. + +- [#11964](https://github.com/withastro/astro/pull/11964) [`06eff60`](https://github.com/withastro/astro/commit/06eff60cabb55d91fe4075421b1693b1ab33225c) Thanks [@TheOtterlord](https://github.com/TheOtterlord)! - Add wayland (wl-copy) support to `astro info` + +## 4.15.5 + +### Patch Changes + - [#11939](https://github.com/withastro/astro/pull/11939) [`7b09c62`](https://github.com/withastro/astro/commit/7b09c62b565cd7b50c35fb68d390729f936a43fb) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Adds support for Zod discriminated unions on Action form inputs. This allows forms with different inputs to be submitted to the same action, using a given input to decide which object should be used for validation. This example accepts either a `create` or `update` form submission, and uses the `type` field to determine which object to validate against. @@ -265,6 +279,9 @@ }), }); ``` +- [#11968](https://github.com/withastro/astro/pull/11968) [`86ad1fd`](https://github.com/withastro/astro/commit/86ad1fd223e2d2c448372caa159090efbee69237) Thanks [@NikolaRHristov](https://github.com/NikolaRHristov)! - Fixes a typo in the server island JSDoc + +- [#11983](https://github.com/withastro/astro/pull/11983) [`633eeaa`](https://github.com/withastro/astro/commit/633eeaa9d8a8a35bba638fde06fd8f52cc1c2ce3) Thanks [@uwej711](https://github.com/uwej711)! - Remove dependency on path-to-regexp ## 4.15.4 diff --git a/packages/astro/package.json b/packages/astro/package.json index 5c8d070f0..ced516808 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -165,7 +165,7 @@ "ora": "^8.1.0", "p-limit": "^6.1.0", "p-queue": "^8.0.1", - "path-to-regexp": "^6.2.2", + "path-to-regexp": "6.2.2", "preferred-pm": "^4.0.0", "prompts": "^2.4.2", "rehype": "^13.0.1", diff --git a/packages/astro/src/cli/info/index.ts b/packages/astro/src/cli/info/index.ts index 9f25a2535..ff0d35081 100644 --- a/packages/astro/src/cli/info/index.ts +++ b/packages/astro/src/cli/info/index.ts @@ -55,6 +55,7 @@ export async function printInfo({ flags }: InfoOptions) { } async function copyToClipboard(text: string) { + text = text.trim(); const system = platform(); let command = ''; if (system === 'darwin') { @@ -62,18 +63,26 @@ async function copyToClipboard(text: string) { } else if (system === 'win32') { command = 'clip'; } else { - try { - // Unix: check if `xclip` is installed - const output = execSync('which xclip', { encoding: 'utf8' }); - if (output[0] !== '/') { - // Did not find a path for xclip, bail out! - return; + // Unix: check if a supported command is installed + const unixCommands = [ + ['xclip', '-sel clipboard -l 1'], + ['wl-copy', '"$0"'], + ]; + for (const [unixCommand, args] of unixCommands) { + try { + const output = execSync(`which ${unixCommand}`, { encoding: 'utf8', stdio: 'pipe' }); + if (output[0] !== '/') { + // Did not find a path. Skip! + continue; + } + command = `${unixCommand} ${args}`; + } catch { + // Failed to execute which. Skip! + continue; } - command = 'xclip -sel clipboard -l 1'; - } catch { - // Did not find xclip, bail out! - return; } + // Did not find supported command. Bail out! + if (!command) return; } console.log(); @@ -86,8 +95,9 @@ async function copyToClipboard(text: string) { if (!shouldCopy) return; try { - execSync(command, { - input: text.trim(), + execSync(command.replaceAll('$0', text), { + stdio: 'ignore', + input: text, encoding: 'utf8', }); } catch { diff --git a/packages/astro/test/fixtures/get-static-paths-pages/src/pages/archive/[...slug]/[...page].astro b/packages/astro/test/fixtures/get-static-paths-pages/src/pages/archive/[...slug]/[...page].astro new file mode 100644 index 000000000..cf5a88640 --- /dev/null +++ b/packages/astro/test/fixtures/get-static-paths-pages/src/pages/archive/[...slug]/[...page].astro @@ -0,0 +1,37 @@ +--- +export async function getStaticPaths({ paginate }) { + + const paths = [ + { + slug: 'news/july-2024', + items: ['item 1', 'item 2', 'item 3', 'item 4', 'item 5', 'item 6'], + contentType: 'news', + monthYear: 'july-2024', + } + ]; + + return paths.flatMap((path) => { + return paginate(path.items, { + params: { slug: path.slug }, + props: { + contentType: path.contentType, + monthYear: path.monthYear, + }, + pageSize: 2, + }); + }); +} + +const { slug, page } = Astro.params; +--- + +<html> + <head> + <title>Testing</title> + </head> + <body> + <h1>Testing</h1> + <p id="slug">{slug}</p> + <p id="page">{page}</p> + </body> +</html> diff --git a/packages/astro/test/get-static-paths-pages.test.js b/packages/astro/test/get-static-paths-pages.test.js index 170e1d485..28c77a5af 100644 --- a/packages/astro/test/get-static-paths-pages.test.js +++ b/packages/astro/test/get-static-paths-pages.test.js @@ -25,4 +25,12 @@ describe('getStaticPaths with trailingSlash: ignore', () => { let $ = cheerio.load(html); assert.equal($('h1').text(), 'Page 2'); }); + + // for regression: https://github.com/withastro/astro/issues/11990 + it('nested static paths generate', async () => { + let html = await fixture.readFile('/archive/news/july-2024/2/index.html'); + let $ = cheerio.load(html); + assert.equal($('#slug').text(), 'news'); + assert.equal($('#page').text(), 'july-2024/2'); + }); }); diff --git a/packages/integrations/mdx/CHANGELOG.md b/packages/integrations/mdx/CHANGELOG.md index 0d8564a69..72e5728f0 100644 --- a/packages/integrations/mdx/CHANGELOG.md +++ b/packages/integrations/mdx/CHANGELOG.md @@ -23,6 +23,12 @@ - astro@5.0.0-alpha.0 - @astrojs/markdown-remark@6.0.0-alpha.0 +## 3.1.6 + +### Patch Changes + +- [#11975](https://github.com/withastro/astro/pull/11975) [`c9ae7b1`](https://github.com/withastro/astro/commit/c9ae7b1b89e050900bbc111f29e8c5d95c26bf36) Thanks [@bluwy](https://github.com/bluwy)! - Handles nested root hast node when optimizing MDX + ## 3.1.5 ### Patch Changes diff --git a/packages/integrations/mdx/src/rehype-optimize-static.ts b/packages/integrations/mdx/src/rehype-optimize-static.ts index 80c28ab9c..eba31cae0 100644 --- a/packages/integrations/mdx/src/rehype-optimize-static.ts +++ b/packages/integrations/mdx/src/rehype-optimize-static.ts @@ -64,8 +64,14 @@ export const rehypeOptimizeStatic: RehypePlugin<[OptimizeOptions?]> = (options) * A non-static node causes all its parents to be non-optimizable */ const isNodeNonStatic = (node: Node) => { - // @ts-expect-error Access `.tagName` naively for perf - return node.type.startsWith('mdx') || ignoreElementNames.has(node.tagName); + return ( + node.type.startsWith('mdx') || + // @ts-expect-error `node` should never have `type: 'root'`, but in some cases plugins may inject it as children, + // which MDX will render as a fragment instead (an MDX fragment is a `mdxJsxFlowElement` type). + node.type === 'root' || + // @ts-expect-error Access `.tagName` naively for perf + ignoreElementNames.has(node.tagName) + ); }; visit(tree as any, { diff --git a/packages/integrations/mdx/test/fixtures/mdx-optimize/astro.config.mjs b/packages/integrations/mdx/test/fixtures/mdx-optimize/astro.config.mjs index 204549479..a3626c3a3 100644 --- a/packages/integrations/mdx/test/fixtures/mdx-optimize/astro.config.mjs +++ b/packages/integrations/mdx/test/fixtures/mdx-optimize/astro.config.mjs @@ -1,9 +1,37 @@ import mdx from '@astrojs/mdx'; export default { - integrations: [mdx({ - optimize: { - ignoreElementNames: ['strong'] - } - })] -} + integrations: [ + mdx({ + optimize: { + ignoreElementNames: ['strong'], + }, + }), + ], + markdown: { + rehypePlugins: [ + () => { + return (tree) => { + tree.children.push({ + type: 'root', + children: [ + { + type: 'element', + tagName: 'p', + properties: { + id: 'injected-root-hast', + }, + children: [ + { + type: 'text', + value: 'Injected root hast from rehype plugin', + }, + ], + }, + ], + }); + }; + }, + ], + }, +}; diff --git a/packages/integrations/mdx/test/mdx-optimize.test.js b/packages/integrations/mdx/test/mdx-optimize.test.js index 47acfdff8..c45ecda15 100644 --- a/packages/integrations/mdx/test/mdx-optimize.test.js +++ b/packages/integrations/mdx/test/mdx-optimize.test.js @@ -47,4 +47,15 @@ describe('MDX optimize', () => { assert.notEqual(blockquote, null); assert.equal(blockquote.textContent.includes('I like pancakes'), true); }); + + it('renders MDX with rehype plugin that incorrectly injects root hast node', async () => { + const html = await fixture.readFile('/import/index.html'); + const { document } = parseHTML(html); + + assert.doesNotMatch(html, /set:html=/); + assert.equal( + document.getElementById('injected-root-hast').textContent, + 'Injected root hast from rehype plugin', + ); + }); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e5e027330..6b1e715bc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -373,7 +373,7 @@ importers: specifier: ^5.0.0-alpha.7 version: link:../../packages/astro postcss: - specifier: ^8.4.43 + specifier: ^8.4.45 version: 8.4.45 react: specifier: ^18.3.1 @@ -406,7 +406,7 @@ importers: specifier: ^5.0.0-alpha.7 version: link:../../packages/astro sass: - specifier: ^1.77.8 + specifier: ^1.78.0 version: 1.78.0 sharp: specifier: ^0.33.3 @@ -670,7 +670,7 @@ importers: specifier: ^8.0.1 version: 8.0.1 path-to-regexp: - specifier: ^6.2.2 + specifier: 6.2.2 version: 6.2.2 preferred-pm: specifier: ^4.0.0 |