From 2aaed2d2a96ab35461af24e8d12b20f1da33983f Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 10 Dec 2024 20:48:38 +0000 Subject: [PATCH 01/26] fix(middleware): don't import via entrypoint (#12707) * fix(middleware): don't import via entrypoint * fix(middleware): don't import via entrypoint --- .changeset/bright-crabs-kick.md | 5 +++++ packages/astro/src/core/build/pipeline.ts | 10 +++++----- .../fixtures/middleware-full-ssr/package.json | 8 ++++++++ .../fixtures/middleware-full-ssr/src/error.js | 1 + .../middleware-full-ssr/src/middleware.js | 2 ++ .../middleware-full-ssr/src/pages/index.astro | 14 ++++++++++++++ packages/astro/test/middleware.test.js | 15 +++++++++++++++ pnpm-lock.yaml | 6 ++++++ 8 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 .changeset/bright-crabs-kick.md create mode 100644 packages/astro/test/fixtures/middleware-full-ssr/package.json create mode 100644 packages/astro/test/fixtures/middleware-full-ssr/src/error.js create mode 100644 packages/astro/test/fixtures/middleware-full-ssr/src/middleware.js create mode 100644 packages/astro/test/fixtures/middleware-full-ssr/src/pages/index.astro diff --git a/.changeset/bright-crabs-kick.md b/.changeset/bright-crabs-kick.md new file mode 100644 index 000000000000..c94a34e9cf9d --- /dev/null +++ b/.changeset/bright-crabs-kick.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a bug where the middleware was incorrectly imported during the build diff --git a/packages/astro/src/core/build/pipeline.ts b/packages/astro/src/core/build/pipeline.ts index 14bb08662a98..3908dffed238 100644 --- a/packages/astro/src/core/build/pipeline.ts +++ b/packages/astro/src/core/build/pipeline.ts @@ -131,11 +131,11 @@ export class BuildPipeline extends Pipeline { const renderers = await import(renderersEntryUrl.toString()); const middleware = internals.middlewareEntryPoint - ? await import(internals.middlewareEntryPoint.toString()).then((mod) => { - return function () { - return { onRequest: mod.onRequest }; - }; - }) + ? async function () { + // @ts-expect-error: the compiler can't understand the previous check + const mod = await import(internals.middlewareEntryPoint.toString()); + return { onRequest: mod.onRequest }; + } : manifest.middleware; if (!renderers) { diff --git a/packages/astro/test/fixtures/middleware-full-ssr/package.json b/packages/astro/test/fixtures/middleware-full-ssr/package.json new file mode 100644 index 000000000000..4f8b625c0b2c --- /dev/null +++ b/packages/astro/test/fixtures/middleware-full-ssr/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/middleware-full-ssr", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/middleware-full-ssr/src/error.js b/packages/astro/test/fixtures/middleware-full-ssr/src/error.js new file mode 100644 index 000000000000..6eed03a82c07 --- /dev/null +++ b/packages/astro/test/fixtures/middleware-full-ssr/src/error.js @@ -0,0 +1 @@ +throw new Error("Shoud not error at build time") diff --git a/packages/astro/test/fixtures/middleware-full-ssr/src/middleware.js b/packages/astro/test/fixtures/middleware-full-ssr/src/middleware.js new file mode 100644 index 000000000000..0061049c13a6 --- /dev/null +++ b/packages/astro/test/fixtures/middleware-full-ssr/src/middleware.js @@ -0,0 +1,2 @@ +import "./error.js" +export const onRequest = (_ , next) => next(); diff --git a/packages/astro/test/fixtures/middleware-full-ssr/src/pages/index.astro b/packages/astro/test/fixtures/middleware-full-ssr/src/pages/index.astro new file mode 100644 index 000000000000..395a4d695cfa --- /dev/null +++ b/packages/astro/test/fixtures/middleware-full-ssr/src/pages/index.astro @@ -0,0 +1,14 @@ +--- +const data = Astro.locals; +--- + + + + Testing + + + + Index +

{data?.name}

+ + diff --git a/packages/astro/test/middleware.test.js b/packages/astro/test/middleware.test.js index 26bc06d77f47..c7c95b5b6645 100644 --- a/packages/astro/test/middleware.test.js +++ b/packages/astro/test/middleware.test.js @@ -171,6 +171,21 @@ describe('Middleware in PROD mode, SSG', () => { }); }); +describe('Middleware should not be executed or imported during', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + it('should build the project without errors', async () => { + fixture = await loadFixture({ + root: './fixtures/middleware-full-ssr/', + output: 'server', + adapter: testAdapter({}), + }); + await fixture.build(); + assert.ok('Should build'); + }); +}); + describe('Middleware API in PROD mode, SSR', () => { /** @type {import('./test-utils').Fixture} */ let fixture; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0270d490a29b..a351d308082f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3324,6 +3324,12 @@ importers: specifier: workspace:* version: link:../../.. + packages/astro/test/fixtures/middleware-full-ssr: + dependencies: + astro: + specifier: workspace:* + version: link:../../.. + packages/astro/test/fixtures/middleware-no-user-middleware: dependencies: astro: From 97c9265754b78af12ad1e399cc75028435028dfa Mon Sep 17 00:00:00 2001 From: Brian Kimball Date: Wed, 11 Dec 2024 04:02:41 -0500 Subject: [PATCH 02/26] Add React 19 stable as peer dependency for React integration (#12678) * Add React 19 as peer dependency * Add React 19 as peer dependency --------- Co-authored-by: bskimball --- .changeset/tame-countries-beg.md | 5 +++++ packages/integrations/react/package.json | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .changeset/tame-countries-beg.md diff --git a/.changeset/tame-countries-beg.md b/.changeset/tame-countries-beg.md new file mode 100644 index 000000000000..2ef89155007d --- /dev/null +++ b/.changeset/tame-countries-beg.md @@ -0,0 +1,5 @@ +--- +'@astrojs/react': minor +--- + +Add React 19 stable to peer dependencies diff --git a/packages/integrations/react/package.json b/packages/integrations/react/package.json index b7302a804c1f..cd7d17632cd5 100644 --- a/packages/integrations/react/package.json +++ b/packages/integrations/react/package.json @@ -63,10 +63,10 @@ "react-dom": "^18.3.1" }, "peerDependencies": { - "@types/react": "^17.0.50 || ^18.0.21", - "@types/react-dom": "^17.0.17 || ^18.0.6", - "react": "^17.0.2 || ^18.0.0 || ^19.0.0-beta", - "react-dom": "^17.0.2 || ^18.0.0 || ^19.0.0-beta" + "@types/react": "^17.0.50 || ^18.0.21 || ^19.0.0", + "@types/react-dom": "^17.0.17 || ^18.0.6 || ^19.0.0", + "react": "^17.0.2 || ^18.0.0 || ^19.0.0", + "react-dom": "^17.0.2 || ^18.0.0 || ^19.0.0" }, "engines": { "node": "^18.17.1 || ^20.3.0 || >=22.0.0" From b01c74aeccc4ec76b64fa75d163df58274b37970 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Wed, 11 Dec 2024 10:21:44 +0000 Subject: [PATCH 03/26] fix: strip query string before checking md extension (#12712) --- .changeset/tidy-ligers-tan.md | 5 ++++ packages/astro/src/core/util.ts | 4 +++- packages/astro/test/astro-markdown.test.js | 23 ++++++++++++++++++- .../src/pages/false-positive.astro | 5 ++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 .changeset/tidy-ligers-tan.md create mode 100644 packages/astro/test/fixtures/astro-markdown/src/pages/false-positive.astro diff --git a/.changeset/tidy-ligers-tan.md b/.changeset/tidy-ligers-tan.md new file mode 100644 index 000000000000..9891877bf850 --- /dev/null +++ b/.changeset/tidy-ligers-tan.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a bug which misidentified pages as markdown if a query string ended in a markdown extension diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index f9dd0ced8b60..458fb9bdc3b2 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -18,9 +18,11 @@ export function isURL(value: unknown): value is URL { } /** Check if a file is a markdown file based on its extension */ export function isMarkdownFile(fileId: string, option?: { suffix?: string }): boolean { + // Strip query string + const id = fileId.split("?")[0]; const _suffix = option?.suffix ?? ''; for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) { - if (fileId.endsWith(`${markdownFileExtension}${_suffix}`)) return true; + if (id.endsWith(`${markdownFileExtension}${_suffix}`)) return true; } return false; } diff --git a/packages/astro/test/astro-markdown.test.js b/packages/astro/test/astro-markdown.test.js index d0a49c873da4..0dae61ebd60c 100644 --- a/packages/astro/test/astro-markdown.test.js +++ b/packages/astro/test/astro-markdown.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { before, describe, it } from 'node:test'; +import { before, describe, it, after } from 'node:test'; import * as cheerio from 'cheerio'; import { fixLineEndings, loadFixture } from './test-utils.js'; @@ -154,4 +154,25 @@ describe('Astro Markdown', () => { assert.ok(title.includes('import.meta.env.TITLE')); }); }); + + describe('dev', () => { + let devServer; + + before(async () => { + devServer = await fixture.startDevServer(); + }); + + it('ignores .md extensions on query params', async () => { + const res = await fixture.fetch('/false-positive?page=page.md'); + assert.ok(res.ok); + const html = await res.text(); + const $ = cheerio.load(html); + assert.equal($('p').text(), 'the page is not markdown'); + }); + + after(async () => { + await devServer.stop(); + }); + + }); }); diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/false-positive.astro b/packages/astro/test/fixtures/astro-markdown/src/pages/false-positive.astro new file mode 100644 index 000000000000..2f39eceadbef --- /dev/null +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/false-positive.astro @@ -0,0 +1,5 @@ +--- +let page = "not markdown" +--- + +

the page is {page}

From d33c2151a37e71ba727c54ef30339df859148612 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Wed, 11 Dec 2024 10:22:32 +0000 Subject: [PATCH 04/26] [ci] format --- packages/astro/src/core/util.ts | 2 +- packages/astro/test/astro-markdown.test.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 458fb9bdc3b2..88e1de81a930 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -19,7 +19,7 @@ export function isURL(value: unknown): value is URL { /** Check if a file is a markdown file based on its extension */ export function isMarkdownFile(fileId: string, option?: { suffix?: string }): boolean { // Strip query string - const id = fileId.split("?")[0]; + const id = fileId.split('?')[0]; const _suffix = option?.suffix ?? ''; for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) { if (id.endsWith(`${markdownFileExtension}${_suffix}`)) return true; diff --git a/packages/astro/test/astro-markdown.test.js b/packages/astro/test/astro-markdown.test.js index 0dae61ebd60c..9d416734182e 100644 --- a/packages/astro/test/astro-markdown.test.js +++ b/packages/astro/test/astro-markdown.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { before, describe, it, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { fixLineEndings, loadFixture } from './test-utils.js'; @@ -173,6 +173,5 @@ describe('Astro Markdown', () => { after(async () => { await devServer.stop(); }); - }); }); From 99266fa2898289a172d70a5ac3ffad7a5dcd2867 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Wed, 11 Dec 2024 11:06:55 +0000 Subject: [PATCH 05/26] chore: refactor query param strip (#12714) --- packages/astro/src/core/util.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 88e1de81a930..3a394764b51a 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -5,7 +5,7 @@ import type { AstroSettings } from '../types/astro.js'; import type { AstroConfig } from '../types/public/config.js'; import type { RouteType } from '../types/public/internal.js'; import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js'; -import { removeTrailingForwardSlash, slash } from './path.js'; +import { removeTrailingForwardSlash, slash, removeQueryString } from './path.js'; /** Returns true if argument is an object of any prototype/class (but not null). */ export function isObject(value: unknown): value is Record { @@ -18,8 +18,7 @@ export function isURL(value: unknown): value is URL { } /** Check if a file is a markdown file based on its extension */ export function isMarkdownFile(fileId: string, option?: { suffix?: string }): boolean { - // Strip query string - const id = fileId.split('?')[0]; + const id = removeQueryString(fileId); const _suffix = option?.suffix ?? ''; for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) { if (id.endsWith(`${markdownFileExtension}${_suffix}`)) return true; From b3dfd9b01bd7424eb67bfbc2612544af5be09442 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Wed, 11 Dec 2024 11:07:45 +0000 Subject: [PATCH 06/26] [ci] format --- packages/astro/src/core/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 3a394764b51a..f0447529a91a 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -5,7 +5,7 @@ import type { AstroSettings } from '../types/astro.js'; import type { AstroConfig } from '../types/public/config.js'; import type { RouteType } from '../types/public/internal.js'; import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js'; -import { removeTrailingForwardSlash, slash, removeQueryString } from './path.js'; +import { removeQueryString, removeTrailingForwardSlash, slash } from './path.js'; /** Returns true if argument is an object of any prototype/class (but not null). */ export function isObject(value: unknown): value is Record { From 929ce2832560f9422a4a9ccb899e0f153d2a3471 Mon Sep 17 00:00:00 2001 From: "Houston (Bot)" <108291165+astrobot-houston@users.noreply.github.com> Date: Wed, 11 Dec 2024 03:07:58 -0800 Subject: [PATCH 07/26] [ci] release (#12698) Co-authored-by: github-actions[bot] --- .changeset/blue-spiders-carry.md | 5 -- .changeset/bright-crabs-kick.md | 5 -- .changeset/famous-teachers-hug.md | 5 -- .changeset/fast-adults-lick.md | 6 -- .changeset/green-coins-tie.md | 5 -- .changeset/shy-worms-talk.md | 5 -- .changeset/tame-countries-beg.md | 5 -- .changeset/tidy-ligers-tan.md | 5 -- .changeset/wild-ducks-decide.md | 5 -- examples/basics/package.json | 2 +- examples/blog/package.json | 2 +- examples/component/package.json | 2 +- examples/container-with-vitest/package.json | 4 +- examples/framework-alpine/package.json | 2 +- examples/framework-multiple/package.json | 6 +- examples/framework-preact/package.json | 2 +- examples/framework-react/package.json | 4 +- examples/framework-solid/package.json | 2 +- examples/framework-svelte/package.json | 2 +- examples/framework-vue/package.json | 4 +- examples/hackernews/package.json | 2 +- examples/integration/package.json | 2 +- examples/minimal/package.json | 2 +- examples/portfolio/package.json | 2 +- examples/ssr/package.json | 2 +- examples/starlog/package.json | 2 +- examples/toolbar-app/package.json | 2 +- examples/with-markdoc/package.json | 4 +- examples/with-mdx/package.json | 2 +- examples/with-nanostores/package.json | 2 +- examples/with-tailwindcss/package.json | 2 +- examples/with-vitest/package.json | 2 +- packages/astro/CHANGELOG.md | 16 ++++ packages/astro/package.json | 2 +- packages/integrations/markdoc/CHANGELOG.md | 6 ++ packages/integrations/markdoc/package.json | 2 +- packages/integrations/react/CHANGELOG.md | 6 ++ packages/integrations/react/package.json | 2 +- packages/integrations/vue/CHANGELOG.md | 6 ++ packages/integrations/vue/package.json | 2 +- packages/upgrade/CHANGELOG.md | 6 ++ packages/upgrade/package.json | 2 +- pnpm-lock.yaml | 88 +++++++-------------- 43 files changed, 103 insertions(+), 139 deletions(-) delete mode 100644 .changeset/blue-spiders-carry.md delete mode 100644 .changeset/bright-crabs-kick.md delete mode 100644 .changeset/famous-teachers-hug.md delete mode 100644 .changeset/fast-adults-lick.md delete mode 100644 .changeset/green-coins-tie.md delete mode 100644 .changeset/shy-worms-talk.md delete mode 100644 .changeset/tame-countries-beg.md delete mode 100644 .changeset/tidy-ligers-tan.md delete mode 100644 .changeset/wild-ducks-decide.md diff --git a/.changeset/blue-spiders-carry.md b/.changeset/blue-spiders-carry.md deleted file mode 100644 index a9819f5db5d6..000000000000 --- a/.changeset/blue-spiders-carry.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Fixes a bug where MDX files with certain characters in the name would cause builds to fail diff --git a/.changeset/bright-crabs-kick.md b/.changeset/bright-crabs-kick.md deleted file mode 100644 index c94a34e9cf9d..000000000000 --- a/.changeset/bright-crabs-kick.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Fixes a bug where the middleware was incorrectly imported during the build diff --git a/.changeset/famous-teachers-hug.md b/.changeset/famous-teachers-hug.md deleted file mode 100644 index 988f2993f985..000000000000 --- a/.changeset/famous-teachers-hug.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Fix a bug that caused builds to fail if an image had a quote mark in its name diff --git a/.changeset/fast-adults-lick.md b/.changeset/fast-adults-lick.md deleted file mode 100644 index 22b2617bedfe..000000000000 --- a/.changeset/fast-adults-lick.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -'@astrojs/markdoc': patch -'astro': patch ---- - -Fixes a bug where the experimental feature `experimental.svg` was incorrectly used when generating ESM images diff --git a/.changeset/green-coins-tie.md b/.changeset/green-coins-tie.md deleted file mode 100644 index 349bf67244f2..000000000000 --- a/.changeset/green-coins-tie.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@astrojs/vue': patch ---- - -fix vite peer dependency issue for vue integration diff --git a/.changeset/shy-worms-talk.md b/.changeset/shy-worms-talk.md deleted file mode 100644 index c22501e2d2fc..000000000000 --- a/.changeset/shy-worms-talk.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Fixes astro info copy to clipboard process not returning to prompt in certain cases. diff --git a/.changeset/tame-countries-beg.md b/.changeset/tame-countries-beg.md deleted file mode 100644 index 2ef89155007d..000000000000 --- a/.changeset/tame-countries-beg.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@astrojs/react': minor ---- - -Add React 19 stable to peer dependencies diff --git a/.changeset/tidy-ligers-tan.md b/.changeset/tidy-ligers-tan.md deleted file mode 100644 index 9891877bf850..000000000000 --- a/.changeset/tidy-ligers-tan.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Fixes a bug which misidentified pages as markdown if a query string ended in a markdown extension diff --git a/.changeset/wild-ducks-decide.md b/.changeset/wild-ducks-decide.md deleted file mode 100644 index 8a6f85be739e..000000000000 --- a/.changeset/wild-ducks-decide.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@astrojs/upgrade': patch ---- - -Fixes a bug that caused registry URLs that specify a port to be incorrectly detected as offline. diff --git a/examples/basics/package.json b/examples/basics/package.json index 405176a207ba..0791668c388e 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -10,6 +10,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^5.0.4" + "astro": "^5.0.5" } } diff --git a/examples/blog/package.json b/examples/blog/package.json index bee6d8b2e01b..52fd4ed3a12a 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -13,6 +13,6 @@ "@astrojs/mdx": "^4.0.2", "@astrojs/rss": "^4.0.10", "@astrojs/sitemap": "^3.2.1", - "astro": "^5.0.4" + "astro": "^5.0.5" } } diff --git a/examples/component/package.json b/examples/component/package.json index 9c4252bca6ec..794471fd9df7 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^5.0.4" + "astro": "^5.0.5" }, "peerDependencies": { "astro": "^4.0.0 || ^5.0.0" diff --git a/examples/container-with-vitest/package.json b/examples/container-with-vitest/package.json index b202ff1f264c..8194688cfe14 100644 --- a/examples/container-with-vitest/package.json +++ b/examples/container-with-vitest/package.json @@ -11,8 +11,8 @@ "test": "vitest run" }, "dependencies": { - "@astrojs/react": "^4.0.0", - "astro": "^5.0.4", + "@astrojs/react": "^4.1.0", + "astro": "^5.0.5", "react": "^18.3.1", "react-dom": "^18.3.1", "vitest": "^2.1.6" diff --git a/examples/framework-alpine/package.json b/examples/framework-alpine/package.json index 9970749bd5d1..d48bcbc833bd 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -13,6 +13,6 @@ "@astrojs/alpinejs": "^0.4.0", "@types/alpinejs": "^3.13.10", "alpinejs": "^3.14.3", - "astro": "^5.0.4" + "astro": "^5.0.5" } } diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index cc1a53493c3e..6759f7ffc52e 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -11,13 +11,13 @@ }, "dependencies": { "@astrojs/preact": "^4.0.0", - "@astrojs/react": "^4.0.0", + "@astrojs/react": "^4.1.0", "@astrojs/solid-js": "^5.0.0", "@astrojs/svelte": "^7.0.1", - "@astrojs/vue": "^5.0.1", + "@astrojs/vue": "^5.0.2", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", - "astro": "^5.0.4", + "astro": "^5.0.5", "preact": "^10.24.3", "react": "^18.3.1", "react-dom": "^18.3.1", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index 952656d3cc79..9cb7beae5ec9 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -12,7 +12,7 @@ "dependencies": { "@astrojs/preact": "^4.0.0", "@preact/signals": "^1.3.0", - "astro": "^5.0.4", + "astro": "^5.0.5", "preact": "^10.24.3" } } diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index 3f666d4c1b57..affb83dadd19 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -10,10 +10,10 @@ "astro": "astro" }, "dependencies": { - "@astrojs/react": "^4.0.0", + "@astrojs/react": "^4.1.0", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", - "astro": "^5.0.4", + "astro": "^5.0.5", "react": "^18.3.1", "react-dom": "^18.3.1" } diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index 018099983ffb..091ec6531ca3 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "@astrojs/solid-js": "^5.0.0", - "astro": "^5.0.4", + "astro": "^5.0.5", "solid-js": "^1.9.3" } } diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index 6ccaa6dbc754..3fa8a0cda5f9 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "@astrojs/svelte": "^7.0.1", - "astro": "^5.0.4", + "astro": "^5.0.5", "svelte": "^5.1.16" } } diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index fe56cf7effc1..60a470e4eddc 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -10,8 +10,8 @@ "astro": "astro" }, "dependencies": { - "@astrojs/vue": "^5.0.1", - "astro": "^5.0.4", + "@astrojs/vue": "^5.0.2", + "astro": "^5.0.5", "vue": "^3.5.12" } } diff --git a/examples/hackernews/package.json b/examples/hackernews/package.json index f2f624df70e8..8153be2ece5f 100644 --- a/examples/hackernews/package.json +++ b/examples/hackernews/package.json @@ -11,6 +11,6 @@ }, "dependencies": { "@astrojs/node": "^9.0.0", - "astro": "^5.0.4" + "astro": "^5.0.5" } } diff --git a/examples/integration/package.json b/examples/integration/package.json index 41da0a86c2a4..320d3b6cd28a 100644 --- a/examples/integration/package.json +++ b/examples/integration/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^5.0.4" + "astro": "^5.0.5" }, "peerDependencies": { "astro": "^4.0.0" diff --git a/examples/minimal/package.json b/examples/minimal/package.json index 1a58ed517837..93faeabeab63 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -10,6 +10,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^5.0.4" + "astro": "^5.0.5" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index 4a8e47a67a16..7db23b1f68e3 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -10,6 +10,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^5.0.4" + "astro": "^5.0.5" } } diff --git a/examples/ssr/package.json b/examples/ssr/package.json index 72b6d1b19270..00f1358841e1 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/node": "^9.0.0", "@astrojs/svelte": "^7.0.1", - "astro": "^5.0.4", + "astro": "^5.0.5", "svelte": "^5.1.16" } } diff --git a/examples/starlog/package.json b/examples/starlog/package.json index 209c54c199c5..8497f0459536 100644 --- a/examples/starlog/package.json +++ b/examples/starlog/package.json @@ -9,7 +9,7 @@ "astro": "astro" }, "dependencies": { - "astro": "^5.0.4", + "astro": "^5.0.5", "sass": "^1.80.6", "sharp": "^0.33.3" } diff --git a/examples/toolbar-app/package.json b/examples/toolbar-app/package.json index e137aea6387d..701bb6ad0a77 100644 --- a/examples/toolbar-app/package.json +++ b/examples/toolbar-app/package.json @@ -15,6 +15,6 @@ "./app": "./dist/app.js" }, "devDependencies": { - "astro": "^5.0.4" + "astro": "^5.0.5" } } diff --git a/examples/with-markdoc/package.json b/examples/with-markdoc/package.json index 111e1486aad4..4ebd866a95bc 100644 --- a/examples/with-markdoc/package.json +++ b/examples/with-markdoc/package.json @@ -10,7 +10,7 @@ "astro": "astro" }, "dependencies": { - "@astrojs/markdoc": "^0.12.2", - "astro": "^5.0.4" + "@astrojs/markdoc": "^0.12.3", + "astro": "^5.0.5" } } diff --git a/examples/with-mdx/package.json b/examples/with-mdx/package.json index 26c8dbb914ff..974009ed55f0 100644 --- a/examples/with-mdx/package.json +++ b/examples/with-mdx/package.json @@ -12,7 +12,7 @@ "dependencies": { "@astrojs/mdx": "^4.0.2", "@astrojs/preact": "^4.0.0", - "astro": "^5.0.4", + "astro": "^5.0.5", "preact": "^10.24.3" } } diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index dea7ea20eef9..b99ca790fab1 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -12,7 +12,7 @@ "dependencies": { "@astrojs/preact": "^4.0.0", "@nanostores/preact": "^0.5.2", - "astro": "^5.0.4", + "astro": "^5.0.5", "nanostores": "^0.11.3", "preact": "^10.24.3" } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index 2d8b72824b6e..4cc92b511a5f 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -13,7 +13,7 @@ "@astrojs/mdx": "^4.0.2", "@astrojs/tailwind": "^5.1.3", "@types/canvas-confetti": "^1.6.4", - "astro": "^5.0.4", + "astro": "^5.0.5", "autoprefixer": "^10.4.20", "canvas-confetti": "^1.9.3", "postcss": "^8.4.49", diff --git a/examples/with-vitest/package.json b/examples/with-vitest/package.json index 7896c5f74e3c..f20af363281e 100644 --- a/examples/with-vitest/package.json +++ b/examples/with-vitest/package.json @@ -11,7 +11,7 @@ "test": "vitest" }, "dependencies": { - "astro": "^5.0.4", + "astro": "^5.0.5", "vitest": "^2.1.6" } } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index 5bcd4ccae0ec..58f4630de192 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,21 @@ # astro +## 5.0.5 + +### Patch Changes + +- [#12705](https://github.com/withastro/astro/pull/12705) [`0d1eab5`](https://github.com/withastro/astro/commit/0d1eab560d56c51c359bbd35e8bfb51e238611ee) Thanks [@ascorbic](https://github.com/ascorbic)! - Fixes a bug where MDX files with certain characters in the name would cause builds to fail + +- [#12707](https://github.com/withastro/astro/pull/12707) [`2aaed2d`](https://github.com/withastro/astro/commit/2aaed2d2a96ab35461af24e8d12b20f1da33983f) Thanks [@ematipico](https://github.com/ematipico)! - Fixes a bug where the middleware was incorrectly imported during the build + +- [#12697](https://github.com/withastro/astro/pull/12697) [`1c4a032`](https://github.com/withastro/astro/commit/1c4a032247747c830be94dbdd0c953511a6bfa53) Thanks [@ascorbic](https://github.com/ascorbic)! - Fix a bug that caused builds to fail if an image had a quote mark in its name + +- [#12694](https://github.com/withastro/astro/pull/12694) [`495f46b`](https://github.com/withastro/astro/commit/495f46bca78665732e51c629d93a68fa392b88a4) Thanks [@ematipico](https://github.com/ematipico)! - Fixes a bug where the experimental feature `experimental.svg` was incorrectly used when generating ESM images + +- [#12658](https://github.com/withastro/astro/pull/12658) [`3169593`](https://github.com/withastro/astro/commit/316959355c3d59723ecb3e0f417becf1f03ddd74) Thanks [@jurajkapsz](https://github.com/jurajkapsz)! - Fixes astro info copy to clipboard process not returning to prompt in certain cases. + +- [#12712](https://github.com/withastro/astro/pull/12712) [`b01c74a`](https://github.com/withastro/astro/commit/b01c74aeccc4ec76b64fa75d163df58274b37970) Thanks [@ascorbic](https://github.com/ascorbic)! - Fixes a bug which misidentified pages as markdown if a query string ended in a markdown extension + ## 5.0.4 ### Patch Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index c588c592df5a..8c7e85a445ac 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "5.0.4", + "version": "5.0.5", "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.", "type": "module", "author": "withastro", diff --git a/packages/integrations/markdoc/CHANGELOG.md b/packages/integrations/markdoc/CHANGELOG.md index f85601a9a75c..1b752b85b2d2 100644 --- a/packages/integrations/markdoc/CHANGELOG.md +++ b/packages/integrations/markdoc/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/markdoc +## 0.12.3 + +### Patch Changes + +- [#12694](https://github.com/withastro/astro/pull/12694) [`495f46b`](https://github.com/withastro/astro/commit/495f46bca78665732e51c629d93a68fa392b88a4) Thanks [@ematipico](https://github.com/ematipico)! - Fixes a bug where the experimental feature `experimental.svg` was incorrectly used when generating ESM images + ## 0.12.2 ### Patch Changes diff --git a/packages/integrations/markdoc/package.json b/packages/integrations/markdoc/package.json index 4c9c26967c3f..5421f82c12ee 100644 --- a/packages/integrations/markdoc/package.json +++ b/packages/integrations/markdoc/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/markdoc", "description": "Add support for Markdoc in your Astro site", - "version": "0.12.2", + "version": "0.12.3", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/packages/integrations/react/CHANGELOG.md b/packages/integrations/react/CHANGELOG.md index ad8fdd7301f2..794f34b25a13 100644 --- a/packages/integrations/react/CHANGELOG.md +++ b/packages/integrations/react/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/react +## 4.1.0 + +### Minor Changes + +- [#12678](https://github.com/withastro/astro/pull/12678) [`97c9265`](https://github.com/withastro/astro/commit/97c9265754b78af12ad1e399cc75028435028dfa) Thanks [@bskimball](https://github.com/bskimball)! - Add React 19 stable to peer dependencies + ## 4.0.0 ### Major Changes diff --git a/packages/integrations/react/package.json b/packages/integrations/react/package.json index cd7d17632cd5..205f5b03774f 100644 --- a/packages/integrations/react/package.json +++ b/packages/integrations/react/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/react", "description": "Use React components within Astro", - "version": "4.0.0", + "version": "4.1.0", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/packages/integrations/vue/CHANGELOG.md b/packages/integrations/vue/CHANGELOG.md index a1f1bb1ae90c..d0f6b8ee7f43 100644 --- a/packages/integrations/vue/CHANGELOG.md +++ b/packages/integrations/vue/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/vue +## 5.0.2 + +### Patch Changes + +- [#12688](https://github.com/withastro/astro/pull/12688) [`7dc2fca`](https://github.com/withastro/astro/commit/7dc2fca2eeb646bf3fd362d21c5bbfe273838b5a) Thanks [@yoyo837](https://github.com/yoyo837)! - fix vite peer dependency issue for vue integration + ## 5.0.1 ### Patch Changes diff --git a/packages/integrations/vue/package.json b/packages/integrations/vue/package.json index 8e9c5d86d16e..49928cefe197 100644 --- a/packages/integrations/vue/package.json +++ b/packages/integrations/vue/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/vue", - "version": "5.0.1", + "version": "5.0.2", "description": "Use Vue components within Astro", "type": "module", "types": "./dist/index.d.ts", diff --git a/packages/upgrade/CHANGELOG.md b/packages/upgrade/CHANGELOG.md index f0014da8d738..a41d315aab85 100644 --- a/packages/upgrade/CHANGELOG.md +++ b/packages/upgrade/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/upgrade +## 0.4.2 + +### Patch Changes + +- [#12706](https://github.com/withastro/astro/pull/12706) [`f6c4214`](https://github.com/withastro/astro/commit/f6c4214042c68de137a69aa15dea81ed9cbc822a) Thanks [@ascorbic](https://github.com/ascorbic)! - Fixes a bug that caused registry URLs that specify a port to be incorrectly detected as offline. + ## 0.4.1 ### Patch Changes diff --git a/packages/upgrade/package.json b/packages/upgrade/package.json index c3cc86f00a2a..ae633f230299 100644 --- a/packages/upgrade/package.json +++ b/packages/upgrade/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/upgrade", - "version": "0.4.1", + "version": "0.4.2", "type": "module", "author": "withastro", "license": "MIT", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a351d308082f..e47377c548b9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -142,7 +142,7 @@ importers: examples/basics: dependencies: astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro examples/blog: @@ -157,22 +157,22 @@ importers: specifier: ^3.2.1 version: link:../../packages/integrations/sitemap astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro examples/component: devDependencies: astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro examples/container-with-vitest: dependencies: '@astrojs/react': - specifier: ^4.0.0 + specifier: ^4.1.0 version: link:../../packages/integrations/react astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro react: specifier: ^18.3.1 @@ -203,7 +203,7 @@ importers: specifier: ^3.14.3 version: 3.14.3 astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro examples/framework-multiple: @@ -212,7 +212,7 @@ importers: specifier: ^4.0.0 version: link:../../packages/integrations/preact '@astrojs/react': - specifier: ^4.0.0 + specifier: ^4.1.0 version: link:../../packages/integrations/react '@astrojs/solid-js': specifier: ^5.0.0 @@ -221,7 +221,7 @@ importers: specifier: ^7.0.1 version: link:../../packages/integrations/svelte '@astrojs/vue': - specifier: ^5.0.1 + specifier: ^5.0.2 version: link:../../packages/integrations/vue '@types/react': specifier: ^18.3.12 @@ -230,7 +230,7 @@ importers: specifier: ^18.3.1 version: 18.3.1 astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro preact: specifier: ^10.24.3 @@ -260,7 +260,7 @@ importers: specifier: ^1.3.0 version: 1.3.0(preact@10.24.3) astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro preact: specifier: ^10.24.3 @@ -269,7 +269,7 @@ importers: examples/framework-react: dependencies: '@astrojs/react': - specifier: ^4.0.0 + specifier: ^4.1.0 version: link:../../packages/integrations/react '@types/react': specifier: ^18.3.12 @@ -278,7 +278,7 @@ importers: specifier: ^18.3.1 version: 18.3.1 astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro react: specifier: ^18.3.1 @@ -293,7 +293,7 @@ importers: specifier: ^5.0.0 version: link:../../packages/integrations/solid astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro solid-js: specifier: ^1.9.3 @@ -305,7 +305,7 @@ importers: specifier: ^7.0.1 version: link:../../packages/integrations/svelte astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro svelte: specifier: ^5.1.16 @@ -314,10 +314,10 @@ importers: examples/framework-vue: dependencies: '@astrojs/vue': - specifier: ^5.0.1 + specifier: ^5.0.2 version: link:../../packages/integrations/vue astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro vue: specifier: ^3.5.12 @@ -329,25 +329,25 @@ importers: specifier: ^9.0.0 version: 9.0.0(astro@packages+astro) astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro examples/integration: devDependencies: astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro examples/minimal: dependencies: astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro examples/portfolio: dependencies: astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro examples/ssr: @@ -359,7 +359,7 @@ importers: specifier: ^7.0.1 version: link:../../packages/integrations/svelte astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro svelte: specifier: ^5.1.16 @@ -368,7 +368,7 @@ importers: examples/starlog: dependencies: astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro sass: specifier: ^1.80.6 @@ -380,16 +380,16 @@ importers: examples/toolbar-app: devDependencies: astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro examples/with-markdoc: dependencies: '@astrojs/markdoc': - specifier: ^0.12.2 + specifier: ^0.12.3 version: link:../../packages/integrations/markdoc astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro examples/with-mdx: @@ -401,7 +401,7 @@ importers: specifier: ^4.0.0 version: link:../../packages/integrations/preact astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro preact: specifier: ^10.24.3 @@ -416,7 +416,7 @@ importers: specifier: ^0.5.2 version: 0.5.2(nanostores@0.11.3)(preact@10.24.3) astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro nanostores: specifier: ^0.11.3 @@ -437,7 +437,7 @@ importers: specifier: ^1.6.4 version: 1.6.4 astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro autoprefixer: specifier: ^10.4.20 @@ -455,7 +455,7 @@ importers: examples/with-vitest: dependencies: astro: - specifier: ^5.0.4 + specifier: ^5.0.5 version: link:../../packages/astro vitest: specifier: ^2.1.6 @@ -5877,28 +5877,24 @@ packages: engines: {node: '>=14.21.3'} cpu: [arm64] os: [linux] - libc: [musl] '@biomejs/cli-linux-arm64@1.9.3': resolution: {integrity: sha512-vJkAimD2+sVviNTbaWOGqEBy31cW0ZB52KtpVIbkuma7PlfII3tsLhFa+cwbRAcRBkobBBhqZ06hXoZAN8NODQ==} engines: {node: '>=14.21.3'} cpu: [arm64] os: [linux] - libc: [glibc] '@biomejs/cli-linux-x64-musl@1.9.3': resolution: {integrity: sha512-TJmnOG2+NOGM72mlczEsNki9UT+XAsMFAOo8J0me/N47EJ/vkLXxf481evfHLlxMejTY6IN8SdRSiPVLv6AHlA==} engines: {node: '>=14.21.3'} cpu: [x64] os: [linux] - libc: [musl] '@biomejs/cli-linux-x64@1.9.3': resolution: {integrity: sha512-x220V4c+romd26Mu1ptU+EudMXVS4xmzKxPVb9mgnfYlN4Yx9vD5NZraSx/onJnd3Gh/y8iPUdU5CDZJKg9COA==} engines: {node: '>=14.21.3'} cpu: [x64] os: [linux] - libc: [glibc] '@biomejs/cli-win32-arm64@1.9.3': resolution: {integrity: sha512-lg/yZis2HdQGsycUvHWSzo9kOvnGgvtrYRgoCEwPBwwAL8/6crOp3+f47tPwI/LI1dZrhSji7PNsGKGHbwyAhw==} @@ -6650,84 +6646,72 @@ packages: engines: {glibc: '>=2.26', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-arm@1.0.2': resolution: {integrity: sha512-iLWCvrKgeFoglQxdEwzu1eQV04o8YeYGFXtfWU26Zr2wWT3q3MTzC+QTCO3ZQfWd3doKHT4Pm2kRmLbupT+sZw==} engines: {glibc: '>=2.28', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-s390x@1.0.2': resolution: {integrity: sha512-cmhQ1J4qVhfmS6szYW7RT+gLJq9dH2i4maq+qyXayUSn9/3iY2ZeWpbAgSpSVbV2E1JUL2Gg7pwnYQ1h8rQIog==} engines: {glibc: '>=2.28', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [s390x] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-x64@1.0.2': resolution: {integrity: sha512-E441q4Qdb+7yuyiADVi5J+44x8ctlrqn8XgkDTwr4qPJzWkaHwD489iZ4nGDgcuya4iMN3ULV6NwbhRZJ9Z7SQ==} engines: {glibc: '>=2.26', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linuxmusl-arm64@1.0.2': resolution: {integrity: sha512-3CAkndNpYUrlDqkCM5qhksfE+qSIREVpyoeHIU6jd48SJZViAmznoQQLAv4hVXF7xyUB9zf+G++e2v1ABjCbEQ==} engines: {musl: '>=1.2.2', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] - libc: [musl] '@img/sharp-libvips-linuxmusl-x64@1.0.2': resolution: {integrity: sha512-VI94Q6khIHqHWNOh6LLdm9s2Ry4zdjWJwH56WoiJU7NTeDwyApdZZ8c+SADC8OH98KWNQXnE01UdJ9CSfZvwZw==} engines: {musl: '>=1.2.2', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] - libc: [musl] '@img/sharp-linux-arm64@0.33.3': resolution: {integrity: sha512-Zf+sF1jHZJKA6Gor9hoYG2ljr4wo9cY4twaxgFDvlG0Xz9V7sinsPp8pFd1XtlhTzYo0IhDbl3rK7P6MzHpnYA==} engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] - libc: [glibc] '@img/sharp-linux-arm@0.33.3': resolution: {integrity: sha512-Q7Ee3fFSC9P7vUSqVEF0zccJsZ8GiiCJYGWDdhEjdlOeS9/jdkyJ6sUSPj+bL8VuOYFSbofrW0t/86ceVhx32w==} engines: {glibc: '>=2.28', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm] os: [linux] - libc: [glibc] '@img/sharp-linux-s390x@0.33.3': resolution: {integrity: sha512-vFk441DKRFepjhTEH20oBlFrHcLjPfI8B0pMIxGm3+yilKyYeHEVvrZhYFdqIseSclIqbQ3SnZMwEMWonY5XFA==} engines: {glibc: '>=2.28', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [s390x] os: [linux] - libc: [glibc] '@img/sharp-linux-x64@0.33.3': resolution: {integrity: sha512-Q4I++herIJxJi+qmbySd072oDPRkCg/SClLEIDh5IL9h1zjhqjv82H0Seupd+q2m0yOfD+/fJnjSoDFtKiHu2g==} engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] - libc: [glibc] '@img/sharp-linuxmusl-arm64@0.33.3': resolution: {integrity: sha512-qnDccehRDXadhM9PM5hLvcPRYqyFCBN31kq+ErBSZtZlsAc1U4Z85xf/RXv1qolkdu+ibw64fUDaRdktxTNP9A==} engines: {musl: '>=1.2.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] - libc: [musl] '@img/sharp-linuxmusl-x64@0.33.3': resolution: {integrity: sha512-Jhchim8kHWIU/GZ+9poHMWRcefeaxFIs9EBqf9KtcC14Ojk6qua7ghKiPs0sbeLbLj/2IGBtDcxHyjCdYWkk2w==} engines: {musl: '>=1.2.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] - libc: [musl] '@img/sharp-wasm32@0.33.3': resolution: {integrity: sha512-68zivsdJ0koE96stdUfM+gmyaK/NcoSZK5dV5CAjES0FUXS9lchYt8LAB5rTbM7nlWtxaU/2GON0HVN6/ZYJAQ==} @@ -6904,35 +6888,30 @@ packages: engines: {node: '>= 10.0.0'} cpu: [arm] os: [linux] - libc: [glibc] '@parcel/watcher-linux-arm64-glibc@2.4.1': resolution: {integrity: sha512-BJ7mH985OADVLpbrzCLgrJ3TOpiZggE9FMblfO65PlOCdG++xJpKUJ0Aol74ZUIYfb8WsRlUdgrZxKkz3zXWYA==} engines: {node: '>= 10.0.0'} cpu: [arm64] os: [linux] - libc: [glibc] '@parcel/watcher-linux-arm64-musl@2.4.1': resolution: {integrity: sha512-p4Xb7JGq3MLgAfYhslU2SjoV9G0kI0Xry0kuxeG/41UfpjHGOhv7UoUDAz/jb1u2elbhazy4rRBL8PegPJFBhA==} engines: {node: '>= 10.0.0'} cpu: [arm64] os: [linux] - libc: [musl] '@parcel/watcher-linux-x64-glibc@2.4.1': resolution: {integrity: sha512-s9O3fByZ/2pyYDPoLM6zt92yu6P4E39a03zvO0qCHOTjxmt3GHRMLuRZEWhWLASTMSrrnVNWdVI/+pUElJBBBg==} engines: {node: '>= 10.0.0'} cpu: [x64] os: [linux] - libc: [glibc] '@parcel/watcher-linux-x64-musl@2.4.1': resolution: {integrity: sha512-L2nZTYR1myLNST0O632g0Dx9LyMNHrn6TOt76sYxWLdff3cB22/GZX2UPtJnaqQPdCRoszoY5rcOj4oMTtp5fQ==} engines: {node: '>= 10.0.0'} cpu: [x64] os: [linux] - libc: [musl] '@parcel/watcher-win32-arm64@2.4.1': resolution: {integrity: sha512-Uq2BPp5GWhrq/lcuItCHoqxjULU1QYEcyjSO5jqqOK8RNFDBQnenMMx4gAl3v8GiWa59E9+uDM7yZ6LxwUIfRg==} @@ -7046,55 +7025,46 @@ packages: resolution: {integrity: sha512-9OwUnK/xKw6DyRlgx8UizeqRFOfi9mf5TYCw1uolDaJSbUmBxP85DE6T4ouCMoN6pXw8ZoTeZCSEfSaYo+/s1w==} cpu: [arm] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.27.4': resolution: {integrity: sha512-Vgdo4fpuphS9V24WOV+KwkCVJ72u7idTgQaBoLRD0UxBAWTF9GWurJO9YD9yh00BzbkhpeXtm6na+MvJU7Z73A==} cpu: [arm] os: [linux] - libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.27.4': resolution: {integrity: sha512-pleyNgyd1kkBkw2kOqlBx+0atfIIkkExOTiifoODo6qKDSpnc6WzUY5RhHdmTdIJXBdSnh6JknnYTtmQyobrVg==} cpu: [arm64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.27.4': resolution: {integrity: sha512-caluiUXvUuVyCHr5DxL8ohaaFFzPGmgmMvwmqAITMpV/Q+tPoaHZ/PWa3t8B2WyoRcIIuu1hkaW5KkeTDNSnMA==} cpu: [arm64] os: [linux] - libc: [musl] '@rollup/rollup-linux-powerpc64le-gnu@4.27.4': resolution: {integrity: sha512-FScrpHrO60hARyHh7s1zHE97u0KlT/RECzCKAdmI+LEoC1eDh/RDji9JgFqyO+wPDb86Oa/sXkily1+oi4FzJQ==} cpu: [ppc64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.27.4': resolution: {integrity: sha512-qyyprhyGb7+RBfMPeww9FlHwKkCXdKHeGgSqmIXw9VSUtvyFZ6WZRtnxgbuz76FK7LyoN8t/eINRbPUcvXB5fw==} cpu: [riscv64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-s390x-gnu@4.27.4': resolution: {integrity: sha512-PFz+y2kb6tbh7m3A7nA9++eInGcDVZUACulf/KzDtovvdTizHpZaJty7Gp0lFwSQcrnebHOqxF1MaKZd7psVRg==} cpu: [s390x] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.27.4': resolution: {integrity: sha512-Ni8mMtfo+o/G7DVtweXXV/Ol2TFf63KYjTtoZ5f078AUgJTmaIJnj4JFU7TK/9SVWTaSJGxPi5zMDgK4w+Ez7Q==} cpu: [x64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-musl@4.27.4': resolution: {integrity: sha512-5AeeAF1PB9TUzD+3cROzFTnAJAcVUGLuR8ng0E0WXGkYhp6RD6L+6szYVX+64Rs0r72019KHZS1ka1q+zU/wUw==} cpu: [x64] os: [linux] - libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.27.4': resolution: {integrity: sha512-yOpVsA4K5qVwu2CaS3hHxluWIK5HQTjNV4tWjQXluMiiiu4pJj4BN98CvxohNCpcjMeTXk/ZMJBRbgRg8HBB6A==} From 618de283f57d19397246f69dd476611abd56cf13 Mon Sep 17 00:00:00 2001 From: Anton Begehr Date: Wed, 11 Dec 2024 13:23:53 +0100 Subject: [PATCH 08/26] =?UTF-8?q?=F0=9F=90=9B=20Fix=20isDbError()-guard=20?= =?UTF-8?q?does=20not=20work=20(#12416)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * isDbError() does not work Fixes #12400 * lint&format * Update packages/db/src/runtime/virtual.ts Co-authored-by: Bjorn Lu * use isDbError instead of "instanceof LibsqlError" * unused imports * mv isDbError to utils * Update .changeset/breezy-radios-grab.md --------- Co-authored-by: Bjorn Lu Co-authored-by: Emanuele Stoppa --- .changeset/breezy-radios-grab.md | 5 +++++ packages/db/src/core/cli/commands/execute/index.ts | 8 +++----- packages/db/src/core/cli/migration-queries.ts | 5 ++--- packages/db/src/core/integration/index.ts | 5 ++--- packages/db/src/runtime/utils.ts | 4 ++++ packages/db/src/runtime/virtual.ts | 5 +---- packages/db/test/test-utils.js | 5 +++-- 7 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 .changeset/breezy-radios-grab.md diff --git a/.changeset/breezy-radios-grab.md b/.changeset/breezy-radios-grab.md new file mode 100644 index 000000000000..afb990a44954 --- /dev/null +++ b/.changeset/breezy-radios-grab.md @@ -0,0 +1,5 @@ +--- +'@astrojs/db': patch +--- + +Fixes `isDbError()` guard for `LibsqlError` diff --git a/packages/db/src/core/cli/commands/execute/index.ts b/packages/db/src/core/cli/commands/execute/index.ts index 9a5a1b8e2f90..66ecdd774b9d 100644 --- a/packages/db/src/core/cli/commands/execute/index.ts +++ b/packages/db/src/core/cli/commands/execute/index.ts @@ -1,5 +1,4 @@ import { existsSync } from 'node:fs'; -import { LibsqlError } from '@libsql/client'; import type { AstroConfig } from 'astro'; import { green } from 'kleur/colors'; import type { Arguments } from 'yargs-parser'; @@ -16,6 +15,7 @@ import { import { bundleFile, importBundledFile } from '../../../load-file.js'; import type { DBConfig } from '../../../types.js'; import { getManagedRemoteToken } from '../../../utils.js'; +import { isDbError } from '../../../../runtime/utils.js'; export async function cmd({ astroConfig, @@ -64,9 +64,7 @@ export async function cmd({ await mod.default(); console.info(`${green('✔')} File run successfully.`); } catch (e) { - if (e instanceof LibsqlError) { - throw new Error(EXEC_ERROR(e.message)); - } - throw e; + if (isDbError(e)) throw new Error(EXEC_ERROR(e.message)); + else throw e; } } diff --git a/packages/db/src/core/cli/migration-queries.ts b/packages/db/src/core/cli/migration-queries.ts index bd6360665d4e..db3972d095d1 100644 --- a/packages/db/src/core/cli/migration-queries.ts +++ b/packages/db/src/core/cli/migration-queries.ts @@ -1,5 +1,4 @@ import { stripVTControlCharacters } from 'node:util'; -import { LibsqlError } from '@libsql/client'; import deepDiff from 'deep-diff'; import { sql } from 'drizzle-orm'; import { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core'; @@ -8,7 +7,7 @@ import { customAlphabet } from 'nanoid'; import { hasPrimaryKey } from '../../runtime/index.js'; import { createRemoteDatabaseClient } from '../../runtime/index.js'; import { isSerializedSQL } from '../../runtime/types.js'; -import { safeFetch } from '../../runtime/utils.js'; +import { isDbError, safeFetch } from '../../runtime/utils.js'; import { MIGRATION_VERSION } from '../consts.js'; import { RENAME_COLUMN_ERROR, RENAME_TABLE_ERROR } from '../errors.js'; import { @@ -454,7 +453,7 @@ async function getDbCurrentSnapshot( } catch (error) { // Don't handle errors that are not from libSQL if ( - error instanceof LibsqlError && + isDbError(error) && // If the schema was never pushed to the database yet the table won't exist. // Treat a missing snapshot table as an empty table. diff --git a/packages/db/src/core/integration/index.ts b/packages/db/src/core/integration/index.ts index 200c7ddc25b2..51d3f80116d9 100644 --- a/packages/db/src/core/integration/index.ts +++ b/packages/db/src/core/integration/index.ts @@ -3,7 +3,6 @@ import { mkdir, writeFile } from 'node:fs/promises'; import { dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import type { ManagedAppToken } from '@astrojs/studio'; -import { LibsqlError } from '@libsql/client'; import type { AstroIntegration } from 'astro'; import { blue, yellow } from 'kleur/colors'; import { @@ -15,7 +14,7 @@ import { mergeConfig, } from 'vite'; import parseArgs from 'yargs-parser'; -import { AstroDbError } from '../../runtime/utils.js'; +import { AstroDbError, isDbError } from '../../runtime/utils.js'; import { CONFIG_FILE_NAMES, DB_PATH, VIRTUAL_MODULE_ID } from '../consts.js'; import { EXEC_DEFAULT_EXPORT_ERROR, EXEC_ERROR } from '../errors.js'; import { resolveDbConfig } from '../load-file.js'; @@ -206,7 +205,7 @@ async function executeSeedFile({ try { await mod.default(); } catch (e) { - if (e instanceof LibsqlError) { + if (isDbError(e)) { throw new AstroDbError(EXEC_ERROR(e.message)); } throw e; diff --git a/packages/db/src/runtime/utils.ts b/packages/db/src/runtime/utils.ts index 64301c39ee2d..74201957ff64 100644 --- a/packages/db/src/runtime/utils.ts +++ b/packages/db/src/runtime/utils.ts @@ -42,6 +42,10 @@ export class DetailedLibsqlError extends LibsqlError { } } +export function isDbError(err: unknown): err is LibsqlError { + return err instanceof LibsqlError || (err instanceof Error && (err as any).libsqlError === true) +} + function slash(path: string) { const isExtendedLengthPath = path.startsWith('\\\\?\\'); diff --git a/packages/db/src/runtime/virtual.ts b/packages/db/src/runtime/virtual.ts index 6f008fe0d8ac..3da0c3549165 100644 --- a/packages/db/src/runtime/virtual.ts +++ b/packages/db/src/runtime/virtual.ts @@ -21,10 +21,6 @@ function createColumn>(type: }; } -export function isDbError(err: unknown): err is LibsqlError { - return err instanceof LibsqlError; -} - export const column = { number: (opts: T = {} as T) => { return createColumn('number', opts) satisfies { type: 'number' }; @@ -90,3 +86,4 @@ export { } from 'drizzle-orm'; export { alias } from 'drizzle-orm/sqlite-core'; +export { isDbError } from './utils.js'; diff --git a/packages/db/test/test-utils.js b/packages/db/test/test-utils.js index 8315e85512fa..b608d75b8b34 100644 --- a/packages/db/test/test-utils.js +++ b/packages/db/test/test-utils.js @@ -1,9 +1,10 @@ import { createServer } from 'node:http'; -import { LibsqlError, createClient } from '@libsql/client'; +import { createClient } from '@libsql/client'; import { z } from 'zod'; import { cli } from '../dist/core/cli/index.js'; import { resolveDbConfig } from '../dist/core/load-file.js'; import { getCreateIndexQueries, getCreateTableQuery } from '../dist/core/queries.js'; +import { isDbError } from '../dist/runtime/utils.js'; const singleQuerySchema = z.object({ sql: z.string(), @@ -142,7 +143,7 @@ function createRemoteDbServer() { JSON.stringify({ success: false, error: { - code: e instanceof LibsqlError ? e.code : 'SQLITE_QUERY_FAILED', + code: isDbError(e) ? e.code : 'SQLITE_QUERY_FAILED', details: e.message, }, }), From dff04a4b152d8b69fd09e01c1ddcae2f52c80bf1 Mon Sep 17 00:00:00 2001 From: Anton Begehr Date: Wed, 11 Dec 2024 12:24:49 +0000 Subject: [PATCH 09/26] [ci] format --- packages/db/src/core/cli/commands/execute/index.ts | 2 +- packages/db/src/runtime/utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/db/src/core/cli/commands/execute/index.ts b/packages/db/src/core/cli/commands/execute/index.ts index 66ecdd774b9d..0537362913ad 100644 --- a/packages/db/src/core/cli/commands/execute/index.ts +++ b/packages/db/src/core/cli/commands/execute/index.ts @@ -2,6 +2,7 @@ import { existsSync } from 'node:fs'; import type { AstroConfig } from 'astro'; import { green } from 'kleur/colors'; import type { Arguments } from 'yargs-parser'; +import { isDbError } from '../../../../runtime/utils.js'; import { EXEC_DEFAULT_EXPORT_ERROR, EXEC_ERROR, @@ -15,7 +16,6 @@ import { import { bundleFile, importBundledFile } from '../../../load-file.js'; import type { DBConfig } from '../../../types.js'; import { getManagedRemoteToken } from '../../../utils.js'; -import { isDbError } from '../../../../runtime/utils.js'; export async function cmd({ astroConfig, diff --git a/packages/db/src/runtime/utils.ts b/packages/db/src/runtime/utils.ts index 74201957ff64..9a979b06276e 100644 --- a/packages/db/src/runtime/utils.ts +++ b/packages/db/src/runtime/utils.ts @@ -43,7 +43,7 @@ export class DetailedLibsqlError extends LibsqlError { } export function isDbError(err: unknown): err is LibsqlError { - return err instanceof LibsqlError || (err instanceof Error && (err as any).libsqlError === true) + return err instanceof LibsqlError || (err instanceof Error && (err as any).libsqlError === true); } function slash(path: string) { From 110fc01a5b82d3dd4ec66653c4cb5488409ec8e5 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Wed, 11 Dec 2024 16:01:06 +0100 Subject: [PATCH 10/26] chore: remove unused imports (#12696) --- benchmark/index.js | 2 +- benchmark/packages/adapter/src/index.ts | 2 +- biome.jsonc | 4 +++- packages/astro/src/assets/utils/imageAttributes.ts | 1 - packages/astro/src/core/app/index.ts | 1 - packages/astro/src/core/build/plugins/plugin-manifest.ts | 1 - packages/astro/src/core/build/plugins/plugin-ssr.ts | 1 - packages/astro/src/vite-plugin-astro-server/route.ts | 2 +- packages/astro/templates/env.mjs | 1 + packages/astro/test/units/routing/route-matching.test.js | 1 - packages/db/src/core/integration/index.ts | 1 - .../markdoc/src/html/transform/html-token-transform.ts | 1 + 12 files changed, 8 insertions(+), 10 deletions(-) diff --git a/benchmark/index.js b/benchmark/index.js index 956b9c3afa0c..0c62036d98d3 100755 --- a/benchmark/index.js +++ b/benchmark/index.js @@ -1,6 +1,6 @@ import fs from 'node:fs/promises'; import path from 'node:path'; -import { fileURLToPath, pathToFileURL } from 'node:url'; +import { pathToFileURL } from 'node:url'; import mri from 'mri'; import { makeProject } from './bench/_util.js'; diff --git a/benchmark/packages/adapter/src/index.ts b/benchmark/packages/adapter/src/index.ts index f2345deb0885..0fc6d67f99c2 100644 --- a/benchmark/packages/adapter/src/index.ts +++ b/benchmark/packages/adapter/src/index.ts @@ -1,4 +1,4 @@ -import type { AstroAdapter, AstroIntegration } from 'astro'; +import type { AstroIntegration } from 'astro'; export default function createIntegration(): AstroIntegration { return { diff --git a/biome.jsonc b/biome.jsonc index bab1f1a05b61..a1000760a743 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -34,6 +34,7 @@ "correctness": { "noUnusedVariables": "info", "noUnusedFunctionParameters": "info", + "noUnusedImports": "warn", }, }, }, @@ -87,11 +88,12 @@ }, }, { - "include": ["*.astro", "client.d.ts"], + "include": ["*.astro", "client.d.ts", "jsx-runtime.d.ts"], "linter": { "rules": { "correctness": { "noUnusedVariables": "off", + "noUnusedImports": "off", }, }, }, diff --git a/packages/astro/src/assets/utils/imageAttributes.ts b/packages/astro/src/assets/utils/imageAttributes.ts index 1b17e11b6320..aa67b528f286 100644 --- a/packages/astro/src/assets/utils/imageAttributes.ts +++ b/packages/astro/src/assets/utils/imageAttributes.ts @@ -1,5 +1,4 @@ import { toStyleString } from '../../runtime/server/render/util.js'; -import type { AstroConfig } from '../../types/public/config.js'; import type { GetImageResult, ImageLayout, LocalImageProps, RemoteImageProps } from '../types.js'; export function addCSSVarsToStyle( diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 36543b5cac9c..d23383133e05 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -5,7 +5,6 @@ import { REROUTABLE_STATUS_CODES, REROUTE_DIRECTIVE_HEADER, clientAddressSymbol, - clientLocalsSymbol, responseSentSymbol, } from '../constants.js'; import { getSetCookiesFromResponse } from '../cookies/index.js'; diff --git a/packages/astro/src/core/build/plugins/plugin-manifest.ts b/packages/astro/src/core/build/plugins/plugin-manifest.ts index caebb470d598..f0589868f72c 100644 --- a/packages/astro/src/core/build/plugins/plugin-manifest.ts +++ b/packages/astro/src/core/build/plugins/plugin-manifest.ts @@ -5,7 +5,6 @@ import type { Plugin as VitePlugin } from 'vite'; import { getAssetsPrefix } from '../../../assets/utils/getAssetsPrefix.js'; import { normalizeTheLocale } from '../../../i18n/index.js'; import { toFallbackType, toRoutingStrategy } from '../../../i18n/utils.js'; -import { unwrapSupportKind } from '../../../integrations/features-validation.js'; import { runHookBuildSsr } from '../../../integrations/hooks.js'; import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../../vite-plugin-scripts/index.js'; import type { diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 473aa950127a..eea2be3e8efd 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -1,5 +1,4 @@ import type { Plugin as VitePlugin } from 'vite'; -import type { AstroSettings } from '../../../types/astro.js'; import type { AstroAdapter } from '../../../types/public/integrations.js'; import { routeIsRedirect } from '../../redirects/index.js'; import { VIRTUAL_ISLAND_MAP_ID } from '../../server-islands/vite-plugin-server-islands.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts index b4b659805408..eb353e501fe0 100644 --- a/packages/astro/src/vite-plugin-astro-server/route.ts +++ b/packages/astro/src/vite-plugin-astro-server/route.ts @@ -11,7 +11,7 @@ import { req } from '../core/messages.js'; import { loadMiddleware } from '../core/middleware/loadMiddleware.js'; import { routeIsRedirect } from '../core/redirects/index.js'; import { RenderContext } from '../core/render-context.js'; -import { type SSROptions, getProps } from '../core/render/index.js'; +import { getProps } from '../core/render/index.js'; import { createRequest } from '../core/request.js'; import { redirectTemplate } from '../core/routing/3xx.js'; import { matchAllRoutes } from '../core/routing/index.js'; diff --git a/packages/astro/templates/env.mjs b/packages/astro/templates/env.mjs index 9f36f1175b1c..6526033514de 100644 --- a/packages/astro/templates/env.mjs +++ b/packages/astro/templates/env.mjs @@ -1,6 +1,7 @@ // @ts-check import { schema } from 'virtual:astro:env/internal'; import { + // biome-ignore lint/correctness/noUnusedImports: `_getEnv` is used by the generated code getEnv as _getEnv, createInvalidVariablesError, getEnvFieldType, diff --git a/packages/astro/test/units/routing/route-matching.test.js b/packages/astro/test/units/routing/route-matching.test.js index b524a7ea103e..72900d3156f8 100644 --- a/packages/astro/test/units/routing/route-matching.test.js +++ b/packages/astro/test/units/routing/route-matching.test.js @@ -1,6 +1,5 @@ import * as assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; -import { fileURLToPath } from 'node:url'; import * as cheerio from 'cheerio'; import { createContainer } from '../../../dist/core/dev/container.js'; import { createViteLoader } from '../../../dist/core/module-loader/vite.js'; diff --git a/packages/db/src/core/integration/index.ts b/packages/db/src/core/integration/index.ts index 51d3f80116d9..36dc6b0f8bce 100644 --- a/packages/db/src/core/integration/index.ts +++ b/packages/db/src/core/integration/index.ts @@ -26,7 +26,6 @@ import { type LateSeedFiles, type LateTables, type SeedHandler, - resolved, vitePluginDb, } from './vite-plugin-db.js'; diff --git a/packages/integrations/markdoc/src/html/transform/html-token-transform.ts b/packages/integrations/markdoc/src/html/transform/html-token-transform.ts index 2c6a5d1e2f09..b80595f97b35 100644 --- a/packages/integrations/markdoc/src/html/transform/html-token-transform.ts +++ b/packages/integrations/markdoc/src/html/transform/html-token-transform.ts @@ -1,6 +1,7 @@ import type { Tokenizer } from '@markdoc/markdoc'; import { Parser } from 'htmlparser2'; // @ts-expect-error This type isn't exported +// biome-ignore lint/correctness/noUnusedImports: not correctly detected because type isn't exported import type * as Token from 'markdown-it/lib/token'; export function htmlTokenTransform(tokenizer: Tokenizer, tokens: Token[]): Token[] { From 51ced3dba8ca2d1b2e5a322100639fd3f933b400 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Wed, 11 Dec 2024 15:02:16 +0000 Subject: [PATCH 11/26] [ci] format --- packages/db/src/runtime/virtual.ts | 2 +- scripts/cmd/build.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/db/src/runtime/virtual.ts b/packages/db/src/runtime/virtual.ts index 3da0c3549165..e01622c4164d 100644 --- a/packages/db/src/runtime/virtual.ts +++ b/packages/db/src/runtime/virtual.ts @@ -1,4 +1,4 @@ -import { LibsqlError } from '@libsql/client'; + import { sql as _sql } from 'drizzle-orm'; import type { BooleanColumnInput, diff --git a/scripts/cmd/build.js b/scripts/cmd/build.js index cf0ee5ad2b89..d5a9336d85df 100644 --- a/scripts/cmd/build.js +++ b/scripts/cmd/build.js @@ -1,6 +1,5 @@ import fs from 'node:fs/promises'; import esbuild from 'esbuild'; -import { copy } from 'esbuild-plugin-copy'; import glob from 'fast-glob'; import { dim, green, red, yellow } from 'kleur/colors'; import prebuild from './prebuild.js'; From f1f3bc043213fe7b3a653fb80d9e1353d58d17ca Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Wed, 11 Dec 2024 15:03:05 +0000 Subject: [PATCH 12/26] [ci] format --- packages/db/src/runtime/virtual.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/db/src/runtime/virtual.ts b/packages/db/src/runtime/virtual.ts index e01622c4164d..5f17823a8547 100644 --- a/packages/db/src/runtime/virtual.ts +++ b/packages/db/src/runtime/virtual.ts @@ -1,4 +1,3 @@ - import { sql as _sql } from 'drizzle-orm'; import type { BooleanColumnInput, From ccc5ad1676db5e7f5049ca2feb59802d1fe3a92e Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 11 Dec 2024 15:23:50 +0000 Subject: [PATCH 13/26] fix(i18n): manual routing with rewrite (#12718) --- .changeset/fuzzy-windows-cover.md | 5 +++++ packages/astro/src/i18n/index.ts | 9 +++++++-- packages/astro/src/i18n/middleware.ts | 1 - packages/astro/src/virtual-modules/i18n.ts | 2 +- .../astro.config.mjs | 5 ++++- .../src/middleware.js | 1 + .../i18n-routing-manual-with-default-middleware.test.js | 9 +++++++++ 7 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 .changeset/fuzzy-windows-cover.md diff --git a/.changeset/fuzzy-windows-cover.md b/.changeset/fuzzy-windows-cover.md new file mode 100644 index 000000000000..7f3b766fc0af --- /dev/null +++ b/.changeset/fuzzy-windows-cover.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue where Astro couldn't correctly handle i18n fallback when using the i18n middleware diff --git a/packages/astro/src/i18n/index.ts b/packages/astro/src/i18n/index.ts index 455e2e141487..e1e3750ea40b 100644 --- a/packages/astro/src/i18n/index.ts +++ b/packages/astro/src/i18n/index.ts @@ -298,9 +298,14 @@ export function redirectToDefaultLocale({ } // NOTE: public function exported to the users via `astro:i18n` module -export function notFound({ base, locales }: MiddlewarePayload) { +export function notFound({ base, locales, fallback }: MiddlewarePayload) { return function (context: APIContext, response?: Response): Response | undefined { - if (response?.headers.get(REROUTE_DIRECTIVE_HEADER) === 'no') return response; + if ( + response?.headers.get(REROUTE_DIRECTIVE_HEADER) === 'no' && + typeof fallback === 'undefined' + ) { + return response; + } const url = context.url; // We return a 404 if: diff --git a/packages/astro/src/i18n/middleware.ts b/packages/astro/src/i18n/middleware.ts index eefb8a9dd56e..c2805b1a3266 100644 --- a/packages/astro/src/i18n/middleware.ts +++ b/packages/astro/src/i18n/middleware.ts @@ -83,7 +83,6 @@ export function createI18nMiddleware( } const { currentLocale } = context; - switch (i18n.strategy) { // NOTE: theoretically, we should never hit this code path case 'manual': { diff --git a/packages/astro/src/virtual-modules/i18n.ts b/packages/astro/src/virtual-modules/i18n.ts index 8f85ae5f6146..d2e193fd7c04 100644 --- a/packages/astro/src/virtual-modules/i18n.ts +++ b/packages/astro/src/virtual-modules/i18n.ts @@ -378,10 +378,10 @@ if (i18n?.routing === 'manual') { fallbackType = toFallbackType(customOptions); const manifest: SSRManifest['i18n'] = { ...i18n, - fallback: undefined, strategy, domainLookupTable: {}, fallbackType, + fallback: i18n.fallback, }; return I18nInternals.createMiddleware(manifest, base, trailingSlash, format); }; diff --git a/packages/astro/test/fixtures/i18n-routing-manual-with-default-middleware/astro.config.mjs b/packages/astro/test/fixtures/i18n-routing-manual-with-default-middleware/astro.config.mjs index 0638988f063b..8006c260f80c 100644 --- a/packages/astro/test/fixtures/i18n-routing-manual-with-default-middleware/astro.config.mjs +++ b/packages/astro/test/fixtures/i18n-routing-manual-with-default-middleware/astro.config.mjs @@ -9,6 +9,9 @@ export default defineConfig({ codes: ["es", "es-ar"] } ], - routing: "manual" + routing: "manual", + fallback: { + it: 'en' + } } }) diff --git a/packages/astro/test/fixtures/i18n-routing-manual-with-default-middleware/src/middleware.js b/packages/astro/test/fixtures/i18n-routing-manual-with-default-middleware/src/middleware.js index 60d179ec7111..afc3c6c607f9 100644 --- a/packages/astro/test/fixtures/i18n-routing-manual-with-default-middleware/src/middleware.js +++ b/packages/astro/test/fixtures/i18n-routing-manual-with-default-middleware/src/middleware.js @@ -18,5 +18,6 @@ export const onRequest = sequence( customLogic, middleware({ prefixDefaultLocale: true, + fallbackType: "rewrite" }) ); diff --git a/packages/astro/test/i18n-routing-manual-with-default-middleware.test.js b/packages/astro/test/i18n-routing-manual-with-default-middleware.test.js index af900a43b589..0b24c6aa7aa5 100644 --- a/packages/astro/test/i18n-routing-manual-with-default-middleware.test.js +++ b/packages/astro/test/i18n-routing-manual-with-default-middleware.test.js @@ -117,4 +117,13 @@ describe('SSR manual routing', () => { const $ = cheerio.load(html); assert.equal($('p').text(), '/en/blog/title/'); }); + + it('should use the fallback', async () => { + let request = new Request('http://example.com/it/start'); + let response = await app.render(request); + assert.equal(response.status, 200); + const html = await response.text(); + const $ = cheerio.load(html); + assert.equal($('p').text(), '/en/blog/title/'); + }); }); From 14dffcc3af49dd975635602a0d1847a3125c0746 Mon Sep 17 00:00:00 2001 From: Magomed Chabaev Date: Wed, 11 Dec 2024 19:06:57 +0300 Subject: [PATCH 14/26] fix(actions): support trailing slash (#12657) * fix(actions): support trailing slash * refactoring --- .changeset/spicy-guests-protect.md | 5 ++++ packages/astro/src/actions/plugins.ts | 7 ++++++ .../src/actions/runtime/virtual/server.ts | 14 ++++++++++- .../src/actions/runtime/virtual/shared.ts | 3 +++ packages/astro/templates/actions.mjs | 17 +++++++++++-- packages/astro/test/actions.test.js | 24 +++++++++++++++++++ 6 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 .changeset/spicy-guests-protect.md diff --git a/.changeset/spicy-guests-protect.md b/.changeset/spicy-guests-protect.md new file mode 100644 index 000000000000..5f77d5ee0100 --- /dev/null +++ b/.changeset/spicy-guests-protect.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Trailing slash support for actions diff --git a/packages/astro/src/actions/plugins.ts b/packages/astro/src/actions/plugins.ts index 77cbddca15af..c97e3ea83573 100644 --- a/packages/astro/src/actions/plugins.ts +++ b/packages/astro/src/actions/plugins.ts @@ -1,6 +1,7 @@ import type fsMod from 'node:fs'; import type { Plugin as VitePlugin } from 'vite'; import type { AstroSettings } from '../types/astro.js'; +import { shouldAppendForwardSlash } from '../core/build/util.js'; import { NOOP_ACTIONS, RESOLVED_VIRTUAL_INTERNAL_MODULE_ID, @@ -84,6 +85,12 @@ export function vitePluginActions({ code += `\nexport * from 'astro/actions/runtime/virtual/server.js';`; } else { code += `\nexport * from 'astro/actions/runtime/virtual/client.js';`; + code = code.replace( + "'/** @TRAILING_SLASH@ **/'", + JSON.stringify( + shouldAppendForwardSlash(settings.config.trailingSlash, settings.config.build.format), + ), + ); } return code; }, diff --git a/packages/astro/src/actions/runtime/virtual/server.ts b/packages/astro/src/actions/runtime/virtual/server.ts index 47decf18e5d4..8005c4d56a06 100644 --- a/packages/astro/src/actions/runtime/virtual/server.ts +++ b/packages/astro/src/actions/runtime/virtual/server.ts @@ -1,6 +1,10 @@ import { z } from 'zod'; import { ActionCalledFromServerError } from '../../../core/errors/errors-data.js'; import { AstroError } from '../../../core/errors/errors.js'; +import type { Pipeline } from '../../../core/base-pipeline.js'; +import { apiContextRoutesSymbol } from '../../../core/render-context.js'; +import { shouldAppendForwardSlash } from '../../../core/build/util.js'; +import { removeTrailingForwardSlash } from '../../../core/path.js'; import type { APIContext } from '../../../types/public/index.js'; import { ACTION_RPC_ROUTE_PATTERN } from '../../consts.js'; import { @@ -279,7 +283,15 @@ export function getActionContext(context: APIContext): ActionMiddlewareContext { calledFrom: callerInfo.from, name: callerInfo.name, handler: async () => { - const baseAction = await getAction(callerInfo.name); + const pipeline: Pipeline = Reflect.get(context, apiContextRoutesSymbol); + const callerInfoName = shouldAppendForwardSlash( + pipeline.manifest.trailingSlash, + pipeline.manifest.buildFormat, + ) + ? removeTrailingForwardSlash(callerInfo.name) + : callerInfo.name; + + const baseAction = await getAction(callerInfoName); let input; try { input = await parseRequestBody(context.request); diff --git a/packages/astro/src/actions/runtime/virtual/shared.ts b/packages/astro/src/actions/runtime/virtual/shared.ts index 4067ad321dfd..36fb53c379bb 100644 --- a/packages/astro/src/actions/runtime/virtual/shared.ts +++ b/packages/astro/src/actions/runtime/virtual/shared.ts @@ -2,6 +2,7 @@ import { parse as devalueParse, stringify as devalueStringify } from 'devalue'; import type { z } from 'zod'; import { REDIRECT_STATUS_CODES } from '../../../core/constants.js'; import { ActionsReturnedInvalidDataError } from '../../../core/errors/errors-data.js'; +import { appendForwardSlash as _appendForwardSlash } from '../../../core/path.js'; import { AstroError } from '../../../core/errors/errors.js'; import { ACTION_QUERY_PARAMS as _ACTION_QUERY_PARAMS } from '../../consts.js'; import type { @@ -13,6 +14,8 @@ import type { export type ActionAPIContext = _ActionAPIContext; export const ACTION_QUERY_PARAMS = _ACTION_QUERY_PARAMS; +export const appendForwardSlash = _appendForwardSlash; + export const ACTION_ERROR_CODES = [ 'BAD_REQUEST', 'UNAUTHORIZED', diff --git a/packages/astro/templates/actions.mjs b/packages/astro/templates/actions.mjs index 82a287448a22..e7343448b487 100644 --- a/packages/astro/templates/actions.mjs +++ b/packages/astro/templates/actions.mjs @@ -1,4 +1,9 @@ -import { ActionError, deserializeActionResult, getActionQueryString } from 'astro:actions'; +import { + ActionError, + deserializeActionResult, + getActionQueryString, + appendForwardSlash, +} from 'astro:actions'; const ENCODED_DOT = '%2E'; @@ -83,7 +88,15 @@ async function handleAction(param, path, context) { headers.set('Content-Length', '0'); } } - const rawResult = await fetch(`${import.meta.env.BASE_URL.replace(/\/$/, '')}/_actions/${path}`, { + + const shouldAppendTrailingSlash = '/** @TRAILING_SLASH@ **/'; + let actionPath = import.meta.env.BASE_URL.replace(/\/$/, '') + '/_actions/' + path; + + if (shouldAppendTrailingSlash) { + actionPath = appendForwardSlash(actionPath); + } + + const rawResult = await fetch(actionPath, { method: 'POST', body, headers, diff --git a/packages/astro/test/actions.test.js b/packages/astro/test/actions.test.js index d8da4e72e308..98e642102ec4 100644 --- a/packages/astro/test/actions.test.js +++ b/packages/astro/test/actions.test.js @@ -564,6 +564,30 @@ it('Base path should be used', async () => { await devServer.stop(); }); +it('Should support trailing slash', async () => { + const fixture = await loadFixture({ + root: './fixtures/actions/', + adapter: testAdapter(), + trailingSlash: "always" + }); + const devServer = await fixture.startDevServer(); + const formData = new FormData(); + formData.append('channel', 'bholmesdev'); + formData.append('comment', 'Hello, World!'); + const res = await fixture.fetch('/_actions/comment/', { + method: 'POST', + body: formData, + }); + + assert.equal(res.ok, true); + assert.equal(res.headers.get('Content-Type'), 'application/json+devalue'); + + const data = devalue.parse(await res.text()); + assert.equal(data.channel, 'bholmesdev'); + assert.equal(data.comment, 'Hello, World!'); + await devServer.stop(); +}); + /** * Follow an expected redirect response. * From eef4b740ffe56b167188fd1723b73a2a327d4640 Mon Sep 17 00:00:00 2001 From: Magomed Chabaev Date: Wed, 11 Dec 2024 16:07:47 +0000 Subject: [PATCH 15/26] [ci] format --- packages/astro/src/actions/plugins.ts | 2 +- packages/astro/src/actions/runtime/virtual/server.ts | 6 +++--- packages/astro/src/actions/runtime/virtual/shared.ts | 2 +- packages/astro/templates/actions.mjs | 2 +- packages/astro/test/actions.test.js | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/astro/src/actions/plugins.ts b/packages/astro/src/actions/plugins.ts index c97e3ea83573..f5bd074dfcca 100644 --- a/packages/astro/src/actions/plugins.ts +++ b/packages/astro/src/actions/plugins.ts @@ -1,7 +1,7 @@ import type fsMod from 'node:fs'; import type { Plugin as VitePlugin } from 'vite'; -import type { AstroSettings } from '../types/astro.js'; import { shouldAppendForwardSlash } from '../core/build/util.js'; +import type { AstroSettings } from '../types/astro.js'; import { NOOP_ACTIONS, RESOLVED_VIRTUAL_INTERNAL_MODULE_ID, diff --git a/packages/astro/src/actions/runtime/virtual/server.ts b/packages/astro/src/actions/runtime/virtual/server.ts index 8005c4d56a06..10624134b2cb 100644 --- a/packages/astro/src/actions/runtime/virtual/server.ts +++ b/packages/astro/src/actions/runtime/virtual/server.ts @@ -1,10 +1,10 @@ import { z } from 'zod'; -import { ActionCalledFromServerError } from '../../../core/errors/errors-data.js'; -import { AstroError } from '../../../core/errors/errors.js'; import type { Pipeline } from '../../../core/base-pipeline.js'; -import { apiContextRoutesSymbol } from '../../../core/render-context.js'; import { shouldAppendForwardSlash } from '../../../core/build/util.js'; +import { ActionCalledFromServerError } from '../../../core/errors/errors-data.js'; +import { AstroError } from '../../../core/errors/errors.js'; import { removeTrailingForwardSlash } from '../../../core/path.js'; +import { apiContextRoutesSymbol } from '../../../core/render-context.js'; import type { APIContext } from '../../../types/public/index.js'; import { ACTION_RPC_ROUTE_PATTERN } from '../../consts.js'; import { diff --git a/packages/astro/src/actions/runtime/virtual/shared.ts b/packages/astro/src/actions/runtime/virtual/shared.ts index 36fb53c379bb..02cc07b52cd6 100644 --- a/packages/astro/src/actions/runtime/virtual/shared.ts +++ b/packages/astro/src/actions/runtime/virtual/shared.ts @@ -2,8 +2,8 @@ import { parse as devalueParse, stringify as devalueStringify } from 'devalue'; import type { z } from 'zod'; import { REDIRECT_STATUS_CODES } from '../../../core/constants.js'; import { ActionsReturnedInvalidDataError } from '../../../core/errors/errors-data.js'; -import { appendForwardSlash as _appendForwardSlash } from '../../../core/path.js'; import { AstroError } from '../../../core/errors/errors.js'; +import { appendForwardSlash as _appendForwardSlash } from '../../../core/path.js'; import { ACTION_QUERY_PARAMS as _ACTION_QUERY_PARAMS } from '../../consts.js'; import type { ErrorInferenceObject, diff --git a/packages/astro/templates/actions.mjs b/packages/astro/templates/actions.mjs index e7343448b487..93aaa4d76262 100644 --- a/packages/astro/templates/actions.mjs +++ b/packages/astro/templates/actions.mjs @@ -1,8 +1,8 @@ import { ActionError, + appendForwardSlash, deserializeActionResult, getActionQueryString, - appendForwardSlash, } from 'astro:actions'; const ENCODED_DOT = '%2E'; diff --git a/packages/astro/test/actions.test.js b/packages/astro/test/actions.test.js index 98e642102ec4..2af8ebdd97fb 100644 --- a/packages/astro/test/actions.test.js +++ b/packages/astro/test/actions.test.js @@ -568,7 +568,7 @@ it('Should support trailing slash', async () => { const fixture = await loadFixture({ root: './fixtures/actions/', adapter: testAdapter(), - trailingSlash: "always" + trailingSlash: 'always', }); const devServer = await fixture.startDevServer(); const formData = new FormData(); From 358eae83b7cf3d79395eea3824e321b502522547 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Thu, 12 Dec 2024 10:29:18 +0000 Subject: [PATCH 16/26] chore: fixes the version of astrojs/db (#12719) --- .changeset/hip-kids-ring.md | 5 +++++ packages/db/package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/hip-kids-ring.md diff --git a/.changeset/hip-kids-ring.md b/.changeset/hip-kids-ring.md new file mode 100644 index 000000000000..5dc22c5b8ea3 --- /dev/null +++ b/.changeset/hip-kids-ring.md @@ -0,0 +1,5 @@ +--- +'@astrojs/db': patch +--- + +Fixes the publishing of the package diff --git a/packages/db/package.json b/packages/db/package.json index 7bac47649a82..16b9b17216f7 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/db", - "version": "0.14.1", + "version": "0.14.3", "description": "Add libSQL and Astro Studio support to your Astro site", "license": "MIT", "repository": { From e3bfd9396969caf35b3b05135539e82aab560c92 Mon Sep 17 00:00:00 2001 From: mtwilliams Date: Thu, 12 Dec 2024 08:29:46 -0500 Subject: [PATCH 17/26] fix(i18n): parse params and props correctly with fallback (#12709) Co-authored-by: Emanuele Stoppa --- .changeset/selfish-paws-play.md | 5 ++ .../astro/src/core/render/params-and-props.ts | 9 ++- .../src/pages/blog/[id].astro | 16 +++- .../src/pages/pt/blog/[id].astro | 10 ++- packages/astro/test/i18n-routing.test.js | 74 ++++++++++++++++++- 5 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 .changeset/selfish-paws-play.md diff --git a/.changeset/selfish-paws-play.md b/.changeset/selfish-paws-play.md new file mode 100644 index 000000000000..6f0e3049b297 --- /dev/null +++ b/.changeset/selfish-paws-play.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a bug where Astro couldn't correctly parse `params` and `props` when receiving i18n fallback URLs diff --git a/packages/astro/src/core/render/params-and-props.ts b/packages/astro/src/core/render/params-and-props.ts index c1fe318cebd3..f8799115b0bc 100644 --- a/packages/astro/src/core/render/params-and-props.ts +++ b/packages/astro/src/core/render/params-and-props.ts @@ -47,7 +47,8 @@ export async function getProps(opts: GetParamsAndPropsOptions): Promise { base, }); - // The pathname used here comes from the server, which already encored. + if (!staticPaths.length) return {}; + // The pathname used here comes from the server, which already encoded. // Since we decided to not mess up with encoding anymore, we need to decode them back so the parameters can match // the ones expected from the users const params = getParams(route, decodeURI(pathname)); @@ -77,7 +78,11 @@ export function getParams(route: RouteData, pathname: string): Params { if (!route.params.length) return {}; // The RegExp pattern expects a decoded string, but the pathname is encoded // when the URL contains non-English characters. - const paramsMatch = route.pattern.exec(pathname); + const paramsMatch = + route.pattern.exec(pathname) || + route.fallbackRoutes + .map((fallbackRoute) => fallbackRoute.pattern.exec(pathname)) + .find((x) => x); if (!paramsMatch) return {}; const params: Params = {}; route.params.forEach((key, i) => { diff --git a/packages/astro/test/fixtures/i18n-routing-fallback/src/pages/blog/[id].astro b/packages/astro/test/fixtures/i18n-routing-fallback/src/pages/blog/[id].astro index 97b41230d6e9..f277b93efe23 100644 --- a/packages/astro/test/fixtures/i18n-routing-fallback/src/pages/blog/[id].astro +++ b/packages/astro/test/fixtures/i18n-routing-fallback/src/pages/blog/[id].astro @@ -1,18 +1,28 @@ --- +// for SSR +const blogs = { + 1: { content: "Hello world" }, + 2: { content: "Eat Something" }, + 3: { content: "How are you?" }, +} +const id = Astro.params?.id; +const ssrContent = id && blogs[id]?.content; + +// for SSG export function getStaticPaths() { return [ {params: {id: '1'}, props: { content: "Hello world" }}, {params: {id: '2'}, props: { content: "Eat Something" }}, {params: {id: '3'}, props: { content: "How are you?" }}, - ]; + ] } -const { content } = Astro.props; +const { content } = Astro.props --- Astro -{content} +{content || ssrContent} diff --git a/packages/astro/test/fixtures/i18n-routing-fallback/src/pages/pt/blog/[id].astro b/packages/astro/test/fixtures/i18n-routing-fallback/src/pages/pt/blog/[id].astro index e37f83a30243..ed4415fc5beb 100644 --- a/packages/astro/test/fixtures/i18n-routing-fallback/src/pages/pt/blog/[id].astro +++ b/packages/astro/test/fixtures/i18n-routing-fallback/src/pages/pt/blog/[id].astro @@ -1,4 +1,12 @@ --- +const blogs = { + 1: { content: "Hola mundo" }, + 2: { content: "Eat Something" }, + 3: { content: "How are you?" }, +} +const id = Astro.params?.id; +const ssrContent = id && blogs[id]?.content; + export function getStaticPaths() { return [ {params: {id: '1'}, props: { content: "Hola mundo" }}, @@ -13,6 +21,6 @@ const { content } = Astro.props; Astro -{content} +{content || ssrContent} diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index 441823fc7a7d..28f4b05f8038 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -1,6 +1,6 @@ +import * as cheerio from 'cheerio'; import * as assert from 'node:assert/strict'; import { after, afterEach, before, describe, it } from 'node:test'; -import * as cheerio from 'cheerio'; import testAdapter from './test-adapter.js'; import { loadFixture } from './test-utils.js'; @@ -2000,12 +2000,14 @@ describe('Fallback rewrite dev server', () => { root: './fixtures/i18n-routing-fallback/', i18n: { defaultLocale: 'en', - locales: ['en', 'fr'], + locales: ['en', 'fr', 'es', 'it', 'pt'], routing: { prefixDefaultLocale: false, }, fallback: { fr: 'en', + it: 'en', + es: 'pt', }, fallbackType: 'rewrite', }, @@ -2021,6 +2023,27 @@ describe('Fallback rewrite dev server', () => { assert.match(html, /Hello/); // assert.fail() }); + + it('should render fallback locale paths with path parameters correctly (fr)', async () => { + let response = await fixture.fetch('/fr/blog/1'); + assert.equal(response.status, 200); + const text = await response.text(); + assert.match(text, /Hello world/); + }); + + it('should render fallback locale paths with path parameters correctly (es)', async () => { + let response = await fixture.fetch('/es/blog/1'); + assert.equal(response.status, 200); + const text = await response.text(); + assert.match(text, /Hola mundo/); + }); + + it('should render fallback locale paths with query parameters correctly (it)', async () => { + let response = await fixture.fetch('/it/blog/1'); + assert.equal(response.status, 200); + const text = await response.text(); + assert.match(text, /Hello world/); + }); }); describe('Fallback rewrite SSG', () => { @@ -2032,13 +2055,15 @@ describe('Fallback rewrite SSG', () => { root: './fixtures/i18n-routing-fallback/', i18n: { defaultLocale: 'en', - locales: ['en', 'fr'], + locales: ['en', 'fr', 'es', 'it', 'pt'], routing: { prefixDefaultLocale: false, fallbackType: 'rewrite', }, fallback: { fr: 'en', + it: 'en', + es: 'pt', }, }, }); @@ -2051,6 +2076,21 @@ describe('Fallback rewrite SSG', () => { assert.match(html, /Hello/); // assert.fail() }); + + it('should render fallback locale paths with path parameters correctly (fr)', async () => { + const html = await fixture.readFile('/fr/blog/1/index.html'); + assert.match(html, /Hello world/); + }); + + it('should render fallback locale paths with path parameters correctly (es)', async () => { + const html = await fixture.readFile('/es/blog/1/index.html'); + assert.match(html, /Hola mundo/); + }); + + it('should render fallback locale paths with query parameters correctly (it)', async () => { + const html = await fixture.readFile('/it/blog/1/index.html'); + assert.match(html, /Hello world/); + }); }); describe('Fallback rewrite SSR', () => { @@ -2066,13 +2106,15 @@ describe('Fallback rewrite SSR', () => { adapter: testAdapter(), i18n: { defaultLocale: 'en', - locales: ['en', 'fr'], + locales: ['en', 'fr', 'es', 'it', 'pt'], routing: { prefixDefaultLocale: false, fallbackType: 'rewrite', }, fallback: { fr: 'en', + it: 'en', + es: 'pt', }, }, }); @@ -2087,4 +2129,28 @@ describe('Fallback rewrite SSR', () => { const html = await response.text(); assert.match(html, /Hello/); }); + + it('should render fallback locale paths with path parameters correctly (fr)', async () => { + let request = new Request('http://example.com/new-site/fr/blog/1'); + let response = await app.render(request); + assert.equal(response.status, 200); + const text = await response.text(); + assert.match(text, /Hello world/); + }); + + it('should render fallback locale paths with path parameters correctly (es)', async () => { + let request = new Request('http://example.com/new-site/es/blog/1'); + let response = await app.render(request); + assert.equal(response.status, 200); + const text = await response.text(); + assert.match(text, /Hola mundo/); + }); + + it('should render fallback locale paths with query parameters correctly (it)', async () => { + let request = new Request('http://example.com/new-site/it/blog/1'); + let response = await app.render(request); + assert.equal(response.status, 200); + const text = await response.text(); + assert.match(text, /Hello world/); + }); }); From 799c8676dfba0d281faf2a3f2d9513518b57593b Mon Sep 17 00:00:00 2001 From: mtwilliams Date: Thu, 12 Dec 2024 13:30:38 +0000 Subject: [PATCH 18/26] [ci] format --- packages/astro/test/i18n-routing.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index 28f4b05f8038..27491069d37c 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import * as assert from 'node:assert/strict'; import { after, afterEach, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import testAdapter from './test-adapter.js'; import { loadFixture } from './test-utils.js'; From 029661daa9b28fd5299d8cc9360025c78f6cd8eb Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Fri, 13 Dec 2024 07:07:21 +0000 Subject: [PATCH 19/26] fix: use atomic writes for data store file operations (#12715) * fix: use atomic writes for data store file operations * Put tmp alongside the target * Implement locking * Refactor * Wording --- .changeset/tame-bags-remember.md | 5 ++ .../astro/src/content/mutable-data-store.ts | 48 +++++++++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 .changeset/tame-bags-remember.md diff --git a/.changeset/tame-bags-remember.md b/.changeset/tame-bags-remember.md new file mode 100644 index 000000000000..3f4f61bce750 --- /dev/null +++ b/.changeset/tame-bags-remember.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a bug that caused errors in dev when editing sites with large numbers of MDX pages diff --git a/packages/astro/src/content/mutable-data-store.ts b/packages/astro/src/content/mutable-data-store.ts index fdffec7cb8cc..573adeaaf963 100644 --- a/packages/astro/src/content/mutable-data-store.ts +++ b/packages/astro/src/content/mutable-data-store.ts @@ -9,6 +9,8 @@ import { contentModuleToId } from './utils.js'; const SAVE_DEBOUNCE_MS = 500; +const MAX_DEPTH = 10; + /** * Extends the DataStore with the ability to change entries and write them to disk. * This is kept as a separate class to avoid needing node builtins at runtime, when read-only access is all that is needed. @@ -86,7 +88,7 @@ export class MutableDataStore extends ImmutableDataStore { if (this.#assetImports.size === 0) { try { - await fs.writeFile(filePath, 'export default new Map();'); + await this.#writeFileAtomic(filePath, 'export default new Map();'); } catch (err) { throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err }); } @@ -110,7 +112,7 @@ ${imports.join('\n')} export default new Map([${exports.join(', ')}]); `; try { - await fs.writeFile(filePath, code); + await this.#writeFileAtomic(filePath, code); } catch (err) { throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err }); } @@ -122,7 +124,7 @@ export default new Map([${exports.join(', ')}]); if (this.#moduleImports.size === 0) { try { - await fs.writeFile(filePath, 'export default new Map();'); + await this.#writeFileAtomic(filePath, 'export default new Map();'); } catch (err) { throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err }); } @@ -143,7 +145,7 @@ export default new Map([${exports.join(', ')}]); export default new Map([\n${lines.join(',\n')}]); `; try { - await fs.writeFile(filePath, code); + await this.#writeFileAtomic(filePath, code); } catch (err) { throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err }); } @@ -190,6 +192,42 @@ export default new Map([\n${lines.join(',\n')}]); } } + #writing = new Set(); + #pending = new Set(); + + async #writeFileAtomic(filePath: PathLike, data: string, depth = 0) { + if(depth > MAX_DEPTH) { + // If we hit the max depth, we skip a write to prevent the stack from growing too large + // In theory this means we may miss the latest data, but in practice this will only happen when the file is being written to very frequently + // so it will be saved on the next write. This is unlikely to ever happen in practice, as the writes are debounced. It requires lots of writes to very large files. + return; + } + const fileKey = filePath.toString(); + // If we are already writing this file, instead of writing now, flag it as pending and write it when we're done. + if (this.#writing.has(fileKey)) { + this.#pending.add(fileKey); + return; + } + // Prevent concurrent writes to this file by flagging it as being written + this.#writing.add(fileKey); + + const tempFile = filePath instanceof URL ? new URL(`${filePath.href}.tmp`) : `${filePath}.tmp`; + try { + // Write it to a temporary file first and then move it to prevent partial reads. + await fs.writeFile(tempFile, data); + await fs.rename(tempFile, filePath); + } finally { + // We're done writing. Unflag the file and check if there are any pending writes for this file. + this.#writing.delete(fileKey); + // If there are pending writes, we need to write again to ensure we flush the latest data. + if (this.#pending.has(fileKey)) { + this.#pending.delete(fileKey); + // Call ourself recursively to write the file again + await this.#writeFileAtomic(filePath, data, depth + 1); + } + } + } + scopedStore(collectionName: string): DataStore { return { get: = Record>(key: string) => @@ -298,7 +336,7 @@ export default new Map([\n${lines.join(',\n')}]); return; } try { - await fs.writeFile(filePath, this.toString()); + await this.#writeFileAtomic(filePath, this.toString()); this.#file = filePath; this.#dirty = false; } catch (err) { From 72f30ddbf3febbf0d60896af4073ffc596ac9eef Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Fri, 13 Dec 2024 07:08:08 +0000 Subject: [PATCH 20/26] [ci] format --- packages/astro/src/content/mutable-data-store.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/content/mutable-data-store.ts b/packages/astro/src/content/mutable-data-store.ts index 573adeaaf963..7f125ed4b4d3 100644 --- a/packages/astro/src/content/mutable-data-store.ts +++ b/packages/astro/src/content/mutable-data-store.ts @@ -196,7 +196,7 @@ export default new Map([\n${lines.join(',\n')}]); #pending = new Set(); async #writeFileAtomic(filePath: PathLike, data: string, depth = 0) { - if(depth > MAX_DEPTH) { + if (depth > MAX_DEPTH) { // If we hit the max depth, we skip a write to prevent the stack from growing too large // In theory this means we may miss the latest data, but in practice this will only happen when the file is being written to very frequently // so it will be saved on the next write. This is unlikely to ever happen in practice, as the writes are debounced. It requires lots of writes to very large files. @@ -213,7 +213,7 @@ export default new Map([\n${lines.join(',\n')}]); const tempFile = filePath instanceof URL ? new URL(`${filePath.href}.tmp`) : `${filePath}.tmp`; try { - // Write it to a temporary file first and then move it to prevent partial reads. + // Write it to a temporary file first and then move it to prevent partial reads. await fs.writeFile(tempFile, data); await fs.rename(tempFile, filePath); } finally { From ee66a45b250703a40b34c0a45ae34aefcb14ea44 Mon Sep 17 00:00:00 2001 From: Adam Argyle Date: Fri, 13 Dec 2024 02:40:23 -0800 Subject: [PATCH 21/26] Adds `closedby` to dialog interface (#12728) * Adds `closedby` to dialog interface Standards status https://chromestatus.com/feature/5097714453577728 * Add changeset --------- Co-authored-by: Chris Swithinbank --- .changeset/neat-pumas-accept.md | 5 +++++ packages/astro/astro-jsx.d.ts | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changeset/neat-pumas-accept.md diff --git a/.changeset/neat-pumas-accept.md b/.changeset/neat-pumas-accept.md new file mode 100644 index 000000000000..8babf49e78ff --- /dev/null +++ b/.changeset/neat-pumas-accept.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Adds type support for the `closedby` attribute for `` elements diff --git a/packages/astro/astro-jsx.d.ts b/packages/astro/astro-jsx.d.ts index ca54b991ed5a..39cb40f61bd4 100644 --- a/packages/astro/astro-jsx.d.ts +++ b/packages/astro/astro-jsx.d.ts @@ -679,6 +679,7 @@ declare namespace astroHTML.JSX { interface DialogHTMLAttributes extends HTMLAttributes { open?: boolean | string | undefined | null; + closedby?: 'none' | 'closerequest' | 'any' | undefined | null; } interface EmbedHTMLAttributes extends HTMLAttributes { From 8b1cecd6b491654ae760a0c75f3270df134c4e25 Mon Sep 17 00:00:00 2001 From: JoeMorgan Date: Fri, 13 Dec 2024 08:59:02 -0500 Subject: [PATCH 22/26] Add inert attribute to boolean list (#12729) * added changeset * added changeset --- .changeset/twelve-donuts-hide.md | 5 +++++ packages/astro/src/runtime/server/render/util.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/twelve-donuts-hide.md diff --git a/.changeset/twelve-donuts-hide.md b/.changeset/twelve-donuts-hide.md new file mode 100644 index 000000000000..504d1b5bea41 --- /dev/null +++ b/.changeset/twelve-donuts-hide.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +"Added `inert` to htmlBooleanAttributes" diff --git a/packages/astro/src/runtime/server/render/util.ts b/packages/astro/src/runtime/server/render/util.ts index 9c771a0de02b..d693ad070f3a 100644 --- a/packages/astro/src/runtime/server/render/util.ts +++ b/packages/astro/src/runtime/server/render/util.ts @@ -7,7 +7,7 @@ import { HTMLString, markHTMLString } from '../escape.js'; export const voidElementNames = /^(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/i; const htmlBooleanAttributes = - /^(?:allowfullscreen|async|autofocus|autoplay|checked|controls|default|defer|disabled|disablepictureinpicture|disableremoteplayback|formnovalidate|hidden|loop|nomodule|novalidate|open|playsinline|readonly|required|reversed|scoped|seamless|selected|itemscope)$/i; + /^(?:allowfullscreen|async|autofocus|autoplay|checked|controls|default|defer|disabled|disablepictureinpicture|disableremoteplayback|formnovalidate|hidden|inert|loop|nomodule|novalidate|open|playsinline|readonly|required|reversed|scoped|seamless|selected|itemscope)$/i; const AMPERSAND_REGEX = /&/g; const DOUBLE_QUOTE_REGEX = /"/g; From 901c21f4f09bf61dfbb5ab04db2d7d90120383cb Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 13 Dec 2024 14:37:25 +0000 Subject: [PATCH 23/26] test: make tailwind test more stable (#12732) --- .../tailwind/test/fixtures/basic/tailwind.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/integrations/tailwind/test/fixtures/basic/tailwind.config.js b/packages/integrations/tailwind/test/fixtures/basic/tailwind.config.js index f1090968169a..278abf14d6a1 100644 --- a/packages/integrations/tailwind/test/fixtures/basic/tailwind.config.js +++ b/packages/integrations/tailwind/test/fixtures/basic/tailwind.config.js @@ -1,6 +1,7 @@ import path from 'node:path'; +import {fileURLToPath} from "node:url"; /** @type {import('tailwindcss').Config} */ export default { - content: [path.join(__dirname, 'src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}')], + content: [path.join(path.dirname(fileURLToPath(import.meta.url)), 'src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}')], }; From 7c7398c04653877da09c7b0f80ee84b02e02aad0 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Fri, 13 Dec 2024 16:37:08 +0100 Subject: [PATCH 24/26] fix(cli): let sync throw in check (#12726) --- .changeset/twenty-keys-divide.md | 5 +++++ packages/astro/src/cli/check/index.ts | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 .changeset/twenty-keys-divide.md diff --git a/.changeset/twenty-keys-divide.md b/.changeset/twenty-keys-divide.md new file mode 100644 index 000000000000..9e840586748e --- /dev/null +++ b/.changeset/twenty-keys-divide.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a case where failing content entries in `astro check` would not be surfaced diff --git a/packages/astro/src/cli/check/index.ts b/packages/astro/src/cli/check/index.ts index c93e3b2f4cff..b7e03aa30e76 100644 --- a/packages/astro/src/cli/check/index.ts +++ b/packages/astro/src/cli/check/index.ts @@ -31,11 +31,7 @@ export async function check(flags: Flags) { // NOTE: In the future, `@astrojs/check` can expose a `before lint` hook so that this works during `astro check --watch` too. // For now, we run this once as usually `astro check --watch` is ran alongside `astro dev` which also calls `astro sync`. const { default: sync } = await import('../../core/sync/index.js'); - try { - await sync(flagsToAstroInlineConfig(flags)); - } catch (_) { - return process.exit(1); - } + await sync(flagsToAstroInlineConfig(flags)); } const { check: checker, parseArgsAsCheckConfig } = checkPackage; From 564ac6c2f2d77ee34f8519f1e5a4db2c6e194f65 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Mon, 16 Dec 2024 15:52:54 +0100 Subject: [PATCH 25/26] feat: route manifest refactor (#12597) Co-authored-by: Emanuele Stoppa --- .changeset/empty-crews-scream.md | 5 +++++ packages/astro/src/assets/endpoint/config.ts | 11 ---------- packages/astro/src/core/app/index.ts | 10 +++++++--- packages/astro/src/core/build/index.ts | 9 +-------- packages/astro/src/core/build/page-data.ts | 6 ++++++ .../src/core/build/plugins/plugin-manifest.ts | 17 ++++++++++++++++ packages/astro/src/core/dev/container.ts | 7 +------ packages/astro/src/core/routing/default.ts | 17 ++++------------ .../astro/src/core/routing/dev-default.ts | 14 ------------- .../astro/src/core/routing/manifest/create.ts | 20 +++++++++++++++++-- .../astro/src/core/server-islands/endpoint.ts | 6 +----- .../src/vite-plugin-astro-server/plugin.ts | 9 ++------- .../astro/test/units/routing/manifest.test.js | 18 +++++++++++++++++ 13 files changed, 80 insertions(+), 69 deletions(-) create mode 100644 .changeset/empty-crews-scream.md delete mode 100644 packages/astro/src/core/routing/dev-default.ts diff --git a/.changeset/empty-crews-scream.md b/.changeset/empty-crews-scream.md new file mode 100644 index 000000000000..c52237ab8cc3 --- /dev/null +++ b/.changeset/empty-crews-scream.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue where image and server islands routes would not be passed to the `astro:routes:resolved` hook during builds diff --git a/packages/astro/src/assets/endpoint/config.ts b/packages/astro/src/assets/endpoint/config.ts index cce5cde5fc37..b59bdc626b9a 100644 --- a/packages/astro/src/assets/endpoint/config.ts +++ b/packages/astro/src/assets/endpoint/config.ts @@ -16,17 +16,6 @@ export function injectImageEndpoint( manifest.routes.unshift(getImageEndpointData(settings, mode, cwd)); } -export function ensureImageEndpointRoute( - settings: AstroSettings, - manifest: ManifestData, - mode: 'dev' | 'build', - cwd?: string, -) { - if (!manifest.routes.some((route) => route.route === settings.config.image.endpoint.route)) { - manifest.routes.unshift(getImageEndpointData(settings, mode, cwd)); - } -} - function getImageEndpointData( settings: AstroSettings, mode: 'dev' | 'build', diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index d23383133e05..a3d08bb642e9 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -20,7 +20,8 @@ import { } from '../path.js'; import { RenderContext } from '../render-context.js'; import { createAssetLink } from '../render/ssr-element.js'; -import { createDefaultRoutes, injectDefaultRoutes } from '../routing/default.js'; +import { ensure404Route } from '../routing/astro-designed-error-pages.js'; +import { createDefaultRoutes } from '../routing/default.js'; import { matchRoute } from '../routing/match.js'; import { AppPipeline } from './pipeline.js'; @@ -88,9 +89,12 @@ export class App { constructor(manifest: SSRManifest, streaming = true) { this.#manifest = manifest; - this.#manifestData = injectDefaultRoutes(manifest, { + this.#manifestData = { routes: manifest.routes.map((route) => route.routeData), - }); + }; + // This is necessary to allow running middlewares for 404 in SSR. There's special handling + // to return the host 404 if the user doesn't provide a custom 404 + ensure404Route(this.#manifestData); this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#manifest.base); this.#pipeline = this.#createPipeline(this.#manifestData, streaming); this.#adapterLogger = new AstroIntegrationLogger( diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 68cf650acd0c..bcc7fb96d56d 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -3,7 +3,6 @@ import { performance } from 'node:perf_hooks'; import { fileURLToPath } from 'node:url'; import { blue, bold, green } from 'kleur/colors'; import type * as vite from 'vite'; -import { injectImageEndpoint } from '../../assets/endpoint/config.js'; import { telemetry } from '../../events/index.js'; import { eventCliSession } from '../../events/session.js'; import { @@ -24,7 +23,6 @@ import type { Logger } from '../logger/core.js'; import { levels, timerMessage } from '../logger/core.js'; import { apply as applyPolyfill } from '../polyfill.js'; import { createRouteManifest } from '../routing/index.js'; -import { getServerIslandRouteData } from '../server-islands/endpoint.js'; import { clearContentLayerCache } from '../sync/index.js'; import { ensureProcessNodeEnv } from '../util.js'; import { collectPagesData } from './page-data.js'; @@ -123,10 +121,6 @@ class AstroBuilder { this.manifest = await createRouteManifest({ settings: this.settings }, this.logger); - if (this.settings.buildOutput === 'server') { - injectImageEndpoint(this.settings, this.manifest, 'build'); - } - await runHookConfigDone({ settings: this.settings, logger: logger, command: 'build' }); // If we're building for the server, we need to ensure that an adapter is installed. @@ -239,8 +233,7 @@ class AstroBuilder { pages: pageNames, routes: Object.values(allPages) .flat() - .map((pageData) => pageData.route) - .concat(hasServerIslands ? getServerIslandRouteData(this.settings.config) : []), + .map((pageData) => pageData.route), logging: this.logger, }); diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts index c36fe0d57b29..59806be58422 100644 --- a/packages/astro/src/core/build/page-data.ts +++ b/packages/astro/src/core/build/page-data.ts @@ -5,6 +5,7 @@ import type { AllPagesData } from './types.js'; import * as colors from 'kleur/colors'; import { debug } from '../logger/core.js'; import { makePageDataKey } from './plugins/util.js'; +import { DEFAULT_COMPONENTS } from '../routing/default.js'; export interface CollectPagesDataOptions { settings: AstroSettings; @@ -29,6 +30,11 @@ export function collectPagesData(opts: CollectPagesDataOptions): CollectPagesDat // and is then cached across all future SSR builds. In the past, we've had trouble // with parallelized builds without guaranteeing that this is called first. for (const route of manifest.routes) { + // There's special handling in SSR + if (DEFAULT_COMPONENTS.some((component) => route.component === component)) { + continue; + } + // Generate a unique key to identify each page in the build process. const key = makePageDataKey(route.route, route.component); // static route: diff --git a/packages/astro/src/core/build/plugins/plugin-manifest.ts b/packages/astro/src/core/build/plugins/plugin-manifest.ts index f0589868f72c..a3bd6239a4ed 100644 --- a/packages/astro/src/core/build/plugins/plugin-manifest.ts +++ b/packages/astro/src/core/build/plugins/plugin-manifest.ts @@ -21,6 +21,7 @@ import { type BuildInternals, cssOrder, mergeInlineCss } from '../internal.js'; import type { AstroBuildPlugin } from '../plugin.js'; import type { StaticBuildOptions } from '../types.js'; import { makePageDataKey } from './util.js'; +import { DEFAULT_COMPONENTS } from '../../routing/default.js'; const manifestReplace = '@@ASTRO_MANIFEST_REPLACE@@'; const replaceExp = new RegExp(`['"]${manifestReplace}['"]`, 'g'); @@ -172,6 +173,22 @@ function buildManifest( } }; + // Default components follow a special flow during build. We prevent their processing earlier + // in the build. As a result, they are not present on `internals.pagesByKeys` and not serialized + // in the manifest file. But we need them in the manifest, so we handle them here + for (const route of opts.manifest.routes) { + if (!DEFAULT_COMPONENTS.find((component) => route.component === component)) { + continue; + } + routes.push({ + file: '', + links: [], + scripts: [], + styles: [], + routeData: serializeRouteData(route, settings.config.trailingSlash), + }); + } + for (const route of opts.manifest.routes) { if (!route.prerender) continue; if (!route.pathname) continue; diff --git a/packages/astro/src/core/dev/container.ts b/packages/astro/src/core/dev/container.ts index 063681f2717c..3484227afb9b 100644 --- a/packages/astro/src/core/dev/container.ts +++ b/packages/astro/src/core/dev/container.ts @@ -7,7 +7,6 @@ import * as vite from 'vite'; import { runHookConfigDone, runHookConfigSetup, - runHookRoutesResolved, runHookServerDone, runHookServerStart, } from '../../integrations/hooks.js'; @@ -16,7 +15,6 @@ import { createDevelopmentManifest } from '../../vite-plugin-astro-server/plugin import { createVite } from '../create-vite.js'; import type { Logger } from '../logger/core.js'; import { apply as applyPolyfill } from '../polyfill.js'; -import { injectDefaultDevRoutes } from '../routing/dev-default.js'; import { createRouteManifest } from '../routing/index.js'; import { syncInternal } from '../sync/index.js'; import { warnMissingAdapter } from './adapter-validation.js'; @@ -84,12 +82,9 @@ export async function createContainer({ .filter(Boolean) as string[]; // Create the route manifest already outside of Vite so that `runHookConfigDone` can use it to inform integrations of the build output - let manifest = await createRouteManifest({ settings, fsMod: fs }, logger, { dev: true }); + const manifest = await createRouteManifest({ settings, fsMod: fs }, logger, { dev: true }); const devSSRManifest = createDevelopmentManifest(settings); - manifest = injectDefaultDevRoutes(settings, devSSRManifest, manifest); - await runHookRoutesResolved({ settings, logger, routes: manifest.routes }); - await runHookConfigDone({ settings, logger, command: 'dev' }); warnMissingAdapter(logger, settings); diff --git a/packages/astro/src/core/routing/default.ts b/packages/astro/src/core/routing/default.ts index 8bcd473d0081..d255b13275f2 100644 --- a/packages/astro/src/core/routing/default.ts +++ b/packages/astro/src/core/routing/default.ts @@ -1,23 +1,12 @@ -import type { ComponentInstance, ManifestData } from '../../types/astro.js'; +import type { ComponentInstance } from '../../types/astro.js'; import type { SSRManifest } from '../app/types.js'; import { DEFAULT_404_COMPONENT } from '../constants.js'; import { SERVER_ISLAND_COMPONENT, SERVER_ISLAND_ROUTE, createEndpoint as createServerIslandEndpoint, - ensureServerIslandRoute, } from '../server-islands/endpoint.js'; -import { - DEFAULT_404_ROUTE, - default404Instance, - ensure404Route, -} from './astro-designed-error-pages.js'; - -export function injectDefaultRoutes(ssrManifest: SSRManifest, routeManifest: ManifestData) { - ensure404Route(routeManifest); - ensureServerIslandRoute(ssrManifest, routeManifest); - return routeManifest; -} +import { DEFAULT_404_ROUTE, default404Instance } from './astro-designed-error-pages.js'; type DefaultRouteParams = { instance: ComponentInstance; @@ -26,6 +15,8 @@ type DefaultRouteParams = { component: string; }; +export const DEFAULT_COMPONENTS = [DEFAULT_404_COMPONENT, SERVER_ISLAND_COMPONENT]; + export function createDefaultRoutes(manifest: SSRManifest): DefaultRouteParams[] { const root = new URL(manifest.hrefRoot); return [ diff --git a/packages/astro/src/core/routing/dev-default.ts b/packages/astro/src/core/routing/dev-default.ts deleted file mode 100644 index ac2ea1d3b03b..000000000000 --- a/packages/astro/src/core/routing/dev-default.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ensureImageEndpointRoute } from '../../assets/endpoint/config.js'; -import type { AstroSettings, ManifestData } from '../../types/astro.js'; -import type { SSRManifest } from '../app/types.js'; -import { injectDefaultRoutes } from './default.js'; - -export function injectDefaultDevRoutes( - settings: AstroSettings, - ssrManifest: SSRManifest, - routeManifest: ManifestData, -) { - ensureImageEndpointRoute(settings, routeManifest, 'dev'); - injectDefaultRoutes(ssrManifest, routeManifest); - return routeManifest; -} diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index 6dbcf18aee68..15d137286955 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -21,6 +21,9 @@ import { routeComparator } from '../priority.js'; import { getRouteGenerator } from './generator.js'; import { getPattern } from './pattern.js'; import { getRoutePrerenderOption } from './prerender.js'; +import { ensure404Route } from '../astro-designed-error-pages.js'; +import { injectImageEndpoint } from '../../../assets/endpoint/config.js'; +import { injectServerIslandRoute } from '../../server-islands/endpoint.js'; const require = createRequire(import.meta.url); interface Item { @@ -732,9 +735,22 @@ export async function createRouteManifest( } } - if (!dev) { - await runHookRoutesResolved({ routes, settings, logger }); + if (dev) { + // In SSR, a 404 route is injected in the App directly for some special handling, + // it must not appear in the manifest + ensure404Route({ routes }); } + if (dev || settings.buildOutput === 'server') { + injectImageEndpoint(settings, { routes }, dev ? 'dev' : 'build'); + // Ideally we would only inject the server islands route if server islands are used in the project. + // Unforunately, there is a "circular dependency": to know if server islands are used, we need to run + // the build but the build relies on the routes manifest. + // This situation also means we cannot update the buildOutput based on wether or not server islands + // are used in the project. If server islands are detected after the build but the buildOutput is + // static, we fail the build. + injectServerIslandRoute(settings.config, { routes }); + } + await runHookRoutesResolved({ routes, settings, logger }); return { routes, diff --git a/packages/astro/src/core/server-islands/endpoint.ts b/packages/astro/src/core/server-islands/endpoint.ts index ca24b54af4b9..5afdde651b7d 100644 --- a/packages/astro/src/core/server-islands/endpoint.ts +++ b/packages/astro/src/core/server-islands/endpoint.ts @@ -37,11 +37,7 @@ export function getServerIslandRouteData(config: ConfigFields) { return route; } -export function ensureServerIslandRoute(config: ConfigFields, routeManifest: ManifestData) { - if (routeManifest.routes.some((route) => route.route === '/_server-islands/[name]')) { - return; - } - +export function injectServerIslandRoute(config: ConfigFields, routeManifest: ManifestData) { routeManifest.routes.unshift(getServerIslandRouteData(config)); } diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts index b706f967d3e8..7e4a7169d5b8 100644 --- a/packages/astro/src/vite-plugin-astro-server/plugin.ts +++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts @@ -13,7 +13,6 @@ import { patchOverlay } from '../core/errors/overlay.js'; import type { Logger } from '../core/logger/core.js'; import { NOOP_MIDDLEWARE_FN } from '../core/middleware/noop-middleware.js'; import { createViteLoader } from '../core/module-loader/index.js'; -import { injectDefaultDevRoutes } from '../core/routing/dev-default.js'; import { createRouteManifest } from '../core/routing/index.js'; import { getRoutePrerenderOption } from '../core/routing/manifest/prerender.js'; import { toFallbackType, toRoutingStrategy } from '../i18n/utils.js'; @@ -74,15 +73,11 @@ export default function createVitePluginAstroServer({ try { const content = await fsMod.promises.readFile(routePath, 'utf-8'); await getRoutePrerenderOption(content, route, settings, logger); + await runHookRoutesResolved({ routes: routeManifest.routes, settings, logger }); } catch (_) {} } else { - routeManifest = injectDefaultDevRoutes( - settings, - devSSRManifest, - await createRouteManifest({ settings, fsMod }, logger, { dev: true }), - ); + routeManifest = await createRouteManifest({ settings, fsMod }, logger, { dev: true }); } - await runHookRoutesResolved({ routes: routeManifest.routes, settings, logger }); warnMissingAdapter(logger, settings); pipeline.manifest.checkOrigin = diff --git a/packages/astro/test/units/routing/manifest.test.js b/packages/astro/test/units/routing/manifest.test.js index d4f9f2514901..a981b8719c0d 100644 --- a/packages/astro/test/units/routing/manifest.test.js +++ b/packages/astro/test/units/routing/manifest.test.js @@ -260,6 +260,14 @@ describe('routing - createRouteManifest', () => { }); assert.deepEqual(getManifestRoutes(manifest), [ + { + route: '/_server-islands/[name]', + type: 'page', + }, + { + route: '/_image', + type: 'endpoint', + }, { route: '/blog/[...slug]', type: 'page', @@ -306,6 +314,14 @@ describe('routing - createRouteManifest', () => { }); assert.deepEqual(getManifestRoutes(manifest), [ + { + route: '/_server-islands/[name]', + type: 'page', + }, + { + route: '/_image', + type: 'endpoint', + }, { route: '/blog/about', type: 'redirect', @@ -441,6 +457,8 @@ describe('routing - createRouteManifest', () => { }); assert.deepEqual(getManifestRoutes(manifest), [ + { type: 'page', route: '/_server-islands/[name]' }, + { type: 'endpoint', route: '/_image' }, { type: 'endpoint', route: '/blog/a-[b].233' }, { type: 'redirect', route: '/posts/a-[b].233' }, { type: 'page', route: '/[c]-d' }, From 25c1e597f1e0f460351c2201a6bc46a77a417968 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Mon, 16 Dec 2024 14:53:44 +0000 Subject: [PATCH 26/26] [ci] format --- packages/astro/src/core/build/page-data.ts | 2 +- packages/astro/src/core/build/plugins/plugin-manifest.ts | 2 +- packages/astro/src/core/routing/manifest/create.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts index 59806be58422..fc33067d07ba 100644 --- a/packages/astro/src/core/build/page-data.ts +++ b/packages/astro/src/core/build/page-data.ts @@ -4,8 +4,8 @@ import type { AllPagesData } from './types.js'; import * as colors from 'kleur/colors'; import { debug } from '../logger/core.js'; -import { makePageDataKey } from './plugins/util.js'; import { DEFAULT_COMPONENTS } from '../routing/default.js'; +import { makePageDataKey } from './plugins/util.js'; export interface CollectPagesDataOptions { settings: AstroSettings; diff --git a/packages/astro/src/core/build/plugins/plugin-manifest.ts b/packages/astro/src/core/build/plugins/plugin-manifest.ts index a3bd6239a4ed..e220292ebf14 100644 --- a/packages/astro/src/core/build/plugins/plugin-manifest.ts +++ b/packages/astro/src/core/build/plugins/plugin-manifest.ts @@ -14,6 +14,7 @@ import type { } from '../../app/types.js'; import { encodeKey } from '../../encryption.js'; import { fileExtension, joinPaths, prependForwardSlash } from '../../path.js'; +import { DEFAULT_COMPONENTS } from '../../routing/default.js'; import { serializeRouteData } from '../../routing/index.js'; import { addRollupInput } from '../add-rollup-input.js'; import { getOutFile, getOutFolder } from '../common.js'; @@ -21,7 +22,6 @@ import { type BuildInternals, cssOrder, mergeInlineCss } from '../internal.js'; import type { AstroBuildPlugin } from '../plugin.js'; import type { StaticBuildOptions } from '../types.js'; import { makePageDataKey } from './util.js'; -import { DEFAULT_COMPONENTS } from '../../routing/default.js'; const manifestReplace = '@@ASTRO_MANIFEST_REPLACE@@'; const replaceExp = new RegExp(`['"]${manifestReplace}['"]`, 'g'); diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index 15d137286955..d1f498432e72 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -7,6 +7,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { bold } from 'kleur/colors'; import pLimit from 'p-limit'; +import { injectImageEndpoint } from '../../../assets/endpoint/config.js'; import { toRoutingStrategy } from '../../../i18n/utils.js'; import { runHookRoutesResolved } from '../../../integrations/hooks.js'; import { getPrerenderDefault } from '../../../prerender/utils.js'; @@ -16,14 +17,13 @@ import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from '../../constants.js'; import { MissingIndexForInternationalization } from '../../errors/errors-data.js'; import { AstroError } from '../../errors/index.js'; import { removeLeadingForwardSlash, slash } from '../../path.js'; +import { injectServerIslandRoute } from '../../server-islands/endpoint.js'; import { resolvePages } from '../../util.js'; +import { ensure404Route } from '../astro-designed-error-pages.js'; import { routeComparator } from '../priority.js'; import { getRouteGenerator } from './generator.js'; import { getPattern } from './pattern.js'; import { getRoutePrerenderOption } from './prerender.js'; -import { ensure404Route } from '../astro-designed-error-pages.js'; -import { injectImageEndpoint } from '../../../assets/endpoint/config.js'; -import { injectServerIslandRoute } from '../../server-islands/endpoint.js'; const require = createRequire(import.meta.url); interface Item {