From d50dddb71d87ce5b7928920f10eb4946a5339f86 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 20 Feb 2024 10:17:40 +0000 Subject: [PATCH 01/19] fix(i18n): make `i18n.routing` fields optional (#10165) * fix(i18n): make `i18n.routing` fields optional * update user config * Update packages/astro/src/core/config/schema.ts Co-authored-by: Chris Swithinbank --------- Co-authored-by: Chris Swithinbank --- .changeset/large-planets-kick.md | 5 ++ packages/astro/src/@types/astro.ts | 86 +++++++++++++++--------------- 2 files changed, 48 insertions(+), 43 deletions(-) create mode 100644 .changeset/large-planets-kick.md diff --git a/.changeset/large-planets-kick.md b/.changeset/large-planets-kick.md new file mode 100644 index 000000000000..f1b58b5e5d34 --- /dev/null +++ b/.changeset/large-planets-kick.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue where the `i18n.routing` object had all its fields defined as mandatory. Now they all are optionals and shouldn't break when using `astro.config.mts`. diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index c07dd0f65399..53b4f28893e1 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1492,7 +1492,7 @@ export interface AstroUserConfig { * URLs will be of the form `example.com/[locale]/content/` for every route, including the default language. * Localized folders are used for every language, including the default. */ - prefixDefaultLocale: boolean; + prefixDefaultLocale?: boolean; /** * @docs @@ -1521,7 +1521,7 @@ export interface AstroUserConfig { * }) *``` * */ - redirectToDefaultLocale: boolean; + redirectToDefaultLocale?: boolean; /** * @name i18n.routing.strategy @@ -1532,48 +1532,48 @@ export interface AstroUserConfig { * * - `"pathname": The strategy is applied to the pathname of the URLs */ - strategy: 'pathname'; - - /** - * @name i18n.domains - * @type {Record } - * @default '{}' - * @version 4.3.0 - * @description - * - * Configures the URL pattern of one or more supported languages to use a custom domain (or sub-domain). - * - * When a locale is mapped to a domain, a `/[locale]/` path prefix will not be used. - * However, localized folders within `src/pages/` are still required, including for your configured `defaultLocale`. - * - * Any other locale not configured will default to a localized path-based URL according to your `prefixDefaultLocale` strategy (e.g. `https://example.com/[locale]/blog`). - * - * ```js - * //astro.config.mjs - * export default defineConfig({ - * site: "https://example.com", - * output: "server", // required, with no prerendered pages - * adapter: node({ - * mode: 'standalone', - * }), - * i18n: { - * defaultLocale: "en", - * locales: ["en", "fr", "pt-br", "es"], - * prefixDefaultLocale: false, - * domains: { - * fr: "https://fr.example.com", - * es: "https://example.es" - * } - * }, - * }) - * ``` - * - * Both page routes built and URLs returned by the `astro:i18n` helper functions [`getAbsoluteLocaleUrl()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurl) and [`getAbsoluteLocaleUrlList()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurllist) will use the options set in `i18n.domains`. - * - * See the [Internationalization Guide](https://docs.astro.build/en/guides/internationalization/#domains) for more details, including the limitations of this feature. - */ - domains?: Record; + strategy?: 'pathname'; }; + + /** + * @name i18n.domains + * @type {Record } + * @default '{}' + * @version 4.3.0 + * @description + * + * Configures the URL pattern of one or more supported languages to use a custom domain (or sub-domain). + * + * When a locale is mapped to a domain, a `/[locale]/` path prefix will not be used. + * However, localized folders within `src/pages/` are still required, including for your configured `defaultLocale`. + * + * Any other locale not configured will default to a localized path-based URL according to your `prefixDefaultLocale` strategy (e.g. `https://example.com/[locale]/blog`). + * + * ```js + * //astro.config.mjs + * export default defineConfig({ + * site: "https://example.com", + * output: "server", // required, with no prerendered pages + * adapter: node({ + * mode: 'standalone', + * }), + * i18n: { + * defaultLocale: "en", + * locales: ["en", "fr", "pt-br", "es"], + * prefixDefaultLocale: false, + * domains: { + * fr: "https://fr.example.com", + * es: "https://example.es" + * } + * }, + * }) + * ``` + * + * Both page routes built and URLs returned by the `astro:i18n` helper functions [`getAbsoluteLocaleUrl()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurl) and [`getAbsoluteLocaleUrlList()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurllist) will use the options set in `i18n.domains`. + * + * See the [Internationalization Guide](https://docs.astro.build/en/guides/internationalization/#domains) for more details, including the limitations of this feature. + */ + domains?: Record; }; /** ⚠️ WARNING: SUBJECT TO CHANGE */ From b92d35f1026f3e99abb888d1a845bdda4efdc327 Mon Sep 17 00:00:00 2001 From: Ming-jun Lu <40516784+mingjunlu@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:22:05 +0800 Subject: [PATCH 02/19] Fix an issue where audit fails to initialize when encountered `` inside `` (#10163) * Fix an issue where audit fails to initialize when encountered `` inside `` * Add changeset --- .changeset/spotty-cobras-warn.md | 5 +++++ .../astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/spotty-cobras-warn.md diff --git a/.changeset/spotty-cobras-warn.md b/.changeset/spotty-cobras-warn.md new file mode 100644 index 000000000000..26fc9e537dc1 --- /dev/null +++ b/.changeset/spotty-cobras-warn.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue where audit fails to initialize when encountered `` inside `` diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts index 3bd296589fe1..45b94b31f6be 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts @@ -338,8 +338,8 @@ export const a11y: AuditRuleWithSelector[] = [ selector: a11y_required_content.join(','), match(element: HTMLElement) { // innerText is used to ignore hidden text - const innerText = element.innerText.trim(); - if (innerText !== '') return false; + const innerText = element.innerText?.trim(); + if (innerText && innerText !== '') return false; // Check for aria-label const ariaLabel = element.getAttribute('aria-label')?.trim(); From 80f8996514e6d0546e94bd927650cd4ab2f1fa2f Mon Sep 17 00:00:00 2001 From: ktym4a Date: Tue, 20 Feb 2024 20:09:20 +0700 Subject: [PATCH 03/19] Fix to get Integration Data even when a page is transitioned by ViewTransition (#10079) * Fix to get Integration Data even when a page is transitioned by ViewTransition. * add test case * add changeset * fix test * Fix typo --- .changeset/tidy-laws-think.md | 5 ++++ packages/astro/e2e/dev-toolbar.test.js | 22 +++++++++++++++ .../dev-toolbar/src/layout/Layout.astro | 18 ++++++++++++ .../src/pages/view-transition-a.astro | 7 +++++ .../src/pages/view-transition-b.astro | 7 +++++ .../runtime/client/dev-toolbar/apps/astro.ts | 28 +++++++++++-------- 6 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 .changeset/tidy-laws-think.md create mode 100644 packages/astro/e2e/fixtures/dev-toolbar/src/layout/Layout.astro create mode 100644 packages/astro/e2e/fixtures/dev-toolbar/src/pages/view-transition-a.astro create mode 100644 packages/astro/e2e/fixtures/dev-toolbar/src/pages/view-transition-b.astro diff --git a/.changeset/tidy-laws-think.md b/.changeset/tidy-laws-think.md new file mode 100644 index 000000000000..9455bfb153f0 --- /dev/null +++ b/.changeset/tidy-laws-think.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fix integrationData fetch to always be called even if View Transition is enabled. diff --git a/packages/astro/e2e/dev-toolbar.test.js b/packages/astro/e2e/dev-toolbar.test.js index 82ae166fa1a0..a4dcc7b20f01 100644 --- a/packages/astro/e2e/dev-toolbar.test.js +++ b/packages/astro/e2e/dev-toolbar.test.js @@ -53,6 +53,28 @@ test.describe('Dev Toolbar', () => { await expect(astroWindow).not.toBeVisible(); }); + test('show integration app', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/view-transition-a')); + + let toolbar = page.locator('astro-dev-toolbar'); + let appButton = toolbar.locator('button[data-app-id="astro"]'); + await appButton.click(); + + let astroAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro"]'); + let astroToolbarCards = await astroAppCanvas.locator('astro-dev-toolbar-card'); + await page.waitForSelector('astro-dev-toolbar-card'); + await expect(astroToolbarCards.first()).toBeVisible(); + + let consolePromise = page.waitForEvent('console'); + await page.click('#go-to-b'); + await consolePromise; + + astroAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro"]'); + astroToolbarCards = await astroAppCanvas.locator('astro-dev-toolbar-card'); + await page.waitForSelector('astro-dev-toolbar-card'); + await expect(astroToolbarCards.first()).toBeVisible(); + }); + test('xray shows highlights and tooltips', async ({ page, astro }) => { await page.goto(astro.resolveUrl('/')); diff --git a/packages/astro/e2e/fixtures/dev-toolbar/src/layout/Layout.astro b/packages/astro/e2e/fixtures/dev-toolbar/src/layout/Layout.astro new file mode 100644 index 000000000000..35c96e3e0281 --- /dev/null +++ b/packages/astro/e2e/fixtures/dev-toolbar/src/layout/Layout.astro @@ -0,0 +1,18 @@ +--- +import { ViewTransitions } from 'astro:transitions'; +--- + + + View Transition Test + + + + + + + diff --git a/packages/astro/e2e/fixtures/dev-toolbar/src/pages/view-transition-a.astro b/packages/astro/e2e/fixtures/dev-toolbar/src/pages/view-transition-a.astro new file mode 100644 index 000000000000..a3c94ddae9e3 --- /dev/null +++ b/packages/astro/e2e/fixtures/dev-toolbar/src/pages/view-transition-a.astro @@ -0,0 +1,7 @@ +--- +import Layout from '../layout/Layout.astro' +--- + +
Test
+
Go to B + diff --git a/packages/astro/e2e/fixtures/dev-toolbar/src/pages/view-transition-b.astro b/packages/astro/e2e/fixtures/dev-toolbar/src/pages/view-transition-b.astro new file mode 100644 index 000000000000..33bb801f4f56 --- /dev/null +++ b/packages/astro/e2e/fixtures/dev-toolbar/src/pages/view-transition-b.astro @@ -0,0 +1,7 @@ +--- +import Layout from '../layout/Layout.astro' +--- + +
Test
+ Go to A +
diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts index 64fcd4577654..27a7b228730e 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts @@ -34,27 +34,31 @@ export default { createCanvas(); document.addEventListener('astro:after-swap', createCanvas); + document.addEventListener('astro:after-swap', fetchIntegrationData); eventTarget.addEventListener('app-toggled', async (event) => { resetDebugButton(); if (!(event instanceof CustomEvent)) return; if (event.detail.state === true) { - if (!integrationData) - fetch('https://astro.build/api/v1/dev-overlay/', { - cache: 'no-cache', - }) - .then((res) => res.json()) - .then((data) => { - integrationData = data; - integrationData.data = integrationData.data.map((integration) => { - return integration; - }); - refreshIntegrationList(); - }); + if (!integrationData) fetchIntegrationData(); } }); + function fetchIntegrationData() { + fetch('https://astro.build/api/v1/dev-overlay/', { + cache: 'no-cache', + }) + .then((res) => res.json()) + .then((data) => { + integrationData = data; + integrationData.data = integrationData.data.map((integration) => { + return integration; + }); + refreshIntegrationList(); + }); + } + function createCanvas() { const links: { icon: Icon; name: string; link: string }[] = [ { From ea990a56145e342e9e1a93a9d877cf97b065550c Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:15:54 +0100 Subject: [PATCH 04/19] fix: dev-toolbar test (#10167) --- packages/astro/e2e/dev-toolbar.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/astro/e2e/dev-toolbar.test.js b/packages/astro/e2e/dev-toolbar.test.js index a4dcc7b20f01..3afdf9036df0 100644 --- a/packages/astro/e2e/dev-toolbar.test.js +++ b/packages/astro/e2e/dev-toolbar.test.js @@ -57,10 +57,10 @@ test.describe('Dev Toolbar', () => { await page.goto(astro.resolveUrl('/view-transition-a')); let toolbar = page.locator('astro-dev-toolbar'); - let appButton = toolbar.locator('button[data-app-id="astro"]'); + let appButton = toolbar.locator('button[data-app-id="astro:home"]'); await appButton.click(); - let astroAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro"]'); + let astroAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:home"]'); let astroToolbarCards = await astroAppCanvas.locator('astro-dev-toolbar-card'); await page.waitForSelector('astro-dev-toolbar-card'); await expect(astroToolbarCards.first()).toBeVisible(); @@ -69,7 +69,7 @@ test.describe('Dev Toolbar', () => { await page.click('#go-to-b'); await consolePromise; - astroAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro"]'); + astroAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:home"]'); astroToolbarCards = await astroAppCanvas.locator('astro-dev-toolbar-card'); await page.waitForSelector('astro-dev-toolbar-card'); await expect(astroToolbarCards.first()).toBeVisible(); From 5acc3135ba5309a566def466fbcbabd23f70cd68 Mon Sep 17 00:00:00 2001 From: Arsh <69170106+lilnasy@users.noreply.github.com> Date: Tue, 20 Feb 2024 07:40:13 -0700 Subject: [PATCH 05/19] refactor: pipeline lifetime (#9795) * Base Environment * SSRRoutePipeline -> AppEnvironment * BuildPipeline -> BuildEnvironment * DevPipeline -> DevEnvironment * per-request pipeline * internal middleware: i18n * delete callEndpoint * pipeline access for internal middleware * Address review comments `environment.ts` is now lives directly in `src/core`, rather than `src/core/render`. `environment.createPipeline` is removed. `Pipeline.create` is used instead. Constructors with positional arguments are replaced by `Environment.create` with named arguments. Clarifies the use of `HiddenPipeline`. * migrate some of `RenderContext`'s responsibilities to `Pipeline` * delete renderPage * RenderContext.params -> Pipeline.params * delete `RenderContext` * `Pipeline` -> `RenderContext` * `Environment` -> `Pipeline` * `AppEnvironment` -> `AppPipeline` * `BuildEnvironment` -> `BuildPipeline` * `DevEnvironment` -> `DevPipeline` * provide locals directly to renderContext * add changeset --- .changeset/hungry-rings-argue.md | 5 + packages/astro/src/assets/build/generate.ts | 5 +- packages/astro/src/core/app/index.ts | 176 +++----------- packages/astro/src/core/app/pipeline.ts | 33 +++ packages/astro/src/core/app/ssrPipeline.ts | 3 - packages/astro/src/core/base-pipeline.ts | 51 ++++ packages/astro/src/core/build/generate.ts | 157 +++--------- packages/astro/src/core/build/index.ts | 4 - .../build/{buildPipeline.ts => pipeline.ts} | 157 ++++++------ packages/astro/src/core/build/types.ts | 2 - packages/astro/src/core/constants.ts | 15 +- packages/astro/src/core/endpoint/index.ts | 52 +--- .../src/core/middleware/callMiddleware.ts | 16 +- packages/astro/src/core/middleware/index.ts | 78 +++++- packages/astro/src/core/pipeline.ts | 132 ---------- packages/astro/src/core/redirects/helpers.ts | 37 +-- packages/astro/src/core/redirects/index.ts | 3 +- packages/astro/src/core/redirects/render.ts | 32 +++ packages/astro/src/core/render-context.ts | 148 ++++++++++++ packages/astro/src/core/render/core.ts | 83 ------- packages/astro/src/core/render/environment.ts | 39 --- packages/astro/src/core/render/index.ts | 21 +- .../astro/src/core/render/params-and-props.ts | 53 ++-- packages/astro/src/core/render/result.ts | 19 +- packages/astro/src/core/routing/index.ts | 1 - packages/astro/src/core/routing/params.ts | 21 -- packages/astro/src/i18n/middleware.ts | 35 +-- .../{core/render/context.ts => i18n/utils.ts} | 103 +------- packages/astro/src/prerender/routing.ts | 7 +- packages/astro/src/runtime/server/consts.ts | 1 - packages/astro/src/runtime/server/endpoint.ts | 4 +- .../vite-plugin-astro-server/devPipeline.ts | 91 ------- .../src/vite-plugin-astro-server/error.ts | 8 +- .../src/vite-plugin-astro-server/index.ts | 31 --- .../src/vite-plugin-astro-server/pipeline.ts | 137 +++++++++++ .../src/vite-plugin-astro-server/plugin.ts | 5 +- .../src/vite-plugin-astro-server/request.ts | 16 +- .../src/vite-plugin-astro-server/route.ts | 227 ++---------------- .../astro.config.mjs | 2 +- .../astro/test/units/i18n/astro_i18n.test.js | 2 +- packages/astro/test/units/render/head.test.js | 55 ++--- packages/astro/test/units/render/jsx.test.js | 48 ++-- .../test/units/routing/route-matching.test.js | 4 +- packages/astro/test/units/test-utils.js | 41 ++-- .../vite-plugin-astro-server/request.test.js | 19 +- .../vite-plugin-astro-server/response.test.js | 2 +- 46 files changed, 828 insertions(+), 1353 deletions(-) create mode 100644 .changeset/hungry-rings-argue.md create mode 100644 packages/astro/src/core/app/pipeline.ts delete mode 100644 packages/astro/src/core/app/ssrPipeline.ts create mode 100644 packages/astro/src/core/base-pipeline.ts rename packages/astro/src/core/build/{buildPipeline.ts => pipeline.ts} (54%) delete mode 100644 packages/astro/src/core/pipeline.ts create mode 100644 packages/astro/src/core/redirects/render.ts create mode 100644 packages/astro/src/core/render-context.ts delete mode 100644 packages/astro/src/core/render/core.ts delete mode 100644 packages/astro/src/core/render/environment.ts rename packages/astro/src/{core/render/context.ts => i18n/utils.ts} (65%) delete mode 100644 packages/astro/src/runtime/server/consts.ts delete mode 100644 packages/astro/src/vite-plugin-astro-server/devPipeline.ts create mode 100644 packages/astro/src/vite-plugin-astro-server/pipeline.ts diff --git a/.changeset/hungry-rings-argue.md b/.changeset/hungry-rings-argue.md new file mode 100644 index 000000000000..1d7252e677be --- /dev/null +++ b/.changeset/hungry-rings-argue.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Refactors internals relating to middleware, endpoints, and page rendering. diff --git a/packages/astro/src/assets/build/generate.ts b/packages/astro/src/assets/build/generate.ts index a73ef11f2768..f106a56ccf5e 100644 --- a/packages/astro/src/assets/build/generate.ts +++ b/packages/astro/src/assets/build/generate.ts @@ -3,7 +3,7 @@ import fs, { readFileSync } from 'node:fs'; import { basename, join } from 'node:path/posix'; import type PQueue from 'p-queue'; import type { AstroConfig } from '../../@types/astro.js'; -import type { BuildPipeline } from '../../core/build/buildPipeline.js'; +import type { BuildPipeline } from '../../core/build/pipeline.js'; import { getOutDirWithinCwd } from '../../core/build/common.js'; import { getTimeStat } from '../../core/build/util.js'; import { AstroError } from '../../core/errors/errors.js'; @@ -50,8 +50,7 @@ export async function prepareAssetsGenerationEnv( pipeline: BuildPipeline, totalCount: number ): Promise { - const config = pipeline.getConfig(); - const logger = pipeline.getLogger(); + const { config, logger } = pipeline; let useCache = true; const assetsCacheDir = new URL('assets/', config.cacheDir); const count = { total: totalCount, current: 1 }; diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index d3f287efd382..481fffb410cd 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -1,17 +1,12 @@ import type { - EndpointHandler, ManifestData, RouteData, - SSRElement, SSRManifest, } from '../../@types/astro.js'; -import { createI18nMiddleware, i18nPipelineHook } from '../../i18n/middleware.js'; -import { REROUTE_DIRECTIVE_HEADER } from '../../runtime/server/consts.js'; import type { SinglePageBuiltModule } from '../build/types.js'; import { getSetCookiesFromResponse } from '../cookies/index.js'; import { consoleLogDestination } from '../logger/console.js'; import { AstroIntegrationLogger, Logger } from '../logger/core.js'; -import { sequence } from '../middleware/index.js'; import { appendForwardSlash, collapseDuplicateSlashes, @@ -20,29 +15,15 @@ import { removeTrailingForwardSlash, } from '../path.js'; import { RedirectSinglePageBuiltModule } from '../redirects/index.js'; -import { createEnvironment, createRenderContext, type RenderContext } from '../render/index.js'; -import { RouteCache } from '../render/route-cache.js'; -import { - createAssetLink, - createModuleScriptElement, - createStylesheetElementSet, -} from '../render/ssr-element.js'; +import { createAssetLink } from '../render/ssr-element.js'; import { matchRoute } from '../routing/match.js'; -import { SSRRoutePipeline } from './ssrPipeline.js'; -import type { RouteInfo } from './types.js'; +import { AppPipeline } from './pipeline.js'; import { normalizeTheLocale } from '../../i18n/index.js'; +import { RenderContext } from '../render-context.js'; +import { clientAddressSymbol, clientLocalsSymbol, responseSentSymbol, REROUTABLE_STATUS_CODES, REROUTE_DIRECTIVE_HEADER } from '../constants.js'; +import { AstroError, AstroErrorData } from '../errors/index.js'; export { deserializeManifest } from './common.js'; -const localsSymbol = Symbol.for('astro.locals'); -const clientAddressSymbol = Symbol.for('astro.clientAddress'); -const responseSentSymbol = Symbol.for('astro.responseSent'); - -/** - * A response with one of these status codes will be rewritten - * with the result of rendering the respective error page. - */ -const REROUTABLE_STATUS_CODES = new Set([404, 500]); - export interface RenderOptions { /** * Whether to automatically add all cookies written by `Astro.cookie.set()` to the response headers. @@ -86,18 +67,14 @@ export interface RenderErrorOptions { } export class App { - /** - * The current environment of the application - */ #manifest: SSRManifest; #manifestData: ManifestData; - #routeDataToRouteInfo: Map; #logger = new Logger({ dest: consoleLogDestination, level: 'info', }); #baseWithoutTrailingSlash: string; - #pipeline: SSRRoutePipeline; + #pipeline: AppPipeline; #adapterLogger: AstroIntegrationLogger; #renderOptionsDeprecationWarningShown = false; @@ -106,9 +83,8 @@ export class App { this.#manifestData = { routes: manifest.routes.map((route) => route.routeData), }; - this.#routeDataToRouteInfo = new Map(manifest.routes.map((route) => [route.routeData, route])); this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#manifest.base); - this.#pipeline = new SSRRoutePipeline(this.#createEnvironment(streaming)); + this.#pipeline = this.#createPipeline(streaming); this.#adapterLogger = new AstroIntegrationLogger( this.#logger.options, this.#manifest.adapterName @@ -120,19 +96,17 @@ export class App { } /** - * Creates an environment by reading the stored manifest + * Creates a pipeline by reading the stored manifest * * @param streaming * @private */ - #createEnvironment(streaming = false) { - return createEnvironment({ - adapterName: this.#manifest.adapterName, + #createPipeline(streaming = false) { + return AppPipeline.create({ logger: this.#logger, + manifest: this.#manifest, mode: 'production', - compressHTML: this.#manifest.compressHTML, renderers: this.#manifest.renderers, - clientDirectives: this.#manifest.clientDirectives, resolve: async (specifier: string) => { if (!(specifier in this.#manifest.entryModules)) { throw new Error(`Unable to resolve [${specifier}]`); @@ -148,11 +122,9 @@ export class App { } } }, - routeCache: new RouteCache(this.#logger), - site: this.#manifest.site, - ssr: true, + serverLike: true, streaming, - }); + }) } set setManifestData(newManifestData: ManifestData) { @@ -297,7 +269,11 @@ export class App { } } if (locals) { - Reflect.set(request, localsSymbol, locals); + if (typeof locals !== 'object') { + this.#logger.error(null, new AstroError(AstroErrorData.LocalsNotAnObject).stack!); + return this.#renderError(request, { status: 500 }); + } + Reflect.set(request, clientLocalsSymbol, locals); } if (clientAddress) { Reflect.set(request, clientAddressSymbol, clientAddress); @@ -316,38 +292,17 @@ export class App { const defaultStatus = this.#getDefaultStatusCode(routeData, pathname); const mod = await this.#getModuleForRoute(routeData); - const pageModule = (await mod.page()) as any; - const url = new URL(request.url); - - const renderContext = await this.#createRenderContext( - url, - request, - routeData, - mod, - defaultStatus - ); let response; try { - const i18nMiddleware = createI18nMiddleware( - this.#manifest.i18n, - this.#manifest.base, - this.#manifest.trailingSlash, - this.#manifest.buildFormat - ); - if (i18nMiddleware) { - this.#pipeline.setMiddlewareFunction(sequence(i18nMiddleware, this.#manifest.middleware)); - this.#pipeline.onBeforeRenderRoute(i18nPipelineHook); - } else { - this.#pipeline.setMiddlewareFunction(this.#manifest.middleware); - } - response = await this.#pipeline.renderRoute(renderContext, pageModule); + const renderContext = RenderContext.create({ pipeline: this.#pipeline, locals, pathname, request, routeData, status: defaultStatus }) + response = await renderContext.render(await mod.page()); } catch (err: any) { this.#logger.error(null, err.stack || err.message || String(err)); return this.#renderError(request, { status: 500 }); } if ( - REROUTABLE_STATUS_CODES.has(response.status) && + REROUTABLE_STATUS_CODES.includes(response.status) && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== 'no' ) { return this.#renderError(request, { @@ -396,72 +351,6 @@ export class App { */ static getSetCookieFromResponse = getSetCookiesFromResponse; - /** - * Creates the render context of the current route - */ - async #createRenderContext( - url: URL, - request: Request, - routeData: RouteData, - page: SinglePageBuiltModule, - status = 200 - ): Promise { - if (routeData.type === 'endpoint') { - const pathname = '/' + this.removeBase(url.pathname); - const mod = await page.page(); - const handler = mod as unknown as EndpointHandler; - - return await createRenderContext({ - request, - pathname, - route: routeData, - status, - env: this.#pipeline.env, - mod: handler as any, - locales: this.#manifest.i18n?.locales, - routing: this.#manifest.i18n?.routing, - defaultLocale: this.#manifest.i18n?.defaultLocale, - }); - } else { - const pathname = prependForwardSlash(this.removeBase(url.pathname)); - const info = this.#routeDataToRouteInfo.get(routeData)!; - // may be used in the future for handling rel=modulepreload, rel=icon, rel=manifest etc. - const links = new Set(); - const styles = createStylesheetElementSet(info.styles); - - let scripts = new Set(); - for (const script of info.scripts) { - if ('stage' in script) { - if (script.stage === 'head-inline') { - scripts.add({ - props: {}, - children: script.children, - }); - } - } else { - scripts.add(createModuleScriptElement(script)); - } - } - const mod = await page.page(); - - return await createRenderContext({ - request, - pathname, - componentMetadata: this.#manifest.componentMetadata, - scripts, - styles, - links, - route: routeData, - status, - mod, - env: this.#pipeline.env, - locales: this.#manifest.i18n?.locales, - routing: this.#manifest.i18n?.routing, - defaultLocale: this.#manifest.i18n?.defaultLocale, - }); - } - } - /** * If it is a known error code, try sending the according page (e.g. 404.astro / 500.astro). * This also handles pre-rendered /404 or /500 routes @@ -490,22 +379,15 @@ export class App { } const mod = await this.#getModuleForRoute(errorRouteData); try { - const newRenderContext = await this.#createRenderContext( - url, + const renderContext = RenderContext.create({ + pipeline: this.#pipeline, + middleware: skipMiddleware ? (_, next) => next() : undefined, + pathname: this.#getPathnameFromRequest(request), request, - errorRouteData, - mod, - status - ); - const page = (await mod.page()) as any; - if (skipMiddleware === false) { - this.#pipeline.setMiddlewareFunction(this.#manifest.middleware); - } - if (skipMiddleware) { - // make sure middleware set by other requests is cleared out - this.#pipeline.unsetMiddlewareFunction(); - } - const response = await this.#pipeline.renderRoute(newRenderContext, page); + routeData: errorRouteData, + status, + }) + const response = await renderContext.render(await mod.page()); return this.#mergeResponses(response, originalResponse); } catch { // Middleware may be the cause of the error, so we try rendering 404/500.astro without it. diff --git a/packages/astro/src/core/app/pipeline.ts b/packages/astro/src/core/app/pipeline.ts new file mode 100644 index 000000000000..74fa95ec6ad2 --- /dev/null +++ b/packages/astro/src/core/app/pipeline.ts @@ -0,0 +1,33 @@ +import type { RouteData, SSRElement, SSRResult } from "../../@types/astro.js"; +import { Pipeline } from "../base-pipeline.js"; +import { createModuleScriptElement, createStylesheetElementSet } from "../render/ssr-element.js"; + +export class AppPipeline extends Pipeline { + static create({ logger, manifest, mode, renderers, resolve, serverLike, streaming }: Pick) { + return new AppPipeline(logger, manifest, mode, renderers, resolve, serverLike, streaming); + } + + headElements(routeData: RouteData): Pick { + const routeInfo = this.manifest.routes.find(route => route.routeData === routeData); + // may be used in the future for handling rel=modulepreload, rel=icon, rel=manifest etc. + const links = new Set(); + const scripts = new Set(); + const styles = createStylesheetElementSet(routeInfo?.styles ?? []); + + for (const script of routeInfo?.scripts ?? []) { + if ('stage' in script) { + if (script.stage === 'head-inline') { + scripts.add({ + props: {}, + children: script.children, + }); + } + } else { + scripts.add(createModuleScriptElement(script)); + } + } + return { links, styles, scripts } + } + + componentMetadata() {} +} diff --git a/packages/astro/src/core/app/ssrPipeline.ts b/packages/astro/src/core/app/ssrPipeline.ts deleted file mode 100644 index f31636f9a51f..000000000000 --- a/packages/astro/src/core/app/ssrPipeline.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Pipeline } from '../pipeline.js'; - -export class SSRRoutePipeline extends Pipeline {} diff --git a/packages/astro/src/core/base-pipeline.ts b/packages/astro/src/core/base-pipeline.ts new file mode 100644 index 000000000000..5fcf639032cb --- /dev/null +++ b/packages/astro/src/core/base-pipeline.ts @@ -0,0 +1,51 @@ +import type { MiddlewareHandler, RouteData, RuntimeMode, SSRLoadedRenderer, SSRManifest, SSRResult } from '../@types/astro.js'; +import type { Logger } from './logger/core.js'; +import { RouteCache } from './render/route-cache.js'; +import { createI18nMiddleware } from '../i18n/middleware.js'; + +/** + * The `Pipeline` represents the static parts of rendering that do not change between requests. + * These are mostly known when the server first starts up and do not change. + * + * Thus, a `Pipeline` is created once at process start and then used by every `RenderContext`. + */ +export abstract class Pipeline { + readonly internalMiddleware: MiddlewareHandler[]; + + constructor( + readonly logger: Logger, + readonly manifest: SSRManifest, + /** + * "development" or "production" + */ + readonly mode: RuntimeMode, + readonly renderers: SSRLoadedRenderer[], + readonly resolve: (s: string) => Promise, + /** + * Based on Astro config's `output` option, `true` if "server" or "hybrid". + */ + readonly serverLike: boolean, + readonly streaming: boolean, + /** + * Used to provide better error messages for `Astro.clientAddress` + */ + readonly adapterName = manifest.adapterName, + readonly clientDirectives = manifest.clientDirectives, + readonly compressHTML = manifest.compressHTML, + readonly i18n = manifest.i18n, + readonly middleware = manifest.middleware, + readonly routeCache = new RouteCache(logger, mode), + /** + * Used for `Astro.site`. + */ + readonly site = manifest.site, + ) { + this.internalMiddleware = [ createI18nMiddleware(i18n, manifest.base, manifest.trailingSlash, manifest.buildFormat) ]; + } + + abstract headElements(routeData: RouteData): Promise | HeadElements + abstract componentMetadata(routeData: RouteData): Promise | void +} + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface HeadElements extends Pick {} diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index b108da5f56c4..14462a412060 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -29,30 +29,21 @@ import { removeLeadingForwardSlash, removeTrailingForwardSlash, } from '../../core/path.js'; -import { createI18nMiddleware, i18nPipelineHook } from '../../i18n/middleware.js'; import { runHookBuildGenerated } from '../../integrations/index.js'; import { getOutputDirectory, isServerLikeOutput } from '../../prerender/utils.js'; -import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import type { SSRManifestI18n } from '../app/types.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; -import { sequence } from '../middleware/index.js'; import { routeIsFallback } from '../redirects/helpers.js'; import { RedirectSinglePageBuiltModule, getRedirectLocationOrThrow, routeIsRedirect, } from '../redirects/index.js'; -import { createRenderContext } from '../render/index.js'; import { callGetStaticPaths } from '../render/route-cache.js'; -import { - createAssetLink, - createModuleScriptsSet, - createStylesheetElementSet, -} from '../render/ssr-element.js'; import { createRequest } from '../request.js'; import { matchRoute } from '../routing/match.js'; import { getOutputFilename } from '../util.js'; -import { BuildPipeline } from './buildPipeline.js'; +import { BuildPipeline } from './pipeline.js'; import { getOutDirWithinCwd, getOutFile, getOutFolder } from './common.js'; import { cssOrder, @@ -68,6 +59,7 @@ import type { } from './types.js'; import { getTimeStat, shouldAppendForwardSlash } from './util.js'; import { NoPrerenderedRoutesWithDomains } from '../errors/errors-data.js'; +import { RenderContext } from '../render-context.js'; function createEntryURL(filePath: string, outFolder: URL) { return new URL('./' + filePath + `?time=${Date.now()}`, outFolder); @@ -138,14 +130,14 @@ export function chunkIsPage( return false; } -export async function generatePages(opts: StaticBuildOptions, internals: BuildInternals) { +export async function generatePages(options: StaticBuildOptions, internals: BuildInternals) { const generatePagesTimer = performance.now(); - const ssr = isServerLikeOutput(opts.settings.config); + const ssr = isServerLikeOutput(options.settings.config); let manifest: SSRManifest; if (ssr) { - manifest = await BuildPipeline.retrieveManifest(opts, internals); + manifest = await BuildPipeline.retrieveManifest(options, internals); } else { - const baseDirectory = getOutputDirectory(opts.settings.config); + const baseDirectory = getOutputDirectory(options.settings.config); const renderersEntryUrl = new URL('renderers.mjs', baseDirectory); const renderers = await import(renderersEntryUrl.toString()); let middleware: MiddlewareHandler = (_, next) => next(); @@ -157,19 +149,19 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn ); } catch {} manifest = createBuildManifest( - opts.settings, + options.settings, internals, renderers.renderers as SSRLoadedRenderer[], middleware ); } - const pipeline = new BuildPipeline(opts, internals, manifest); + const pipeline = BuildPipeline.create({ internals, manifest, options }); + const { config, logger } = pipeline; const outFolder = ssr - ? opts.settings.config.build.server - : getOutDirWithinCwd(opts.settings.config.outDir); + ? options.settings.config.build.server + : getOutDirWithinCwd(options.settings.config.outDir); - const logger = pipeline.getLogger(); // HACK! `astro:assets` relies on a global to know if its running in dev, prod, ssr, ssg, full moon // If we don't delete it here, it's technically not impossible (albeit improbable) for it to leak if (ssr && !hasPrerenderedPages(internals)) { @@ -181,7 +173,6 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn logger.info('SKIP_FORMAT', `\n${bgGreen(black(` ${verb} static routes `))}`); const builtPaths = new Set(); const pagesToGenerate = pipeline.retrieveRoutesToGenerate(); - const config = pipeline.getConfig(); if (ssr) { for (const [pageData, filePath] of pagesToGenerate) { if (pageData.route.prerender) { @@ -195,7 +186,7 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn const ssrEntryURLPage = createEntryURL(filePath, outFolder); const ssrEntryPage = await import(ssrEntryURLPage.toString()); - if (opts.settings.adapter?.adapterFeatures?.functionPerRoute) { + if (options.settings.adapter?.adapterFeatures?.functionPerRoute) { // forcing to use undefined, so we fail in an expected way if the module is not even there. const ssrEntry = ssrEntryPage?.pageModule; if (ssrEntry) { @@ -240,12 +231,12 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn .map((x) => x.transforms.size) .reduce((a, b) => a + b, 0); const cpuCount = os.cpus().length; - const assetsCreationEnvironment = await prepareAssetsGenerationEnv(pipeline, totalCount); + const assetsCreationpipeline = await prepareAssetsGenerationEnv(pipeline, totalCount); const queue = new PQueue({ concurrency: Math.max(cpuCount, 1) }); const assetsTimer = performance.now(); for (const [originalPath, transforms] of staticImageList) { - await generateImagesForPath(originalPath, transforms, assetsCreationEnvironment, queue); + await generateImagesForPath(originalPath, transforms, assetsCreationpipeline, queue); } await queue.onIdle(); @@ -255,10 +246,7 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn delete globalThis?.astroAsset?.addStaticImage; } - await runHookBuildGenerated({ - config: opts.settings.config, - logger: pipeline.getLogger(), - }); + await runHookBuildGenerated({ config, logger }); } async function generatePage( @@ -268,12 +256,9 @@ async function generatePage( pipeline: BuildPipeline ) { // prepare information we need - const logger = pipeline.getLogger(); - const config = pipeline.getConfig(); - const manifest = pipeline.getManifest(); + const { config, internals, logger } = pipeline; const pageModulePromise = ssrEntry.page; - const onRequest = manifest.middleware; - const pageInfo = getPageDataByComponent(pipeline.getInternals(), pageData.route.component); + const pageInfo = getPageDataByComponent(internals, pageData.route.component); // Calculate information of the page, like scripts, links and styles const styles = pageData.styles @@ -283,19 +268,6 @@ async function generatePage( // may be used in the future for handling rel=modulepreload, rel=icon, rel=manifest etc. const linkIds: [] = []; const scripts = pageInfo?.hoistedScript ?? null; - // prepare the middleware - const i18nMiddleware = createI18nMiddleware( - manifest.i18n, - manifest.base, - manifest.trailingSlash, - manifest.buildFormat - ); - if (config.i18n && i18nMiddleware) { - pipeline.setMiddlewareFunction(sequence(i18nMiddleware, onRequest)); - pipeline.onBeforeRenderRoute(i18nPipelineHook); - } else { - pipeline.setMiddlewareFunction(onRequest); - } if (!pageModulePromise) { throw new Error( `Unable to find the module for ${pageData.component}. This is unexpected and likely a bug in Astro, please report.` @@ -322,8 +294,8 @@ async function generatePage( let prevTimeEnd = timeStart; for (let i = 0; i < paths.length; i++) { const path = paths[i]; - pipeline.getEnvironment().logger.debug('build', `Generating: ${path}`); - const filePath = getOutputFilename(pipeline.getConfig(), path, pageData.route.type); + pipeline.logger.debug('build', `Generating: ${path}`); + const filePath = getOutputFilename(config, path, pageData.route.type); const lineIcon = i === paths.length - 1 ? '└─' : '├─'; logger.info(null, ` ${blue(lineIcon)} ${dim(filePath)}`, false); await generatePath(path, pipeline, generationOptions, route); @@ -349,8 +321,7 @@ async function getPathsForRoute( pipeline: BuildPipeline, builtPaths: Set ): Promise> { - const opts = pipeline.getStaticBuildOptions(); - const logger = pipeline.getLogger(); + const { logger, options, routeCache, serverLike } = pipeline; let paths: Array = []; if (route.pathname) { paths.push(route.pathname); @@ -365,9 +336,9 @@ async function getPathsForRoute( const staticPaths = await callGetStaticPaths({ mod, route, - routeCache: opts.routeCache, + routeCache, logger, - ssr: isServerLikeOutput(opts.settings.config), + ssr: serverLike, }).catch((err) => { logger.debug('build', `├── ${bold(red('✗'))} ${route.component}`); throw err; @@ -401,7 +372,7 @@ async function getPathsForRoute( // NOTE: The same URL may match multiple routes in the manifest. // Routing priority needs to be verified here for any duplicate // paths to ensure routing priority rules are enforced in the final build. - const matchedRoute = matchRoute(staticPath, opts.manifest); + const matchedRoute = matchRoute(staticPath, options.manifest); return matchedRoute === route; }); @@ -504,84 +475,36 @@ async function generatePath( gopts: GeneratePathOptions, route: RouteData ) { - const { mod, scripts: hoistedScripts, styles: _styles } = gopts; - const manifest = pipeline.getManifest(); - const logger = pipeline.getLogger(); + const { mod } = gopts; + const { config, logger, options, serverLike } = pipeline; logger.debug('build', `Generating: ${pathname}`); - const links = new Set(); - const scripts = createModuleScriptsSet( - hoistedScripts ? [hoistedScripts] : [], - manifest.base, - manifest.assetsPrefix - ); - const styles = createStylesheetElementSet(_styles, manifest.base, manifest.assetsPrefix); - - if (pipeline.getSettings().scripts.some((script) => script.stage === 'page')) { - const hashedFilePath = pipeline.getInternals().entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID); - if (typeof hashedFilePath !== 'string') { - throw new Error(`Cannot find the built path for ${PAGE_SCRIPT_ID}`); - } - const src = createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix); - scripts.add({ - props: { type: 'module', src }, - children: '', - }); - } - - // Add all injected scripts to the page. - for (const script of pipeline.getSettings().scripts) { - if (script.stage === 'head-inline') { - scripts.add({ - props: {}, - children: script.content, - }); - } - } - // This adds the page name to the array so it can be shown as part of stats. if (route.type === 'page') { - addPageName(pathname, pipeline.getStaticBuildOptions()); + addPageName(pathname, options); } - const ssr = isServerLikeOutput(pipeline.getConfig()); const url = getUrlForPath( pathname, - pipeline.getConfig().base, - pipeline.getStaticBuildOptions().origin, - pipeline.getConfig().build.format, - pipeline.getConfig().trailingSlash, + config.base, + options.origin, + config.build.format, + config.trailingSlash, route.type ); const request = createRequest({ url, headers: new Headers(), - logger: pipeline.getLogger(), - ssr, - }); - const i18n = pipeline.getConfig().i18n; - - const renderContext = await createRenderContext({ - pathname, - request, - componentMetadata: manifest.componentMetadata, - scripts, - styles, - links, - route, - env: pipeline.getEnvironment(), - mod, - locales: i18n?.locales, - routing: i18n?.routing, - defaultLocale: i18n?.defaultLocale, + logger, + ssr: serverLike, }); + const renderContext = RenderContext.create({ pipeline, pathname, request, routeData: route }) let body: string | Uint8Array; - let response: Response; try { - response = await pipeline.renderRoute(renderContext, mod); + response = await renderContext.render(mod); } catch (err) { if (!AstroError.is(err) && !(err as SSRError).id && typeof err === 'object') { (err as SSRError).id = route.component; @@ -591,13 +514,13 @@ async function generatePath( if (response.status >= 300 && response.status < 400) { // If redirects is set to false, don't output the HTML - if (!pipeline.getConfig().build.redirects) { + if (!config.build.redirects) { return; } const locationSite = getRedirectLocationOrThrow(response.headers); - const siteURL = pipeline.getConfig().site; + const siteURL = config.site; const location = siteURL ? new URL(locationSite, siteURL) : locationSite; - const fromPath = new URL(renderContext.request.url).pathname; + const fromPath = new URL(request.url).pathname; // A short delay causes Google to interpret the redirect as temporary. // https://developers.google.com/search/docs/crawling-indexing/301-redirects#metarefresh const delay = response.status === 302 ? 2 : 0; @@ -609,7 +532,7 @@ async function generatePath( Redirecting from ${fromPath} to ${location} `; - if (pipeline.getConfig().compressHTML === true) { + if (config.compressHTML === true) { body = body.replaceAll('\n', ''); } // A dynamic redirect, set the location so that integrations know about it. @@ -622,8 +545,8 @@ async function generatePath( body = Buffer.from(await response.arrayBuffer()); } - const outFolder = getOutFolder(pipeline.getConfig(), pathname, route); - const outFile = getOutFile(pipeline.getConfig(), outFolder, pathname, route); + const outFolder = getOutFolder(config, pathname, route); + const outFile = getOutFile(config, outFolder, pathname, route); route.distURL = outFile; await fs.promises.mkdir(outFolder, { recursive: true }); diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 553497bc5b40..7e245726a7a0 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -27,7 +27,6 @@ import { createVite } from '../create-vite.js'; import type { Logger } from '../logger/core.js'; import { levels, timerMessage } from '../logger/core.js'; import { apply as applyPolyfill } from '../polyfill.js'; -import { RouteCache } from '../render/route-cache.js'; import { createRouteManifest } from '../routing/index.js'; import { collectPagesData } from './page-data.js'; import { staticBuild, viteBuild } from './static-build.js'; @@ -98,7 +97,6 @@ class AstroBuilder { private logger: Logger; private mode: RuntimeMode = 'production'; private origin: string; - private routeCache: RouteCache; private manifest: ManifestData; private timer: Record; private teardownCompiler: boolean; @@ -110,7 +108,6 @@ class AstroBuilder { this.settings = settings; this.logger = options.logger; this.teardownCompiler = options.teardownCompiler ?? true; - this.routeCache = new RouteCache(this.logger); this.origin = settings.config.site ? new URL(settings.config.site).origin : `http://localhost:${settings.config.server.port}`; @@ -195,7 +192,6 @@ class AstroBuilder { mode: this.mode, origin: this.origin, pageNames, - routeCache: this.routeCache, teardownCompiler: this.teardownCompiler, viteConfig, }; diff --git a/packages/astro/src/core/build/buildPipeline.ts b/packages/astro/src/core/build/pipeline.ts similarity index 54% rename from packages/astro/src/core/build/buildPipeline.ts rename to packages/astro/src/core/build/pipeline.ts index 60527b27f548..a2647e4564a3 100644 --- a/packages/astro/src/core/build/buildPipeline.ts +++ b/packages/astro/src/core/build/pipeline.ts @@ -1,13 +1,11 @@ -import type { AstroConfig, AstroSettings, SSRLoadedRenderer } from '../../@types/astro.js'; +import type { RouteData, SSRLoadedRenderer, SSRResult } from '../../@types/astro.js'; import { getOutputDirectory, isServerLikeOutput } from '../../prerender/utils.js'; -import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; +import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import type { SSRManifest } from '../app/types.js'; -import type { Logger } from '../logger/core.js'; -import { Pipeline } from '../pipeline.js'; import { routeIsFallback, routeIsRedirect } from '../redirects/helpers.js'; -import { createEnvironment } from '../render/index.js'; -import { createAssetLink } from '../render/ssr-element.js'; -import type { BuildInternals } from './internal.js'; +import { Pipeline } from '../render/index.js'; +import { createAssetLink, createModuleScriptsSet, createStylesheetElementSet } from '../render/ssr-element.js'; +import { getPageDataByComponent, type BuildInternals, cssOrder, mergeInlineCss } from './internal.js'; import { ASTRO_PAGE_RESOLVED_MODULE_ID, getVirtualModulePageNameFromPath, @@ -18,79 +16,42 @@ import type { PageBuildData, StaticBuildOptions } from './types.js'; import { i18nHasFallback } from './util.js'; /** - * This pipeline is responsible to gather the files emitted by the SSR build and generate the pages by executing these files. + * The build pipeline is responsible to gather the files emitted by the SSR build and generate the pages by executing these files. */ export class BuildPipeline extends Pipeline { - #internals: BuildInternals; - #staticBuildOptions: StaticBuildOptions; - #manifest: SSRManifest; - - constructor( - staticBuildOptions: StaticBuildOptions, - internals: BuildInternals, - manifest: SSRManifest + private constructor( + readonly internals: BuildInternals, + readonly manifest: SSRManifest, + readonly options: StaticBuildOptions, + readonly config = options.settings.config, + readonly settings = options.settings ) { - const ssr = isServerLikeOutput(staticBuildOptions.settings.config); const resolveCache = new Map(); - super( - createEnvironment({ - adapterName: manifest.adapterName, - logger: staticBuildOptions.logger, - mode: staticBuildOptions.mode, - renderers: manifest.renderers, - clientDirectives: manifest.clientDirectives, - compressHTML: manifest.compressHTML, - async resolve(specifier: string) { - if (resolveCache.has(specifier)) { - return resolveCache.get(specifier)!; - } - const hashedFilePath = manifest.entryModules[specifier]; - if (typeof hashedFilePath !== 'string' || hashedFilePath === '') { - // If no "astro:scripts/before-hydration.js" script exists in the build, - // then we can assume that no before-hydration scripts are needed. - if (specifier === BEFORE_HYDRATION_SCRIPT_ID) { - resolveCache.set(specifier, ''); - return ''; - } - throw new Error(`Cannot find the built path for ${specifier}`); - } - const assetLink = createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix); - resolveCache.set(specifier, assetLink); - return assetLink; - }, - routeCache: staticBuildOptions.routeCache, - site: manifest.site, - ssr, - streaming: true, - }) - ); - this.#internals = internals; - this.#staticBuildOptions = staticBuildOptions; - this.#manifest = manifest; - } - - getInternals(): Readonly { - return this.#internals; - } - - getSettings(): Readonly { - return this.#staticBuildOptions.settings; - } - - getStaticBuildOptions(): Readonly { - return this.#staticBuildOptions; - } - - getConfig(): AstroConfig { - return this.#staticBuildOptions.settings.config; - } - - getManifest(): SSRManifest { - return this.#manifest; + async function resolve(specifier: string) { + if (resolveCache.has(specifier)) { + return resolveCache.get(specifier)!; + } + const hashedFilePath = manifest.entryModules[specifier]; + if (typeof hashedFilePath !== 'string' || hashedFilePath === '') { + // If no "astro:scripts/before-hydration.js" script exists in the build, + // then we can assume that no before-hydration scripts are needed. + if (specifier === BEFORE_HYDRATION_SCRIPT_ID) { + resolveCache.set(specifier, ''); + return ''; + } + throw new Error(`Cannot find the built path for ${specifier}`); + } + const assetLink = createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix); + resolveCache.set(specifier, assetLink); + return assetLink; + } + const serverLike = isServerLikeOutput(config); + const streaming = true; + super(options.logger, manifest, options.mode, manifest.renderers, resolve, serverLike, streaming) } - getLogger(): Logger { - return this.getEnvironment().logger; + static create({ internals, manifest, options }: Pick) { + return new BuildPipeline(internals, manifest, options); } /** @@ -144,6 +105,44 @@ export class BuildPipeline extends Pipeline { }; } + headElements(routeData: RouteData): Pick { + const { internals, manifest: { assetsPrefix, base }, settings } = this + const links = new Set(); + const pageBuildData = getPageDataByComponent(internals, routeData.component) + const scripts = createModuleScriptsSet( + pageBuildData?.hoistedScript ? [pageBuildData.hoistedScript] : [], + base, + assetsPrefix + ); + const sortedCssAssets = pageBuildData?.styles.sort(cssOrder).map(({ sheet }) => sheet).reduce(mergeInlineCss, []); + const styles = createStylesheetElementSet(sortedCssAssets ?? [], base, assetsPrefix); + + if (settings.scripts.some((script) => script.stage === 'page')) { + const hashedFilePath = internals.entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID); + if (typeof hashedFilePath !== 'string') { + throw new Error(`Cannot find the built path for ${PAGE_SCRIPT_ID}`); + } + const src = createAssetLink(hashedFilePath, base, assetsPrefix); + scripts.add({ + props: { type: 'module', src }, + children: '', + }); + } + + // Add all injected scripts to the page. + for (const script of settings.scripts) { + if (script.stage === 'head-inline') { + scripts.add({ + props: {}, + children: script.content, + }); + } + } + return { scripts, styles, links } + } + + componentMetadata() {} + /** * It collects the routes to generate during the build. * @@ -152,7 +151,7 @@ export class BuildPipeline extends Pipeline { retrieveRoutesToGenerate(): Map { const pages = new Map(); - for (const [entrypoint, filePath] of this.#internals.entrySpecifierToBundleMap) { + for (const [entrypoint, filePath] of this.internals.entrySpecifierToBundleMap) { // virtual pages can be emitted with different prefixes: // - the classic way are pages emitted with prefix ASTRO_PAGE_RESOLVED_MODULE_ID -> plugin-pages // - pages emitted using `build.split`, in this case pages are emitted with prefix RESOLVED_SPLIT_MODULE_ID @@ -161,7 +160,7 @@ export class BuildPipeline extends Pipeline { entrypoint.includes(RESOLVED_SPLIT_MODULE_ID) ) { const [, pageName] = entrypoint.split(':'); - const pageData = this.#internals.pagesByComponent.get( + const pageData = this.internals.pagesByComponent.get( `${pageName.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, '.')}` ); if (!pageData) { @@ -174,12 +173,12 @@ export class BuildPipeline extends Pipeline { } } - for (const [path, pageData] of this.#internals.pagesByComponent.entries()) { + for (const [path, pageData] of this.internals.pagesByComponent.entries()) { if (routeIsRedirect(pageData.route)) { pages.set(pageData, path); } else if ( routeIsFallback(pageData.route) && - (i18nHasFallback(this.getConfig()) || + (i18nHasFallback(this.config) || (routeIsFallback(pageData.route) && pageData.route.route === '/')) ) { // The original component is transformed during the first build, so we have to retrieve @@ -190,7 +189,7 @@ export class BuildPipeline extends Pipeline { // Here, we take the component path and transform it in the virtual module name const moduleSpecifier = getVirtualModulePageNameFromPath(path); // We retrieve the original JS module - const filePath = this.#internals.entrySpecifierToBundleMap.get(moduleSpecifier); + const filePath = this.internals.entrySpecifierToBundleMap.get(moduleSpecifier); if (filePath) { // it exists, added it to pages to render, using the file path that we jus retrieved pages.set(pageData, filePath); diff --git a/packages/astro/src/core/build/types.ts b/packages/astro/src/core/build/types.ts index b67d7d2225ef..9608ba04c524 100644 --- a/packages/astro/src/core/build/types.ts +++ b/packages/astro/src/core/build/types.ts @@ -11,7 +11,6 @@ import type { SSRLoadedRenderer, } from '../../@types/astro.js'; import type { Logger } from '../logger/core.js'; -import type { RouteCache } from '../render/route-cache.js'; export type ComponentPath = string; export type ViteID = string; @@ -43,7 +42,6 @@ export interface StaticBuildOptions { mode: RuntimeMode; origin: string; pageNames: string[]; - routeCache: RouteCache; viteConfig: InlineConfig; teardownCompiler: boolean; } diff --git a/packages/astro/src/core/constants.ts b/packages/astro/src/core/constants.ts index af00d655d7c2..1466ab86af49 100644 --- a/packages/astro/src/core/constants.ts +++ b/packages/astro/src/core/constants.ts @@ -1,6 +1,19 @@ // process.env.PACKAGE_VERSION is injected when we build and publish the astro package. export const ASTRO_VERSION = process.env.PACKAGE_VERSION ?? 'development'; +export const REROUTE_DIRECTIVE_HEADER = 'X-Astro-Reroute'; +export const ROUTE_TYPE_HEADER = 'X-Astro-Route-Type'; + +/** + * A response with one of these status codes will be rewritten + * with the result of rendering the respective error page. + */ +export const REROUTABLE_STATUS_CODES = [404, 500]; + +export const clientAddressSymbol = Symbol.for('astro.clientAddress'); +export const clientLocalsSymbol = Symbol.for('astro.locals'); +export const responseSentSymbol = Symbol.for('astro.responseSent'); + // possible extensions for markdown files export const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [ '.markdown', @@ -13,5 +26,3 @@ export const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [ // The folder name where to find the middleware export const MIDDLEWARE_PATH_SEGMENT_NAME = 'middleware'; - -export const ROUTE_DATA_SYMBOL = 'astro.routeData'; diff --git a/packages/astro/src/core/endpoint/index.ts b/packages/astro/src/core/endpoint/index.ts index e8264e881a9d..7a64366a33df 100644 --- a/packages/astro/src/core/endpoint/index.ts +++ b/packages/astro/src/core/endpoint/index.ts @@ -1,26 +1,18 @@ import type { APIContext, - EndpointHandler, Locales, - MiddlewareHandler, Params, } from '../../@types/astro.js'; -import { renderEndpoint } from '../../runtime/server/index.js'; -import { ASTRO_VERSION } from '../constants.js'; -import { AstroCookies, attachCookiesToResponse } from '../cookies/index.js'; +import { ASTRO_VERSION, clientAddressSymbol, clientLocalsSymbol } from '../constants.js'; +import type { AstroCookies } from '../cookies/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; -import { callMiddleware } from '../middleware/callMiddleware.js'; import { computeCurrentLocale, computePreferredLocale, computePreferredLocaleList, -} from '../render/context.js'; -import { type Environment, type RenderContext } from '../render/index.js'; +} from '../../i18n/utils.js'; import type { RoutingStrategies } from '../config/schema.js'; -const clientAddressSymbol = Symbol.for('astro.clientAddress'); -const clientLocalsSymbol = Symbol.for('astro.locals'); - type CreateAPIContext = { request: Request; params: Params; @@ -30,6 +22,8 @@ type CreateAPIContext = { locales: Locales | undefined; routingStrategy: RoutingStrategies | undefined; defaultLocale: string | undefined; + route: string; + cookies: AstroCookies }; /** @@ -46,13 +40,15 @@ export function createAPIContext({ locales, routingStrategy, defaultLocale, + route, + cookies }: CreateAPIContext): APIContext { let preferredLocale: string | undefined = undefined; let preferredLocaleList: string[] | undefined = undefined; let currentLocale: string | undefined = undefined; const context = { - cookies: new AstroCookies(request), + cookies, request, params, site: site ? new URL(site) : undefined, @@ -93,7 +89,7 @@ export function createAPIContext({ return currentLocale; } if (locales) { - currentLocale = computeCurrentLocale(request, locales, routingStrategy, defaultLocale); + currentLocale = computeCurrentLocale(route, locales, routingStrategy, defaultLocale); } return currentLocale; @@ -138,33 +134,3 @@ export function createAPIContext({ return context; } - -export async function callEndpoint( - mod: EndpointHandler, - env: Environment, - ctx: RenderContext, - onRequest: MiddlewareHandler | undefined -): Promise { - const context = createAPIContext({ - request: ctx.request, - params: ctx.params, - props: ctx.props, - site: env.site, - adapterName: env.adapterName, - routingStrategy: ctx.routing, - defaultLocale: ctx.defaultLocale, - locales: ctx.locales, - }); - - let response; - if (onRequest) { - response = await callMiddleware(onRequest, context, async () => { - return await renderEndpoint(mod, context, env.ssr, env.logger); - }); - } else { - response = await renderEndpoint(mod, context, env.ssr, env.logger); - } - - attachCookiesToResponse(response, context.cookies); - return response; -} diff --git a/packages/astro/src/core/middleware/callMiddleware.ts b/packages/astro/src/core/middleware/callMiddleware.ts index 4d79cd566364..0133c13d032d 100644 --- a/packages/astro/src/core/middleware/callMiddleware.ts +++ b/packages/astro/src/core/middleware/callMiddleware.ts @@ -1,5 +1,4 @@ import type { APIContext, MiddlewareHandler, MiddlewareNext } from '../../@types/astro.js'; -import { attachCookiesToResponse, responseHasCookies } from '../cookies/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; /** @@ -39,10 +38,10 @@ import { AstroError, AstroErrorData } from '../errors/index.js'; export async function callMiddleware( onRequest: MiddlewareHandler, apiContext: APIContext, - responseFunction: () => Promise + responseFunction: () => Promise | Response ): Promise { let nextCalled = false; - let responseFunctionPromise: Promise | undefined = undefined; + let responseFunctionPromise: Promise | Response | undefined = undefined; const next: MiddlewareNext = async () => { nextCalled = true; responseFunctionPromise = responseFunction(); @@ -67,7 +66,7 @@ export async function callMiddleware( if (value instanceof Response === false) { throw new AstroError(AstroErrorData.MiddlewareNotAResponse); } - return ensureCookiesAttached(apiContext, value); + return value; } else { /** * Here we handle the case where `next` was called and returned nothing. @@ -90,14 +89,7 @@ export async function callMiddleware( throw new AstroError(AstroErrorData.MiddlewareNotAResponse); } else { // Middleware did not call resolve and returned a value - return ensureCookiesAttached(apiContext, value); + return value; } }); } - -function ensureCookiesAttached(apiContext: APIContext, response: Response): Response { - if (apiContext.cookies !== undefined && !responseHasCookies(response)) { - attachCookiesToResponse(response, apiContext.cookies); - } - return response; -} diff --git a/packages/astro/src/core/middleware/index.ts b/packages/astro/src/core/middleware/index.ts index ffaafb3e56b2..b72a13f0a66b 100644 --- a/packages/astro/src/core/middleware/index.ts +++ b/packages/astro/src/core/middleware/index.ts @@ -1,6 +1,16 @@ -import type { MiddlewareHandler, Params } from '../../@types/astro.js'; -import { createAPIContext } from '../endpoint/index.js'; +import type { APIContext, MiddlewareHandler, Params } from '../../@types/astro.js'; +import { AstroCookies } from '../cookies/index.js'; import { sequence } from './sequence.js'; +import { ASTRO_VERSION } from '../constants.js'; +import { AstroError, AstroErrorData } from '../errors/index.js'; +import { + computeCurrentLocale, + computePreferredLocale, + computePreferredLocaleList, +} from '../../i18n/utils.js'; + +const clientAddressSymbol = Symbol.for('astro.clientAddress'); +const clientLocalsSymbol = Symbol.for('astro.locals'); function defineMiddleware(fn: MiddlewareHandler) { return fn; @@ -28,16 +38,64 @@ export type CreateContext = { /** * Creates a context to be passed to Astro middleware `onRequest` function. */ -function createContext({ request, params, userDefinedLocales = [] }: CreateContext) { - return createAPIContext({ +function createContext({ request, params = {}, userDefinedLocales = [] }: CreateContext): APIContext { + let preferredLocale: string | undefined = undefined; + let preferredLocaleList: string[] | undefined = undefined; + let currentLocale: string | undefined = undefined; + const url = new URL(request.url); + const route = url.pathname + + return { + cookies: new AstroCookies(request), request, - params: params ?? {}, - props: {}, + params, site: undefined, - locales: userDefinedLocales, - defaultLocale: undefined, - routingStrategy: undefined, - }); + generator: `Astro v${ASTRO_VERSION}`, + props: {}, + redirect(path, status) { + return new Response(null, { + status: status || 302, + headers: { + Location: path, + }, + }); + }, + get preferredLocale(): string | undefined { + return preferredLocale ??= computePreferredLocale(request, userDefinedLocales); + }, + get preferredLocaleList(): string[] | undefined { + return preferredLocaleList ??= computePreferredLocaleList(request, userDefinedLocales); + }, + get currentLocale(): string | undefined { + return currentLocale ??= computeCurrentLocale(route, userDefinedLocales, undefined, undefined); + }, + url, + get clientAddress() { + if (clientAddressSymbol in request) { + return Reflect.get(request, clientAddressSymbol) as string; + } + throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable); + }, + get locals() { + let locals = Reflect.get(request, clientLocalsSymbol); + if (locals === undefined) { + locals = {}; + Reflect.set(request, clientLocalsSymbol, locals); + } + if (typeof locals !== 'object') { + throw new AstroError(AstroErrorData.LocalsNotAnObject); + } + return locals; + }, + // We define a custom property, so we can check the value passed to locals + set locals(val) { + if (typeof val !== 'object') { + throw new AstroError(AstroErrorData.LocalsNotAnObject); + } else { + Reflect.set(request, clientLocalsSymbol, val); + } + }, + }; } /** diff --git a/packages/astro/src/core/pipeline.ts b/packages/astro/src/core/pipeline.ts deleted file mode 100644 index 88b8e800daaa..000000000000 --- a/packages/astro/src/core/pipeline.ts +++ /dev/null @@ -1,132 +0,0 @@ -import type { ComponentInstance, EndpointHandler, MiddlewareHandler } from '../@types/astro.js'; -import { callEndpoint, createAPIContext } from './endpoint/index.js'; -import { callMiddleware } from './middleware/callMiddleware.js'; -import { renderPage } from './render/core.js'; -import { type Environment, type RenderContext } from './render/index.js'; - -type PipelineHooks = { - before: PipelineHookFunction[]; -}; - -export type PipelineHookFunction = (ctx: RenderContext, mod: ComponentInstance | undefined) => void; - -/** - * This is the basic class of a pipeline. - * - * Check the {@link ./README.md|README} for more information about the pipeline. - */ -export class Pipeline { - env: Environment; - #onRequest?: MiddlewareHandler; - #hooks: PipelineHooks = { - before: [], - }; - - /** - * When creating a pipeline, an environment is mandatory. - * The environment won't change for the whole lifetime of the pipeline. - */ - constructor(env: Environment) { - this.env = env; - } - - setEnvironment() {} - - /** - * A middleware function that will be called before each request. - */ - setMiddlewareFunction(onRequest: MiddlewareHandler) { - this.#onRequest = onRequest; - } - - /** - * Removes the current middleware function. Subsequent requests won't trigger any middleware. - */ - unsetMiddlewareFunction() { - this.#onRequest = undefined; - } - /** - * Returns the current environment - */ - getEnvironment(): Readonly { - return this.env; - } - - /** - * The main function of the pipeline. Use this function to render any route known to Astro; - */ - async renderRoute( - renderContext: RenderContext, - componentInstance: ComponentInstance | undefined - ): Promise { - for (const hook of this.#hooks.before) { - hook(renderContext, componentInstance); - } - return await this.#tryRenderRoute(renderContext, this.env, componentInstance, this.#onRequest); - } - - /** - * It attempts to render a route. A route can be a: - * - page - * - redirect - * - endpoint - * - * ## Errors - * - * It throws an error if the page can't be rendered. - */ - async #tryRenderRoute( - renderContext: Readonly, - env: Readonly, - mod: Readonly | undefined, - onRequest?: MiddlewareHandler - ): Promise { - const apiContext = createAPIContext({ - request: renderContext.request, - params: renderContext.params, - props: renderContext.props, - site: env.site, - adapterName: env.adapterName, - locales: renderContext.locales, - routingStrategy: renderContext.routing, - defaultLocale: renderContext.defaultLocale, - }); - - switch (renderContext.route.type) { - case 'page': - case 'fallback': - case 'redirect': { - if (onRequest) { - return await callMiddleware(onRequest, apiContext, () => { - return renderPage({ - mod, - renderContext, - env, - cookies: apiContext.cookies, - }); - }); - } else { - return await renderPage({ - mod, - renderContext, - env, - cookies: apiContext.cookies, - }); - } - } - case 'endpoint': { - return await callEndpoint(mod as any as EndpointHandler, env, renderContext, onRequest); - } - default: - throw new Error(`Couldn't find route of type [${renderContext.route.type}]`); - } - } - - /** - * Store a function that will be called before starting the rendering phase. - * @param fn - */ - onBeforeRenderRoute(fn: PipelineHookFunction) { - this.#hooks.before.push(fn); - } -} diff --git a/packages/astro/src/core/redirects/helpers.ts b/packages/astro/src/core/redirects/helpers.ts index e171aebe6624..a55eacfdf416 100644 --- a/packages/astro/src/core/redirects/helpers.ts +++ b/packages/astro/src/core/redirects/helpers.ts @@ -1,9 +1,4 @@ -import type { - Params, - RedirectRouteData, - RouteData, - ValidRedirectStatus, -} from '../../@types/astro.js'; +import type { RedirectRouteData, RouteData } from '../../@types/astro.js'; export function routeIsRedirect(route: RouteData | undefined): route is RedirectRouteData { return route?.type === 'redirect'; @@ -13,33 +8,3 @@ export function routeIsFallback(route: RouteData | undefined): route is Redirect return route?.type === 'fallback'; } -export function redirectRouteGenerate(redirectRoute: RouteData, data: Params): string { - const routeData = redirectRoute.redirectRoute; - const route = redirectRoute.redirect; - - if (typeof routeData !== 'undefined') { - return routeData?.generate(data) || routeData?.pathname || '/'; - } else if (typeof route === 'string') { - // TODO: this logic is duplicated between here and manifest/create.ts - let target = route; - for (const param of Object.keys(data)) { - const paramValue = data[param]!; - target = target.replace(`[${param}]`, paramValue); - target = target.replace(`[...${param}]`, paramValue); - } - return target; - } else if (typeof route === 'undefined') { - return '/'; - } - return route.destination; -} - -export function redirectRouteStatus(redirectRoute: RouteData, method = 'GET'): ValidRedirectStatus { - const routeData = redirectRoute.redirectRoute; - if (routeData && typeof redirectRoute.redirect === 'object') { - return redirectRoute.redirect.status; - } else if (method !== 'GET') { - return 308; - } - return 301; -} diff --git a/packages/astro/src/core/redirects/index.ts b/packages/astro/src/core/redirects/index.ts index 4f705afdf832..321195cbd54d 100644 --- a/packages/astro/src/core/redirects/index.ts +++ b/packages/astro/src/core/redirects/index.ts @@ -1,3 +1,4 @@ export { RedirectComponentInstance, RedirectSinglePageBuiltModule } from './component.js'; -export { redirectRouteGenerate, redirectRouteStatus, routeIsRedirect } from './helpers.js'; +export { routeIsRedirect } from './helpers.js'; export { getRedirectLocationOrThrow } from './validate.js'; +export { renderRedirect } from './render.js'; diff --git a/packages/astro/src/core/redirects/render.ts b/packages/astro/src/core/redirects/render.ts new file mode 100644 index 000000000000..08cf908500f7 --- /dev/null +++ b/packages/astro/src/core/redirects/render.ts @@ -0,0 +1,32 @@ +import type { RenderContext } from '../render-context.js'; + +export async function renderRedirect(renderContext: RenderContext) { + const { request: { method }, routeData } = renderContext; + const { redirect, redirectRoute } = routeData; + const status = + redirectRoute && typeof redirect === "object" ? redirect.status + : method === "GET" ? 301 + : 308 + const headers = { location: redirectRouteGenerate(renderContext) }; + return new Response(null, { status, headers }); +} + +function redirectRouteGenerate(renderContext: RenderContext): string { + const { params, routeData: { redirect, redirectRoute } } = renderContext; + + if (typeof redirectRoute !== 'undefined') { + return redirectRoute?.generate(params) || redirectRoute?.pathname || '/'; + } else if (typeof redirect === 'string') { + // TODO: this logic is duplicated between here and manifest/create.ts + let target = redirect; + for (const param of Object.keys(params)) { + const paramValue = params[param]!; + target = target.replace(`[${param}]`, paramValue); + target = target.replace(`[...${param}]`, paramValue); + } + return target; + } else if (typeof redirect === 'undefined') { + return '/'; + } + return redirect.destination; +} diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts new file mode 100644 index 000000000000..fd9ed3d1c44f --- /dev/null +++ b/packages/astro/src/core/render-context.ts @@ -0,0 +1,148 @@ +import type { APIContext, ComponentInstance, MiddlewareHandler, RouteData } from '../@types/astro.js'; +import { renderEndpoint } from '../runtime/server/endpoint.js'; +import { attachCookiesToResponse } from './cookies/index.js'; +import { callMiddleware } from './middleware/callMiddleware.js'; +import { sequence } from './middleware/index.js'; +import { AstroCookies } from './cookies/index.js'; +import { createResult } from './render/index.js'; +import { renderPage } from '../runtime/server/index.js'; +import { ASTRO_VERSION, ROUTE_TYPE_HEADER, clientAddressSymbol, clientLocalsSymbol } from './constants.js'; +import { getParams, getProps, type Pipeline } from './render/index.js'; +import { AstroError, AstroErrorData } from './errors/index.js'; +import { + computeCurrentLocale, + computePreferredLocale, + computePreferredLocaleList, +} from '../i18n/utils.js'; +import { renderRedirect } from './redirects/render.js'; + +export class RenderContext { + private constructor( + readonly pipeline: Pipeline, + public locals: App.Locals, + readonly middleware: MiddlewareHandler, + readonly pathname: string, + readonly request: Request, + readonly routeData: RouteData, + public status: number, + readonly cookies = new AstroCookies(request), + readonly params = getParams(routeData, pathname), + ) {} + + static create({ locals = {}, middleware, pathname, pipeline, request, routeData, status = 200 }: Pick & Partial>) { + return new RenderContext(pipeline, locals, sequence(...pipeline.internalMiddleware, middleware ?? pipeline.middleware), pathname, request, routeData, status); + } + + /** + * The main function of the RenderContext. + * + * Use this function to render any route known to Astro. + * It attempts to render a route. A route can be a: + * + * - page + * - redirect + * - endpoint + * - fallback + */ + async render(componentInstance: ComponentInstance | undefined): Promise { + const { cookies, middleware, pathname, pipeline, routeData } = this; + const { logger, routeCache, serverLike, streaming } = pipeline; + const props = await getProps({ mod: componentInstance, routeData, routeCache, pathname, logger, serverLike }); + const apiContext = this.createAPIContext(props); + const { type } = routeData; + + const lastNext = + type === 'endpoint' ? () => renderEndpoint(componentInstance as any, apiContext, serverLike, logger) : + type === 'redirect' ? () => renderRedirect(this) : + type === 'page' ? async () => { + const result = await this.createResult(componentInstance!); + const response = await renderPage(result, componentInstance?.default as any, props, {}, streaming, routeData); + response.headers.set(ROUTE_TYPE_HEADER, "page"); + return response; + } : + type === 'fallback' ? () => new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: "fallback" } }) : + () => { throw new Error("Unknown type of route: " + type) } + + const response = await callMiddleware(middleware, apiContext, lastNext); + if (response.headers.get(ROUTE_TYPE_HEADER)) { + response.headers.delete(ROUTE_TYPE_HEADER) + } + // LEGACY: we put cookies on the response object, + // where the adapter might be expecting to read it. + // New code should be using `app.render({ addCookieHeader: true })` instead. + attachCookiesToResponse(response, cookies); + return response; + } + + createAPIContext(props: APIContext['props']): APIContext { + const renderContext = this; + const { cookies, i18nData, params, pipeline, request } = this; + const { currentLocale, preferredLocale, preferredLocaleList } = i18nData; + const generator = `Astro v${ASTRO_VERSION}`; + const redirect = (path: string, status = 302) => new Response(null, { status, headers: { Location: path } }); + const site = pipeline.site ? new URL(pipeline.site) : undefined; + const url = new URL(request.url); + return { + cookies, currentLocale, generator, params, preferredLocale, preferredLocaleList, props, redirect, request, site, url, + get clientAddress() { + if (clientAddressSymbol in request) { + return Reflect.get(request, clientAddressSymbol) as string; + } + if (pipeline.adapterName) { + throw new AstroError({ + ...AstroErrorData.ClientAddressNotAvailable, + message: AstroErrorData.ClientAddressNotAvailable.message(pipeline.adapterName), + }); + } else { + throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable); + } + }, + get locals() { + return renderContext.locals; + }, + // TODO(breaking): disallow replacing the locals object + set locals(val) { + if (typeof val !== 'object') { + throw new AstroError(AstroErrorData.LocalsNotAnObject); + } else { + renderContext.locals = val; + // we also put it on the original Request object, + // where the adapter might be expecting to read it after the response. + Reflect.set(request, clientLocalsSymbol, val); + } + } + } + } + + async createResult(mod: ComponentInstance) { + const { cookies, locals, params, pathname, pipeline, request, routeData, status } = this; + const { adapterName, clientDirectives, compressHTML, i18n, manifest, logger, renderers, resolve, site, serverLike } = pipeline; + const { links, scripts, styles } = await pipeline.headElements(routeData); + const componentMetadata = await pipeline.componentMetadata(routeData) ?? manifest.componentMetadata; + const { defaultLocale, locales, routing: routingStrategy } = i18n ?? {}; + const partial = Boolean(mod.partial); + return createResult({ adapterName, clientDirectives, componentMetadata, compressHTML, cookies, defaultLocale, locales, locals, logger, links, params, partial, pathname, renderers, resolve, request, route: routeData.route, routingStrategy, site, scripts, ssr: serverLike, status, styles }); + } + + /** + * API Context may be created multiple times per request, i18n data needs to be computed only once. + * So, it is computed and saved here on creation of the first APIContext and reused for later ones. + */ + #i18nData?: Pick + + get i18nData() { + if (this.#i18nData) return this.#i18nData + const { pipeline: { i18n }, request, routeData } = this; + if (!i18n) return { + currentLocale: undefined, + preferredLocale: undefined, + preferredLocaleList: undefined + } + const { defaultLocale, locales, routing } = i18n + return this.#i18nData = { + currentLocale: computeCurrentLocale(routeData.route, locales, routing, defaultLocale), + preferredLocale: computePreferredLocale(request, locales), + preferredLocaleList: computePreferredLocaleList(request, locales) + } + } +} diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts deleted file mode 100644 index 1175f55d7bc3..000000000000 --- a/packages/astro/src/core/render/core.ts +++ /dev/null @@ -1,83 +0,0 @@ -import type { AstroCookies, ComponentInstance } from '../../@types/astro.js'; -import { renderPage as runtimeRenderPage } from '../../runtime/server/index.js'; -import { attachCookiesToResponse } from '../cookies/index.js'; -import { CantRenderPage } from '../errors/errors-data.js'; -import { AstroError } from '../errors/index.js'; -import { routeIsFallback } from '../redirects/helpers.js'; -import { redirectRouteGenerate, redirectRouteStatus, routeIsRedirect } from '../redirects/index.js'; -import type { RenderContext } from './context.js'; -import type { Environment } from './environment.js'; -import { createResult } from './result.js'; - -export type RenderPage = { - mod: ComponentInstance | undefined; - renderContext: RenderContext; - env: Environment; - cookies: AstroCookies; -}; - -export async function renderPage({ mod, renderContext, env, cookies }: RenderPage) { - if (routeIsRedirect(renderContext.route)) { - return new Response(null, { - status: redirectRouteStatus(renderContext.route, renderContext.request.method), - headers: { - location: redirectRouteGenerate(renderContext.route, renderContext.params), - }, - }); - } else if (routeIsFallback(renderContext.route)) { - // We return a 404 because fallback routes don't exist. - // It's responsibility of the middleware to catch them and re-route the requests - return new Response(null, { - status: 404, - }); - } else if (!mod) { - throw new AstroError(CantRenderPage); - } - - // Validate the page component before rendering the page - const Component = mod.default; - if (!Component) - throw new Error(`Expected an exported Astro component but received typeof ${typeof Component}`); - - const result = createResult({ - adapterName: env.adapterName, - links: renderContext.links, - styles: renderContext.styles, - logger: env.logger, - params: renderContext.params, - pathname: renderContext.pathname, - componentMetadata: renderContext.componentMetadata, - resolve: env.resolve, - renderers: env.renderers, - clientDirectives: env.clientDirectives, - compressHTML: env.compressHTML, - request: renderContext.request, - partial: !!mod.partial, - site: env.site, - scripts: renderContext.scripts, - ssr: env.ssr, - status: renderContext.status ?? 200, - cookies, - locals: renderContext.locals ?? {}, - locales: renderContext.locales, - defaultLocale: renderContext.defaultLocale, - routingStrategy: renderContext.routing, - }); - - const response = await runtimeRenderPage( - result, - Component, - renderContext.props, - {}, - env.streaming, - renderContext.route - ); - - // If there is an Astro.cookies instance, attach it to the response so that - // adapters can grab the Set-Cookie headers. - if (result.cookies) { - attachCookiesToResponse(response, result.cookies); - } - - return response; -} diff --git a/packages/astro/src/core/render/environment.ts b/packages/astro/src/core/render/environment.ts deleted file mode 100644 index 582ee61299d9..000000000000 --- a/packages/astro/src/core/render/environment.ts +++ /dev/null @@ -1,39 +0,0 @@ -import type { RuntimeMode, SSRLoadedRenderer } from '../../@types/astro.js'; -import type { Logger } from '../logger/core.js'; -import type { RouteCache } from './route-cache.js'; - -/** - * An environment represents the static parts of rendering that do not change - * between requests. These are mostly known when the server first starts up and do not change. - * Thus, they can be created once and passed through to renderPage on each request. - */ -export interface Environment { - /** - * Used to provide better error messages for `Astro.clientAddress` - */ - adapterName?: string; - /** logging options */ - logger: Logger; - /** "development" or "production" */ - mode: RuntimeMode; - compressHTML: boolean; - renderers: SSRLoadedRenderer[]; - clientDirectives: Map; - resolve: (s: string) => Promise; - routeCache: RouteCache; - /** - * Used for `Astro.site` - */ - site?: string; - /** - * Value of Astro config's `output` option, true if "server" or "hybrid" - */ - ssr: boolean; - streaming: boolean; -} - -export type CreateEnvironmentArgs = Environment; - -export function createEnvironment(options: CreateEnvironmentArgs): Environment { - return options; -} diff --git a/packages/astro/src/core/render/index.ts b/packages/astro/src/core/render/index.ts index 5f3a702a3083..266abf696080 100644 --- a/packages/astro/src/core/render/index.ts +++ b/packages/astro/src/core/render/index.ts @@ -1,16 +1,13 @@ -import type { AstroMiddlewareInstance, ComponentInstance, RouteData } from '../../@types/astro.js'; -import type { Environment } from './environment.js'; -export { computePreferredLocale, createRenderContext } from './context.js'; -export type { RenderContext } from './context.js'; -export { createEnvironment } from './environment.js'; -export { getParamsAndProps } from './params-and-props.js'; +import type { ComponentInstance, RouteData } from '../../@types/astro.js'; +import type { Pipeline } from '../base-pipeline.js'; +export { Pipeline } from '../base-pipeline.js'; +export { getParams, getProps } from './params-and-props.js'; export { loadRenderer } from './renderer.js'; - -export type { Environment }; +export { createResult } from './result.js'; export interface SSROptions { - /** The environment instance */ - env: Environment; + /** The pipeline instance */ + pipeline: Pipeline; /** location of file on disk */ filePath: URL; /** the web request (needed for dynamic routes) */ @@ -21,8 +18,4 @@ export interface SSROptions { request: Request; /** optional, in case we need to render something outside a dev server */ route: RouteData; - /** - * Optional middlewares - */ - middleware?: AstroMiddlewareInstance; } diff --git a/packages/astro/src/core/render/params-and-props.ts b/packages/astro/src/core/render/params-and-props.ts index 3532c5f83726..ff901cd844e9 100644 --- a/packages/astro/src/core/render/params-and-props.ts +++ b/packages/astro/src/core/render/params-and-props.ts @@ -3,35 +3,34 @@ import { AstroError, AstroErrorData } from '../errors/index.js'; import type { Logger } from '../logger/core.js'; import { routeIsFallback } from '../redirects/helpers.js'; import { routeIsRedirect } from '../redirects/index.js'; -import { getParams } from '../routing/params.js'; import type { RouteCache } from './route-cache.js'; import { callGetStaticPaths, findPathItemByKey } from './route-cache.js'; interface GetParamsAndPropsOptions { mod: ComponentInstance | undefined; - route?: RouteData | undefined; + routeData?: RouteData | undefined; routeCache: RouteCache; pathname: string; logger: Logger; - ssr: boolean; + serverLike: boolean; } -export async function getParamsAndProps(opts: GetParamsAndPropsOptions): Promise<[Params, Props]> { - const { logger, mod, route, routeCache, pathname, ssr } = opts; +export async function getProps(opts: GetParamsAndPropsOptions): Promise { + const { logger, mod, routeData: route, routeCache, pathname, serverLike } = opts; // If there's no route, or if there's a pathname (e.g. a static `src/pages/normal.astro` file), // then we know for sure they don't have params and props, return a fallback value. if (!route || route.pathname) { - return [{}, {}]; + return {}; } - // This is a dynamic route, start getting the params - const params = getRouteParams(route, pathname) ?? {}; - + if (routeIsRedirect(route) || routeIsFallback(route)) { - return [params, {}]; + return {}; } - + + // This is a dynamic route, start getting the params + const params = getParams(route, pathname); if (mod) { validatePrerenderEndpointCollision(route, mod, params); } @@ -43,11 +42,11 @@ export async function getParamsAndProps(opts: GetParamsAndPropsOptions): Promise route, routeCache, logger, - ssr, + ssr: serverLike, }); const matchedStaticPath = findPathItemByKey(staticPaths, params, route, logger); - if (!matchedStaticPath && (ssr ? route.prerender : true)) { + if (!matchedStaticPath && (serverLike ? route.prerender : true)) { throw new AstroError({ ...AstroErrorData.NoMatchingStaticPathFound, message: AstroErrorData.NoMatchingStaticPathFound.message(pathname), @@ -57,18 +56,28 @@ export async function getParamsAndProps(opts: GetParamsAndPropsOptions): Promise const props: Props = matchedStaticPath?.props ? { ...matchedStaticPath.props } : {}; - return [params, props]; + return props; } -function getRouteParams(route: RouteData, pathname: string): Params | undefined { - if (route.params.length) { - // The RegExp pattern expects a decoded string, but the pathname is encoded - // when the URL contains non-English characters. - const paramsMatch = route.pattern.exec(decodeURIComponent(pathname)); - if (paramsMatch) { - return getParams(route.params)(paramsMatch); +/** + * When given a route with the pattern `/[x]/[y]/[z]/svelte`, and a pathname `/a/b/c/svelte`, + * returns the params object: { x: "a", y: "b", z: "c" }. + */ +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(decodeURIComponent(pathname)); + if (!paramsMatch) return {}; + const params: Params = {}; + route.params.forEach((key, i) => { + if (key.startsWith('...')) { + params[key.slice(3)] = paramsMatch[i + 1] ? paramsMatch[i + 1] : undefined; + } else { + params[key] = paramsMatch[i + 1]; } - } + }); + return params; } /** diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 5faa6442c3e0..6c1314f3c782 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -17,11 +17,9 @@ import { computeCurrentLocale, computePreferredLocale, computePreferredLocaleList, -} from './context.js'; +} from '../../i18n/utils.js'; import type { RoutingStrategies } from '../config/schema.js'; - -const clientAddressSymbol = Symbol.for('astro.clientAddress'); -const responseSentSymbol = Symbol.for('astro.responseSent'); +import { clientAddressSymbol, responseSentSymbol } from '../constants.js'; export interface CreateResultArgs { /** @@ -44,16 +42,17 @@ export interface CreateResultArgs { * Used for `Astro.site` */ site: string | undefined; - links?: Set; - scripts?: Set; - styles?: Set; - componentMetadata?: SSRResult['componentMetadata']; + links: Set; + scripts: Set; + styles: Set; + componentMetadata: SSRResult['componentMetadata']; request: Request; status: number; locals: App.Locals; - cookies?: AstroCookies; + cookies: AstroCookies; locales: Locales | undefined; defaultLocale: string | undefined; + route: string; routingStrategy: RoutingStrategies | undefined; } @@ -233,7 +232,7 @@ export function createResult(args: CreateResultArgs): SSRResult { } if (args.locales) { currentLocale = computeCurrentLocale( - request, + url.pathname, args.locales, args.routingStrategy, args.defaultLocale diff --git a/packages/astro/src/core/routing/index.ts b/packages/astro/src/core/routing/index.ts index b568bb1217e5..3ddc559ad5c4 100644 --- a/packages/astro/src/core/routing/index.ts +++ b/packages/astro/src/core/routing/index.ts @@ -1,5 +1,4 @@ export { createRouteManifest } from './manifest/create.js'; export { deserializeRouteData, serializeRouteData } from './manifest/serialization.js'; export { matchAllRoutes, matchRoute } from './match.js'; -export { getParams } from './params.js'; export { validateDynamicRouteModule, validateGetStaticPathsResult } from './validation.js'; diff --git a/packages/astro/src/core/routing/params.ts b/packages/astro/src/core/routing/params.ts index 973f7f2b5e99..de2a8e979597 100644 --- a/packages/astro/src/core/routing/params.ts +++ b/packages/astro/src/core/routing/params.ts @@ -2,27 +2,6 @@ import type { GetStaticPathsItem, Params, RouteData } from '../../@types/astro.j import { trimSlashes } from '../path.js'; import { validateGetStaticPathsParameter } from './validation.js'; -/** - * given an array of params like `['x', 'y', 'z']` for - * src/routes/[x]/[y]/[z]/svelte, create a function - * that turns a RegExpExecArray into ({ x, y, z }) - */ -export function getParams(array: string[]) { - const fn = (match: RegExpExecArray) => { - const params: Params = {}; - array.forEach((key, i) => { - if (key.startsWith('...')) { - params[key.slice(3)] = match[i + 1] ? match[i + 1] : undefined; - } else { - params[key] = match[i + 1]; - } - }); - return params; - }; - - return fn; -} - /** * given a route's Params object, validate parameter * values and create a stringified key for the route diff --git a/packages/astro/src/i18n/middleware.ts b/packages/astro/src/i18n/middleware.ts index 73a43d471c25..91091cbec4c3 100644 --- a/packages/astro/src/i18n/middleware.ts +++ b/packages/astro/src/i18n/middleware.ts @@ -1,18 +1,9 @@ import { appendForwardSlash, joinPaths } from '@astrojs/internal-helpers/path'; -import type { - APIContext, - Locales, - MiddlewareHandler, - RouteData, - SSRManifest, -} from '../@types/astro.js'; -import type { PipelineHookFunction } from '../core/pipeline.js'; +import type { APIContext, Locales, MiddlewareHandler, SSRManifest } from '../@types/astro.js'; import { getPathByLocale, normalizeTheLocale } from './index.js'; import { shouldAppendForwardSlash } from '../core/build/util.js'; -import { ROUTE_DATA_SYMBOL } from '../core/constants.js'; -import type { SSRManifestI18n } from '../core/app/types.js'; - -const routeDataSymbol = Symbol.for(ROUTE_DATA_SYMBOL); +import type { SSRManifestI18n } from '../core/app/types.js' +import { ROUTE_TYPE_HEADER } from '../core/constants.js'; // Checks if the pathname has any locale, exception for the defaultLocale, which is ignored on purpose. function pathnameHasLocale(pathname: string, locales: Locales): boolean { @@ -107,18 +98,16 @@ export function createI18nMiddleware( }; return async (context, next) => { - const routeData: RouteData | undefined = Reflect.get(context.request, routeDataSymbol); + const response = await next(); + const type = response.headers.get(ROUTE_TYPE_HEADER); // If the route we're processing is not a page, then we ignore it - if (routeData?.type !== 'page' && routeData?.type !== 'fallback') { - return await next(); + if (type !== 'page' && type !== 'fallback') { + return response } - const currentLocale = context.currentLocale; - const url = context.url; + const { url, currentLocale } = context; const { locales, defaultLocale, fallback, routing } = i18n; - const response = await next(); - if (response instanceof Response) { switch (i18n.routing) { case 'domains-prefix-other-locales': { if (localeHasntDomain(i18n, currentLocale)) { @@ -207,19 +196,11 @@ export function createI18nMiddleware( return context.redirect(newPathname); } } - } return response; }; } -/** - * This pipeline hook attaches a `RouteData` object to the `Request` - */ -export const i18nPipelineHook: PipelineHookFunction = (ctx) => { - Reflect.set(ctx.request, routeDataSymbol, ctx.route); -}; - /** * Checks if the current locale doesn't belong to a configured domain * @param i18n diff --git a/packages/astro/src/core/render/context.ts b/packages/astro/src/i18n/utils.ts similarity index 65% rename from packages/astro/src/core/render/context.ts rename to packages/astro/src/i18n/utils.ts index 8511942f348a..4cfec633b3a2 100644 --- a/packages/astro/src/core/render/context.ts +++ b/packages/astro/src/i18n/utils.ts @@ -1,92 +1,6 @@ -import type { - ComponentInstance, - Locales, - Params, - Props, - RouteData, - SSRElement, - SSRResult, -} from '../../@types/astro.js'; -import { normalizeTheLocale, toCodes } from '../../i18n/index.js'; -import { AstroError, AstroErrorData } from '../errors/index.js'; -import type { Environment } from './environment.js'; -import { getParamsAndProps } from './params-and-props.js'; -import type { RoutingStrategies } from '../config/schema.js'; -import { ROUTE_DATA_SYMBOL } from '../constants.js'; - -const clientLocalsSymbol = Symbol.for('astro.locals'); -const routeDataSymbol = Symbol.for(ROUTE_DATA_SYMBOL); - -/** - * The RenderContext represents the parts of rendering that are specific to one request. - */ -export interface RenderContext { - request: Request; - pathname: string; - scripts?: Set; - links?: Set; - styles?: Set; - componentMetadata?: SSRResult['componentMetadata']; - route: RouteData; - status?: number; - params: Params; - props: Props; - locals?: object; - locales: Locales | undefined; - defaultLocale: string | undefined; - routing: RoutingStrategies | undefined; -} - -export type CreateRenderContextArgs = Partial< - Omit -> & { - route: RouteData; - request: RenderContext['request']; - mod: ComponentInstance | undefined; - env: Environment; -}; - -export async function createRenderContext( - options: CreateRenderContextArgs -): Promise { - const request = options.request; - const pathname = options.pathname ?? new URL(request.url).pathname; - const [params, props] = await getParamsAndProps({ - mod: options.mod as any, - route: options.route, - routeCache: options.env.routeCache, - pathname: pathname, - logger: options.env.logger, - ssr: options.env.ssr, - }); - - const context: RenderContext = { - ...options, - pathname, - params, - props, - locales: options.locales, - routing: options.routing, - defaultLocale: options.defaultLocale, - }; - - // We define a custom property, so we can check the value passed to locals - Object.defineProperty(context, 'locals', { - enumerable: true, - get() { - return Reflect.get(request, clientLocalsSymbol); - }, - set(val) { - if (typeof val !== 'object') { - throw new AstroError(AstroErrorData.LocalsNotAnObject); - } else { - Reflect.set(request, clientLocalsSymbol, val); - } - }, - }); - - return context; -} +import type { Locales } from '../@types/astro.js'; +import { normalizeTheLocale, toCodes } from './index.js'; +import type { RoutingStrategies } from '../core/config/schema.js'; type BrowserLocale = { locale: string; @@ -240,19 +154,12 @@ export function computePreferredLocaleList(request: Request, locales: Locales): } export function computeCurrentLocale( - request: Request, + pathname: string, locales: Locales, routingStrategy: RoutingStrategies | undefined, defaultLocale: string | undefined ): undefined | string { - const routeData: RouteData | undefined = Reflect.get(request, routeDataSymbol); - if (!routeData) { - return defaultLocale; - } - // Typically, RouteData::pathname has the correct information in SSR, but it's not available in SSG, so we fall back - // to use the pathname from the Request - const pathname = routeData.pathname ?? new URL(request.url).pathname; - for (const segment of pathname.split('/').filter(Boolean)) { + for (const segment of pathname.split('/')) { for (const locale of locales) { if (typeof locale === 'string') { // we skip ta locale that isn't present in the current segment diff --git a/packages/astro/src/prerender/routing.ts b/packages/astro/src/prerender/routing.ts index d8250b98ffe4..8ecf20a5f4e7 100644 --- a/packages/astro/src/prerender/routing.ts +++ b/packages/astro/src/prerender/routing.ts @@ -1,7 +1,6 @@ import type { AstroSettings, ComponentInstance, RouteData } from '../@types/astro.js'; import { RedirectComponentInstance, routeIsRedirect } from '../core/redirects/index.js'; -import type DevPipeline from '../vite-plugin-astro-server/devPipeline.js'; -import { preload } from '../vite-plugin-astro-server/index.js'; +import type { DevPipeline } from '../vite-plugin-astro-server/pipeline.js'; import { getPrerenderStatus } from './metadata.js'; type GetSortedPreloadedMatchesParams = { @@ -52,12 +51,12 @@ async function preloadAndSetPrerenderStatus({ continue; } - const preloadedComponent = await preload({ pipeline, filePath }); + const preloadedComponent = await pipeline.preload(filePath); // gets the prerender metadata set by the `astro:scanner` vite plugin const prerenderStatus = getPrerenderStatus({ filePath, - loader: pipeline.getModuleLoader(), + loader: pipeline.loader, }); if (prerenderStatus !== undefined) { diff --git a/packages/astro/src/runtime/server/consts.ts b/packages/astro/src/runtime/server/consts.ts deleted file mode 100644 index d8d7ccb828ca..000000000000 --- a/packages/astro/src/runtime/server/consts.ts +++ /dev/null @@ -1 +0,0 @@ -export const REROUTE_DIRECTIVE_HEADER = 'X-Astro-Reroute'; diff --git a/packages/astro/src/runtime/server/endpoint.ts b/packages/astro/src/runtime/server/endpoint.ts index 9b5f3e40e0da..2afee2f23594 100644 --- a/packages/astro/src/runtime/server/endpoint.ts +++ b/packages/astro/src/runtime/server/endpoint.ts @@ -1,5 +1,5 @@ import { bold } from 'kleur/colors'; -import { REROUTE_DIRECTIVE_HEADER } from './consts.js'; +import { REROUTABLE_STATUS_CODES, REROUTE_DIRECTIVE_HEADER } from '../../core/constants.js';; import type { APIContext, EndpointHandler } from '../../@types/astro.js'; import type { Logger } from '../../core/logger/core.js'; @@ -51,7 +51,7 @@ export async function renderEndpoint( const response = await handler.call(mod, context); // Endpoints explicitly returning 404 or 500 response status should // NOT be subject to rerouting to 404.astro or 500.astro. - if (response.status === 404 || response.status === 500) { + if (REROUTABLE_STATUS_CODES.includes(response.status)) { // Only `Response.redirect` headers are immutable, therefore a `try..catch` is not necessary. // Note: `Response.redirect` can only be called with HTTP status codes: 301, 302, 303, 307, 308. // Source: https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static#parameters diff --git a/packages/astro/src/vite-plugin-astro-server/devPipeline.ts b/packages/astro/src/vite-plugin-astro-server/devPipeline.ts deleted file mode 100644 index 409851eafdc5..000000000000 --- a/packages/astro/src/vite-plugin-astro-server/devPipeline.ts +++ /dev/null @@ -1,91 +0,0 @@ -import type { - AstroConfig, - AstroSettings, - RuntimeMode, - SSRLoadedRenderer, - SSRManifest, -} from '../@types/astro.js'; -import type { Logger } from '../core/logger/core.js'; -import type { ModuleLoader } from '../core/module-loader/index.js'; -import { Pipeline } from '../core/pipeline.js'; -import type { Environment } from '../core/render/index.js'; -import { createEnvironment, loadRenderer } from '../core/render/index.js'; -import { RouteCache } from '../core/render/route-cache.js'; -import { isServerLikeOutput } from '../prerender/utils.js'; -import { createResolve } from './resolve.js'; - -export default class DevPipeline extends Pipeline { - #settings: AstroSettings; - #loader: ModuleLoader; - #devLogger: Logger; - - constructor({ - manifest, - logger, - settings, - loader, - }: { - manifest: SSRManifest; - logger: Logger; - settings: AstroSettings; - loader: ModuleLoader; - }) { - const env = DevPipeline.createDevelopmentEnvironment(manifest, settings, logger, loader); - super(env); - this.#devLogger = logger; - this.#settings = settings; - this.#loader = loader; - } - - clearRouteCache() { - this.env.routeCache.clearAll(); - } - - getSettings(): Readonly { - return this.#settings; - } - - getConfig(): Readonly { - return this.#settings.config; - } - - getModuleLoader(): Readonly { - return this.#loader; - } - - get logger(): Readonly { - return this.#devLogger; - } - - async loadRenderers() { - const renderers = await Promise.all( - this.#settings.renderers.map((r) => loadRenderer(r, this.#loader)) - ); - this.env.renderers = renderers.filter(Boolean) as SSRLoadedRenderer[]; - } - - static createDevelopmentEnvironment( - manifest: SSRManifest, - settings: AstroSettings, - logger: Logger, - loader: ModuleLoader - ): Environment { - const mode: RuntimeMode = 'development'; - return createEnvironment({ - adapterName: manifest.adapterName, - logger, - mode, - // This will be overridden in the dev server - renderers: [], - clientDirectives: manifest.clientDirectives, - compressHTML: manifest.compressHTML, - resolve: createResolve(loader, settings.config.root), - routeCache: new RouteCache(logger, mode), - site: manifest.site, - ssr: isServerLikeOutput(settings.config), - streaming: true, - }); - } - - async handleFallback() {} -} diff --git a/packages/astro/src/vite-plugin-astro-server/error.ts b/packages/astro/src/vite-plugin-astro-server/error.ts index 7c478fc6eb68..3bfd9f5f996b 100644 --- a/packages/astro/src/vite-plugin-astro-server/error.ts +++ b/packages/astro/src/vite-plugin-astro-server/error.ts @@ -1,6 +1,6 @@ import type { ModuleLoader } from '../core/module-loader/index.js'; import type { AstroConfig } from '../@types/astro.js'; -import type DevPipeline from './devPipeline.js'; +import type { DevPipeline } from './pipeline.js'; import { collectErrorMetadata } from '../core/errors/dev/index.js'; import { createSafeError, AstroErrorData } from '../core/errors/index.js'; @@ -10,7 +10,7 @@ import { eventError, telemetry } from '../events/index.js'; export function recordServerError( loader: ModuleLoader, config: AstroConfig, - pipeline: DevPipeline, + { logger }: DevPipeline, _err: unknown ) { const err = createSafeError(_err); @@ -29,9 +29,9 @@ export function recordServerError( telemetry.record(eventError({ cmd: 'dev', err: errorWithMetadata, isFatal: false })); } - pipeline.logger.error( + logger.error( null, - formatErrorMessage(errorWithMetadata, pipeline.logger.level() === 'debug') + formatErrorMessage(errorWithMetadata, logger.level() === 'debug') ); return { diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index 97592d47a4f9..14172e8ae827 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -1,34 +1,3 @@ -import type { ComponentInstance } from '../@types/astro.js'; -import { enhanceViteSSRError } from '../core/errors/dev/index.js'; -import { AggregateError, CSSError, MarkdownError } from '../core/errors/index.js'; -import { viteID } from '../core/util.js'; -import type DevPipeline from './devPipeline.js'; - -export async function preload({ - pipeline, - filePath, -}: { - pipeline: DevPipeline; - filePath: URL; -}): Promise { - // Important: This needs to happen first, in case a renderer provides polyfills. - await pipeline.loadRenderers(); - - try { - // Load the module from the Vite SSR Runtime. - const mod = (await pipeline.getModuleLoader().import(viteID(filePath))) as ComponentInstance; - - return mod; - } catch (error) { - // If the error came from Markdown or CSS, we already handled it and there's no need to enhance it - if (MarkdownError.is(error) || CSSError.is(error) || AggregateError.is(error)) { - throw error; - } - - throw enhanceViteSSRError({ error, filePath, loader: pipeline.getModuleLoader() }); - } -} - export { createController, runWithErrorHandling } from './controller.js'; export { default as vitePluginAstroServer } from './plugin.js'; export { handleRequest } from './request.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/pipeline.ts b/packages/astro/src/vite-plugin-astro-server/pipeline.ts new file mode 100644 index 000000000000..f2a6a1712bcc --- /dev/null +++ b/packages/astro/src/vite-plugin-astro-server/pipeline.ts @@ -0,0 +1,137 @@ +import url from 'node:url' +import type { AstroSettings, ComponentInstance, DevToolbarMetadata, RouteData, SSRElement, SSRLoadedRenderer, SSRManifest } from '../@types/astro.js'; +import type { Logger } from '../core/logger/core.js'; +import type { ModuleLoader } from '../core/module-loader/index.js'; +import { Pipeline, loadRenderer } from '../core/render/index.js'; +import { isPage, resolveIdToUrl, viteID } from '../core/util.js'; +import { isServerLikeOutput } from '../prerender/utils.js'; +import { createResolve } from './resolve.js'; +import { AggregateError, CSSError, MarkdownError } from '../core/errors/index.js'; +import { enhanceViteSSRError } from '../core/errors/dev/index.js'; +import type { HeadElements } from '../core/base-pipeline.js'; +import { getScriptsForURL } from './scripts.js'; +import { ASTRO_VERSION } from '../core/constants.js'; +import { getInfoOutput } from '../cli/info/index.js'; +import { PAGE_SCRIPT_ID } from '../vite-plugin-scripts/index.js'; +import { getStylesForURL } from './css.js'; +import { getComponentMetadata } from './metadata.js'; + +export class DevPipeline extends Pipeline { + // renderers are loaded on every request, + // so it needs to be mutable here unlike in other environments + override renderers = new Array + + private constructor( + readonly loader: ModuleLoader, + readonly logger: Logger, + readonly manifest: SSRManifest, + readonly settings: AstroSettings, + readonly config = settings.config, + ) { + const mode = 'development' + const resolve = createResolve(loader, config.root); + const serverLike = isServerLikeOutput(config); + const streaming = true; + super(logger, manifest, mode, [], resolve, serverLike, streaming); + } + + static create({ loader, logger, manifest, settings }: Pick) { + return new DevPipeline(loader, logger, manifest, settings) + } + + async headElements(routeData: RouteData): Promise { + const { config: { root }, loader, mode, settings } = this; + const filePath = new URL(`./${routeData.component}`, root); + const { scripts } = await getScriptsForURL(filePath, root, loader); + + // Inject HMR scripts + if (isPage(filePath, settings) && mode === 'development') { + scripts.add({ + props: { type: 'module', src: '/@vite/client' }, + children: '', + }); + + if ( + settings.config.devToolbar.enabled && + (await settings.preferences.get('devToolbar.enabled')) + ) { + const src = await resolveIdToUrl(loader, 'astro/runtime/client/dev-toolbar/entrypoint.js') + scripts.add({ props: { type: 'module', src }, children: '' }); + + const additionalMetadata: DevToolbarMetadata['__astro_dev_toolbar__'] = { + root: url.fileURLToPath(settings.config.root), + version: ASTRO_VERSION, + debugInfo: await getInfoOutput({ userConfig: settings.config, print: false }), + }; + + // Additional data for the dev overlay + const children = `window.__astro_dev_toolbar__ = ${JSON.stringify(additionalMetadata)}`; + scripts.add({ props: {}, children }); + } + } + + // TODO: We should allow adding generic HTML elements to the head, not just scripts + for (const script of settings.scripts) { + if (script.stage === 'head-inline') { + scripts.add({ + props: {}, + children: script.content, + }); + } else if (script.stage === 'page' && isPage(filePath, settings)) { + scripts.add({ + props: { type: 'module', src: `/@id/${PAGE_SCRIPT_ID}` }, + children: '', + }); + } + } + + // Pass framework CSS in as style tags to be appended to the page. + const links = new Set(); + const { urls, styles: _styles } = await getStylesForURL(filePath, loader); + for (const href of urls) { + links.add({ props: { rel: 'stylesheet', href }, children: '' }); + } + + const styles = new Set(); + for (const { id, url: src, content } of _styles) { + // Vite handles HMR for styles injected as scripts + scripts.add({ props: { type: 'module', src }, children: '' }); + // But we still want to inject the styles to avoid FOUC. The style tags + // should emulate what Vite injects so further HMR works as expected. + styles.add({ props: { 'data-vite-dev-id': id }, children: content }); + }; + + return { scripts, styles, links } + } + + componentMetadata(routeData: RouteData) { + const { config: { root }, loader } = this; + const filePath = new URL(`./${routeData.component}`, root); + return getComponentMetadata(filePath, loader) + } + + async preload(filePath: URL) { + const { loader } = this; + + // Important: This needs to happen first, in case a renderer provides polyfills. + const renderers__ = this.settings.renderers.map((r) => loadRenderer(r, loader)); + const renderers_ = await Promise.all(renderers__); + this.renderers = renderers_.filter((r): r is SSRLoadedRenderer => Boolean(r)); + + try { + // Load the module from the Vite SSR Runtime. + return await loader.import(viteID(filePath)) as ComponentInstance; + } catch (error) { + // If the error came from Markdown or CSS, we already handled it and there's no need to enhance it + if (MarkdownError.is(error) || CSSError.is(error) || AggregateError.is(error)) { + throw error; + } + + throw enhanceViteSSRError({ error, filePath, loader }); + } + } + + clearRouteCache() { + this.routeCache.clearAll(); + } +} diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts index ba33c3ebd44b..e149acad0a15 100644 --- a/packages/astro/src/vite-plugin-astro-server/plugin.ts +++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts @@ -8,7 +8,7 @@ import { createViteLoader } from '../core/module-loader/index.js'; import { createRouteManifest } from '../core/routing/index.js'; import { baseMiddleware } from './base.js'; import { createController } from './controller.js'; -import DevPipeline from './devPipeline.js'; +import { DevPipeline } from './pipeline.js'; import { handleRequest } from './request.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; import { getViteErrorPayload } from '../core/errors/dev/index.js'; @@ -33,7 +33,7 @@ export default function createVitePluginAstroServer({ configureServer(viteServer) { const loader = createViteLoader(viteServer); const manifest = createDevelopmentManifest(settings); - const pipeline = new DevPipeline({ logger, manifest, settings, loader }); + const pipeline = DevPipeline.create({ loader, logger, manifest, settings }); let manifestData: ManifestData = createRouteManifest({ settings, fsMod }, logger); const controller = createController({ loader }); const localStorage = new AsyncLocalStorage(); @@ -90,7 +90,6 @@ export default function createVitePluginAstroServer({ controller, incomingRequest: request, incomingResponse: response, - manifest, }); }); }); diff --git a/packages/astro/src/vite-plugin-astro-server/request.ts b/packages/astro/src/vite-plugin-astro-server/request.ts index 29ceafa0c5ab..f86609c8c076 100644 --- a/packages/astro/src/vite-plugin-astro-server/request.ts +++ b/packages/astro/src/vite-plugin-astro-server/request.ts @@ -1,10 +1,10 @@ import type http from 'node:http'; -import type { ManifestData, SSRManifest } from '../@types/astro.js'; +import type { ManifestData } from '../@types/astro.js'; import { collapseDuplicateSlashes, removeTrailingForwardSlash } from '../core/path.js'; import { isServerLikeOutput } from '../prerender/utils.js'; import type { DevServerController } from './controller.js'; import { runWithErrorHandling } from './controller.js'; -import type DevPipeline from './devPipeline.js'; +import type { DevPipeline } from './pipeline.js'; import { handle500Response } from './response.js'; import { handleRoute, matchRoute } from './route.js'; import { recordServerError } from './error.js'; @@ -15,7 +15,6 @@ type HandleRequest = { controller: DevServerController; incomingRequest: http.IncomingMessage; incomingResponse: http.ServerResponse; - manifest: SSRManifest; }; /** The main logic to route dev server requests to pages in Astro. */ @@ -25,11 +24,9 @@ export async function handleRequest({ controller, incomingRequest, incomingResponse, - manifest, }: HandleRequest) { - const config = pipeline.getConfig(); - const moduleLoader = pipeline.getModuleLoader(); - const origin = `${moduleLoader.isHttps() ? 'https' : 'http'}://${incomingRequest.headers.host}`; + const { config, loader } = pipeline; + const origin = `${loader.isHttps() ? 'https' : 'http'}://${incomingRequest.headers.host}`; const buildingToSSR = isServerLikeOutput(config); const url = new URL(collapseDuplicateSlashes(origin + incomingRequest.url)); @@ -82,12 +79,11 @@ export async function handleRequest({ manifestData, incomingRequest: incomingRequest, incomingResponse: incomingResponse, - manifest, }); }, onError(_err) { - const { error, errorWithMetadata } = recordServerError(moduleLoader, config, pipeline, _err); - handle500Response(moduleLoader, incomingResponse, errorWithMetadata); + const { error, errorWithMetadata } = recordServerError(loader, config, pipeline, _err); + handle500Response(loader, incomingResponse, errorWithMetadata); return error; }, }); diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts index 0cc8a819326d..ff76d4556132 100644 --- a/packages/astro/src/vite-plugin-astro-server/route.ts +++ b/packages/astro/src/vite-plugin-astro-server/route.ts @@ -1,43 +1,22 @@ import type http from 'node:http'; -import { fileURLToPath } from 'node:url'; import type { ComponentInstance, - DevToolbarMetadata, ManifestData, - MiddlewareHandler, RouteData, - SSRElement, - SSRManifest, } from '../@types/astro.js'; -import { getInfoOutput } from '../cli/info/index.js'; -import { ASTRO_VERSION } from '../core/constants.js'; import { AstroErrorData, isAstroError } from '../core/errors/index.js'; import { req } from '../core/messages.js'; -import { sequence } from '../core/middleware/index.js'; import { loadMiddleware } from '../core/middleware/loadMiddleware.js'; -import { - createRenderContext, - getParamsAndProps, - type RenderContext, - type SSROptions, -} from '../core/render/index.js'; +import { getProps, type SSROptions } from '../core/render/index.js'; import { createRequest } from '../core/request.js'; import { matchAllRoutes } from '../core/routing/index.js'; -import { isPage, resolveIdToUrl } from '../core/util.js'; import { normalizeTheLocale } from '../i18n/index.js'; -import { createI18nMiddleware, i18nPipelineHook } from '../i18n/middleware.js'; import { getSortedPreloadedMatches } from '../prerender/routing.js'; import { isServerLikeOutput } from '../prerender/utils.js'; -import { PAGE_SCRIPT_ID } from '../vite-plugin-scripts/index.js'; -import { getStylesForURL } from './css.js'; -import type DevPipeline from './devPipeline.js'; -import { preload } from './index.js'; -import { getComponentMetadata } from './metadata.js'; +import type { DevPipeline } from './pipeline.js'; import { handle404Response, writeSSRResult, writeWebResponse } from './response.js'; -import { getScriptsForURL } from './scripts.js'; -import { REROUTE_DIRECTIVE_HEADER } from '../runtime/server/consts.js'; - -const clientLocalsSymbol = Symbol.for('astro.locals'); +import { REROUTE_DIRECTIVE_HEADER, clientLocalsSymbol } from '../core/constants.js'; +import { RenderContext } from '../core/render-context.js'; type AsyncReturnType Promise> = T extends ( ...args: any @@ -67,27 +46,22 @@ export async function matchRoute( manifestData: ManifestData, pipeline: DevPipeline ): Promise { - const env = pipeline.getEnvironment(); - const { routeCache, logger } = env; - let matches = matchAllRoutes(pathname, manifestData); + const { config, logger, routeCache, serverLike, settings } = pipeline; + const matches = matchAllRoutes(pathname, manifestData); - const preloadedMatches = await getSortedPreloadedMatches({ - pipeline, - matches, - settings: pipeline.getSettings(), - }); + const preloadedMatches = await getSortedPreloadedMatches({ pipeline, matches, settings }); for await (const { preloadedComponent, route: maybeRoute, filePath } of preloadedMatches) { // attempt to get static paths // if this fails, we have a bad URL match! try { - await getParamsAndProps({ + await getProps({ mod: preloadedComponent, - route: maybeRoute, + routeData: maybeRoute, routeCache, pathname: pathname, logger, - ssr: isServerLikeOutput(pipeline.getConfig()), + serverLike, }); return { route: maybeRoute, @@ -116,7 +90,7 @@ export async function matchRoute( if (matches.length) { const possibleRoutes = matches.flatMap((route) => route.component); - pipeline.logger.warn( + logger.warn( 'router', `${AstroErrorData.NoMatchingStaticPathFound.message( pathname @@ -127,8 +101,8 @@ export async function matchRoute( const custom404 = getCustom404Route(manifestData); if (custom404) { - const filePath = new URL(`./${custom404.component}`, pipeline.getConfig().root); - const preloadedComponent = await preload({ pipeline, filePath }); + const filePath = new URL(`./${custom404.component}`, config.root); + const preloadedComponent = await pipeline.preload(filePath); return { route: custom404, @@ -151,7 +125,6 @@ type HandleRoute = { manifestData: ManifestData; incomingRequest: http.IncomingMessage; incomingResponse: http.ServerResponse; - manifest: SSRManifest; status?: 404 | 500; pipeline: DevPipeline; }; @@ -167,13 +140,9 @@ export async function handleRoute({ manifestData, incomingRequest, incomingResponse, - manifest, }: HandleRoute): Promise { const timeStart = performance.now(); - const env = pipeline.getEnvironment(); - const config = pipeline.getConfig(); - const moduleLoader = pipeline.getModuleLoader(); - const { logger } = env; + const { config, loader, logger } = pipeline; if (!matchedRoute && !config.i18n) { if (isLoggedRequest(pathname)) { logger.info(null, req({ url: pathname, method: incomingRequest.method, statusCode: 404 })); @@ -188,8 +157,8 @@ export async function handleRoute({ let mod: ComponentInstance | undefined = undefined; let options: SSROptions | undefined = undefined; let route: RouteData; - const middleware = await loadMiddleware(moduleLoader); - + const middleware = (await loadMiddleware(loader)).onRequest; + if (!matchedRoute) { if (config.i18n) { const locales = config.i18n.locales; @@ -239,16 +208,7 @@ export async function handleRoute({ fallbackRoutes: [], isIndex: false, }; - renderContext = await createRenderContext({ - request, - pathname, - env, - mod, - route, - locales: manifest.i18n?.locales, - routing: manifest.i18n?.routing, - defaultLocale: manifest.i18n?.defaultLocale, - }); + renderContext = RenderContext.create({ pipeline: pipeline, pathname, middleware, request, routeData: route }); } else { return handle404Response(origin, incomingRequest, incomingResponse); } @@ -256,16 +216,17 @@ export async function handleRoute({ const filePath: URL | undefined = matchedRoute.filePath; const { preloadedComponent } = matchedRoute; route = matchedRoute.route; - // Headers are only available when using SSR. + // Allows adapters to pass in locals in dev mode. + const locals = Reflect.get(incomingRequest, clientLocalsSymbol) request = createRequest({ url, + // Headers are only available when using SSR. headers: buildingToSSR ? incomingRequest.headers : new Headers(), method: incomingRequest.method, body, logger, ssr: buildingToSSR, clientAddress: buildingToSSR ? incomingRequest.socket.remoteAddress : undefined, - locals: Reflect.get(incomingRequest, clientLocalsSymbol), // Allows adapters to pass in locals in dev mode. }); // Set user specified headers to response object. @@ -274,60 +235,19 @@ export async function handleRoute({ } options = { - env, + pipeline, filePath, preload: preloadedComponent, pathname, request, route, - middleware, }; - mod = options.preload; - - const { scripts, links, styles, metadata } = await getScriptsAndStyles({ - pipeline, - filePath: options.filePath, - }); - - const i18n = pipeline.getConfig().i18n; - - renderContext = await createRenderContext({ - request: options.request, - pathname: options.pathname, - scripts, - links, - styles, - componentMetadata: metadata, - route: options.route, - mod, - env, - locales: i18n?.locales, - routing: i18n?.routing, - defaultLocale: i18n?.defaultLocale, - }); - } - - const onRequest: MiddlewareHandler = middleware.onRequest; - if (config.i18n) { - const i18Middleware = createI18nMiddleware( - manifest.i18n, - config.base, - config.trailingSlash, - config.build.format - ); - - if (i18Middleware) { - pipeline.setMiddlewareFunction(sequence(i18Middleware, onRequest)); - pipeline.onBeforeRenderRoute(i18nPipelineHook); - } else { - pipeline.setMiddlewareFunction(onRequest); - } - } else { - pipeline.setMiddlewareFunction(onRequest); + mod = preloadedComponent; + renderContext = RenderContext.create({ locals, pipeline, pathname, middleware, request, routeData: route }); } - let response = await pipeline.renderRoute(renderContext, mod); + let response = await renderContext.render(mod); if (isLoggedRequest(pathname)) { const timeEnd = performance.now(); logger.info( @@ -358,7 +278,6 @@ export async function handleRoute({ manifestData, incomingRequest, incomingResponse, - manifest, }); } if (route.type === 'endpoint') { @@ -385,104 +304,6 @@ export async function handleRoute({ await writeSSRResult(request, response, incomingResponse); } -interface GetScriptsAndStylesParams { - pipeline: DevPipeline; - filePath: URL; -} - -async function getScriptsAndStyles({ pipeline, filePath }: GetScriptsAndStylesParams) { - const moduleLoader = pipeline.getModuleLoader(); - const settings = pipeline.getSettings(); - const mode = pipeline.getEnvironment().mode; - // Add hoisted script tags - const { scripts } = await getScriptsForURL(filePath, settings.config.root, moduleLoader); - - // Inject HMR scripts - if (isPage(filePath, settings) && mode === 'development') { - scripts.add({ - props: { type: 'module', src: '/@vite/client' }, - children: '', - }); - - if ( - settings.config.devToolbar.enabled && - (await settings.preferences.get('devToolbar.enabled')) - ) { - scripts.add({ - props: { - type: 'module', - src: await resolveIdToUrl(moduleLoader, 'astro/runtime/client/dev-toolbar/entrypoint.js'), - }, - children: '', - }); - - const additionalMetadata: DevToolbarMetadata['__astro_dev_toolbar__'] = { - root: fileURLToPath(settings.config.root), - version: ASTRO_VERSION, - debugInfo: await getInfoOutput({ userConfig: settings.config, print: false }), - }; - - // Additional data for the dev overlay - scripts.add({ - props: {}, - children: `window.__astro_dev_toolbar__ = ${JSON.stringify(additionalMetadata)}`, - }); - } - } - - // TODO: We should allow adding generic HTML elements to the head, not just scripts - for (const script of settings.scripts) { - if (script.stage === 'head-inline') { - scripts.add({ - props: {}, - children: script.content, - }); - } else if (script.stage === 'page' && isPage(filePath, settings)) { - scripts.add({ - props: { type: 'module', src: `/@id/${PAGE_SCRIPT_ID}` }, - children: '', - }); - } - } - - // Pass framework CSS in as style tags to be appended to the page. - const { urls: styleUrls, styles: importedStyles } = await getStylesForURL(filePath, moduleLoader); - let links = new Set(); - [...styleUrls].forEach((href) => { - links.add({ - props: { - rel: 'stylesheet', - href, - }, - children: '', - }); - }); - - let styles = new Set(); - importedStyles.forEach(({ id, url, content }) => { - // Vite handles HMR for styles injected as scripts - scripts.add({ - props: { - type: 'module', - src: url, - }, - children: '', - }); - // But we still want to inject the styles to avoid FOUC. The style tags - // should emulate what Vite injects so further HMR works as expected. - styles.add({ - props: { - 'data-vite-dev-id': id, - }, - children: content, - }); - }); - - const metadata = await getComponentMetadata(filePath, moduleLoader); - - return { scripts, styles, links, metadata }; -} - function getStatus(matchedRoute?: MatchedRoute): 404 | 500 | undefined { if (!matchedRoute) return 404; if (matchedRoute.route.route === '/404') return 404; diff --git a/packages/astro/test/fixtures/i18n-routing-prefix-always/astro.config.mjs b/packages/astro/test/fixtures/i18n-routing-prefix-always/astro.config.mjs index 7a612488d4ca..cc445b3962c8 100644 --- a/packages/astro/test/fixtures/i18n-routing-prefix-always/astro.config.mjs +++ b/packages/astro/test/fixtures/i18n-routing-prefix-always/astro.config.mjs @@ -1,4 +1,4 @@ -import { defineConfig} from "astro/config"; +import { defineConfig } from "astro/config"; export default defineConfig({ i18n: { diff --git a/packages/astro/test/units/i18n/astro_i18n.test.js b/packages/astro/test/units/i18n/astro_i18n.test.js index 56be06194b0b..d7702f7fd0d3 100644 --- a/packages/astro/test/units/i18n/astro_i18n.test.js +++ b/packages/astro/test/units/i18n/astro_i18n.test.js @@ -4,7 +4,7 @@ import { getLocaleAbsoluteUrl, getLocaleAbsoluteUrlList, } from '../../../dist/i18n/index.js'; -import { parseLocale } from '../../../dist/core/render/context.js'; +import { parseLocale } from '../../../dist/i18n/utils.js'; import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; import { validateConfig } from '../../../dist/core/config/config.js'; diff --git a/packages/astro/test/units/render/head.test.js b/packages/astro/test/units/render/head.test.js index ab84534aac17..67077c9dd6d7 100644 --- a/packages/astro/test/units/render/head.test.js +++ b/packages/astro/test/units/render/head.test.js @@ -9,18 +9,22 @@ import { renderHead, Fragment, } from '../../../dist/runtime/server/index.js'; -import { createRenderContext } from '../../../dist/core/render/index.js'; -import { createBasicEnvironment } from '../test-utils.js'; +import { RenderContext } from '../../../dist/core/render-context.js'; +import { createBasicPipeline } from '../test-utils.js'; import * as cheerio from 'cheerio'; -import { Pipeline } from '../../../dist/core/pipeline.js'; const createAstroModule = (AstroComponent) => ({ default: AstroComponent }); describe('core/render', () => { describe('Injected head contents', () => { - let env; + let pipeline; before(async () => { - env = createBasicEnvironment(); + pipeline = createBasicPipeline(); + pipeline.headElements = () => ({ + links: new Set([{ name: 'link', props: { rel: 'stylesheet', href: '/main.css' }, children: '' }]), + scripts: new Set, + styles: new Set + }); }); it('Multi-level layouts and head injection, with explicit head', async () => { @@ -90,16 +94,10 @@ describe('core/render', () => { }); const PageModule = createAstroModule(Page); - const ctx = await createRenderContext({ - route: { type: 'page', pathname: '/index', component: 'src/pages/index.astro' }, - request: new Request('http://example.com/'), - links: [{ name: 'link', props: { rel: 'stylesheet', href: '/main.css' }, children: '' }], - mod: PageModule, - env, - }); - - const pipeline = new Pipeline(env); - const response = await pipeline.renderRoute(ctx, PageModule); + const request = new Request('http://example.com/'); + const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.astro', params: {} }; + const renderContext = RenderContext.create({ pipeline, request, routeData }); + const response = await renderContext.render(PageModule); const html = await response.text(); const $ = cheerio.load(html); @@ -172,17 +170,11 @@ describe('core/render', () => { }); const PageModule = createAstroModule(Page); - const ctx = await createRenderContext({ - route: { type: 'page', pathname: '/index', component: 'src/pages/index.astro' }, - request: new Request('http://example.com/'), - links: [{ name: 'link', props: { rel: 'stylesheet', href: '/main.css' }, children: '' }], - env, - mod: PageModule, - }); - - const pipeline = new Pipeline(env); + const request = new Request('http://example.com/'); + const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.astro', params: {} }; + const renderContext = RenderContext.create({ pipeline, request, routeData }); + const response = await renderContext.render(PageModule); - const response = await pipeline.renderRoute(ctx, PageModule); const html = await response.text(); const $ = cheerio.load(html); @@ -221,16 +213,11 @@ describe('core/render', () => { }); const PageModule = createAstroModule(Page); - const ctx = await createRenderContext({ - route: { type: 'page', pathname: '/index', component: 'src/pages/index.astro' }, - request: new Request('http://example.com/'), - links: [{ name: 'link', props: { rel: 'stylesheet', href: '/main.css' }, children: '' }], - env, - mod: PageModule, - }); + const request = new Request('http://example.com/'); + const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.astro', params: {} }; + const renderContext = RenderContext.create({ pipeline, request, routeData }); + const response = await renderContext.render(PageModule); - const pipeline = new Pipeline(env); - const response = await pipeline.renderRoute(ctx, PageModule); const html = await response.text(); const $ = cheerio.load(html); diff --git a/packages/astro/test/units/render/jsx.test.js b/packages/astro/test/units/render/jsx.test.js index 757a0e35d36b..ca2485a458c5 100644 --- a/packages/astro/test/units/render/jsx.test.js +++ b/packages/astro/test/units/render/jsx.test.js @@ -7,19 +7,19 @@ import { renderSlot, } from '../../../dist/runtime/server/index.js'; import { jsx } from '../../../dist/jsx-runtime/index.js'; -import { createRenderContext, loadRenderer } from '../../../dist/core/render/index.js'; +import { loadRenderer } from '../../../dist/core/render/index.js'; +import { RenderContext } from '../../../dist/core/render-context.js'; import { createAstroJSXComponent, renderer as jsxRenderer } from '../../../dist/jsx/index.js'; -import { createBasicEnvironment } from '../test-utils.js'; -import { Pipeline } from '../../../dist/core/pipeline.js'; +import { createBasicPipeline } from '../test-utils.js'; const createAstroModule = (AstroComponent) => ({ default: AstroComponent }); const loadJSXRenderer = () => loadRenderer(jsxRenderer, { import: (s) => import(s) }); describe('core/render', () => { describe('Astro JSX components', () => { - let env; + let pipeline; before(async () => { - env = createBasicEnvironment({ + pipeline = createBasicPipeline({ renderers: [await loadJSXRenderer()], }); }); @@ -42,15 +42,10 @@ describe('core/render', () => { }); const mod = createAstroModule(Page); - const ctx = await createRenderContext({ - route: { type: 'page', pathname: '/index', component: 'src/pages/index.mdx' }, - request: new Request('http://example.com/'), - env, - mod, - }); - - const pipeline = new Pipeline(env); - const response = await pipeline.renderRoute(ctx, mod); + const request = new Request('http://example.com/'); + const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.mdx', params: {} }; + const renderContext = RenderContext.create({ pipeline, request, routeData }); + const response = await renderContext.render(mod); assert.equal(response.status, 200); @@ -89,14 +84,10 @@ describe('core/render', () => { }); const mod = createAstroModule(Page); - const ctx = await createRenderContext({ - route: { type: 'page', pathname: '/index', component: 'src/pages/index.mdx' }, - request: new Request('http://example.com/'), - env, - mod, - }); - const pipeline = new Pipeline(env); - const response = await pipeline.renderRoute(ctx, mod); + const request = new Request('http://example.com/'); + const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.mdx', params: {} }; + const renderContext = RenderContext.create({ pipeline, request, routeData }); + const response = await renderContext.render(mod); assert.equal(response.status, 200); @@ -119,15 +110,10 @@ describe('core/render', () => { }); const mod = createAstroModule(Page); - const ctx = await createRenderContext({ - route: { type: 'page', pathname: '/index', component: 'src/pages/index.mdx' }, - request: new Request('http://example.com/'), - env, - mod, - }); - - const pipeline = new Pipeline(env); - const response = await pipeline.renderRoute(ctx, mod); + const request = new Request('http://example.com/'); + const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.mdx', params: {} }; + const renderContext = RenderContext.create({ pipeline, request, routeData }); + const response = await renderContext.render(mod); try { await response.text(); diff --git a/packages/astro/test/units/routing/route-matching.test.js b/packages/astro/test/units/routing/route-matching.test.js index 0eeb47ca5f02..01b1d000a1bb 100644 --- a/packages/astro/test/units/routing/route-matching.test.js +++ b/packages/astro/test/units/routing/route-matching.test.js @@ -14,7 +14,7 @@ import * as cheerio from 'cheerio'; import testAdapter from '../../test-adapter.js'; import { getSortedPreloadedMatches } from '../../../dist/prerender/routing.js'; import { createDevelopmentManifest } from '../../../dist/vite-plugin-astro-server/plugin.js'; -import DevPipeline from '../../../dist/vite-plugin-astro-server/devPipeline.js'; +import { DevPipeline } from '../../../dist/vite-plugin-astro-server/pipeline.js'; const root = new URL('../../fixtures/alias/', import.meta.url); const fileSystem = { @@ -146,7 +146,7 @@ describe('Route matching', () => { const loader = createViteLoader(container.viteServer); const manifest = createDevelopmentManifest(container.settings); - pipeline = new DevPipeline({ manifest, logger: defaultLogger, settings, loader }); + pipeline = DevPipeline.create({ loader, logger: defaultLogger, manifest, settings }); manifestData = createRouteManifest( { cwd: fileURLToPath(root), diff --git a/packages/astro/test/units/test-utils.js b/packages/astro/test/units/test-utils.js index d81e42a72ebb..d9d7c7c4e5b8 100644 --- a/packages/astro/test/units/test-utils.js +++ b/packages/astro/test/units/test-utils.js @@ -6,7 +6,7 @@ import npath from 'node:path'; import { fileURLToPath } from 'node:url'; import { getDefaultClientDirectives } from '../../dist/core/client-directive/index.js'; import { nodeLogDestination } from '../../dist/core/logger/node.js'; -import { createEnvironment } from '../../dist/core/render/index.js'; +import { Pipeline } from '../../dist/core/render/index.js'; import { RouteCache } from '../../dist/core/render/route-cache.js'; import { resolveConfig } from '../../dist/core/config/index.js'; import { createBaseSettings } from '../../dist/core/config/settings.js'; @@ -181,25 +181,30 @@ export function buffersToString(buffers) { export const createAstroModule = (AstroComponent) => ({ default: AstroComponent }); /** - * @param {Partial} options - * @returns {import('../../src/core/render/environment.js').Environment} + * @param {Partial} options + * @returns {Pipeline} */ -export function createBasicEnvironment(options = {}) { +export function createBasicPipeline(options = {}) { const mode = options.mode ?? 'development'; - return createEnvironment({ - ...options, - markdown: { - ...(options.markdown ?? {}), - }, - mode, - renderers: options.renderers ?? [], - clientDirectives: getDefaultClientDirectives(), - resolve: options.resolve ?? ((s) => Promise.resolve(s)), - routeCache: new RouteCache(options.logging, mode), - logger: options.logger ?? defaultLogger, - ssr: options.ssr ?? true, - streaming: options.streaming ?? true, - }); + const pipeline = new Pipeline( + options.logger ?? defaultLogger, + options.manifest ?? {}, + options.mode ?? 'development', + options.renderers ?? [], + options.resolve ?? (s => Promise.resolve(s)), + options.serverLike ?? true, + options.streaming ?? true, + options.adapterName, + options.clientDirectives ?? getDefaultClientDirectives(), + options.compressHTML, + options.i18n, + options.middleware, + options.routeCache ?? new RouteCache(options.logging, mode), + options.site + ); + pipeline.headElements = () => ({ scripts: new Set, styles: new Set, links: new Set }); + pipeline.componentMetadata = () => {}; + return pipeline } /** diff --git a/packages/astro/test/units/vite-plugin-astro-server/request.test.js b/packages/astro/test/units/vite-plugin-astro-server/request.test.js index f79c86f84717..36f05c41a877 100644 --- a/packages/astro/test/units/vite-plugin-astro-server/request.test.js +++ b/packages/astro/test/units/vite-plugin-astro-server/request.test.js @@ -12,19 +12,14 @@ import { defaultLogger, } from '../test-utils.js'; import { createDevelopmentManifest } from '../../../dist/vite-plugin-astro-server/plugin.js'; -import DevPipeline from '../../../dist/vite-plugin-astro-server/devPipeline.js'; +import { DevPipeline } from '../../../dist/vite-plugin-astro-server/pipeline.js'; async function createDevPipeline(overrides = {}) { const settings = overrides.settings ?? (await createBasicSettings({ root: '/' })); const loader = overrides.loader ?? createLoader(); const manifest = createDevelopmentManifest(settings); - return new DevPipeline({ - manifest, - settings, - logger: defaultLogger, - loader, - }); + return DevPipeline.create({ loader, logger: defaultLogger, manifest, settings }); } describe('vite-plugin-astro-server', () => { @@ -32,7 +27,10 @@ describe('vite-plugin-astro-server', () => { it('renders a request', async () => { const pipeline = await createDevPipeline({ loader: createLoader({ - import() { + import(id) { + if (id === '\0astro-internal:middleware') { + return { onRequest: (_, next) => next() } + } const Page = createComponent(() => { return render`
testing
`; }); @@ -40,7 +38,7 @@ describe('vite-plugin-astro-server', () => { }, }), }); - const controller = createController({ loader: pipeline.getModuleLoader() }); + const controller = createController({ loader: pipeline.loader }); const { req, res, text } = createRequestAndResponse(); const fs = createFs( { @@ -52,7 +50,7 @@ describe('vite-plugin-astro-server', () => { const manifestData = createRouteManifest( { fsMod: fs, - settings: pipeline.getSettings(), + settings: pipeline.settings, }, defaultLogger ); @@ -64,6 +62,7 @@ describe('vite-plugin-astro-server', () => { controller, incomingRequest: req, incomingResponse: res, + manifest: {} }); } catch (err) { assert.equal(err.message, undefined); diff --git a/packages/astro/test/units/vite-plugin-astro-server/response.test.js b/packages/astro/test/units/vite-plugin-astro-server/response.test.js index bb7afbc3736a..42cd90e88cc4 100644 --- a/packages/astro/test/units/vite-plugin-astro-server/response.test.js +++ b/packages/astro/test/units/vite-plugin-astro-server/response.test.js @@ -84,7 +84,7 @@ describe('endpoints', () => { }); }); - it('Headers with multiple values (set-cookie special case)', async () => { + it('Can bail on streaming', async () => { const { req, res, done } = createRequestAndResponse({ method: 'GET', url: '/streaming', From c1671dff22db2f9361c0d42dbf4d5dd6fb0674d0 Mon Sep 17 00:00:00 2001 From: Arsh Date: Tue, 20 Feb 2024 14:41:38 +0000 Subject: [PATCH 06/19] [ci] format --- packages/astro/src/core/app/index.ts | 27 ++- packages/astro/src/core/app/pipeline.ts | 29 ++- packages/astro/src/core/base-pipeline.ts | 21 +- packages/astro/src/core/build/generate.ts | 2 +- packages/astro/src/core/build/pipeline.ts | 48 ++++- packages/astro/src/core/endpoint/index.ts | 10 +- packages/astro/src/core/middleware/index.ts | 19 +- packages/astro/src/core/redirects/helpers.ts | 1 - packages/astro/src/core/redirects/render.ts | 16 +- packages/astro/src/core/render-context.ts | 180 ++++++++++++++---- .../astro/src/core/render/params-and-props.ts | 3 +- packages/astro/src/i18n/middleware.ts | 128 ++++++------- packages/astro/src/runtime/server/endpoint.ts | 2 +- .../src/vite-plugin-astro-server/error.ts | 5 +- .../src/vite-plugin-astro-server/pipeline.ts | 57 ++++-- .../src/vite-plugin-astro-server/route.ts | 27 ++- packages/astro/test/units/render/head.test.js | 29 ++- packages/astro/test/units/render/jsx.test.js | 21 +- packages/astro/test/units/test-utils.js | 6 +- .../vite-plugin-astro-server/request.test.js | 4 +- 20 files changed, 429 insertions(+), 206 deletions(-) diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 481fffb410cd..094ac97b56fa 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -1,8 +1,4 @@ -import type { - ManifestData, - RouteData, - SSRManifest, -} from '../../@types/astro.js'; +import type { ManifestData, RouteData, SSRManifest } from '../../@types/astro.js'; import type { SinglePageBuiltModule } from '../build/types.js'; import { getSetCookiesFromResponse } from '../cookies/index.js'; import { consoleLogDestination } from '../logger/console.js'; @@ -20,7 +16,13 @@ import { matchRoute } from '../routing/match.js'; import { AppPipeline } from './pipeline.js'; import { normalizeTheLocale } from '../../i18n/index.js'; import { RenderContext } from '../render-context.js'; -import { clientAddressSymbol, clientLocalsSymbol, responseSentSymbol, REROUTABLE_STATUS_CODES, REROUTE_DIRECTIVE_HEADER } from '../constants.js'; +import { + clientAddressSymbol, + clientLocalsSymbol, + responseSentSymbol, + REROUTABLE_STATUS_CODES, + REROUTE_DIRECTIVE_HEADER, +} from '../constants.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; export { deserializeManifest } from './common.js'; @@ -124,7 +126,7 @@ export class App { }, serverLike: true, streaming, - }) + }); } set setManifestData(newManifestData: ManifestData) { @@ -294,7 +296,14 @@ export class App { let response; try { - const renderContext = RenderContext.create({ pipeline: this.#pipeline, locals, pathname, request, routeData, status: defaultStatus }) + const renderContext = RenderContext.create({ + pipeline: this.#pipeline, + locals, + pathname, + request, + routeData, + status: defaultStatus, + }); response = await renderContext.render(await mod.page()); } catch (err: any) { this.#logger.error(null, err.stack || err.message || String(err)); @@ -386,7 +395,7 @@ export class App { request, routeData: errorRouteData, status, - }) + }); const response = await renderContext.render(await mod.page()); return this.#mergeResponses(response, originalResponse); } catch { diff --git a/packages/astro/src/core/app/pipeline.ts b/packages/astro/src/core/app/pipeline.ts index 74fa95ec6ad2..b1c615a1eb36 100644 --- a/packages/astro/src/core/app/pipeline.ts +++ b/packages/astro/src/core/app/pipeline.ts @@ -1,14 +1,25 @@ -import type { RouteData, SSRElement, SSRResult } from "../../@types/astro.js"; -import { Pipeline } from "../base-pipeline.js"; -import { createModuleScriptElement, createStylesheetElementSet } from "../render/ssr-element.js"; +import type { RouteData, SSRElement, SSRResult } from '../../@types/astro.js'; +import { Pipeline } from '../base-pipeline.js'; +import { createModuleScriptElement, createStylesheetElementSet } from '../render/ssr-element.js'; export class AppPipeline extends Pipeline { - static create({ logger, manifest, mode, renderers, resolve, serverLike, streaming }: Pick) { - return new AppPipeline(logger, manifest, mode, renderers, resolve, serverLike, streaming); - } + static create({ + logger, + manifest, + mode, + renderers, + resolve, + serverLike, + streaming, + }: Pick< + AppPipeline, + 'logger' | 'manifest' | 'mode' | 'renderers' | 'resolve' | 'serverLike' | 'streaming' + >) { + return new AppPipeline(logger, manifest, mode, renderers, resolve, serverLike, streaming); + } - headElements(routeData: RouteData): Pick { - const routeInfo = this.manifest.routes.find(route => route.routeData === routeData); + headElements(routeData: RouteData): Pick { + const routeInfo = this.manifest.routes.find((route) => route.routeData === routeData); // may be used in the future for handling rel=modulepreload, rel=icon, rel=manifest etc. const links = new Set(); const scripts = new Set(); @@ -26,7 +37,7 @@ export class AppPipeline extends Pipeline { scripts.add(createModuleScriptElement(script)); } } - return { links, styles, scripts } + return { links, styles, scripts }; } componentMetadata() {} diff --git a/packages/astro/src/core/base-pipeline.ts b/packages/astro/src/core/base-pipeline.ts index 5fcf639032cb..139ee9485811 100644 --- a/packages/astro/src/core/base-pipeline.ts +++ b/packages/astro/src/core/base-pipeline.ts @@ -1,4 +1,11 @@ -import type { MiddlewareHandler, RouteData, RuntimeMode, SSRLoadedRenderer, SSRManifest, SSRResult } from '../@types/astro.js'; +import type { + MiddlewareHandler, + RouteData, + RuntimeMode, + SSRLoadedRenderer, + SSRManifest, + SSRResult, +} from '../@types/astro.js'; import type { Logger } from './logger/core.js'; import { RouteCache } from './render/route-cache.js'; import { createI18nMiddleware } from '../i18n/middleware.js'; @@ -6,7 +13,7 @@ import { createI18nMiddleware } from '../i18n/middleware.js'; /** * The `Pipeline` represents the static parts of rendering that do not change between requests. * These are mostly known when the server first starts up and do not change. - * + * * Thus, a `Pipeline` is created once at process start and then used by every `RenderContext`. */ export abstract class Pipeline { @@ -38,13 +45,15 @@ export abstract class Pipeline { /** * Used for `Astro.site`. */ - readonly site = manifest.site, + readonly site = manifest.site ) { - this.internalMiddleware = [ createI18nMiddleware(i18n, manifest.base, manifest.trailingSlash, manifest.buildFormat) ]; + this.internalMiddleware = [ + createI18nMiddleware(i18n, manifest.base, manifest.trailingSlash, manifest.buildFormat), + ]; } - abstract headElements(routeData: RouteData): Promise | HeadElements - abstract componentMetadata(routeData: RouteData): Promise | void + abstract headElements(routeData: RouteData): Promise | HeadElements; + abstract componentMetadata(routeData: RouteData): Promise | void; } // eslint-disable-next-line @typescript-eslint/no-empty-interface diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 14462a412060..29a32a88b780 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -499,7 +499,7 @@ async function generatePath( logger, ssr: serverLike, }); - const renderContext = RenderContext.create({ pipeline, pathname, request, routeData: route }) + const renderContext = RenderContext.create({ pipeline, pathname, request, routeData: route }); let body: string | Uint8Array; let response: Response; diff --git a/packages/astro/src/core/build/pipeline.ts b/packages/astro/src/core/build/pipeline.ts index a2647e4564a3..e6e51c87549c 100644 --- a/packages/astro/src/core/build/pipeline.ts +++ b/packages/astro/src/core/build/pipeline.ts @@ -4,8 +4,17 @@ import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../vite-plugin-sc import type { SSRManifest } from '../app/types.js'; import { routeIsFallback, routeIsRedirect } from '../redirects/helpers.js'; import { Pipeline } from '../render/index.js'; -import { createAssetLink, createModuleScriptsSet, createStylesheetElementSet } from '../render/ssr-element.js'; -import { getPageDataByComponent, type BuildInternals, cssOrder, mergeInlineCss } from './internal.js'; +import { + createAssetLink, + createModuleScriptsSet, + createStylesheetElementSet, +} from '../render/ssr-element.js'; +import { + getPageDataByComponent, + type BuildInternals, + cssOrder, + mergeInlineCss, +} from './internal.js'; import { ASTRO_PAGE_RESOLVED_MODULE_ID, getVirtualModulePageNameFromPath, @@ -47,10 +56,22 @@ export class BuildPipeline extends Pipeline { } const serverLike = isServerLikeOutput(config); const streaming = true; - super(options.logger, manifest, options.mode, manifest.renderers, resolve, serverLike, streaming) + super( + options.logger, + manifest, + options.mode, + manifest.renderers, + resolve, + serverLike, + streaming + ); } - static create({ internals, manifest, options }: Pick) { + static create({ + internals, + manifest, + options, + }: Pick) { return new BuildPipeline(internals, manifest, options); } @@ -106,17 +127,24 @@ export class BuildPipeline extends Pipeline { } headElements(routeData: RouteData): Pick { - const { internals, manifest: { assetsPrefix, base }, settings } = this + const { + internals, + manifest: { assetsPrefix, base }, + settings, + } = this; const links = new Set(); - const pageBuildData = getPageDataByComponent(internals, routeData.component) + const pageBuildData = getPageDataByComponent(internals, routeData.component); const scripts = createModuleScriptsSet( pageBuildData?.hoistedScript ? [pageBuildData.hoistedScript] : [], base, assetsPrefix ); - const sortedCssAssets = pageBuildData?.styles.sort(cssOrder).map(({ sheet }) => sheet).reduce(mergeInlineCss, []); + const sortedCssAssets = pageBuildData?.styles + .sort(cssOrder) + .map(({ sheet }) => sheet) + .reduce(mergeInlineCss, []); const styles = createStylesheetElementSet(sortedCssAssets ?? [], base, assetsPrefix); - + if (settings.scripts.some((script) => script.stage === 'page')) { const hashedFilePath = internals.entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID); if (typeof hashedFilePath !== 'string') { @@ -128,7 +156,7 @@ export class BuildPipeline extends Pipeline { children: '', }); } - + // Add all injected scripts to the page. for (const script of settings.scripts) { if (script.stage === 'head-inline') { @@ -138,7 +166,7 @@ export class BuildPipeline extends Pipeline { }); } } - return { scripts, styles, links } + return { scripts, styles, links }; } componentMetadata() {} diff --git a/packages/astro/src/core/endpoint/index.ts b/packages/astro/src/core/endpoint/index.ts index 7a64366a33df..54b5dff4769d 100644 --- a/packages/astro/src/core/endpoint/index.ts +++ b/packages/astro/src/core/endpoint/index.ts @@ -1,8 +1,4 @@ -import type { - APIContext, - Locales, - Params, -} from '../../@types/astro.js'; +import type { APIContext, Locales, Params } from '../../@types/astro.js'; import { ASTRO_VERSION, clientAddressSymbol, clientLocalsSymbol } from '../constants.js'; import type { AstroCookies } from '../cookies/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; @@ -23,7 +19,7 @@ type CreateAPIContext = { routingStrategy: RoutingStrategies | undefined; defaultLocale: string | undefined; route: string; - cookies: AstroCookies + cookies: AstroCookies; }; /** @@ -41,7 +37,7 @@ export function createAPIContext({ routingStrategy, defaultLocale, route, - cookies + cookies, }: CreateAPIContext): APIContext { let preferredLocale: string | undefined = undefined; let preferredLocaleList: string[] | undefined = undefined; diff --git a/packages/astro/src/core/middleware/index.ts b/packages/astro/src/core/middleware/index.ts index b72a13f0a66b..138005f96036 100644 --- a/packages/astro/src/core/middleware/index.ts +++ b/packages/astro/src/core/middleware/index.ts @@ -38,12 +38,16 @@ export type CreateContext = { /** * Creates a context to be passed to Astro middleware `onRequest` function. */ -function createContext({ request, params = {}, userDefinedLocales = [] }: CreateContext): APIContext { +function createContext({ + request, + params = {}, + userDefinedLocales = [], +}: CreateContext): APIContext { let preferredLocale: string | undefined = undefined; let preferredLocaleList: string[] | undefined = undefined; let currentLocale: string | undefined = undefined; const url = new URL(request.url); - const route = url.pathname + const route = url.pathname; return { cookies: new AstroCookies(request), @@ -61,13 +65,18 @@ function createContext({ request, params = {}, userDefinedLocales = [] }: Create }); }, get preferredLocale(): string | undefined { - return preferredLocale ??= computePreferredLocale(request, userDefinedLocales); + return (preferredLocale ??= computePreferredLocale(request, userDefinedLocales)); }, get preferredLocaleList(): string[] | undefined { - return preferredLocaleList ??= computePreferredLocaleList(request, userDefinedLocales); + return (preferredLocaleList ??= computePreferredLocaleList(request, userDefinedLocales)); }, get currentLocale(): string | undefined { - return currentLocale ??= computeCurrentLocale(route, userDefinedLocales, undefined, undefined); + return (currentLocale ??= computeCurrentLocale( + route, + userDefinedLocales, + undefined, + undefined + )); }, url, get clientAddress() { diff --git a/packages/astro/src/core/redirects/helpers.ts b/packages/astro/src/core/redirects/helpers.ts index a55eacfdf416..80f18ae0f123 100644 --- a/packages/astro/src/core/redirects/helpers.ts +++ b/packages/astro/src/core/redirects/helpers.ts @@ -7,4 +7,3 @@ export function routeIsRedirect(route: RouteData | undefined): route is Redirect export function routeIsFallback(route: RouteData | undefined): route is RedirectRouteData { return route?.type === 'fallback'; } - diff --git a/packages/astro/src/core/redirects/render.ts b/packages/astro/src/core/redirects/render.ts index 08cf908500f7..120fab26e4c8 100644 --- a/packages/astro/src/core/redirects/render.ts +++ b/packages/astro/src/core/redirects/render.ts @@ -1,18 +1,22 @@ import type { RenderContext } from '../render-context.js'; export async function renderRedirect(renderContext: RenderContext) { - const { request: { method }, routeData } = renderContext; + const { + request: { method }, + routeData, + } = renderContext; const { redirect, redirectRoute } = routeData; const status = - redirectRoute && typeof redirect === "object" ? redirect.status - : method === "GET" ? 301 - : 308 - const headers = { location: redirectRouteGenerate(renderContext) }; + redirectRoute && typeof redirect === 'object' ? redirect.status : method === 'GET' ? 301 : 308; + const headers = { location: redirectRouteGenerate(renderContext) }; return new Response(null, { status, headers }); } function redirectRouteGenerate(renderContext: RenderContext): string { - const { params, routeData: { redirect, redirectRoute } } = renderContext; + const { + params, + routeData: { redirect, redirectRoute }, + } = renderContext; if (typeof redirectRoute !== 'undefined') { return redirectRoute?.generate(params) || redirectRoute?.pathname || '/'; diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts index fd9ed3d1c44f..299c188aff3a 100644 --- a/packages/astro/src/core/render-context.ts +++ b/packages/astro/src/core/render-context.ts @@ -1,4 +1,9 @@ -import type { APIContext, ComponentInstance, MiddlewareHandler, RouteData } from '../@types/astro.js'; +import type { + APIContext, + ComponentInstance, + MiddlewareHandler, + RouteData, +} from '../@types/astro.js'; import { renderEndpoint } from '../runtime/server/endpoint.js'; import { attachCookiesToResponse } from './cookies/index.js'; import { callMiddleware } from './middleware/callMiddleware.js'; @@ -6,7 +11,12 @@ import { sequence } from './middleware/index.js'; import { AstroCookies } from './cookies/index.js'; import { createResult } from './render/index.js'; import { renderPage } from '../runtime/server/index.js'; -import { ASTRO_VERSION, ROUTE_TYPE_HEADER, clientAddressSymbol, clientLocalsSymbol } from './constants.js'; +import { + ASTRO_VERSION, + ROUTE_TYPE_HEADER, + clientAddressSymbol, + clientLocalsSymbol, +} from './constants.js'; import { getParams, getProps, type Pipeline } from './render/index.js'; import { AstroError, AstroErrorData } from './errors/index.js'; import { @@ -26,19 +36,36 @@ export class RenderContext { readonly routeData: RouteData, public status: number, readonly cookies = new AstroCookies(request), - readonly params = getParams(routeData, pathname), + readonly params = getParams(routeData, pathname) ) {} - static create({ locals = {}, middleware, pathname, pipeline, request, routeData, status = 200 }: Pick & Partial>) { - return new RenderContext(pipeline, locals, sequence(...pipeline.internalMiddleware, middleware ?? pipeline.middleware), pathname, request, routeData, status); + static create({ + locals = {}, + middleware, + pathname, + pipeline, + request, + routeData, + status = 200, + }: Pick & + Partial>) { + return new RenderContext( + pipeline, + locals, + sequence(...pipeline.internalMiddleware, middleware ?? pipeline.middleware), + pathname, + request, + routeData, + status + ); } /** * The main function of the RenderContext. - * + * * Use this function to render any route known to Astro. * It attempts to render a route. A route can be a: - * + * * - page * - redirect * - endpoint @@ -47,25 +74,46 @@ export class RenderContext { async render(componentInstance: ComponentInstance | undefined): Promise { const { cookies, middleware, pathname, pipeline, routeData } = this; const { logger, routeCache, serverLike, streaming } = pipeline; - const props = await getProps({ mod: componentInstance, routeData, routeCache, pathname, logger, serverLike }); + const props = await getProps({ + mod: componentInstance, + routeData, + routeCache, + pathname, + logger, + serverLike, + }); const apiContext = this.createAPIContext(props); const { type } = routeData; - + const lastNext = - type === 'endpoint' ? () => renderEndpoint(componentInstance as any, apiContext, serverLike, logger) : - type === 'redirect' ? () => renderRedirect(this) : - type === 'page' ? async () => { - const result = await this.createResult(componentInstance!); - const response = await renderPage(result, componentInstance?.default as any, props, {}, streaming, routeData); - response.headers.set(ROUTE_TYPE_HEADER, "page"); - return response; - } : - type === 'fallback' ? () => new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: "fallback" } }) : - () => { throw new Error("Unknown type of route: " + type) } - + type === 'endpoint' + ? () => renderEndpoint(componentInstance as any, apiContext, serverLike, logger) + : type === 'redirect' + ? () => renderRedirect(this) + : type === 'page' + ? async () => { + const result = await this.createResult(componentInstance!); + const response = await renderPage( + result, + componentInstance?.default as any, + props, + {}, + streaming, + routeData + ); + response.headers.set(ROUTE_TYPE_HEADER, 'page'); + return response; + } + : type === 'fallback' + ? () => + new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: 'fallback' } }) + : () => { + throw new Error('Unknown type of route: ' + type); + }; + const response = await callMiddleware(middleware, apiContext, lastNext); if (response.headers.get(ROUTE_TYPE_HEADER)) { - response.headers.delete(ROUTE_TYPE_HEADER) + response.headers.delete(ROUTE_TYPE_HEADER); } // LEGACY: we put cookies on the response object, // where the adapter might be expecting to read it. @@ -79,11 +127,22 @@ export class RenderContext { const { cookies, i18nData, params, pipeline, request } = this; const { currentLocale, preferredLocale, preferredLocaleList } = i18nData; const generator = `Astro v${ASTRO_VERSION}`; - const redirect = (path: string, status = 302) => new Response(null, { status, headers: { Location: path } }); + const redirect = (path: string, status = 302) => + new Response(null, { status, headers: { Location: path } }); const site = pipeline.site ? new URL(pipeline.site) : undefined; const url = new URL(request.url); return { - cookies, currentLocale, generator, params, preferredLocale, preferredLocaleList, props, redirect, request, site, url, + cookies, + currentLocale, + generator, + params, + preferredLocale, + preferredLocaleList, + props, + redirect, + request, + site, + url, get clientAddress() { if (clientAddressSymbol in request) { return Reflect.get(request, clientAddressSymbol) as string; @@ -110,39 +169,80 @@ export class RenderContext { // where the adapter might be expecting to read it after the response. Reflect.set(request, clientLocalsSymbol, val); } - } - } + }, + }; } async createResult(mod: ComponentInstance) { const { cookies, locals, params, pathname, pipeline, request, routeData, status } = this; - const { adapterName, clientDirectives, compressHTML, i18n, manifest, logger, renderers, resolve, site, serverLike } = pipeline; + const { + adapterName, + clientDirectives, + compressHTML, + i18n, + manifest, + logger, + renderers, + resolve, + site, + serverLike, + } = pipeline; const { links, scripts, styles } = await pipeline.headElements(routeData); - const componentMetadata = await pipeline.componentMetadata(routeData) ?? manifest.componentMetadata; + const componentMetadata = + (await pipeline.componentMetadata(routeData)) ?? manifest.componentMetadata; const { defaultLocale, locales, routing: routingStrategy } = i18n ?? {}; const partial = Boolean(mod.partial); - return createResult({ adapterName, clientDirectives, componentMetadata, compressHTML, cookies, defaultLocale, locales, locals, logger, links, params, partial, pathname, renderers, resolve, request, route: routeData.route, routingStrategy, site, scripts, ssr: serverLike, status, styles }); + return createResult({ + adapterName, + clientDirectives, + componentMetadata, + compressHTML, + cookies, + defaultLocale, + locales, + locals, + logger, + links, + params, + partial, + pathname, + renderers, + resolve, + request, + route: routeData.route, + routingStrategy, + site, + scripts, + ssr: serverLike, + status, + styles, + }); } /** * API Context may be created multiple times per request, i18n data needs to be computed only once. * So, it is computed and saved here on creation of the first APIContext and reused for later ones. */ - #i18nData?: Pick + #i18nData?: Pick; get i18nData() { - if (this.#i18nData) return this.#i18nData - const { pipeline: { i18n }, request, routeData } = this; - if (!i18n) return { - currentLocale: undefined, - preferredLocale: undefined, - preferredLocaleList: undefined - } - const { defaultLocale, locales, routing } = i18n - return this.#i18nData = { + if (this.#i18nData) return this.#i18nData; + const { + pipeline: { i18n }, + request, + routeData, + } = this; + if (!i18n) + return { + currentLocale: undefined, + preferredLocale: undefined, + preferredLocaleList: undefined, + }; + const { defaultLocale, locales, routing } = i18n; + return (this.#i18nData = { currentLocale: computeCurrentLocale(routeData.route, locales, routing, defaultLocale), preferredLocale: computePreferredLocale(request, locales), - preferredLocaleList: computePreferredLocaleList(request, locales) - } + preferredLocaleList: computePreferredLocaleList(request, locales), + }); } } diff --git a/packages/astro/src/core/render/params-and-props.ts b/packages/astro/src/core/render/params-and-props.ts index ff901cd844e9..b0a589ab1655 100644 --- a/packages/astro/src/core/render/params-and-props.ts +++ b/packages/astro/src/core/render/params-and-props.ts @@ -24,11 +24,10 @@ export async function getProps(opts: GetParamsAndPropsOptions): Promise { return {}; } - if (routeIsRedirect(route) || routeIsFallback(route)) { return {}; } - + // This is a dynamic route, start getting the params const params = getParams(route, pathname); if (mod) { diff --git a/packages/astro/src/i18n/middleware.ts b/packages/astro/src/i18n/middleware.ts index 91091cbec4c3..815ac2e9c8a1 100644 --- a/packages/astro/src/i18n/middleware.ts +++ b/packages/astro/src/i18n/middleware.ts @@ -2,7 +2,7 @@ import { appendForwardSlash, joinPaths } from '@astrojs/internal-helpers/path'; import type { APIContext, Locales, MiddlewareHandler, SSRManifest } from '../@types/astro.js'; import { getPathByLocale, normalizeTheLocale } from './index.js'; import { shouldAppendForwardSlash } from '../core/build/util.js'; -import type { SSRManifestI18n } from '../core/app/types.js' +import type { SSRManifestI18n } from '../core/app/types.js'; import { ROUTE_TYPE_HEADER } from '../core/constants.js'; // Checks if the pathname has any locale, exception for the defaultLocale, which is ignored on purpose. @@ -102,100 +102,100 @@ export function createI18nMiddleware( const type = response.headers.get(ROUTE_TYPE_HEADER); // If the route we're processing is not a page, then we ignore it if (type !== 'page' && type !== 'fallback') { - return response + return response; } const { url, currentLocale } = context; const { locales, defaultLocale, fallback, routing } = i18n; - switch (i18n.routing) { - case 'domains-prefix-other-locales': { - if (localeHasntDomain(i18n, currentLocale)) { - const result = prefixOtherLocales(url, response); - if (result) { - return result; - } - } - break; - } - case 'pathname-prefix-other-locales': { + switch (i18n.routing) { + case 'domains-prefix-other-locales': { + if (localeHasntDomain(i18n, currentLocale)) { const result = prefixOtherLocales(url, response); if (result) { return result; } - break; } - - case 'domains-prefix-always-no-redirect': { - if (localeHasntDomain(i18n, currentLocale)) { - const result = prefixAlwaysNoRedirect(url, response); - if (result) { - return result; - } - } - break; + break; + } + case 'pathname-prefix-other-locales': { + const result = prefixOtherLocales(url, response); + if (result) { + return result; } + break; + } - case 'pathname-prefix-always-no-redirect': { + case 'domains-prefix-always-no-redirect': { + if (localeHasntDomain(i18n, currentLocale)) { const result = prefixAlwaysNoRedirect(url, response); if (result) { return result; } - break; } + break; + } + + case 'pathname-prefix-always-no-redirect': { + const result = prefixAlwaysNoRedirect(url, response); + if (result) { + return result; + } + break; + } - case 'pathname-prefix-always': { + case 'pathname-prefix-always': { + const result = prefixAlways(url, response, context); + if (result) { + return result; + } + break; + } + case 'domains-prefix-always': { + if (localeHasntDomain(i18n, currentLocale)) { const result = prefixAlways(url, response, context); if (result) { return result; } - break; - } - case 'domains-prefix-always': { - if (localeHasntDomain(i18n, currentLocale)) { - const result = prefixAlways(url, response, context); - if (result) { - return result; - } - } - break; } + break; } + } + + if (response.status >= 300 && fallback) { + const fallbackKeys = i18n.fallback ? Object.keys(i18n.fallback) : []; - if (response.status >= 300 && fallback) { - const fallbackKeys = i18n.fallback ? Object.keys(i18n.fallback) : []; - - // we split the URL using the `/`, and then check in the returned array we have the locale - const segments = url.pathname.split('/'); - const urlLocale = segments.find((segment) => { - for (const locale of locales) { - if (typeof locale === 'string') { - if (locale === segment) { - return true; - } - } else if (locale.path === segment) { + // we split the URL using the `/`, and then check in the returned array we have the locale + const segments = url.pathname.split('/'); + const urlLocale = segments.find((segment) => { + for (const locale of locales) { + if (typeof locale === 'string') { + if (locale === segment) { return true; } + } else if (locale.path === segment) { + return true; } - return false; - }); - - if (urlLocale && fallbackKeys.includes(urlLocale)) { - const fallbackLocale = fallback[urlLocale]; - // the user might have configured the locale using the granular locales, so we want to retrieve its corresponding path instead - const pathFallbackLocale = getPathByLocale(fallbackLocale, locales); - let newPathname: string; - // If a locale falls back to the default locale, we want to **remove** the locale because - // the default locale doesn't have a prefix - if (pathFallbackLocale === defaultLocale && routing === 'pathname-prefix-other-locales') { - newPathname = url.pathname.replace(`/${urlLocale}`, ``); - } else { - newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`); - } + } + return false; + }); - return context.redirect(newPathname); + if (urlLocale && fallbackKeys.includes(urlLocale)) { + const fallbackLocale = fallback[urlLocale]; + // the user might have configured the locale using the granular locales, so we want to retrieve its corresponding path instead + const pathFallbackLocale = getPathByLocale(fallbackLocale, locales); + let newPathname: string; + // If a locale falls back to the default locale, we want to **remove** the locale because + // the default locale doesn't have a prefix + if (pathFallbackLocale === defaultLocale && routing === 'pathname-prefix-other-locales') { + newPathname = url.pathname.replace(`/${urlLocale}`, ``); + } else { + newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`); } + + return context.redirect(newPathname); } + } return response; }; diff --git a/packages/astro/src/runtime/server/endpoint.ts b/packages/astro/src/runtime/server/endpoint.ts index 2afee2f23594..55dd5d0aefcf 100644 --- a/packages/astro/src/runtime/server/endpoint.ts +++ b/packages/astro/src/runtime/server/endpoint.ts @@ -1,5 +1,5 @@ import { bold } from 'kleur/colors'; -import { REROUTABLE_STATUS_CODES, REROUTE_DIRECTIVE_HEADER } from '../../core/constants.js';; +import { REROUTABLE_STATUS_CODES, REROUTE_DIRECTIVE_HEADER } from '../../core/constants.js'; import type { APIContext, EndpointHandler } from '../../@types/astro.js'; import type { Logger } from '../../core/logger/core.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/error.ts b/packages/astro/src/vite-plugin-astro-server/error.ts index 3bfd9f5f996b..d096c0422ea9 100644 --- a/packages/astro/src/vite-plugin-astro-server/error.ts +++ b/packages/astro/src/vite-plugin-astro-server/error.ts @@ -29,10 +29,7 @@ export function recordServerError( telemetry.record(eventError({ cmd: 'dev', err: errorWithMetadata, isFatal: false })); } - logger.error( - null, - formatErrorMessage(errorWithMetadata, logger.level() === 'debug') - ); + logger.error(null, formatErrorMessage(errorWithMetadata, logger.level() === 'debug')); return { error: err, diff --git a/packages/astro/src/vite-plugin-astro-server/pipeline.ts b/packages/astro/src/vite-plugin-astro-server/pipeline.ts index f2a6a1712bcc..bf0a666e37b1 100644 --- a/packages/astro/src/vite-plugin-astro-server/pipeline.ts +++ b/packages/astro/src/vite-plugin-astro-server/pipeline.ts @@ -1,5 +1,13 @@ -import url from 'node:url' -import type { AstroSettings, ComponentInstance, DevToolbarMetadata, RouteData, SSRElement, SSRLoadedRenderer, SSRManifest } from '../@types/astro.js'; +import url from 'node:url'; +import type { + AstroSettings, + ComponentInstance, + DevToolbarMetadata, + RouteData, + SSRElement, + SSRLoadedRenderer, + SSRManifest, +} from '../@types/astro.js'; import type { Logger } from '../core/logger/core.js'; import type { ModuleLoader } from '../core/module-loader/index.js'; import { Pipeline, loadRenderer } from '../core/render/index.js'; @@ -19,28 +27,38 @@ import { getComponentMetadata } from './metadata.js'; export class DevPipeline extends Pipeline { // renderers are loaded on every request, // so it needs to be mutable here unlike in other environments - override renderers = new Array + override renderers = new Array(); private constructor( readonly loader: ModuleLoader, readonly logger: Logger, readonly manifest: SSRManifest, readonly settings: AstroSettings, - readonly config = settings.config, + readonly config = settings.config ) { - const mode = 'development' + const mode = 'development'; const resolve = createResolve(loader, config.root); const serverLike = isServerLikeOutput(config); const streaming = true; super(logger, manifest, mode, [], resolve, serverLike, streaming); } - static create({ loader, logger, manifest, settings }: Pick) { - return new DevPipeline(loader, logger, manifest, settings) + static create({ + loader, + logger, + manifest, + settings, + }: Pick) { + return new DevPipeline(loader, logger, manifest, settings); } async headElements(routeData: RouteData): Promise { - const { config: { root }, loader, mode, settings } = this; + const { + config: { root }, + loader, + mode, + settings, + } = this; const filePath = new URL(`./${routeData.component}`, root); const { scripts } = await getScriptsForURL(filePath, root, loader); @@ -55,9 +73,9 @@ export class DevPipeline extends Pipeline { settings.config.devToolbar.enabled && (await settings.preferences.get('devToolbar.enabled')) ) { - const src = await resolveIdToUrl(loader, 'astro/runtime/client/dev-toolbar/entrypoint.js') + const src = await resolveIdToUrl(loader, 'astro/runtime/client/dev-toolbar/entrypoint.js'); scripts.add({ props: { type: 'module', src }, children: '' }); - + const additionalMetadata: DevToolbarMetadata['__astro_dev_toolbar__'] = { root: url.fileURLToPath(settings.config.root), version: ASTRO_VERSION, @@ -69,7 +87,7 @@ export class DevPipeline extends Pipeline { scripts.add({ props: {}, children }); } } - + // TODO: We should allow adding generic HTML elements to the head, not just scripts for (const script of settings.scripts) { if (script.stage === 'head-inline') { @@ -99,15 +117,18 @@ export class DevPipeline extends Pipeline { // But we still want to inject the styles to avoid FOUC. The style tags // should emulate what Vite injects so further HMR works as expected. styles.add({ props: { 'data-vite-dev-id': id }, children: content }); - }; - - return { scripts, styles, links } + } + + return { scripts, styles, links }; } componentMetadata(routeData: RouteData) { - const { config: { root }, loader } = this; + const { + config: { root }, + loader, + } = this; const filePath = new URL(`./${routeData.component}`, root); - return getComponentMetadata(filePath, loader) + return getComponentMetadata(filePath, loader); } async preload(filePath: URL) { @@ -120,13 +141,13 @@ export class DevPipeline extends Pipeline { try { // Load the module from the Vite SSR Runtime. - return await loader.import(viteID(filePath)) as ComponentInstance; + return (await loader.import(viteID(filePath))) as ComponentInstance; } catch (error) { // If the error came from Markdown or CSS, we already handled it and there's no need to enhance it if (MarkdownError.is(error) || CSSError.is(error) || AggregateError.is(error)) { throw error; } - + throw enhanceViteSSRError({ error, filePath, loader }); } } diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts index ff76d4556132..bc9c5de03072 100644 --- a/packages/astro/src/vite-plugin-astro-server/route.ts +++ b/packages/astro/src/vite-plugin-astro-server/route.ts @@ -1,9 +1,5 @@ import type http from 'node:http'; -import type { - ComponentInstance, - ManifestData, - RouteData, -} from '../@types/astro.js'; +import type { ComponentInstance, ManifestData, RouteData } from '../@types/astro.js'; import { AstroErrorData, isAstroError } from '../core/errors/index.js'; import { req } from '../core/messages.js'; import { loadMiddleware } from '../core/middleware/loadMiddleware.js'; @@ -158,7 +154,7 @@ export async function handleRoute({ let options: SSROptions | undefined = undefined; let route: RouteData; const middleware = (await loadMiddleware(loader)).onRequest; - + if (!matchedRoute) { if (config.i18n) { const locales = config.i18n.locales; @@ -208,7 +204,13 @@ export async function handleRoute({ fallbackRoutes: [], isIndex: false, }; - renderContext = RenderContext.create({ pipeline: pipeline, pathname, middleware, request, routeData: route }); + renderContext = RenderContext.create({ + pipeline: pipeline, + pathname, + middleware, + request, + routeData: route, + }); } else { return handle404Response(origin, incomingRequest, incomingResponse); } @@ -217,7 +219,7 @@ export async function handleRoute({ const { preloadedComponent } = matchedRoute; route = matchedRoute.route; // Allows adapters to pass in locals in dev mode. - const locals = Reflect.get(incomingRequest, clientLocalsSymbol) + const locals = Reflect.get(incomingRequest, clientLocalsSymbol); request = createRequest({ url, // Headers are only available when using SSR. @@ -244,7 +246,14 @@ export async function handleRoute({ }; mod = preloadedComponent; - renderContext = RenderContext.create({ locals, pipeline, pathname, middleware, request, routeData: route }); + renderContext = RenderContext.create({ + locals, + pipeline, + pathname, + middleware, + request, + routeData: route, + }); } let response = await renderContext.render(mod); diff --git a/packages/astro/test/units/render/head.test.js b/packages/astro/test/units/render/head.test.js index 67077c9dd6d7..ce494336afa0 100644 --- a/packages/astro/test/units/render/head.test.js +++ b/packages/astro/test/units/render/head.test.js @@ -21,9 +21,11 @@ describe('core/render', () => { before(async () => { pipeline = createBasicPipeline(); pipeline.headElements = () => ({ - links: new Set([{ name: 'link', props: { rel: 'stylesheet', href: '/main.css' }, children: '' }]), - scripts: new Set, - styles: new Set + links: new Set([ + { name: 'link', props: { rel: 'stylesheet', href: '/main.css' }, children: '' }, + ]), + scripts: new Set(), + styles: new Set(), }); }); @@ -95,7 +97,12 @@ describe('core/render', () => { const PageModule = createAstroModule(Page); const request = new Request('http://example.com/'); - const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.astro', params: {} }; + const routeData = { + type: 'page', + pathname: '/index', + component: 'src/pages/index.astro', + params: {}, + }; const renderContext = RenderContext.create({ pipeline, request, routeData }); const response = await renderContext.render(PageModule); @@ -171,7 +178,12 @@ describe('core/render', () => { const PageModule = createAstroModule(Page); const request = new Request('http://example.com/'); - const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.astro', params: {} }; + const routeData = { + type: 'page', + pathname: '/index', + component: 'src/pages/index.astro', + params: {}, + }; const renderContext = RenderContext.create({ pipeline, request, routeData }); const response = await renderContext.render(PageModule); @@ -214,7 +226,12 @@ describe('core/render', () => { const PageModule = createAstroModule(Page); const request = new Request('http://example.com/'); - const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.astro', params: {} }; + const routeData = { + type: 'page', + pathname: '/index', + component: 'src/pages/index.astro', + params: {}, + }; const renderContext = RenderContext.create({ pipeline, request, routeData }); const response = await renderContext.render(PageModule); diff --git a/packages/astro/test/units/render/jsx.test.js b/packages/astro/test/units/render/jsx.test.js index ca2485a458c5..e2df9a60d50e 100644 --- a/packages/astro/test/units/render/jsx.test.js +++ b/packages/astro/test/units/render/jsx.test.js @@ -43,7 +43,12 @@ describe('core/render', () => { const mod = createAstroModule(Page); const request = new Request('http://example.com/'); - const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.mdx', params: {} }; + const routeData = { + type: 'page', + pathname: '/index', + component: 'src/pages/index.mdx', + params: {}, + }; const renderContext = RenderContext.create({ pipeline, request, routeData }); const response = await renderContext.render(mod); @@ -85,7 +90,12 @@ describe('core/render', () => { const mod = createAstroModule(Page); const request = new Request('http://example.com/'); - const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.mdx', params: {} }; + const routeData = { + type: 'page', + pathname: '/index', + component: 'src/pages/index.mdx', + params: {}, + }; const renderContext = RenderContext.create({ pipeline, request, routeData }); const response = await renderContext.render(mod); @@ -111,7 +121,12 @@ describe('core/render', () => { const mod = createAstroModule(Page); const request = new Request('http://example.com/'); - const routeData = { type: 'page', pathname: '/index', component: 'src/pages/index.mdx', params: {} }; + const routeData = { + type: 'page', + pathname: '/index', + component: 'src/pages/index.mdx', + params: {}, + }; const renderContext = RenderContext.create({ pipeline, request, routeData }); const response = await renderContext.render(mod); diff --git a/packages/astro/test/units/test-utils.js b/packages/astro/test/units/test-utils.js index d9d7c7c4e5b8..6133687ae3c3 100644 --- a/packages/astro/test/units/test-utils.js +++ b/packages/astro/test/units/test-utils.js @@ -191,7 +191,7 @@ export function createBasicPipeline(options = {}) { options.manifest ?? {}, options.mode ?? 'development', options.renderers ?? [], - options.resolve ?? (s => Promise.resolve(s)), + options.resolve ?? ((s) => Promise.resolve(s)), options.serverLike ?? true, options.streaming ?? true, options.adapterName, @@ -202,9 +202,9 @@ export function createBasicPipeline(options = {}) { options.routeCache ?? new RouteCache(options.logging, mode), options.site ); - pipeline.headElements = () => ({ scripts: new Set, styles: new Set, links: new Set }); + pipeline.headElements = () => ({ scripts: new Set(), styles: new Set(), links: new Set() }); pipeline.componentMetadata = () => {}; - return pipeline + return pipeline; } /** diff --git a/packages/astro/test/units/vite-plugin-astro-server/request.test.js b/packages/astro/test/units/vite-plugin-astro-server/request.test.js index 36f05c41a877..63d2d2a5f21c 100644 --- a/packages/astro/test/units/vite-plugin-astro-server/request.test.js +++ b/packages/astro/test/units/vite-plugin-astro-server/request.test.js @@ -29,7 +29,7 @@ describe('vite-plugin-astro-server', () => { loader: createLoader({ import(id) { if (id === '\0astro-internal:middleware') { - return { onRequest: (_, next) => next() } + return { onRequest: (_, next) => next() }; } const Page = createComponent(() => { return render`
testing
`; @@ -62,7 +62,7 @@ describe('vite-plugin-astro-server', () => { controller, incomingRequest: req, incomingResponse: res, - manifest: {} + manifest: {}, }); } catch (err) { assert.equal(err.message, undefined); From 052d3271d4a9f12b88897c57cdfa134cb83c9eee Mon Sep 17 00:00:00 2001 From: "Houston (Bot)" <108291165+astrobot-houston@users.noreply.github.com> Date: Tue, 20 Feb 2024 06:48:30 -0800 Subject: [PATCH 07/19] [ci] release (#10131) Co-authored-by: github-actions[bot] --- .changeset/eighty-falcons-tease.md | 24 --------- .changeset/hungry-rings-argue.md | 5 -- .changeset/itchy-monkeys-fail.md | 5 -- .changeset/large-planets-kick.md | 5 -- .changeset/poor-llamas-chew.md | 5 -- .changeset/spotty-cobras-warn.md | 5 -- .changeset/tidy-laws-think.md | 5 -- .changeset/twenty-monkeys-thank.md | 5 -- examples/basics/package.json | 2 +- examples/blog/package.json | 4 +- examples/component/package.json | 2 +- examples/framework-alpine/package.json | 2 +- examples/framework-lit/package.json | 2 +- examples/framework-multiple/package.json | 2 +- examples/framework-preact/package.json | 2 +- examples/framework-react/package.json | 2 +- examples/framework-solid/package.json | 2 +- examples/framework-svelte/package.json | 2 +- examples/framework-vue/package.json | 2 +- examples/hackernews/package.json | 2 +- examples/integration/package.json | 2 +- examples/middleware/package.json | 2 +- examples/minimal/package.json | 2 +- examples/non-html-pages/package.json | 2 +- examples/portfolio/package.json | 2 +- examples/ssr/package.json | 2 +- examples/starlog/package.json | 2 +- examples/view-transitions/package.json | 2 +- examples/with-markdoc/package.json | 2 +- examples/with-markdown-plugins/package.json | 2 +- examples/with-markdown-shiki/package.json | 2 +- 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 | 18 +++++++ packages/astro/package.json | 2 +- packages/integrations/sitemap/CHANGELOG.md | 25 +++++++++ packages/integrations/sitemap/package.json | 2 +- pnpm-lock.yaml | 56 ++++++++++----------- 40 files changed, 101 insertions(+), 117 deletions(-) delete mode 100644 .changeset/eighty-falcons-tease.md delete mode 100644 .changeset/hungry-rings-argue.md delete mode 100644 .changeset/itchy-monkeys-fail.md delete mode 100644 .changeset/large-planets-kick.md delete mode 100644 .changeset/poor-llamas-chew.md delete mode 100644 .changeset/spotty-cobras-warn.md delete mode 100644 .changeset/tidy-laws-think.md delete mode 100644 .changeset/twenty-monkeys-thank.md diff --git a/.changeset/eighty-falcons-tease.md b/.changeset/eighty-falcons-tease.md deleted file mode 100644 index 7ea106f1e86b..000000000000 --- a/.changeset/eighty-falcons-tease.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -"@astrojs/sitemap": minor ---- - -Adds a new configuration option `prefix` that allows you to change the default `sitemap-*.xml` file name. - -By default, running `astro build` creates both `sitemap-index.xml` and `sitemap-0.xml` in your output directory. - -To change the names of these files (e.g. to `astrosite-index.xml` and `astrosite-0.xml`), set the `prefix` option in your `sitemap` integration configuration: - -``` -import { defineConfig } from 'astro/config'; -import sitemap from '@astrojs/sitemap'; -export default defineConfig({ - site: 'https://example.com', - integrations: [ - sitemap({ - prefix: 'astrosite-', - }), - ], -}); -``` - -This option is useful when Google Search Console is unable to fetch your default sitemap files, but can read renamed files. diff --git a/.changeset/hungry-rings-argue.md b/.changeset/hungry-rings-argue.md deleted file mode 100644 index 1d7252e677be..000000000000 --- a/.changeset/hungry-rings-argue.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Refactors internals relating to middleware, endpoints, and page rendering. diff --git a/.changeset/itchy-monkeys-fail.md b/.changeset/itchy-monkeys-fail.md deleted file mode 100644 index 5e638e5da41b..000000000000 --- a/.changeset/itchy-monkeys-fail.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Fixes an issue where some astro commands failed if the astro config file or an integration used the global `crypto` object. diff --git a/.changeset/large-planets-kick.md b/.changeset/large-planets-kick.md deleted file mode 100644 index f1b58b5e5d34..000000000000 --- a/.changeset/large-planets-kick.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Fixes an issue where the `i18n.routing` object had all its fields defined as mandatory. Now they all are optionals and shouldn't break when using `astro.config.mts`. diff --git a/.changeset/poor-llamas-chew.md b/.changeset/poor-llamas-chew.md deleted file mode 100644 index 695b78f0d4a6..000000000000 --- a/.changeset/poor-llamas-chew.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Simplifies internal Vite preview server teardown diff --git a/.changeset/spotty-cobras-warn.md b/.changeset/spotty-cobras-warn.md deleted file mode 100644 index 26fc9e537dc1..000000000000 --- a/.changeset/spotty-cobras-warn.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Fixes an issue where audit fails to initialize when encountered `` inside `` diff --git a/.changeset/tidy-laws-think.md b/.changeset/tidy-laws-think.md deleted file mode 100644 index 9455bfb153f0..000000000000 --- a/.changeset/tidy-laws-think.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Fix integrationData fetch to always be called even if View Transition is enabled. diff --git a/.changeset/twenty-monkeys-thank.md b/.changeset/twenty-monkeys-thank.md deleted file mode 100644 index 02ce782ab007..000000000000 --- a/.changeset/twenty-monkeys-thank.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Fixes style-only change detection for Astro files if both the markup and styles are updated diff --git a/examples/basics/package.json b/examples/basics/package.json index 71f1f46325ef..1af476fc27f2 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.0" + "astro": "^4.4.1" } } diff --git a/examples/blog/package.json b/examples/blog/package.json index cd34a1db4953..bb04d449ae33 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/mdx": "^2.1.1", "@astrojs/rss": "^4.0.5", - "@astrojs/sitemap": "^3.0.5", - "astro": "^4.4.0" + "@astrojs/sitemap": "^3.1.0", + "astro": "^4.4.1" } } diff --git a/examples/component/package.json b/examples/component/package.json index f7fc654c7cf4..7b5c75756e74 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^4.4.0" + "astro": "^4.4.1" }, "peerDependencies": { "astro": "^4.0.0" diff --git a/examples/framework-alpine/package.json b/examples/framework-alpine/package.json index 2828ea1da1a4..e0ed476b4e07 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -14,6 +14,6 @@ "@astrojs/alpinejs": "^0.4.0", "@types/alpinejs": "^3.13.5", "alpinejs": "^3.13.3", - "astro": "^4.4.0" + "astro": "^4.4.1" } } diff --git a/examples/framework-lit/package.json b/examples/framework-lit/package.json index b6ec446278ae..df48b694cf67 100644 --- a/examples/framework-lit/package.json +++ b/examples/framework-lit/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/lit": "^4.0.1", "@webcomponents/template-shadowroot": "^0.2.1", - "astro": "^4.4.0", + "astro": "^4.4.1", "lit": "^3.1.2" } } diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index 6d6f15b187db..0bd249be1c81 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -16,7 +16,7 @@ "@astrojs/solid-js": "^4.0.1", "@astrojs/svelte": "^5.0.3", "@astrojs/vue": "^4.0.8", - "astro": "^4.4.0", + "astro": "^4.4.1", "preact": "^10.19.2", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index 05a20ac55446..8faa4f978e9a 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/preact": "^3.1.0", "@preact/signals": "^1.2.1", - "astro": "^4.4.0", + "astro": "^4.4.1", "preact": "^10.19.2" } } diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index bfc2185a3146..e7aa3ea0429e 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -14,7 +14,7 @@ "@astrojs/react": "^3.0.10", "@types/react": "^18.2.37", "@types/react-dom": "^18.2.15", - "astro": "^4.4.0", + "astro": "^4.4.1", "react": "^18.2.0", "react-dom": "^18.2.0" } diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index 0d5d1ad826fe..b542af8a8a88 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/solid-js": "^4.0.1", - "astro": "^4.4.0", + "astro": "^4.4.1", "solid-js": "^1.8.5" } } diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index 47bad67779fa..53674d1ab8b0 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/svelte": "^5.0.3", - "astro": "^4.4.0", + "astro": "^4.4.1", "svelte": "^4.2.5" } } diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index 1e4d48f73db5..5a890f864ab8 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/vue": "^4.0.8", - "astro": "^4.4.0", + "astro": "^4.4.1", "vue": "^3.3.8" } } diff --git a/examples/hackernews/package.json b/examples/hackernews/package.json index 5de5ce72e05c..81873cea60cb 100644 --- a/examples/hackernews/package.json +++ b/examples/hackernews/package.json @@ -12,6 +12,6 @@ }, "dependencies": { "@astrojs/node": "^8.2.0", - "astro": "^4.4.0" + "astro": "^4.4.1" } } diff --git a/examples/integration/package.json b/examples/integration/package.json index fe1cc6956c9e..f0e7010ea73b 100644 --- a/examples/integration/package.json +++ b/examples/integration/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^4.4.0" + "astro": "^4.4.1" }, "peerDependencies": { "astro": "^4.0.0" diff --git a/examples/middleware/package.json b/examples/middleware/package.json index bc45d6c5810f..0bf01e5cc366 100644 --- a/examples/middleware/package.json +++ b/examples/middleware/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@astrojs/node": "^8.2.0", - "astro": "^4.4.0", + "astro": "^4.4.1", "html-minifier": "^4.0.0" }, "devDependencies": { diff --git a/examples/minimal/package.json b/examples/minimal/package.json index c38793704c7b..29cf0a82f36d 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.0" + "astro": "^4.4.1" } } diff --git a/examples/non-html-pages/package.json b/examples/non-html-pages/package.json index e4fe1319c69e..206c843bc54a 100644 --- a/examples/non-html-pages/package.json +++ b/examples/non-html-pages/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.0" + "astro": "^4.4.1" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index d1718dcd1693..63e5fc06a4eb 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.0" + "astro": "^4.4.1" } } diff --git a/examples/ssr/package.json b/examples/ssr/package.json index d09f8b6c3796..91167e75077f 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -14,7 +14,7 @@ "dependencies": { "@astrojs/node": "^8.2.0", "@astrojs/svelte": "^5.0.3", - "astro": "^4.4.0", + "astro": "^4.4.1", "svelte": "^4.2.5" } } diff --git a/examples/starlog/package.json b/examples/starlog/package.json index 29574c27ccb7..304bd3eb40ac 100644 --- a/examples/starlog/package.json +++ b/examples/starlog/package.json @@ -10,7 +10,7 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.0", + "astro": "^4.4.1", "sass": "^1.69.5", "sharp": "^0.32.6" } diff --git a/examples/view-transitions/package.json b/examples/view-transitions/package.json index ca15bfaf960f..eba4bb4061fa 100644 --- a/examples/view-transitions/package.json +++ b/examples/view-transitions/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@astrojs/tailwind": "^5.1.0", "@astrojs/node": "^8.2.0", - "astro": "^4.4.0" + "astro": "^4.4.1" } } diff --git a/examples/with-markdoc/package.json b/examples/with-markdoc/package.json index 71ef15830456..3a2ad4dc20c8 100644 --- a/examples/with-markdoc/package.json +++ b/examples/with-markdoc/package.json @@ -12,6 +12,6 @@ }, "dependencies": { "@astrojs/markdoc": "^0.9.0", - "astro": "^4.4.0" + "astro": "^4.4.1" } } diff --git a/examples/with-markdown-plugins/package.json b/examples/with-markdown-plugins/package.json index 44363b152acb..4e4b51729a01 100644 --- a/examples/with-markdown-plugins/package.json +++ b/examples/with-markdown-plugins/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/markdown-remark": "^4.2.1", - "astro": "^4.4.0", + "astro": "^4.4.1", "hast-util-select": "^6.0.2", "rehype-autolink-headings": "^7.1.0", "rehype-slug": "^6.0.0", diff --git a/examples/with-markdown-shiki/package.json b/examples/with-markdown-shiki/package.json index 7b7d9d6c3d9e..783fef8fa44e 100644 --- a/examples/with-markdown-shiki/package.json +++ b/examples/with-markdown-shiki/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.0" + "astro": "^4.4.1" } } diff --git a/examples/with-mdx/package.json b/examples/with-mdx/package.json index f76ee2b6c313..a931380ea1b0 100644 --- a/examples/with-mdx/package.json +++ b/examples/with-mdx/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/mdx": "^2.1.1", "@astrojs/preact": "^3.1.0", - "astro": "^4.4.0", + "astro": "^4.4.1", "preact": "^10.19.2" } } diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index 1472aade1205..272b17ea9af0 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/preact": "^3.1.0", "@nanostores/preact": "^0.5.0", - "astro": "^4.4.0", + "astro": "^4.4.1", "nanostores": "^0.9.5", "preact": "^10.19.2" } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index 7f68711efe09..7ecfff2cd0b2 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -14,7 +14,7 @@ "@astrojs/mdx": "^2.1.1", "@astrojs/tailwind": "^5.1.0", "@types/canvas-confetti": "^1.6.3", - "astro": "^4.4.0", + "astro": "^4.4.1", "autoprefixer": "^10.4.15", "canvas-confetti": "^1.9.1", "postcss": "^8.4.28", diff --git a/examples/with-vitest/package.json b/examples/with-vitest/package.json index 49bd77304850..1f8c0775565e 100644 --- a/examples/with-vitest/package.json +++ b/examples/with-vitest/package.json @@ -12,7 +12,7 @@ "test": "vitest" }, "dependencies": { - "astro": "^4.4.0", + "astro": "^4.4.1", "vitest": "^1.2.2" } } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index bf874bcb8bed..1a1daffbca74 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,23 @@ # astro +## 4.4.1 + +### Patch Changes + +- [#9795](https://github.com/withastro/astro/pull/9795) [`5acc3135ba5309a566def466fbcbabd23f70cd68`](https://github.com/withastro/astro/commit/5acc3135ba5309a566def466fbcbabd23f70cd68) Thanks [@lilnasy](https://github.com/lilnasy)! - Refactors internals relating to middleware, endpoints, and page rendering. + +- [#10105](https://github.com/withastro/astro/pull/10105) [`1f598b372410066c6fcd41cba9915f6aaf7befa8`](https://github.com/withastro/astro/commit/1f598b372410066c6fcd41cba9915f6aaf7befa8) Thanks [@negativems](https://github.com/negativems)! - Fixes an issue where some astro commands failed if the astro config file or an integration used the global `crypto` object. + +- [#10165](https://github.com/withastro/astro/pull/10165) [`d50dddb71d87ce5b7928920f10eb4946a5339f86`](https://github.com/withastro/astro/commit/d50dddb71d87ce5b7928920f10eb4946a5339f86) Thanks [@ematipico](https://github.com/ematipico)! - Fixes an issue where the `i18n.routing` object had all its fields defined as mandatory. Now they all are optionals and shouldn't break when using `astro.config.mts`. + +- [#10132](https://github.com/withastro/astro/pull/10132) [`1da9c5f2f3fe70b0206d1b3e0c01744fa40d511c`](https://github.com/withastro/astro/commit/1da9c5f2f3fe70b0206d1b3e0c01744fa40d511c) Thanks [@bluwy](https://github.com/bluwy)! - Simplifies internal Vite preview server teardown + +- [#10163](https://github.com/withastro/astro/pull/10163) [`b92d35f1026f3e99abb888d1a845bdda4efdc327`](https://github.com/withastro/astro/commit/b92d35f1026f3e99abb888d1a845bdda4efdc327) Thanks [@mingjunlu](https://github.com/mingjunlu)! - Fixes an issue where audit fails to initialize when encountered `` inside `` + +- [#10079](https://github.com/withastro/astro/pull/10079) [`80f8996514e6d0546e94bd927650cd4ab2f1fa2f`](https://github.com/withastro/astro/commit/80f8996514e6d0546e94bd927650cd4ab2f1fa2f) Thanks [@ktym4a](https://github.com/ktym4a)! - Fix integrationData fetch to always be called even if View Transition is enabled. + +- [#10139](https://github.com/withastro/astro/pull/10139) [`3c73441eb2eaba767d6dad1b30c0353195d28791`](https://github.com/withastro/astro/commit/3c73441eb2eaba767d6dad1b30c0353195d28791) Thanks [@bluwy](https://github.com/bluwy)! - Fixes style-only change detection for Astro files if both the markup and styles are updated + ## 4.4.0 ### Minor Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index 635c9e69211e..fd36bbd592d7 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "4.4.0", + "version": "4.4.1", "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/sitemap/CHANGELOG.md b/packages/integrations/sitemap/CHANGELOG.md index a6ee0c46ccfb..3a275957b49f 100644 --- a/packages/integrations/sitemap/CHANGELOG.md +++ b/packages/integrations/sitemap/CHANGELOG.md @@ -1,5 +1,30 @@ # @astrojs/sitemap +## 3.1.0 + +### Minor Changes + +- [#9846](https://github.com/withastro/astro/pull/9846) [`9b78c992750cdb99c40a89a00ea2a0d1c00877d7`](https://github.com/withastro/astro/commit/9b78c992750cdb99c40a89a00ea2a0d1c00877d7) Thanks [@ktym4a](https://github.com/ktym4a)! - Adds a new configuration option `prefix` that allows you to change the default `sitemap-*.xml` file name. + + By default, running `astro build` creates both `sitemap-index.xml` and `sitemap-0.xml` in your output directory. + + To change the names of these files (e.g. to `astrosite-index.xml` and `astrosite-0.xml`), set the `prefix` option in your `sitemap` integration configuration: + + ``` + import { defineConfig } from 'astro/config'; + import sitemap from '@astrojs/sitemap'; + export default defineConfig({ + site: 'https://example.com', + integrations: [ + sitemap({ + prefix: 'astrosite-', + }), + ], + }); + ``` + + This option is useful when Google Search Console is unable to fetch your default sitemap files, but can read renamed files. + ## 3.0.5 ### Patch Changes diff --git a/packages/integrations/sitemap/package.json b/packages/integrations/sitemap/package.json index 2bc76067d39b..e44836779a3d 100644 --- a/packages/integrations/sitemap/package.json +++ b/packages/integrations/sitemap/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/sitemap", "description": "Generate a sitemap for your Astro site", - "version": "3.0.5", + "version": "3.1.0", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 83ce94248ce3..9ff7f3fa769a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -131,7 +131,7 @@ importers: examples/basics: dependencies: astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/blog: @@ -143,16 +143,16 @@ importers: specifier: ^4.0.5 version: link:../../packages/astro-rss '@astrojs/sitemap': - specifier: ^3.0.5 + specifier: ^3.1.0 version: link:../../packages/integrations/sitemap astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/component: devDependencies: astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/framework-alpine: @@ -167,7 +167,7 @@ importers: specifier: ^3.13.3 version: 3.13.3 astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/framework-lit: @@ -179,7 +179,7 @@ importers: specifier: ^0.2.1 version: 0.2.1 astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro lit: specifier: ^3.1.2 @@ -203,7 +203,7 @@ importers: specifier: ^4.0.8 version: link:../../packages/integrations/vue astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro preact: specifier: ^10.19.2 @@ -233,7 +233,7 @@ importers: specifier: ^1.2.1 version: 1.2.1(preact@10.19.3) astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro preact: specifier: ^10.19.2 @@ -251,7 +251,7 @@ importers: specifier: ^18.2.15 version: 18.2.18 astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro react: specifier: ^18.2.0 @@ -266,7 +266,7 @@ importers: specifier: ^4.0.1 version: link:../../packages/integrations/solid astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro solid-js: specifier: ^1.8.5 @@ -278,7 +278,7 @@ importers: specifier: ^5.0.3 version: link:../../packages/integrations/svelte astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro svelte: specifier: ^4.2.5 @@ -290,7 +290,7 @@ importers: specifier: ^4.0.8 version: link:../../packages/integrations/vue astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro vue: specifier: ^3.3.8 @@ -302,13 +302,13 @@ importers: specifier: ^8.2.0 version: link:../../packages/integrations/node astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/integration: devDependencies: astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/middleware: @@ -317,7 +317,7 @@ importers: specifier: ^8.2.0 version: link:../../packages/integrations/node astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro html-minifier: specifier: ^4.0.0 @@ -330,19 +330,19 @@ importers: examples/minimal: dependencies: astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/non-html-pages: dependencies: astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/portfolio: dependencies: astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/ssr: @@ -354,7 +354,7 @@ importers: specifier: ^5.0.3 version: link:../../packages/integrations/svelte astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro svelte: specifier: ^4.2.5 @@ -363,7 +363,7 @@ importers: examples/starlog: dependencies: astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro sass: specifier: ^1.69.5 @@ -381,7 +381,7 @@ importers: specifier: ^5.1.0 version: link:../../packages/integrations/tailwind astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/with-markdoc: @@ -390,7 +390,7 @@ importers: specifier: ^0.9.0 version: link:../../packages/integrations/markdoc astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/with-markdown-plugins: @@ -399,7 +399,7 @@ importers: specifier: ^4.2.1 version: link:../../packages/markdown/remark astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro hast-util-select: specifier: ^6.0.2 @@ -420,7 +420,7 @@ importers: examples/with-markdown-shiki: dependencies: astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro examples/with-mdx: @@ -432,7 +432,7 @@ importers: specifier: ^3.1.0 version: link:../../packages/integrations/preact astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro preact: specifier: ^10.19.2 @@ -447,7 +447,7 @@ importers: specifier: ^0.5.0 version: 0.5.0(nanostores@0.9.5)(preact@10.19.3) astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro nanostores: specifier: ^0.9.5 @@ -468,7 +468,7 @@ importers: specifier: ^1.6.3 version: 1.6.4 astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro autoprefixer: specifier: ^10.4.15 @@ -486,7 +486,7 @@ importers: examples/with-vitest: dependencies: astro: - specifier: ^4.4.0 + specifier: ^4.4.1 version: link:../../packages/astro vitest: specifier: ^1.2.2 From aa5efd1bb20a3e416001817531ff6de020255eea Mon Sep 17 00:00:00 2001 From: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Date: Tue, 20 Feb 2024 14:21:03 -0300 Subject: [PATCH 08/19] Fix typo in `errors-data.ts` (#10172) --- packages/astro/src/core/errors/errors-data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index e1eeae984d59..5336a47b3fa7 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -872,7 +872,7 @@ export const LocalImageUsedWrongly = { * @see * - [Astro.glob](https://docs.astro.build/en/reference/api-reference/#astroglob) * @description - * `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vitejs.dev/guide/features.html#glob-import) instead to acheive the same result. + * `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vitejs.dev/guide/features.html#glob-import) instead to achieve the same result. */ export const AstroGlobUsedOutside = { name: 'AstroGlobUsedOutside', From a46249173edde66b03c19441144272baa8394fb4 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 21 Feb 2024 07:42:06 +0000 Subject: [PATCH 09/19] fix(i18n): move transformation outside the user schema (#10169) * fix(i18n): move transformation outside the user schema * fix condition * cleanup * ops * fix regression --- .changeset/loud-snakes-behave.md | 5 + packages/astro/src/core/app/index.ts | 6 +- packages/astro/src/core/app/types.ts | 4 +- packages/astro/src/core/build/generate.ts | 3 +- .../src/core/build/plugins/plugin-manifest.ts | 12 +- packages/astro/src/core/config/schema.ts | 65 +---- packages/astro/src/core/endpoint/index.ts | 2 +- packages/astro/src/core/render-context.ts | 8 +- packages/astro/src/core/render/result.ts | 6 +- .../astro/src/core/routing/manifest/create.ts | 8 +- packages/astro/src/i18n/index.ts | 16 +- packages/astro/src/i18n/middleware.ts | 6 +- packages/astro/src/i18n/utils.ts | 39 ++- packages/astro/src/virtual-modules/i18n.ts | 13 +- .../src/vite-plugin-astro-server/plugin.ts | 3 +- .../astro/test/units/i18n/astro_i18n.test.js | 224 +++++++++++------- 16 files changed, 229 insertions(+), 191 deletions(-) create mode 100644 .changeset/loud-snakes-behave.md diff --git a/.changeset/loud-snakes-behave.md b/.changeset/loud-snakes-behave.md new file mode 100644 index 000000000000..f9f077f6e0c3 --- /dev/null +++ b/.changeset/loud-snakes-behave.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue with the `i18n.routing` types, where an internal transformation was causing the generation of incorrect types for integrations. diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 094ac97b56fa..74bd4ecbb6f6 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -166,9 +166,9 @@ export class App { if ( this.#manifest.i18n && - (this.#manifest.i18n.routing === 'domains-prefix-always' || - this.#manifest.i18n.routing === 'domains-prefix-other-locales' || - this.#manifest.i18n.routing === 'domains-prefix-always-no-redirect') + (this.#manifest.i18n.strategy === 'domains-prefix-always' || + this.#manifest.i18n.strategy === 'domains-prefix-other-locales' || + this.#manifest.i18n.strategy === 'domains-prefix-always-no-redirect') ) { // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host let host = request.headers.get('X-Forwarded-Host'); diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index 17b7c0872b0f..740165710cb0 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -8,7 +8,7 @@ import type { SSRResult, } from '../../@types/astro.js'; import type { SinglePageBuiltModule } from '../build/types.js'; -import type { RoutingStrategies } from '../config/schema.js'; +import type { RoutingStrategies } from '../../i18n/utils.js'; export type ComponentPath = string; @@ -60,7 +60,7 @@ export type SSRManifest = { export type SSRManifestI18n = { fallback?: Record; - routing: RoutingStrategies; + strategy: RoutingStrategies; locales: Locales; defaultLocale: string; domainLookupTable: Record; diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 29a32a88b780..e27f71fccd18 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -60,6 +60,7 @@ import type { import { getTimeStat, shouldAppendForwardSlash } from './util.js'; import { NoPrerenderedRoutesWithDomains } from '../errors/errors-data.js'; import { RenderContext } from '../render-context.js'; +import { toRoutingStrategy } from '../../i18n/utils.js'; function createEntryURL(filePath: string, outFolder: URL) { return new URL('./' + filePath + `?time=${Date.now()}`, outFolder); @@ -582,7 +583,7 @@ function createBuildManifest( if (settings.config.i18n) { i18nManifest = { fallback: settings.config.i18n.fallback, - routing: settings.config.i18n.routing, + strategy: toRoutingStrategy(settings.config.i18n), defaultLocale: settings.config.i18n.defaultLocale, locales: settings.config.i18n.locales, domainLookupTable: {}, diff --git a/packages/astro/src/core/build/plugins/plugin-manifest.ts b/packages/astro/src/core/build/plugins/plugin-manifest.ts index 8b97651dbfbf..35c3632d02db 100644 --- a/packages/astro/src/core/build/plugins/plugin-manifest.ts +++ b/packages/astro/src/core/build/plugins/plugin-manifest.ts @@ -17,6 +17,7 @@ import { cssOrder, mergeInlineCss, type BuildInternals } from '../internal.js'; import type { AstroBuildPlugin } from '../plugin.js'; import type { StaticBuildOptions } from '../types.js'; import { normalizeTheLocale } from '../../../i18n/index.js'; +import { toRoutingStrategy } from '../../../i18n/utils.js'; const manifestReplace = '@@ASTRO_MANIFEST_REPLACE@@'; const replaceExp = new RegExp(`['"]${manifestReplace}['"]`, 'g'); @@ -235,14 +236,7 @@ function buildManifest( * logic meant for i18n domain support, where we fill the lookup table */ const i18n = settings.config.i18n; - if ( - settings.config.experimental.i18nDomains && - i18n && - i18n.domains && - (i18n.routing === 'domains-prefix-always' || - i18n.routing === 'domains-prefix-other-locales' || - i18n.routing === 'domains-prefix-always-no-redirect') - ) { + if (settings.config.experimental.i18nDomains && i18n && i18n.domains) { for (const [locale, domainValue] of Object.entries(i18n.domains)) { domainLookupTable[domainValue] = normalizeTheLocale(locale); } @@ -257,7 +251,7 @@ function buildManifest( if (settings.config.i18n) { i18nManifest = { fallback: settings.config.i18n.fallback, - routing: settings.config.i18n.routing, + strategy: toRoutingStrategy(settings.config.i18n), locales: settings.config.i18n.locales, defaultLocale: settings.config.i18n.defaultLocale, domainLookupTable, diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index e840f93a91cd..f62e322c5bb8 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -66,14 +66,6 @@ const ASTRO_CONFIG_DEFAULTS = { }, } satisfies AstroUserConfig & { server: { open: boolean } }; -export type RoutingStrategies = - | 'pathname-prefix-always' - | 'pathname-prefix-other-locales' - | 'pathname-prefix-always-no-redirect' - | 'domains-prefix-always' - | 'domains-prefix-other-locales' - | 'domains-prefix-always-no-redirect'; - export const AstroConfigSchema = z.object({ root: z .string() @@ -363,37 +355,6 @@ export const AstroConfigSchema = z.object({ ), }) .optional() - .transform((i18n) => { - if (i18n) { - let { routing, domains } = i18n; - let strategy: RoutingStrategies; - const hasDomains = domains ? Object.keys(domains).length > 0 : false; - if (!hasDomains) { - if (routing.prefixDefaultLocale === true) { - if (routing.redirectToDefaultLocale) { - strategy = 'pathname-prefix-always'; - } else { - strategy = 'pathname-prefix-always-no-redirect'; - } - } else { - strategy = 'pathname-prefix-other-locales'; - } - } else { - if (routing.prefixDefaultLocale === true) { - if (routing.redirectToDefaultLocale) { - strategy = 'domains-prefix-always'; - } else { - strategy = 'domains-prefix-always-no-redirect'; - } - } else { - strategy = 'domains-prefix-other-locales'; - } - } - - return { ...i18n, routing: strategy }; - } - return undefined; - }) .superRefine((i18n, ctx) => { if (i18n) { const { defaultLocale, locales: _locales, fallback, domains, routing } = i18n; @@ -436,20 +397,15 @@ export const AstroConfigSchema = z.object({ } if (domains) { const entries = Object.entries(domains); - if (entries.length > 0) { - if ( - routing !== 'domains-prefix-other-locales' && - routing !== 'domains-prefix-always-no-redirect' && - routing !== 'domains-prefix-always' - ) { - ctx.addIssue({ - code: z.ZodIssueCode.custom, - message: `When specifying some domains, the property \`i18n.routingStrategy\` must be set to \`"domains"\`.`, - }); - } + const hasDomains = domains ? Object.keys(domains).length > 0 : false; + if (entries.length > 0 && !hasDomains) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: `When specifying some domains, the property \`i18n.routingStrategy\` must be set to \`"domains"\`.`, + }); } - for (const [domainKey, domainValue] of Object.entries(domains)) { + for (const [domainKey, domainValue] of entries) { if (!locales.includes(domainKey)) { ctx.addIssue({ code: z.ZodIssueCode.custom, @@ -625,11 +581,8 @@ export function createRelativeSchema(cmd: string, fileProtocolRoot: string) { .superRefine((configuration, ctx) => { const { site, experimental, i18n, output } = configuration; if (experimental.i18nDomains) { - if ( - i18n?.routing === 'domains-prefix-other-locales' || - i18n?.routing === 'domains-prefix-always-no-redirect' || - i18n?.routing === 'domains-prefix-always' - ) { + const hasDomains = i18n?.domains ? Object.keys(i18n.domains).length > 0 : false; + if (hasDomains) { if (!site) { ctx.addIssue({ code: z.ZodIssueCode.custom, diff --git a/packages/astro/src/core/endpoint/index.ts b/packages/astro/src/core/endpoint/index.ts index 54b5dff4769d..d65b5e6c06f0 100644 --- a/packages/astro/src/core/endpoint/index.ts +++ b/packages/astro/src/core/endpoint/index.ts @@ -6,8 +6,8 @@ import { computeCurrentLocale, computePreferredLocale, computePreferredLocaleList, + type RoutingStrategies, } from '../../i18n/utils.js'; -import type { RoutingStrategies } from '../config/schema.js'; type CreateAPIContext = { request: Request; diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts index 299c188aff3a..c0cc55c81d20 100644 --- a/packages/astro/src/core/render-context.ts +++ b/packages/astro/src/core/render-context.ts @@ -190,7 +190,7 @@ export class RenderContext { const { links, scripts, styles } = await pipeline.headElements(routeData); const componentMetadata = (await pipeline.componentMetadata(routeData)) ?? manifest.componentMetadata; - const { defaultLocale, locales, routing: routingStrategy } = i18n ?? {}; + const { defaultLocale, locales, strategy } = i18n ?? {}; const partial = Boolean(mod.partial); return createResult({ adapterName, @@ -210,7 +210,7 @@ export class RenderContext { resolve, request, route: routeData.route, - routingStrategy, + strategy, site, scripts, ssr: serverLike, @@ -238,9 +238,9 @@ export class RenderContext { preferredLocale: undefined, preferredLocaleList: undefined, }; - const { defaultLocale, locales, routing } = i18n; + const { defaultLocale, locales, strategy } = i18n; return (this.#i18nData = { - currentLocale: computeCurrentLocale(routeData.route, locales, routing, defaultLocale), + currentLocale: computeCurrentLocale(routeData.route, locales, strategy, defaultLocale), preferredLocale: computePreferredLocale(request, locales), preferredLocaleList: computePreferredLocaleList(request, locales), }); diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 6c1314f3c782..cc7fa219e9c2 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -17,8 +17,8 @@ import { computeCurrentLocale, computePreferredLocale, computePreferredLocaleList, + type RoutingStrategies, } from '../../i18n/utils.js'; -import type { RoutingStrategies } from '../config/schema.js'; import { clientAddressSymbol, responseSentSymbol } from '../constants.js'; export interface CreateResultArgs { @@ -53,7 +53,7 @@ export interface CreateResultArgs { locales: Locales | undefined; defaultLocale: string | undefined; route: string; - routingStrategy: RoutingStrategies | undefined; + strategy: RoutingStrategies | undefined; } function getFunctionExpression(slot: any) { @@ -234,7 +234,7 @@ export function createResult(args: CreateResultArgs): SSRResult { currentLocale = computeCurrentLocale( url.pathname, args.locales, - args.routingStrategy, + args.strategy, args.defaultLocale ); if (currentLocale) { diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index 93b3770b1d60..804cacc83fde 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -20,6 +20,7 @@ import { AstroError } from '../../errors/index.js'; import { removeLeadingForwardSlash, slash } from '../../path.js'; import { resolvePages } from '../../util.js'; import { getRouteGenerator } from './generator.js'; +import { toRoutingStrategy } from '../../../i18n/utils.js'; const require = createRequire(import.meta.url); interface Item { @@ -686,8 +687,9 @@ export function createRouteManifest( const i18n = settings.config.i18n; if (i18n) { + const strategy = toRoutingStrategy(i18n); // First we check if the user doesn't have an index page. - if (i18n.routing === 'pathname-prefix-always') { + if (strategy === 'pathname-prefix-always') { let index = routes.find((route) => route.route === '/'); if (!index) { let relativePath = path.relative( @@ -755,7 +757,7 @@ export function createRouteManifest( // Work done, now we start creating "fallback" routes based on the configuration - if (i18n.routing === 'pathname-prefix-always') { + if (strategy === 'pathname-prefix-always') { // we attempt to retrieve the index page of the default locale const defaultLocaleRoutes = routesByLocale.get(i18n.defaultLocale); if (defaultLocaleRoutes) { @@ -830,7 +832,7 @@ export function createRouteManifest( let route: string; if ( fallbackToLocale === i18n.defaultLocale && - i18n.routing === 'pathname-prefix-other-locales' + strategy === 'pathname-prefix-other-locales' ) { if (fallbackToRoute.pathname) { pathname = `/${fallbackFromLocale}${fallbackToRoute.pathname}`; diff --git a/packages/astro/src/i18n/index.ts b/packages/astro/src/i18n/index.ts index 4d66a56c3fc8..0b93f1d785b7 100644 --- a/packages/astro/src/i18n/index.ts +++ b/packages/astro/src/i18n/index.ts @@ -3,7 +3,7 @@ import type { AstroConfig, Locales } from '../@types/astro.js'; import { shouldAppendForwardSlash } from '../core/build/util.js'; import { MissingLocale } from '../core/errors/errors-data.js'; import { AstroError } from '../core/errors/index.js'; -import type { RoutingStrategies } from '../core/config/schema.js'; +import type { RoutingStrategies } from './utils.js'; type GetLocaleRelativeUrl = GetLocaleOptions & { locale: string; @@ -11,7 +11,7 @@ type GetLocaleRelativeUrl = GetLocaleOptions & { locales: Locales; trailingSlash: AstroConfig['trailingSlash']; format: AstroConfig['build']['format']; - routing?: RoutingStrategies; + strategy?: RoutingStrategies; defaultLocale: string; domains: Record | undefined; path?: string; @@ -45,7 +45,7 @@ export function getLocaleRelativeUrl({ path, prependWith, normalizeLocale = true, - routing = 'pathname-prefix-other-locales', + strategy = 'pathname-prefix-other-locales', defaultLocale, }: GetLocaleRelativeUrl) { const codeToUse = peekCodePathToUse(_locales, locale); @@ -58,10 +58,10 @@ export function getLocaleRelativeUrl({ const pathsToJoin = [base, prependWith]; const normalizedLocale = normalizeLocale ? normalizeTheLocale(codeToUse) : codeToUse; if ( - routing === 'pathname-prefix-always' || - routing === 'pathname-prefix-always-no-redirect' || - routing === 'domains-prefix-always' || - routing === 'domains-prefix-always-no-redirect' + strategy === 'pathname-prefix-always' || + strategy === 'pathname-prefix-always-no-redirect' || + strategy === 'domains-prefix-always' || + strategy === 'domains-prefix-always-no-redirect' ) { pathsToJoin.push(normalizedLocale); } else if (locale !== defaultLocale) { @@ -107,7 +107,7 @@ interface GetLocalesRelativeUrlList extends GetLocaleOptions { locales: Locales; trailingSlash: AstroConfig['trailingSlash']; format: AstroConfig['build']['format']; - routing?: RoutingStrategies; + strategy?: RoutingStrategies; defaultLocale: string; domains: Record | undefined; } diff --git a/packages/astro/src/i18n/middleware.ts b/packages/astro/src/i18n/middleware.ts index 815ac2e9c8a1..c3f85064b7d0 100644 --- a/packages/astro/src/i18n/middleware.ts +++ b/packages/astro/src/i18n/middleware.ts @@ -106,9 +106,9 @@ export function createI18nMiddleware( } const { url, currentLocale } = context; - const { locales, defaultLocale, fallback, routing } = i18n; + const { locales, defaultLocale, fallback, strategy } = i18n; - switch (i18n.routing) { + switch (i18n.strategy) { case 'domains-prefix-other-locales': { if (localeHasntDomain(i18n, currentLocale)) { const result = prefixOtherLocales(url, response); @@ -187,7 +187,7 @@ export function createI18nMiddleware( let newPathname: string; // If a locale falls back to the default locale, we want to **remove** the locale because // the default locale doesn't have a prefix - if (pathFallbackLocale === defaultLocale && routing === 'pathname-prefix-other-locales') { + if (pathFallbackLocale === defaultLocale && strategy === 'pathname-prefix-other-locales') { newPathname = url.pathname.replace(`/${urlLocale}`, ``); } else { newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`); diff --git a/packages/astro/src/i18n/utils.ts b/packages/astro/src/i18n/utils.ts index 4cfec633b3a2..d3dddba1f8c5 100644 --- a/packages/astro/src/i18n/utils.ts +++ b/packages/astro/src/i18n/utils.ts @@ -1,6 +1,5 @@ -import type { Locales } from '../@types/astro.js'; +import type { AstroConfig, AstroUserConfig, Locales } from '../@types/astro.js'; import { normalizeTheLocale, toCodes } from './index.js'; -import type { RoutingStrategies } from '../core/config/schema.js'; type BrowserLocale = { locale: string; @@ -190,3 +189,39 @@ export function computeCurrentLocale( } return undefined; } + +export type RoutingStrategies = + | 'pathname-prefix-always' + | 'pathname-prefix-other-locales' + | 'pathname-prefix-always-no-redirect' + | 'domains-prefix-always' + | 'domains-prefix-other-locales' + | 'domains-prefix-always-no-redirect'; +export function toRoutingStrategy(i18n: NonNullable) { + let { routing, domains } = i18n; + let strategy: RoutingStrategies; + const hasDomains = domains ? Object.keys(domains).length > 0 : false; + if (!hasDomains) { + if (routing?.prefixDefaultLocale === true) { + if (routing.redirectToDefaultLocale) { + strategy = 'pathname-prefix-always'; + } else { + strategy = 'pathname-prefix-always-no-redirect'; + } + } else { + strategy = 'pathname-prefix-other-locales'; + } + } else { + if (routing?.prefixDefaultLocale === true) { + if (routing.redirectToDefaultLocale) { + strategy = 'domains-prefix-always'; + } else { + strategy = 'domains-prefix-always-no-redirect'; + } + } else { + strategy = 'domains-prefix-other-locales'; + } + } + + return strategy; +} diff --git a/packages/astro/src/virtual-modules/i18n.ts b/packages/astro/src/virtual-modules/i18n.ts index f71068667787..3358a880b23c 100644 --- a/packages/astro/src/virtual-modules/i18n.ts +++ b/packages/astro/src/virtual-modules/i18n.ts @@ -1,13 +1,16 @@ import * as I18nInternals from '../i18n/index.js'; import type { I18nInternalConfig } from '../i18n/vite-plugin-i18n.js'; +import { toRoutingStrategy } from '../i18n/utils.js'; export { normalizeTheLocale, toCodes, toPaths } from '../i18n/index.js'; const { trailingSlash, format, site, i18n, isBuild } = // @ts-expect-error __ASTRO_INTERNAL_I18N_CONFIG__ as I18nInternalConfig; -const { defaultLocale, locales, routing, domains } = i18n!; +const { defaultLocale, locales, domains } = i18n!; const base = import.meta.env.BASE_URL; +const routing = toRoutingStrategy(i18n!); + export type GetLocaleOptions = I18nInternals.GetLocaleOptions; /** @@ -40,7 +43,7 @@ export const getRelativeLocaleUrl = (locale: string, path?: string, options?: Ge format, defaultLocale, locales, - routing, + strategy: routing, domains, ...options, }); @@ -80,7 +83,7 @@ export const getAbsoluteLocaleUrl = (locale: string, path?: string, options?: Ge site, defaultLocale, locales, - routing, + strategy: routing, domains, isBuild, ...options, @@ -100,7 +103,7 @@ export const getRelativeLocaleUrlList = (path?: string, options?: GetLocaleOptio format, defaultLocale, locales, - routing, + strategy: routing, domains, ...options, }); @@ -120,7 +123,7 @@ export const getAbsoluteLocaleUrlList = (path?: string, options?: GetLocaleOptio format, defaultLocale, locales, - routing, + strategy: routing, domains, isBuild, ...options, diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts index e149acad0a15..bea6d75ef0e4 100644 --- a/packages/astro/src/vite-plugin-astro-server/plugin.ts +++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts @@ -16,6 +16,7 @@ import { AsyncLocalStorage } from 'node:async_hooks'; import { IncomingMessage } from 'node:http'; import { setRouteError } from './server-state.js'; import { recordServerError } from './error.js'; +import { toRoutingStrategy } from '../i18n/utils.js'; export interface AstroPluginOptions { settings: AstroSettings; @@ -117,7 +118,7 @@ export function createDevelopmentManifest(settings: AstroSettings): SSRManifest if (settings.config.i18n) { i18nManifest = { fallback: settings.config.i18n.fallback, - routing: settings.config.i18n.routing, + strategy: toRoutingStrategy(settings.config.i18n), defaultLocale: settings.config.i18n.defaultLocale, locales: settings.config.i18n.locales, domainLookupTable: {}, diff --git a/packages/astro/test/units/i18n/astro_i18n.test.js b/packages/astro/test/units/i18n/astro_i18n.test.js index d7702f7fd0d3..0e8fdb4b5c89 100644 --- a/packages/astro/test/units/i18n/astro_i18n.test.js +++ b/packages/astro/test/units/i18n/astro_i18n.test.js @@ -10,6 +10,7 @@ import * as assert from 'node:assert/strict'; import { validateConfig } from '../../../dist/core/config/config.js'; import { AstroError } from '#astro/core/errors/index'; import { MissingLocale } from '#astro/core/errors/errors-data'; +import { toRoutingStrategy } from '#astro/i18n/utils'; describe('getLocaleRelativeUrl', () => { it('should correctly return the URL with the base', () => { @@ -231,11 +232,9 @@ describe('getLocaleRelativeUrl', () => { */ const config = { base: '/blog', - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'en_US', 'en_AU'], - }, + i18n: { + defaultLocale: 'en', + locales: ['en', 'en_US', 'en_AU'], }, }; @@ -243,9 +242,10 @@ describe('getLocaleRelativeUrl', () => { getLocaleRelativeUrl({ locale: 'en_US', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'directory', + strategy: toRoutingStrategy(config.i18n), }), '/blog/en-us/' ); @@ -254,10 +254,11 @@ describe('getLocaleRelativeUrl', () => { getLocaleRelativeUrl({ locale: 'en_US', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'directory', normalizeLocale: false, + strategy: toRoutingStrategy(config.i18n), }), '/blog/en_US/' ); @@ -266,9 +267,10 @@ describe('getLocaleRelativeUrl', () => { getLocaleRelativeUrl({ locale: 'en_AU', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'directory', + strategy: toRoutingStrategy(config.i18n), }), '/blog/en-au/' ); @@ -281,11 +283,11 @@ describe('getLocaleRelativeUrl', () => { */ const config = { base: '/blog', - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'es', 'en_US', 'en_AU'], - routing: 'pathname-prefix-always', + i18n: { + defaultLocale: 'en', + locales: ['en', 'es', 'en_US', 'en_AU'], + routing: { + prefixDefaultLocale: true, }, }, }; @@ -297,7 +299,8 @@ describe('getLocaleRelativeUrl', () => { base: '/blog/', trailingSlash: 'always', format: 'directory', - ...config.experimental.i18n, + ...config.i18n, + strategy: toRoutingStrategy(config.i18n), }), '/blog/en/' ); @@ -305,9 +308,10 @@ describe('getLocaleRelativeUrl', () => { getLocaleRelativeUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'directory', + strategy: toRoutingStrategy(config.i18n), }), '/blog/es/' ); @@ -317,9 +321,10 @@ describe('getLocaleRelativeUrl', () => { getLocaleRelativeUrl({ locale: 'en', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'file', + strategy: toRoutingStrategy(config.i18n), }), '/blog/en/' ); @@ -327,9 +332,10 @@ describe('getLocaleRelativeUrl', () => { getLocaleRelativeUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'file', + strategy: toRoutingStrategy(config.i18n), }), '/blog/es/' ); @@ -342,11 +348,12 @@ describe('getLocaleRelativeUrl', () => { */ const config = { base: '/blog', - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'es', 'en_US', 'en_AU'], - routing: 'pathname-prefix-always-no-redirect', + i18n: { + defaultLocale: 'en', + locales: ['en', 'es', 'en_US', 'en_AU'], + routing: { + prefixDefaultLocale: true, + redirectToDefaultLocale: false, }, }, }; @@ -358,7 +365,8 @@ describe('getLocaleRelativeUrl', () => { base: '/blog/', trailingSlash: 'always', format: 'directory', - ...config.experimental.i18n, + ...config.i18n, + strategy: toRoutingStrategy(config.i18n), }), '/blog/en/' ); @@ -366,9 +374,10 @@ describe('getLocaleRelativeUrl', () => { getLocaleRelativeUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'directory', + strategy: toRoutingStrategy(config.i18n), }), '/blog/es/' ); @@ -378,9 +387,10 @@ describe('getLocaleRelativeUrl', () => { getLocaleRelativeUrl({ locale: 'en', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'file', + strategy: toRoutingStrategy(config.i18n), }), '/blog/en/' ); @@ -388,9 +398,10 @@ describe('getLocaleRelativeUrl', () => { getLocaleRelativeUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'file', + strategy: toRoutingStrategy(config.i18n), }), '/blog/es/' ); @@ -576,11 +587,11 @@ describe('getLocaleRelativeUrlList', () => { * @type {import("../../../dist/@types").AstroUserConfig} */ const config = { - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'en_US', 'es'], - routing: 'pathname-prefix-always', + i18n: { + defaultLocale: 'en', + locales: ['en', 'en_US', 'es'], + routing: { + prefixDefaultLocale: true, }, }, }; @@ -589,9 +600,10 @@ describe('getLocaleRelativeUrlList', () => { getLocaleRelativeUrlList({ locale: 'en', base: '/blog', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'never', format: 'directory', + strategy: toRoutingStrategy(config.i18n), }), ['/blog/en', '/blog/en-us', '/blog/es'] ); @@ -603,11 +615,12 @@ describe('getLocaleRelativeUrlList', () => { * @type {import("../../../dist/@types").AstroUserConfig} */ const config = { - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'en_US', 'es'], - routing: 'pathname-prefix-always-no-redirect', + i18n: { + defaultLocale: 'en', + locales: ['en', 'en_US', 'es'], + routing: { + prefixDefaultLocale: true, + redirectToDefaultLocale: false, }, }, }; @@ -616,9 +629,10 @@ describe('getLocaleRelativeUrlList', () => { getLocaleRelativeUrlList({ locale: 'en', base: '/blog', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'never', format: 'directory', + strategy: toRoutingStrategy(config.i18n), }), ['/blog/en', '/blog/en-us', '/blog/es'] ); @@ -795,14 +809,14 @@ describe('getLocaleAbsoluteUrl', () => { */ const config = { base: '/blog', - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'en_US', 'es'], - domains: { - es: 'https://es.example.com', - }, - routing: 'pathname-prefix-always', + i18n: { + defaultLocale: 'en', + locales: ['en', 'en_US', 'es'], + domains: { + es: 'https://es.example.com', + }, + routing: { + prefixDefaultLocale: true, }, }, }; @@ -815,7 +829,8 @@ describe('getLocaleAbsoluteUrl', () => { trailingSlash: 'always', format: 'directory', site: 'https://example.com', - ...config.experimental.i18n, + ...config.i18n, + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/en/' ); @@ -824,10 +839,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'directory', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/es/' ); @@ -837,10 +853,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'en', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'file', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/en/' ); @@ -848,10 +865,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'file', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/es/' ); @@ -860,11 +878,12 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'file', site: 'https://example.com', isBuild: true, + strategy: toRoutingStrategy(config.i18n), }), 'https://es.example.com/blog/' ); @@ -874,12 +893,13 @@ describe('getLocaleAbsoluteUrl', () => { locale: 'es', base: '/blog/', prependWith: 'some-name', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'file', site: 'https://example.com', path: 'first-post', isBuild: true, + strategy: toRoutingStrategy(config.i18n), }), 'https://es.example.com/blog/some-name/first-post/' ); @@ -890,11 +910,11 @@ describe('getLocaleAbsoluteUrl', () => { * @type {import("../../../dist/@types").AstroUserConfig} */ const config = { - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'es'], - routing: 'pathname-prefix-always', + i18n: { + defaultLocale: 'en', + locales: ['en', 'es'], + routing: { + prefixDefaultLocale: true, }, }, }; @@ -903,10 +923,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'en', base: '/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'directory', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/en/' ); @@ -914,10 +935,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'es', base: '/', - ...config.experimental.i18n, + ...config.i18n, trailingSlash: 'always', format: 'directory', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/es/' ); @@ -932,7 +954,9 @@ describe('getLocaleAbsoluteUrl', () => { i18n: { defaultLocale: 'en', locales: ['en', 'es'], - routing: 'pathname-prefix-always', + routing: { + prefixDefaultLocale: true, + }, }, }; // directory format @@ -944,6 +968,7 @@ describe('getLocaleAbsoluteUrl', () => { trailingSlash: 'never', format: 'directory', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/en' ); @@ -955,6 +980,7 @@ describe('getLocaleAbsoluteUrl', () => { trailingSlash: 'always', format: 'directory', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/es/' ); @@ -967,6 +993,7 @@ describe('getLocaleAbsoluteUrl', () => { trailingSlash: 'ignore', format: 'directory', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/en/' ); @@ -980,6 +1007,7 @@ describe('getLocaleAbsoluteUrl', () => { trailingSlash: 'never', format: 'file', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/en' ); @@ -991,6 +1019,7 @@ describe('getLocaleAbsoluteUrl', () => { trailingSlash: 'always', format: 'file', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/es/' ); @@ -1004,6 +1033,7 @@ describe('getLocaleAbsoluteUrl', () => { trailingSlash: 'ignore', format: 'file', site: 'https://example.com', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/en' ); @@ -1067,11 +1097,11 @@ describe('getLocaleAbsoluteUrl', () => { */ const config = { base: '/blog', - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'es', 'en_US', 'en_AU'], - routing: 'pathname-prefix-always', + i18n: { + defaultLocale: 'en', + locales: ['en', 'es', 'en_US', 'en_AU'], + routing: { + prefixDefaultLocale: true, }, }, }; @@ -1084,7 +1114,8 @@ describe('getLocaleAbsoluteUrl', () => { trailingSlash: 'always', site: 'https://example.com', format: 'directory', - ...config.experimental.i18n, + ...config.i18n, + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/en/' ); @@ -1092,10 +1123,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, site: 'https://example.com', trailingSlash: 'always', format: 'directory', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/es/' ); @@ -1105,10 +1137,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'en', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, site: 'https://example.com', trailingSlash: 'always', format: 'file', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/en/' ); @@ -1116,10 +1149,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, site: 'https://example.com', trailingSlash: 'always', format: 'file', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/es/' ); @@ -1132,11 +1166,12 @@ describe('getLocaleAbsoluteUrl', () => { */ const config = { base: '/blog', - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'es', 'en_US', 'en_AU'], - routing: 'pathname-prefix-always-no-redirect', + i18n: { + defaultLocale: 'en', + locales: ['en', 'es', 'en_US', 'en_AU'], + routing: { + prefixDefaultLocale: true, + redirectToDefaultLocale: false, }, }, }; @@ -1149,7 +1184,8 @@ describe('getLocaleAbsoluteUrl', () => { trailingSlash: 'always', site: 'https://example.com', format: 'directory', - ...config.experimental.i18n, + ...config.i18n, + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/en/' ); @@ -1157,10 +1193,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, site: 'https://example.com', trailingSlash: 'always', format: 'directory', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/es/' ); @@ -1170,10 +1207,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'en', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, site: 'https://example.com', trailingSlash: 'always', format: 'file', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/en/' ); @@ -1181,10 +1219,11 @@ describe('getLocaleAbsoluteUrl', () => { getLocaleAbsoluteUrl({ locale: 'es', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, site: 'https://example.com', trailingSlash: 'always', format: 'file', + strategy: toRoutingStrategy(config.i18n), }), 'https://example.com/blog/es/' ); @@ -1491,6 +1530,7 @@ describe('getLocaleAbsoluteUrlList', () => { path: 'download', ...config, ...config.i18n, + strategy: toRoutingStrategy(config.i18n), }), [ 'https://example.com/en/download/', @@ -1530,6 +1570,7 @@ describe('getLocaleAbsoluteUrlList', () => { path: 'download', ...config, ...config.i18n, + strategy: toRoutingStrategy(config.i18n), isBuild: true, }), [ @@ -1671,11 +1712,11 @@ describe('getLocaleAbsoluteUrlList', () => { * @type {import("../../../dist/@types").AstroUserConfig} */ const config = { - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'en_US', 'es'], - routing: 'pathname-prefix-always', + i18n: { + defaultLocale: 'en', + locales: ['en', 'en_US', 'es'], + routing: { + prefixDefaultLocale: true, }, }, }; @@ -1684,7 +1725,8 @@ describe('getLocaleAbsoluteUrlList', () => { getLocaleAbsoluteUrlList({ locale: 'en', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, + strategy: toRoutingStrategy(config.i18n), trailingSlash: 'ignore', format: 'directory', site: 'https://example.com', @@ -1703,11 +1745,12 @@ describe('getLocaleAbsoluteUrlList', () => { * @type {import("../../../dist/@types").AstroUserConfig} */ const config = { - experimental: { - i18n: { - defaultLocale: 'en', - locales: ['en', 'en_US', 'es'], - routing: 'pathname-prefix-always-no-redirect', + i18n: { + defaultLocale: 'en', + locales: ['en', 'en_US', 'es'], + routing: { + prefixDefaultLocale: true, + redirectToDefaultLocale: false, }, }, }; @@ -1716,7 +1759,8 @@ describe('getLocaleAbsoluteUrlList', () => { getLocaleAbsoluteUrlList({ locale: 'en', base: '/blog/', - ...config.experimental.i18n, + ...config.i18n, + strategy: toRoutingStrategy(config.i18n), trailingSlash: 'ignore', format: 'directory', site: 'https://example.com', From 9001d063aeb19677ba556c2890e4b8b9513fd6de Mon Sep 17 00:00:00 2001 From: zsombok Date: Wed, 21 Feb 2024 08:42:43 +0100 Subject: [PATCH 10/19] Fix blog ordering (#10168) Co-authored-by: David Zsombok --- examples/blog/src/content/blog/second-post.md | 2 +- examples/blog/src/content/blog/third-post.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/blog/src/content/blog/second-post.md b/examples/blog/src/content/blog/second-post.md index 19a910598e9f..f47e0937eb1c 100644 --- a/examples/blog/src/content/blog/second-post.md +++ b/examples/blog/src/content/blog/second-post.md @@ -1,7 +1,7 @@ --- title: 'Second post' description: 'Lorem ipsum dolor sit amet' -pubDate: 'Jul 22 2022' +pubDate: 'Jul 15 2022' heroImage: '/blog-placeholder-4.jpg' --- diff --git a/examples/blog/src/content/blog/third-post.md b/examples/blog/src/content/blog/third-post.md index 463cd253d181..af82f0eff4c8 100644 --- a/examples/blog/src/content/blog/third-post.md +++ b/examples/blog/src/content/blog/third-post.md @@ -1,7 +1,7 @@ --- title: 'Third post' description: 'Lorem ipsum dolor sit amet' -pubDate: 'Jul 15 2022' +pubDate: 'Jul 22 2022' heroImage: '/blog-placeholder-2.jpg' --- From ec7d2ebbd96b8c2dfdadaf076bbf7953007536ed Mon Sep 17 00:00:00 2001 From: Piotr Losiak <47902696+moose96@users.noreply.github.com> Date: Wed, 21 Feb 2024 08:43:22 +0100 Subject: [PATCH 11/19] fix(sitemap): url when rest parameter is used in page file names (#9975) * fix(sitemap): url when rest parameter is used in page file names * Update .changeset/sour-ties-sparkle.md Co-authored-by: Florian Lefebvre * Apply suggestions from code review --------- Co-authored-by: Florian Lefebvre Co-authored-by: Emanuele Stoppa --- .changeset/sour-ties-sparkle.md | 5 ++++ packages/integrations/sitemap/src/index.ts | 2 ++ .../sitemap/test/dynamic-path.test.js | 24 +++++++++++++++++++ .../test/fixtures/dynamic/astro.config.mjs | 7 ++++++ .../test/fixtures/dynamic/package.json | 9 +++++++ .../dynamic/src/pages/[...slug].astro | 21 ++++++++++++++++ pnpm-lock.yaml | 9 +++++++ 7 files changed, 77 insertions(+) create mode 100644 .changeset/sour-ties-sparkle.md create mode 100644 packages/integrations/sitemap/test/dynamic-path.test.js create mode 100644 packages/integrations/sitemap/test/fixtures/dynamic/astro.config.mjs create mode 100644 packages/integrations/sitemap/test/fixtures/dynamic/package.json create mode 100644 packages/integrations/sitemap/test/fixtures/dynamic/src/pages/[...slug].astro diff --git a/.changeset/sour-ties-sparkle.md b/.changeset/sour-ties-sparkle.md new file mode 100644 index 000000000000..17088feae350 --- /dev/null +++ b/.changeset/sour-ties-sparkle.md @@ -0,0 +1,5 @@ +--- +"@astrojs/sitemap": patch +--- + +Fixes URL generation for routes that rest parameters and start with `/` diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 4c049df9170b..4d280112b9ac 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -98,6 +98,8 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { .map((p) => { if (p.pathname !== '' && !finalSiteUrl.pathname.endsWith('/')) finalSiteUrl.pathname += '/'; + if (p.pathname.startsWith('/')) + p.pathname = p.pathname.slice(1); const fullPath = finalSiteUrl.pathname + p.pathname; return new URL(fullPath, finalSiteUrl).href; }); diff --git a/packages/integrations/sitemap/test/dynamic-path.test.js b/packages/integrations/sitemap/test/dynamic-path.test.js new file mode 100644 index 000000000000..4f84af39e7af --- /dev/null +++ b/packages/integrations/sitemap/test/dynamic-path.test.js @@ -0,0 +1,24 @@ +import {before, describe, it} from "node:test"; +import {loadFixture, readXML} from "./test-utils.js"; +import assert from "node:assert/strict"; + +describe('Dynamic with rest parameter', () => { + /** @type {import('./test-utils.js').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/dynamic', + }); + await fixture.build(); + }); + + it('Should generate correct urls', async () => { + const data = await readXML(fixture.readFile('/sitemap-0.xml')); + const urls = data.urlset.url.map((url) => url.loc[0]); + + assert.ok(urls.includes('http://example.com/')); + assert.ok(urls.includes('http://example.com/blog/')); + assert.ok(urls.includes('http://example.com/test/')); + }); +}) diff --git a/packages/integrations/sitemap/test/fixtures/dynamic/astro.config.mjs b/packages/integrations/sitemap/test/fixtures/dynamic/astro.config.mjs new file mode 100644 index 000000000000..7d02e26caf3a --- /dev/null +++ b/packages/integrations/sitemap/test/fixtures/dynamic/astro.config.mjs @@ -0,0 +1,7 @@ +import { defineConfig } from 'astro/config'; +import sitemap from '@astrojs/sitemap'; + +export default defineConfig({ + integrations: [sitemap()], + site: 'http://example.com' +}) diff --git a/packages/integrations/sitemap/test/fixtures/dynamic/package.json b/packages/integrations/sitemap/test/fixtures/dynamic/package.json new file mode 100644 index 000000000000..1eac19a1bc3d --- /dev/null +++ b/packages/integrations/sitemap/test/fixtures/dynamic/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/sitemap-dynamic", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*", + "@astrojs/sitemap": "workspace:*" + } +} diff --git a/packages/integrations/sitemap/test/fixtures/dynamic/src/pages/[...slug].astro b/packages/integrations/sitemap/test/fixtures/dynamic/src/pages/[...slug].astro new file mode 100644 index 000000000000..9622cb374c20 --- /dev/null +++ b/packages/integrations/sitemap/test/fixtures/dynamic/src/pages/[...slug].astro @@ -0,0 +1,21 @@ +--- +export async function getStaticPaths() { + return [ + { + params: { + slug: undefined, + } + }, + { + params: { + slug: '/blog' + } + }, + { + params: { + slug: '/test' + } + } + ]; +} +--- diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ff7f3fa769a..a6e62986d847 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4577,6 +4577,15 @@ importers: specifier: 0.6.2 version: 0.6.2 + packages/integrations/sitemap/test/fixtures/dynamic: + dependencies: + '@astrojs/sitemap': + specifier: workspace:* + version: link:../../.. + astro: + specifier: workspace:* + version: link:../../../../../astro + packages/integrations/sitemap/test/fixtures/ssr: dependencies: '@astrojs/sitemap': From 8e51bf9ea9661c5228ec43e30b661fc422a5803d Mon Sep 17 00:00:00 2001 From: Piotr Losiak Date: Wed, 21 Feb 2024 07:44:29 +0000 Subject: [PATCH 12/19] [ci] format --- packages/integrations/sitemap/src/index.ts | 3 +-- .../integrations/sitemap/test/dynamic-path.test.js | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 4d280112b9ac..5d2a271d2cb9 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -98,8 +98,7 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { .map((p) => { if (p.pathname !== '' && !finalSiteUrl.pathname.endsWith('/')) finalSiteUrl.pathname += '/'; - if (p.pathname.startsWith('/')) - p.pathname = p.pathname.slice(1); + if (p.pathname.startsWith('/')) p.pathname = p.pathname.slice(1); const fullPath = finalSiteUrl.pathname + p.pathname; return new URL(fullPath, finalSiteUrl).href; }); diff --git a/packages/integrations/sitemap/test/dynamic-path.test.js b/packages/integrations/sitemap/test/dynamic-path.test.js index 4f84af39e7af..851462ceb207 100644 --- a/packages/integrations/sitemap/test/dynamic-path.test.js +++ b/packages/integrations/sitemap/test/dynamic-path.test.js @@ -1,24 +1,24 @@ -import {before, describe, it} from "node:test"; -import {loadFixture, readXML} from "./test-utils.js"; -import assert from "node:assert/strict"; +import { before, describe, it } from 'node:test'; +import { loadFixture, readXML } from './test-utils.js'; +import assert from 'node:assert/strict'; describe('Dynamic with rest parameter', () => { /** @type {import('./test-utils.js').Fixture} */ let fixture; - + before(async () => { fixture = await loadFixture({ root: './fixtures/dynamic', }); await fixture.build(); }); - + it('Should generate correct urls', async () => { const data = await readXML(fixture.readFile('/sitemap-0.xml')); const urls = data.urlset.url.map((url) => url.loc[0]); - + assert.ok(urls.includes('http://example.com/')); assert.ok(urls.includes('http://example.com/blog/')); assert.ok(urls.includes('http://example.com/test/')); }); -}) +}); From 062623438b5dfd66682a967edc7b7c91bd29e888 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 21 Feb 2024 14:08:19 +0000 Subject: [PATCH 13/19] chore: use biome to sort imports - only test files (#10180) * chore: use biome to sort imports * do the sorting * Update package.json Co-authored-by: Bjorn Lu --------- Co-authored-by: Bjorn Lu --- biome.json | 16 ++++ package.json | 7 +- .../test/pagesGlobToRssItems.test.js | 2 +- packages/astro-rss/test/rss.test.js | 2 +- packages/astro/e2e/error-cyclic.test.js | 2 +- packages/astro/e2e/error-sass.test.js | 2 +- packages/astro/e2e/nested-recursive.test.js | 2 +- packages/astro/e2e/vue-component.test.js | 2 +- packages/astro/test/0-css.test.js | 2 +- .../test/alias-tsconfig-baseurl-only.test.js | 2 +- packages/astro/test/alias-tsconfig.test.js | 2 +- packages/astro/test/alias.test.js | 2 +- packages/astro/test/asset-url-base.test.js | 2 +- .../astro/test/astro-assets-prefix.test.js | 2 +- packages/astro/test/astro-assets.test.js | 4 +- packages/astro/test/astro-attrs.test.js | 2 +- packages/astro/test/astro-basic.test.js | 2 +- packages/astro/test/astro-children.test.js | 2 +- packages/astro/test/astro-class-list.test.js | 2 +- packages/astro/test/astro-client-only.test.js | 2 +- .../test/astro-component-bundling.test.js | 2 +- .../astro/test/astro-component-code.test.js | 2 +- packages/astro/test/astro-cookies.test.js | 4 +- .../astro/test/astro-css-bundling.test.js | 2 +- packages/astro/test/astro-directives.test.js | 2 +- packages/astro/test/astro-doctype.test.js | 2 +- packages/astro/test/astro-dynamic.test.js | 2 +- packages/astro/test/astro-envs.test.js | 2 +- packages/astro/test/astro-expr.test.js | 2 +- .../astro/test/astro-external-files.test.js | 2 +- packages/astro/test/astro-fallback.test.js | 2 +- packages/astro/test/astro-generator.test.js | 2 +- .../astro/test/astro-get-static-paths.test.js | 2 +- packages/astro/test/astro-global.test.js | 2 +- packages/astro/test/astro-head.test.js | 2 +- ...tro-markdown-frontmatter-injection.test.js | 2 +- .../astro/test/astro-markdown-plugins.test.js | 4 +- .../test/astro-markdown-remarkRehype.test.js | 2 +- .../astro/test/astro-markdown-shiki.test.js | 2 +- packages/astro/test/astro-markdown.test.js | 4 +- .../astro/test/astro-not-response.test.js | 2 +- .../astro/test/astro-object-style.test.js | 2 +- .../astro/test/astro-pageDirectoryUrl.test.js | 2 +- packages/astro/test/astro-pages.test.js | 4 +- .../test/astro-pagination-root-spread.test.js | 2 +- packages/astro/test/astro-pagination.test.js | 2 +- .../astro/test/astro-partial-html.test.js | 2 +- packages/astro/test/astro-public.test.js | 2 +- packages/astro/test/astro-response.test.js | 2 +- packages/astro/test/astro-scripts.test.js | 2 +- .../astro/test/astro-slot-with-client.test.js | 2 +- .../astro/test/astro-slots-nested.test.js | 2 +- packages/astro/test/astro-slots.test.js | 2 +- packages/astro/test/before-hydration.test.js | 4 +- packages/astro/test/build-assets.test.js | 4 +- packages/astro/test/cli.test.js | 8 +- packages/astro/test/client-address.test.js | 6 +- packages/astro/test/code-component.test.js | 2 +- packages/astro/test/component-library.test.js | 2 +- packages/astro/test/config-mode.test.js | 4 +- .../astro/test/config-vite-css-target.test.js | 2 +- packages/astro/test/config-vite.test.js | 2 +- .../content-collection-references.test.js | 2 +- .../test/content-collections-render.test.js | 4 +- .../astro/test/content-collections.test.js | 8 +- .../astro/test/core-image-infersize.test.js | 4 +- .../test/core-image-remark-imgattr.test.js | 4 +- packages/astro/test/core-image.test.js | 4 +- packages/astro/test/css-assets.test.js | 2 +- .../test/css-dangling-references.test.js | 2 +- .../astro/test/css-import-as-inline.test.js | 2 +- .../astro/test/css-inline-stylesheets.test.js | 4 +- packages/astro/test/css-no-code-split.test.js | 2 +- packages/astro/test/css-order-import.test.js | 2 +- packages/astro/test/css-order-layout.test.js | 2 +- packages/astro/test/css-order.test.js | 4 +- packages/astro/test/custom-404-html.test.js | 4 +- .../custom-404-implicit-rerouting.test.js | 4 +- .../test/custom-404-injected-from-dep.test.js | 4 +- .../astro/test/custom-404-injected.test.js | 4 +- packages/astro/test/custom-404-md.test.js | 4 +- packages/astro/test/custom-404-static.test.js | 4 +- .../astro/test/custom-assets-name.test.js | 2 +- packages/astro/test/data-collections.test.js | 2 +- packages/astro/test/debug-component.test.js | 4 +- packages/astro/test/dev-routing.test.js | 2 +- packages/astro/test/dont-delete-root.test.js | 2 +- .../test/dynamic-endpoint-collision.test.js | 2 +- .../test/dynamic-route-build-file.test.js | 2 +- packages/astro/test/entry-file-names.test.js | 2 +- packages/astro/test/error-bad-js.test.js | 2 +- packages/astro/test/error-non-error.test.js | 2 +- ...ntal-content-collection-references.test.js | 2 +- ...collections-css-inline-stylesheets.test.js | 4 +- ...imental-content-collections-render.test.js | 4 +- .../experimental-content-collections.test.js | 8 +- packages/astro/test/featuresSupport.test.js | 2 +- packages/astro/test/fetch.test.js | 2 +- packages/astro/test/fontsource.test.js | 2 +- .../astro/test/get-static-paths-pages.test.js | 2 +- packages/astro/test/glob-pages-css.test.js | 2 +- packages/astro/test/head-injection.test.js | 2 +- packages/astro/test/hoisted-imports.test.js | 4 +- packages/astro/test/html-component.test.js | 2 +- .../astro/test/html-escape-complex.test.js | 2 +- packages/astro/test/html-escape.test.js | 2 +- packages/astro/test/html-page.test.js | 2 +- packages/astro/test/html-slots.test.js | 2 +- packages/astro/test/hydration-race.test.js | 2 +- packages/astro/test/i18n-routing.test.js | 4 +- packages/astro/test/image-deletion.test.js | 2 +- packages/astro/test/import-ts-with-js.test.js | 2 +- packages/astro/test/impostor-mdx-file.test.js | 2 +- .../integration-add-page-extension.test.js | 2 +- .../test/integration-server-setup.test.js | 2 +- packages/astro/test/jsx.test.js | 2 +- packages/astro/test/lazy-layout.test.js | 2 +- packages/astro/test/lit-element.test.js | 2 +- packages/astro/test/markdown.test.js | 2 +- packages/astro/test/middleware.test.js | 4 +- packages/astro/test/minification-html.test.js | 4 +- .../astro/test/multiple-renderers.test.js | 2 +- packages/astro/test/non-ascii-path.test.js | 2 +- packages/astro/test/non-html-pages.test.js | 2 +- packages/astro/test/partials.test.js | 2 +- .../test/preact-compat-component.test.js | 2 +- packages/astro/test/preview-routing.test.js | 2 +- packages/astro/test/public-base-404.test.js | 2 +- packages/astro/test/redirects.test.js | 4 +- packages/astro/test/routing-priority.test.js | 2 +- .../astro/test/scoped-style-strategy.test.js | 2 +- packages/astro/test/set-html.test.js | 2 +- packages/astro/test/solid-component.test.js | 2 +- .../astro/test/space-in-folder-name.test.js | 2 +- ...special-chars-in-component-imports.test.js | 2 +- .../test/ssr-adapter-build-config.test.js | 4 +- packages/astro/test/ssr-api-route.test.js | 2 +- packages/astro/test/ssr-assets.test.js | 4 +- packages/astro/test/ssr-dynamic.test.js | 4 +- packages/astro/test/ssr-env.test.js | 4 +- packages/astro/test/ssr-error-pages.test.js | 6 +- .../astro/test/ssr-hoisted-script.test.js | 4 +- packages/astro/test/ssr-large-array.test.js | 4 +- packages/astro/test/ssr-lit.test.js | 4 +- packages/astro/test/ssr-locals.test.js | 4 +- packages/astro/test/ssr-manifest.test.js | 6 +- packages/astro/test/ssr-markdown.test.js | 4 +- packages/astro/test/ssr-params.test.js | 4 +- packages/astro/test/ssr-partytown.test.js | 4 +- .../ssr-prerender-get-static-paths.test.js | 2 +- packages/astro/test/ssr-prerender.test.js | 4 +- packages/astro/test/ssr-preview.test.js | 4 +- packages/astro/test/ssr-request.test.js | 4 +- packages/astro/test/ssr-response.test.js | 4 +- packages/astro/test/ssr-scripts.test.js | 4 +- .../astro/test/ssr-split-manifest.test.js | 10 +- .../test/static-build-code-component.test.js | 2 +- .../test/static-build-frameworks.test.js | 4 +- packages/astro/test/static-build.test.js | 4 +- packages/astro/test/streaming.test.js | 2 +- packages/astro/test/svelte-component.test.js | 2 +- packages/astro/test/third-party-astro.test.js | 2 +- packages/astro/test/units/app/headers.test.js | 2 +- .../test/units/assets/remote-pattern.test.js | 6 +- .../test/units/build/static-build.test.js | 2 +- .../test/units/compile/invalid-css.test.js | 6 +- .../test/units/config/config-resolve.test.js | 4 +- .../test/units/config/config-server.test.js | 4 +- .../test/units/config/config-tsconfig.test.js | 2 +- .../test/units/config/config-validate.test.js | 8 +- .../astro/test/units/config/format.test.js | 4 +- .../content-collections/error-map.test.js | 6 +- .../content-collections/frontmatter.test.js | 2 +- .../get-entry-info.test.js | 4 +- .../get-entry-type.test.js | 2 +- .../astro/test/units/cookies/delete.test.js | 2 +- .../astro/test/units/cookies/error.test.js | 2 +- packages/astro/test/units/cookies/get.test.js | 2 +- packages/astro/test/units/cookies/has.test.js | 2 +- packages/astro/test/units/cookies/set.test.js | 2 +- packages/astro/test/units/dev/base.test.js | 2 +- .../collections-mixed-content-errors.test.js | 2 +- .../units/dev/collections-renderentry.test.js | 4 +- packages/astro/test/units/dev/dev.test.js | 4 +- .../test/units/dev/head-injection.test.js | 4 +- .../astro/test/units/dev/hydration.test.js | 2 +- packages/astro/test/units/dev/restart.test.js | 4 +- packages/astro/test/units/dev/styles.test.js | 4 +- .../astro/test/units/i18n/astro_i18n.test.js | 16 ++-- .../astro/test/units/integrations/api.test.js | 6 +- .../astro/test/units/logger/locale.test.js | 2 +- .../astro/test/units/render/chunk.test.js | 4 +- .../test/units/render/components.test.js | 4 +- packages/astro/test/units/render/head.test.js | 12 +-- packages/astro/test/units/render/jsx.test.js | 10 +- .../test/units/routing/endpoints.test.js | 10 +- .../astro/test/units/routing/manifest.test.js | 4 +- .../test/units/routing/route-matching.test.js | 22 ++--- .../units/routing/route-sanitization.test.js | 12 +-- .../test/units/routing/trailing-slash.test.js | 10 +- .../test/units/runtime/astro-global.test.js | 2 +- .../controller.test.js | 2 +- .../vite-plugin-astro-server/request.test.js | 6 +- .../vite-plugin-astro-server/response.test.js | 10 +- .../units/vite-plugin-astro/compile.test.js | 6 +- .../test/units/vite-plugin-astro/hmr.test.js | 2 +- .../units/vite-plugin-scanner/scan.test.js | 2 +- packages/astro/test/view-transitions.test.js | 2 +- packages/astro/test/vue-component.test.js | 2 +- packages/create-astro/test/context.test.js | 2 +- .../create-astro/test/dependencies.test.js | 2 +- packages/create-astro/test/git.test.js | 4 +- packages/create-astro/test/typescript.test.js | 6 +- packages/create-astro/test/verify.test.js | 2 +- packages/integrations/lit/test/sass.test.js | 2 +- packages/integrations/lit/test/server.test.js | 6 +- .../markdoc/test/content-collections.test.js | 6 +- .../markdoc/test/headings.test.js | 4 +- .../markdoc/test/image-assets.test.js | 4 +- .../markdoc/test/propagated-assets.test.js | 4 +- .../markdoc/test/render-html.test.js | 4 +- .../integrations/markdoc/test/render.test.js | 4 +- .../markdoc/test/syntax-highlighting.test.js | 10 +- .../markdoc/test/variables.test.js | 4 +- .../mdx/test/css-head-mdx.test.js | 6 +- .../mdx/test/invalid-mdx-component.test.js | 2 +- .../mdx-astro-markdown-remarkRehype.test.js | 2 +- .../mdx/test/mdx-component.test.js | 2 +- .../integrations/mdx/test/mdx-escape.test.js | 2 +- .../test/mdx-frontmatter-injection.test.js | 2 +- .../mdx/test/mdx-frontmatter.test.js | 2 +- .../mdx/test/mdx-get-headings.test.js | 2 +- .../mdx/test/mdx-get-static-paths.test.js | 4 +- .../integrations/mdx/test/mdx-images.test.js | 2 +- .../mdx/test/mdx-infinite-loop.test.js | 2 +- .../integrations/mdx/test/mdx-math.test.js | 8 +- .../mdx/test/mdx-namespace.test.js | 2 +- .../mdx/test/mdx-optimize.test.js | 2 +- .../integrations/mdx/test/mdx-page.test.js | 2 +- .../integrations/mdx/test/mdx-plugins.test.js | 6 +- .../mdx/test/mdx-plus-react.test.js | 2 +- .../mdx/test/mdx-script-style-raw.test.js | 4 +- .../integrations/mdx/test/mdx-slots.test.js | 2 +- .../mdx/test/mdx-syntax-highlighting.test.js | 6 +- .../mdx/test/mdx-url-export.test.js | 2 +- .../mdx/test/mdx-vite-env-vars.test.js | 2 +- .../mdx/test/remark-imgattr.test.js | 2 +- .../integrations/node/test/api-route.test.js | 8 +- .../integrations/node/test/assets.test.js | 4 +- .../integrations/node/test/bad-urls.test.js | 2 +- .../integrations/node/test/encoded.test.js | 4 +- .../integrations/node/test/errors.test.js | 4 +- .../integrations/node/test/headers.test.js | 4 +- packages/integrations/node/test/image.test.js | 2 +- .../integrations/node/test/locals.test.js | 4 +- .../node/test/node-middleware.test.js | 6 +- .../node/test/prerender-404-500.test.js | 4 +- .../integrations/node/test/prerender.test.js | 4 +- .../node/test/url-protocol.test.js | 2 +- .../node/test/well-known-locations.test.js | 2 +- .../react/test/react-component.test.js | 2 +- .../sitemap/test/base-path.test.js | 2 +- .../sitemap/test/dynamic-path.test.js | 2 +- .../integrations/sitemap/test/filter.test.js | 2 +- .../integrations/sitemap/test/prefix.test.js | 4 +- .../integrations/sitemap/test/routes.test.js | 2 +- .../integrations/sitemap/test/ssr.test.js | 2 +- .../sitemap/test/staticPaths.test.js | 2 +- .../sitemap/test/trailing-slash.test.js | 2 +- .../integrations/tailwind/test/basic.test.js | 2 +- .../integrations/vercel/test/image.test.js | 2 +- packages/integrations/vercel/test/isr.test.js | 2 +- .../vercel/test/max-duration.test.js | 2 +- .../vercel/test/no-output.test.js | 2 +- .../test/prerendered-error-pages.test.js | 2 +- .../vercel/test/speed-insights.test.js | 2 +- .../integrations/vercel/test/split.test.js | 2 +- .../integrations/vercel/test/static.test.js | 2 +- .../vercel/test/streaming.test.js | 2 +- .../vercel/test/web-analytics.test.js | 2 +- .../vue/test/app-entrypoint-css.test.js | 4 +- .../vue/test/app-entrypoint.test.js | 4 +- packages/integrations/vue/test/basics.test.js | 4 +- .../markdown/remark/test/autolinking.test.js | 2 +- packages/markdown/remark/test/browser.test.js | 2 +- .../markdown/remark/test/entities.test.js | 2 +- packages/markdown/remark/test/plugins.test.js | 2 +- .../remark/test/remark-collect-images.test.js | 2 +- packages/telemetry/test/index.test.js | 2 +- .../underscore-redirects/test/astro.test.js | 2 +- .../underscore-redirects/test/print.test.js | 2 +- .../underscore-redirects/test/weight.test.js | 2 +- packages/upgrade/test/context.test.js | 2 +- packages/upgrade/test/install.test.js | 4 +- packages/upgrade/test/verify.test.js | 2 +- pnpm-lock.yaml | 91 +++++++++++++++++++ 296 files changed, 584 insertions(+), 476 deletions(-) create mode 100644 biome.json diff --git a/biome.json b/biome.json new file mode 100644 index 000000000000..d3d01f78d530 --- /dev/null +++ b/biome.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", + "files": { + "include": ["*.test.js"], + "ignore": ["vendor"] + }, + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": false + }, + "formatter": { + "enabled": false + } +} diff --git a/package.json b/package.json index d26d4fac2558..b12affb58558 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,10 @@ "build:ci": "turbo run build:ci --filter=astro --filter=create-astro --filter=\"@astrojs/*\" --filter=\"@benchmark/*\"", "build:examples": "turbo run build --filter=\"@example/*\"", "dev": "turbo run dev --concurrency=40 --parallel --filter=astro --filter=create-astro --filter=\"@astrojs/*\" --filter=\"@benchmark/*\"", - "format": "pnpm run format:code", - "format:ci": "pnpm run format:code", + "format": "pnpm run format:code && pnpm run format:imports", + "format:ci": "pnpm run format:code && pnpm run format:imports", "format:code": "prettier -w \"**/*\" --ignore-unknown --cache", - "format:imports": "organize-imports-cli ./packages/*/tsconfig.json ./packages/*/*/tsconfig.json", + "format:imports": "biome check --apply .", "test": "turbo run test --concurrency=1 --filter=astro --filter=create-astro --filter=\"@astrojs/*\"", "test:match": "cd packages/astro && pnpm run test:match", "test:unit": "cd packages/astro && pnpm run test:unit", @@ -45,6 +45,7 @@ }, "packageManager": "pnpm@8.6.12", "dependencies": { + "@biomejs/biome": "^1.5.3", "astro-benchmark": "workspace:*" }, "devDependencies": { diff --git a/packages/astro-rss/test/pagesGlobToRssItems.test.js b/packages/astro-rss/test/pagesGlobToRssItems.test.js index e3da7351b0fb..560ede268c47 100644 --- a/packages/astro-rss/test/pagesGlobToRssItems.test.js +++ b/packages/astro-rss/test/pagesGlobToRssItems.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; -import { phpFeedItem, web1FeedItem } from './test-utils.js'; import { pagesGlobToRssItems } from '../dist/index.js'; +import { phpFeedItem, web1FeedItem } from './test-utils.js'; describe('pagesGlobToRssItems', () => { it('should generate on valid result', async () => { diff --git a/packages/astro-rss/test/rss.test.js b/packages/astro-rss/test/rss.test.js index 02df32f4810c..2d5a0f6c810b 100644 --- a/packages/astro-rss/test/rss.test.js +++ b/packages/astro-rss/test/rss.test.js @@ -6,6 +6,7 @@ import rss, { getRssString } from '../dist/index.js'; import { rssSchema } from '../dist/schema.js'; import { description, + parseXmlString, phpFeedItem, phpFeedItemWithContent, phpFeedItemWithCustomData, @@ -14,7 +15,6 @@ import { web1FeedItem, web1FeedItemWithAllData, web1FeedItemWithContent, - parseXmlString, } from './test-utils.js'; // note: I spent 30 minutes looking for a nice node-based snapshot tool diff --git a/packages/astro/e2e/error-cyclic.test.js b/packages/astro/e2e/error-cyclic.test.js index 32cbc050ac07..84f4d1d1dce3 100644 --- a/packages/astro/e2e/error-cyclic.test.js +++ b/packages/astro/e2e/error-cyclic.test.js @@ -1,5 +1,5 @@ import { expect } from '@playwright/test'; -import { testFactory, getErrorOverlayContent } from './test-utils.js'; +import { getErrorOverlayContent, testFactory } from './test-utils.js'; const test = testFactory({ root: './fixtures/error-cyclic/', diff --git a/packages/astro/e2e/error-sass.test.js b/packages/astro/e2e/error-sass.test.js index a4e68f57b797..11862fb86e65 100644 --- a/packages/astro/e2e/error-sass.test.js +++ b/packages/astro/e2e/error-sass.test.js @@ -1,5 +1,5 @@ import { expect } from '@playwright/test'; -import { testFactory, getErrorOverlayContent } from './test-utils.js'; +import { getErrorOverlayContent, testFactory } from './test-utils.js'; const test = testFactory({ root: './fixtures/error-sass/', diff --git a/packages/astro/e2e/nested-recursive.test.js b/packages/astro/e2e/nested-recursive.test.js index 262cd67723e9..8271c6557587 100644 --- a/packages/astro/e2e/nested-recursive.test.js +++ b/packages/astro/e2e/nested-recursive.test.js @@ -1,4 +1,4 @@ -import { test as base, expect } from '@playwright/test'; +import { expect, test as base } from '@playwright/test'; import { loadFixture, waitForHydrate } from './test-utils.js'; const test = base.extend({ diff --git a/packages/astro/e2e/vue-component.test.js b/packages/astro/e2e/vue-component.test.js index 5d0455dee66c..ca491de90867 100644 --- a/packages/astro/e2e/vue-component.test.js +++ b/packages/astro/e2e/vue-component.test.js @@ -1,5 +1,5 @@ -import { prepareTestFactory } from './shared-component-tests.js'; import { expect } from '@playwright/test'; +import { prepareTestFactory } from './shared-component-tests.js'; const { test, createTests } = prepareTestFactory({ root: './fixtures/vue-component/' }); const config = { diff --git a/packages/astro/test/0-css.test.js b/packages/astro/test/0-css.test.js index 4cc1d18645ca..e3f182b161e9 100644 --- a/packages/astro/test/0-css.test.js +++ b/packages/astro/test/0-css.test.js @@ -5,7 +5,7 @@ */ import assert from 'node:assert/strict'; -import { describe, before, it, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/alias-tsconfig-baseurl-only.test.js b/packages/astro/test/alias-tsconfig-baseurl-only.test.js index c1f79c6c09f6..20c2884ccb06 100644 --- a/packages/astro/test/alias-tsconfig-baseurl-only.test.js +++ b/packages/astro/test/alias-tsconfig-baseurl-only.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/alias-tsconfig.test.js b/packages/astro/test/alias-tsconfig.test.js index 006e1270564d..86853baf2320 100644 --- a/packages/astro/test/alias-tsconfig.test.js +++ b/packages/astro/test/alias-tsconfig.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/alias.test.js b/packages/astro/test/alias.test.js index e9f4ab63832d..4e3b14a9e45c 100644 --- a/packages/astro/test/alias.test.js +++ b/packages/astro/test/alias.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { isWindows, loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/asset-url-base.test.js b/packages/astro/test/asset-url-base.test.js index 93695e2e7b1d..18269b6540b1 100644 --- a/packages/astro/test/asset-url-base.test.js +++ b/packages/astro/test/asset-url-base.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-assets-prefix.test.js b/packages/astro/test/astro-assets-prefix.test.js index de5aa84f4f28..08af026c1543 100644 --- a/packages/astro/test/astro-assets-prefix.test.js +++ b/packages/astro/test/astro-assets-prefix.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import testAdapter from './test-adapter.js'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-assets.test.js b/packages/astro/test/astro-assets.test.js index 266159b707b8..68e8da2b01b5 100644 --- a/packages/astro/test/astro-assets.test.js +++ b/packages/astro/test/astro-assets.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import srcsetParse from 'srcset-parse'; +import { loadFixture } from './test-utils.js'; // This package isn't real ESM, so have to coerce it const matchSrcset = srcsetParse.default; diff --git a/packages/astro/test/astro-attrs.test.js b/packages/astro/test/astro-attrs.test.js index a3a8b7e81737..0866e4828ba3 100644 --- a/packages/astro/test/astro-attrs.test.js +++ b/packages/astro/test/astro-attrs.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-basic.test.js b/packages/astro/test/astro-basic.test.js index 869abe3de181..cb7c06ce0efd 100644 --- a/packages/astro/test/astro-basic.test.js +++ b/packages/astro/test/astro-basic.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-children.test.js b/packages/astro/test/astro-children.test.js index 1e2e00d2c701..91afe112e99d 100644 --- a/packages/astro/test/astro-children.test.js +++ b/packages/astro/test/astro-children.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-class-list.test.js b/packages/astro/test/astro-class-list.test.js index 7d300e997fe9..9044661239b2 100644 --- a/packages/astro/test/astro-class-list.test.js +++ b/packages/astro/test/astro-class-list.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-client-only.test.js b/packages/astro/test/astro-client-only.test.js index 88b762e73a2a..33626e2f3efb 100644 --- a/packages/astro/test/astro-client-only.test.js +++ b/packages/astro/test/astro-client-only.test.js @@ -1,6 +1,6 @@ -import { load as cheerioLoad } from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { load as cheerioLoad } from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Client only components', () => { diff --git a/packages/astro/test/astro-component-bundling.test.js b/packages/astro/test/astro-component-bundling.test.js index 2d8b75aa55a6..619f0af045d1 100644 --- a/packages/astro/test/astro-component-bundling.test.js +++ b/packages/astro/test/astro-component-bundling.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Component bundling', () => { diff --git a/packages/astro/test/astro-component-code.test.js b/packages/astro/test/astro-component-code.test.js index 1a3a23ea7f93..3e5bf5d9e3a6 100644 --- a/packages/astro/test/astro-component-code.test.js +++ b/packages/astro/test/astro-component-code.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('', () => { diff --git a/packages/astro/test/astro-cookies.test.js b/packages/astro/test/astro-cookies.test.js index 34f548109a9f..9d7136c4f8c6 100644 --- a/packages/astro/test/astro-cookies.test.js +++ b/packages/astro/test/astro-cookies.test.js @@ -1,8 +1,8 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import * as cheerio from 'cheerio'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Astro.cookies', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/astro-css-bundling.test.js b/packages/astro/test/astro-css-bundling.test.js index 150f9a381924..91f75ec52a1b 100644 --- a/packages/astro/test/astro-css-bundling.test.js +++ b/packages/astro/test/astro-css-bundling.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; // note: the hashes should be deterministic, but updating the file contents will change hashes diff --git a/packages/astro/test/astro-directives.test.js b/packages/astro/test/astro-directives.test.js index 5b9e0b672410..2a2ae26ef3ae 100644 --- a/packages/astro/test/astro-directives.test.js +++ b/packages/astro/test/astro-directives.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Directives', async () => { diff --git a/packages/astro/test/astro-doctype.test.js b/packages/astro/test/astro-doctype.test.js index ada762d82ae4..dbe05092f909 100644 --- a/packages/astro/test/astro-doctype.test.js +++ b/packages/astro/test/astro-doctype.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Doctype', () => { diff --git a/packages/astro/test/astro-dynamic.test.js b/packages/astro/test/astro-dynamic.test.js index 63ed2582ad9b..47344bf0ea97 100644 --- a/packages/astro/test/astro-dynamic.test.js +++ b/packages/astro/test/astro-dynamic.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Dynamic components', () => { diff --git a/packages/astro/test/astro-envs.test.js b/packages/astro/test/astro-envs.test.js index b477b0394c20..6af981930f85 100644 --- a/packages/astro/test/astro-envs.test.js +++ b/packages/astro/test/astro-envs.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; import * as cheerio from 'cheerio'; +import { loadFixture } from './test-utils.js'; describe('Environment Variables', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/astro-expr.test.js b/packages/astro/test/astro-expr.test.js index 48e73c6c8dc3..3b47cae818a5 100644 --- a/packages/astro/test/astro-expr.test.js +++ b/packages/astro/test/astro-expr.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Expressions', () => { diff --git a/packages/astro/test/astro-external-files.test.js b/packages/astro/test/astro-external-files.test.js index 5db44bc21a55..ecd92a912d53 100644 --- a/packages/astro/test/astro-external-files.test.js +++ b/packages/astro/test/astro-external-files.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('External file references', () => { diff --git a/packages/astro/test/astro-fallback.test.js b/packages/astro/test/astro-fallback.test.js index 2cc36bdbcbba..bdd44afa4374 100644 --- a/packages/astro/test/astro-fallback.test.js +++ b/packages/astro/test/astro-fallback.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Dynamic component fallback', () => { diff --git a/packages/astro/test/astro-generator.test.js b/packages/astro/test/astro-generator.test.js index 1ede062a734a..df1f1ffa5db9 100644 --- a/packages/astro/test/astro-generator.test.js +++ b/packages/astro/test/astro-generator.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-get-static-paths.test.js b/packages/astro/test/astro-get-static-paths.test.js index 390879c6522b..36aa051f4417 100644 --- a/packages/astro/test/astro-get-static-paths.test.js +++ b/packages/astro/test/astro-get-static-paths.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { after, afterEach, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('getStaticPaths - build calls', () => { diff --git a/packages/astro/test/astro-global.test.js b/packages/astro/test/astro-global.test.js index 08e744dd88cd..119a8413f924 100644 --- a/packages/astro/test/astro-global.test.js +++ b/packages/astro/test/astro-global.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Astro Global', () => { diff --git a/packages/astro/test/astro-head.test.js b/packages/astro/test/astro-head.test.js index 05fb32e572a2..303d74baafcd 100644 --- a/packages/astro/test/astro-head.test.js +++ b/packages/astro/test/astro-head.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-markdown-frontmatter-injection.test.js b/packages/astro/test/astro-markdown-frontmatter-injection.test.js index b40b352b8d5c..850453306f98 100644 --- a/packages/astro/test/astro-markdown-frontmatter-injection.test.js +++ b/packages/astro/test/astro-markdown-frontmatter-injection.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; const FIXTURE_ROOT = './fixtures/astro-markdown-frontmatter-injection/'; diff --git a/packages/astro/test/astro-markdown-plugins.test.js b/packages/astro/test/astro-markdown-plugins.test.js index 03863a1ed3ca..09cb76d2decc 100644 --- a/packages/astro/test/astro-markdown-plugins.test.js +++ b/packages/astro/test/astro-markdown-plugins.test.js @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import addClasses from './fixtures/astro-markdown-plugins/add-classes.mjs'; +import { loadFixture } from './test-utils.js'; const defaultMarkdownConfig = { gfm: true, diff --git a/packages/astro/test/astro-markdown-remarkRehype.test.js b/packages/astro/test/astro-markdown-remarkRehype.test.js index 40f9613e5373..4725437ccf82 100644 --- a/packages/astro/test/astro-markdown-remarkRehype.test.js +++ b/packages/astro/test/astro-markdown-remarkRehype.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-markdown-shiki.test.js b/packages/astro/test/astro-markdown-shiki.test.js index 411a7256ec15..982b30e8b561 100644 --- a/packages/astro/test/astro-markdown-shiki.test.js +++ b/packages/astro/test/astro-markdown-shiki.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-markdown.test.js b/packages/astro/test/astro-markdown.test.js index 958b1cb4f1f5..9ae09ff9274f 100644 --- a/packages/astro/test/astro-markdown.test.js +++ b/packages/astro/test/astro-markdown.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture, fixLineEndings } from './test-utils.js'; +import { fixLineEndings, loadFixture } from './test-utils.js'; const FIXTURE_ROOT = './fixtures/astro-markdown/'; diff --git a/packages/astro/test/astro-not-response.test.js b/packages/astro/test/astro-not-response.test.js index e7d23d18d0cc..467ca27aff7e 100644 --- a/packages/astro/test/astro-not-response.test.js +++ b/packages/astro/test/astro-not-response.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; // Asset bundling diff --git a/packages/astro/test/astro-object-style.test.js b/packages/astro/test/astro-object-style.test.js index 5c620b8d9db5..b6ae7ff08f0d 100644 --- a/packages/astro/test/astro-object-style.test.js +++ b/packages/astro/test/astro-object-style.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Object style', async () => { diff --git a/packages/astro/test/astro-pageDirectoryUrl.test.js b/packages/astro/test/astro-pageDirectoryUrl.test.js index 040c614ea2ee..76e224b07466 100644 --- a/packages/astro/test/astro-pageDirectoryUrl.test.js +++ b/packages/astro/test/astro-pageDirectoryUrl.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('build format', () => { diff --git a/packages/astro/test/astro-pages.test.js b/packages/astro/test/astro-pages.test.js index 0a1601c397c2..c3af8d0e4c6d 100644 --- a/packages/astro/test/astro-pages.test.js +++ b/packages/astro/test/astro-pages.test.js @@ -1,7 +1,7 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; -import { loadFixture, isWindows } from './test-utils.js'; +import * as cheerio from 'cheerio'; +import { isWindows, loadFixture } from './test-utils.js'; describe('Pages', () => { let fixture; diff --git a/packages/astro/test/astro-pagination-root-spread.test.js b/packages/astro/test/astro-pagination-root-spread.test.js index 9c9ea4e45da3..c1f5c0ba5e2f 100644 --- a/packages/astro/test/astro-pagination-root-spread.test.js +++ b/packages/astro/test/astro-pagination-root-spread.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-pagination.test.js b/packages/astro/test/astro-pagination.test.js index 44aaec773fe1..a78a2f23e1da 100644 --- a/packages/astro/test/astro-pagination.test.js +++ b/packages/astro/test/astro-pagination.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-partial-html.test.js b/packages/astro/test/astro-partial-html.test.js index 48024b35bcdb..f6ea0de9525f 100644 --- a/packages/astro/test/astro-partial-html.test.js +++ b/packages/astro/test/astro-partial-html.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Partial HTML', async () => { diff --git a/packages/astro/test/astro-public.test.js b/packages/astro/test/astro-public.test.js index 056f626478d5..1c44d9c8423c 100644 --- a/packages/astro/test/astro-public.test.js +++ b/packages/astro/test/astro-public.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Public', () => { diff --git a/packages/astro/test/astro-response.test.js b/packages/astro/test/astro-response.test.js index 3a1bc306f252..87313a76a26f 100644 --- a/packages/astro/test/astro-response.test.js +++ b/packages/astro/test/astro-response.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; // Asset bundling diff --git a/packages/astro/test/astro-scripts.test.js b/packages/astro/test/astro-scripts.test.js index a9cdc991b31f..ec2d3e805c3a 100644 --- a/packages/astro/test/astro-scripts.test.js +++ b/packages/astro/test/astro-scripts.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Scripts (hoisted and not)', () => { diff --git a/packages/astro/test/astro-slot-with-client.test.js b/packages/astro/test/astro-slot-with-client.test.js index d0789689d56e..a52d9b907964 100644 --- a/packages/astro/test/astro-slot-with-client.test.js +++ b/packages/astro/test/astro-slot-with-client.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/astro-slots-nested.test.js b/packages/astro/test/astro-slots-nested.test.js index 7f924d7094b8..3d04b00e27ba 100644 --- a/packages/astro/test/astro-slots-nested.test.js +++ b/packages/astro/test/astro-slots-nested.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Nested Slots', () => { diff --git a/packages/astro/test/astro-slots.test.js b/packages/astro/test/astro-slots.test.js index 5e916685f54e..5653e0421ce3 100644 --- a/packages/astro/test/astro-slots.test.js +++ b/packages/astro/test/astro-slots.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/before-hydration.test.js b/packages/astro/test/before-hydration.test.js index 76d824a75098..d14b347bfe42 100644 --- a/packages/astro/test/before-hydration.test.js +++ b/packages/astro/test/before-hydration.test.js @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import { preact } from './fixtures/before-hydration/deps.mjs'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Astro Scripts before-hydration', () => { describe('SSG', () => { diff --git a/packages/astro/test/build-assets.test.js b/packages/astro/test/build-assets.test.js index cba3e5b46a37..b33b0a0d1eba 100644 --- a/packages/astro/test/build-assets.test.js +++ b/packages/astro/test/build-assets.test.js @@ -1,9 +1,9 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import { preact } from './fixtures/before-hydration/deps.mjs'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('build assets (static)', () => { describe('with default configuration', () => { diff --git a/packages/astro/test/cli.test.js b/packages/astro/test/cli.test.js index 6a88b5b5d9c5..99a70e6688d1 100644 --- a/packages/astro/test/cli.test.js +++ b/packages/astro/test/cli.test.js @@ -1,12 +1,12 @@ import assert from 'node:assert/strict'; -import { describe, it } from 'node:test'; -import { cli, parseCliDevStart, cliServerLogSetup, loadFixture } from './test-utils.js'; -import stripAnsi from 'strip-ansi'; import { promises as fs, readFileSync } from 'node:fs'; -import { fileURLToPath } from 'node:url'; import { isIPv4 } from 'node:net'; import { join } from 'node:path'; import { Writable } from 'node:stream'; +import { describe, it } from 'node:test'; +import { fileURLToPath } from 'node:url'; +import stripAnsi from 'strip-ansi'; +import { cli, cliServerLogSetup, loadFixture, parseCliDevStart } from './test-utils.js'; describe('astro cli', () => { const cliServerLogSetupWithFixture = (flags, cmd) => { diff --git a/packages/astro/test/client-address.test.js b/packages/astro/test/client-address.test.js index de4a6a4f4270..667133fe28b2 100644 --- a/packages/astro/test/client-address.test.js +++ b/packages/astro/test/client-address.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it, after } from 'node:test'; -import { loadFixture } from './test-utils.js'; -import testAdapter from './test-adapter.js'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; +import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Astro.clientAddress', () => { describe('SSR', () => { diff --git a/packages/astro/test/code-component.test.js b/packages/astro/test/code-component.test.js index a3ed65088e6d..1024e4ccd4d2 100644 --- a/packages/astro/test/code-component.test.js +++ b/packages/astro/test/code-component.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/component-library.test.js b/packages/astro/test/component-library.test.js index 9533509d6374..503599cd0cd3 100644 --- a/packages/astro/test/component-library.test.js +++ b/packages/astro/test/component-library.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/config-mode.test.js b/packages/astro/test/config-mode.test.js index 2b5533f4dff4..99ad99e1ccd1 100644 --- a/packages/astro/test/config-mode.test.js +++ b/packages/astro/test/config-mode.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { before, describe, it } from 'node:test'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('AstroConfig - config.output', () => { describe(`output: 'server'`, () => { diff --git a/packages/astro/test/config-vite-css-target.test.js b/packages/astro/test/config-vite-css-target.test.js index 97cba273fa4e..1a2137d68d5a 100644 --- a/packages/astro/test/config-vite-css-target.test.js +++ b/packages/astro/test/config-vite-css-target.test.js @@ -3,7 +3,7 @@ */ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/config-vite.test.js b/packages/astro/test/config-vite.test.js index 24927e9c743e..6f9b20599d27 100644 --- a/packages/astro/test/config-vite.test.js +++ b/packages/astro/test/config-vite.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/content-collection-references.test.js b/packages/astro/test/content-collection-references.test.js index bf31f5dc46ae..2305ece31657 100644 --- a/packages/astro/test/content-collection-references.test.js +++ b/packages/astro/test/content-collection-references.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { fixLineEndings, loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/content-collections-render.test.js b/packages/astro/test/content-collections-render.test.js index b177fa54263f..0e8e37fb176b 100644 --- a/packages/astro/test/content-collections-render.test.js +++ b/packages/astro/test/content-collections-render.test.js @@ -1,8 +1,8 @@ import * as assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture, isWindows } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { isWindows, loadFixture } from './test-utils.js'; if (!isWindows) { describe(); diff --git a/packages/astro/test/content-collections.test.js b/packages/astro/test/content-collections.test.js index 28c153150cf3..d4aaebaf8fba 100644 --- a/packages/astro/test/content-collections.test.js +++ b/packages/astro/test/content-collections.test.js @@ -1,10 +1,10 @@ -import * as devalue from 'devalue'; -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; +import * as devalue from 'devalue'; import testAdapter from './test-adapter.js'; import { preventNodeBuiltinDependencyPlugin } from './test-plugins.js'; +import { loadFixture } from './test-utils.js'; describe('Content Collections', () => { describe('Query', () => { diff --git a/packages/astro/test/core-image-infersize.test.js b/packages/astro/test/core-image-infersize.test.js index 44c571d17709..9abf24b1f79e 100644 --- a/packages/astro/test/core-image-infersize.test.js +++ b/packages/astro/test/core-image-infersize.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, before, after, it } from 'node:test'; -import * as cheerio from 'cheerio'; import { Writable } from 'node:stream'; +import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { Logger } from '../dist/core/logger/core.js'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/core-image-remark-imgattr.test.js b/packages/astro/test/core-image-remark-imgattr.test.js index 936decfd2849..f62123942189 100644 --- a/packages/astro/test/core-image-remark-imgattr.test.js +++ b/packages/astro/test/core-image-remark-imgattr.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, before, after, it } from 'node:test'; -import * as cheerio from 'cheerio'; import { Writable } from 'node:stream'; +import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { Logger } from '../dist/core/logger/core.js'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/core-image.test.js b/packages/astro/test/core-image.test.js index 561c7dc2e6a4..8724df88bac0 100644 --- a/packages/astro/test/core-image.test.js +++ b/packages/astro/test/core-image.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, after, it } from 'node:test'; -import * as cheerio from 'cheerio'; import { basename } from 'node:path'; import { Writable } from 'node:stream'; +import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import parseSrcset from 'parse-srcset'; import { removeDir } from '../dist/core/fs/index.js'; import { Logger } from '../dist/core/logger/core.js'; diff --git a/packages/astro/test/css-assets.test.js b/packages/astro/test/css-assets.test.js index 386d8b5751e1..194094c05a32 100644 --- a/packages/astro/test/css-assets.test.js +++ b/packages/astro/test/css-assets.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/css-dangling-references.test.js b/packages/astro/test/css-dangling-references.test.js index 58e01d85c7ef..f4c40709200d 100644 --- a/packages/astro/test/css-dangling-references.test.js +++ b/packages/astro/test/css-dangling-references.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; const cssAssetReferenceRegExp = /_astro\/[A-Za-z\d\-]+\.[\da-f]{8}\.css/g; diff --git a/packages/astro/test/css-import-as-inline.test.js b/packages/astro/test/css-import-as-inline.test.js index 86bb75556136..9941887062c3 100644 --- a/packages/astro/test/css-import-as-inline.test.js +++ b/packages/astro/test/css-import-as-inline.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, before, it, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/css-inline-stylesheets.test.js b/packages/astro/test/css-inline-stylesheets.test.js index 1cce302cc0cb..d066f530a6d3 100644 --- a/packages/astro/test/css-inline-stylesheets.test.js +++ b/packages/astro/test/css-inline-stylesheets.test.js @@ -1,8 +1,8 @@ import * as assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Setting inlineStylesheets to never in static output', () => { let fixture; diff --git a/packages/astro/test/css-no-code-split.test.js b/packages/astro/test/css-no-code-split.test.js index ba7680d49d91..5d7731bcd106 100644 --- a/packages/astro/test/css-no-code-split.test.js +++ b/packages/astro/test/css-no-code-split.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/css-order-import.test.js b/packages/astro/test/css-order-import.test.js index e2ba60e28b5a..d8ee74a1d0bf 100644 --- a/packages/astro/test/css-order-import.test.js +++ b/packages/astro/test/css-order-import.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, before, it, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/css-order-layout.test.js b/packages/astro/test/css-order-layout.test.js index c1c71fd91530..3ce08a7b3f5b 100644 --- a/packages/astro/test/css-order-layout.test.js +++ b/packages/astro/test/css-order-layout.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/css-order.test.js b/packages/astro/test/css-order.test.js index e9476256ddeb..ee2992a31ba4 100644 --- a/packages/astro/test/css-order.test.js +++ b/packages/astro/test/css-order.test.js @@ -1,8 +1,8 @@ import * as assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('CSS production ordering', () => { function getLinks(html) { diff --git a/packages/astro/test/custom-404-html.test.js b/packages/astro/test/custom-404-html.test.js index 80504f59d5de..8e59f40852a7 100644 --- a/packages/astro/test/custom-404-html.test.js +++ b/packages/astro/test/custom-404-html.test.js @@ -1,7 +1,7 @@ +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; -import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; describe('Custom 404.html', () => { let fixture; diff --git a/packages/astro/test/custom-404-implicit-rerouting.test.js b/packages/astro/test/custom-404-implicit-rerouting.test.js index 35b5afa3aea7..4986b34c42ba 100644 --- a/packages/astro/test/custom-404-implicit-rerouting.test.js +++ b/packages/astro/test/custom-404-implicit-rerouting.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; for (const caseNumber of [1, 2, 3, 4]) { describe(`Custom 404 with implicit rerouting - Case #${caseNumber}`, () => { diff --git a/packages/astro/test/custom-404-injected-from-dep.test.js b/packages/astro/test/custom-404-injected-from-dep.test.js index 13764d5098f1..beffa27176d9 100644 --- a/packages/astro/test/custom-404-injected-from-dep.test.js +++ b/packages/astro/test/custom-404-injected-from-dep.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; describe('Custom 404 with injectRoute from dependency', () => { describe('build', () => { diff --git a/packages/astro/test/custom-404-injected.test.js b/packages/astro/test/custom-404-injected.test.js index 48319734a008..2dae399a269d 100644 --- a/packages/astro/test/custom-404-injected.test.js +++ b/packages/astro/test/custom-404-injected.test.js @@ -1,7 +1,7 @@ +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; -import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; describe('Custom 404 with injectRoute', () => { let fixture; diff --git a/packages/astro/test/custom-404-md.test.js b/packages/astro/test/custom-404-md.test.js index 68b5a5ebaa6b..3cd97482cedd 100644 --- a/packages/astro/test/custom-404-md.test.js +++ b/packages/astro/test/custom-404-md.test.js @@ -1,7 +1,7 @@ +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; -import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; describe('Custom 404 Markdown', () => { let fixture; diff --git a/packages/astro/test/custom-404-static.test.js b/packages/astro/test/custom-404-static.test.js index 5ab923dc4a2a..ba351ae11c7d 100644 --- a/packages/astro/test/custom-404-static.test.js +++ b/packages/astro/test/custom-404-static.test.js @@ -1,7 +1,7 @@ +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; -import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; describe('Custom 404 with Static', () => { let fixture; diff --git a/packages/astro/test/custom-assets-name.test.js b/packages/astro/test/custom-assets-name.test.js index 7f101cbf1ff9..63cd3eb171f2 100644 --- a/packages/astro/test/custom-assets-name.test.js +++ b/packages/astro/test/custom-assets-name.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('custom the assets name function', () => { diff --git a/packages/astro/test/data-collections.test.js b/packages/astro/test/data-collections.test.js index 1e47b03f95ff..68f15a773370 100644 --- a/packages/astro/test/data-collections.test.js +++ b/packages/astro/test/data-collections.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; const authorIds = ['Ben Holmes', 'Fred K Schott', 'Nate Moore']; diff --git a/packages/astro/test/debug-component.test.js b/packages/astro/test/debug-component.test.js index 27cffe1a13d5..1414505417e5 100644 --- a/packages/astro/test/debug-component.test.js +++ b/packages/astro/test/debug-component.test.js @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; -import { loadFixture, isMacOS } from './test-utils.js'; +import { after, before, describe, it } from 'node:test'; +import { isMacOS, loadFixture } from './test-utils.js'; // TODO: fix this tests in macOS if (!isMacOS) { diff --git a/packages/astro/test/dev-routing.test.js b/packages/astro/test/dev-routing.test.js index df10e0d42b44..cc0a3fa1c0c0 100644 --- a/packages/astro/test/dev-routing.test.js +++ b/packages/astro/test/dev-routing.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Development Routing', () => { diff --git a/packages/astro/test/dont-delete-root.test.js b/packages/astro/test/dont-delete-root.test.js index 3a81c16bbeaf..7ae7b5267d1a 100644 --- a/packages/astro/test/dont-delete-root.test.js +++ b/packages/astro/test/dont-delete-root.test.js @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; import * as fs from 'node:fs'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('outDir set to project root', async () => { diff --git a/packages/astro/test/dynamic-endpoint-collision.test.js b/packages/astro/test/dynamic-endpoint-collision.test.js index d3beaa76aebc..b1aa42f9fdb8 100644 --- a/packages/astro/test/dynamic-endpoint-collision.test.js +++ b/packages/astro/test/dynamic-endpoint-collision.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/dynamic-route-build-file.test.js b/packages/astro/test/dynamic-route-build-file.test.js index c251d43c712e..12787dd3a17b 100644 --- a/packages/astro/test/dynamic-route-build-file.test.js +++ b/packages/astro/test/dynamic-route-build-file.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/entry-file-names.test.js b/packages/astro/test/entry-file-names.test.js index b1fb2e293cd3..2dc6e5998c9a 100644 --- a/packages/astro/test/entry-file-names.test.js +++ b/packages/astro/test/entry-file-names.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/error-bad-js.test.js b/packages/astro/test/error-bad-js.test.js index 4e015c6d9214..b89cf6652173 100644 --- a/packages/astro/test/error-bad-js.test.js +++ b/packages/astro/test/error-bad-js.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Errors in JavaScript', () => { diff --git a/packages/astro/test/error-non-error.test.js b/packages/astro/test/error-non-error.test.js index 66c386b9c18a..c7b7e8ed040c 100644 --- a/packages/astro/test/error-non-error.test.js +++ b/packages/astro/test/error-non-error.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Can handle errors that are not instanceof Error', () => { diff --git a/packages/astro/test/experimental-content-collection-references.test.js b/packages/astro/test/experimental-content-collection-references.test.js index 755aaaf05421..b53f5f7ee2b9 100644 --- a/packages/astro/test/experimental-content-collection-references.test.js +++ b/packages/astro/test/experimental-content-collection-references.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, after, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { fixLineEndings, loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/experimental-content-collections-css-inline-stylesheets.test.js b/packages/astro/test/experimental-content-collections-css-inline-stylesheets.test.js index 8126485c1747..6722fc46bcf7 100644 --- a/packages/astro/test/experimental-content-collections-css-inline-stylesheets.test.js +++ b/packages/astro/test/experimental-content-collections-css-inline-stylesheets.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, after, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Experimental Content Collections cache inlineStylesheets', () => { let fixture; diff --git a/packages/astro/test/experimental-content-collections-render.test.js b/packages/astro/test/experimental-content-collections-render.test.js index f2ad6dfa950d..93ef150fc5a9 100644 --- a/packages/astro/test/experimental-content-collections-render.test.js +++ b/packages/astro/test/experimental-content-collections-render.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, after, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture, isWindows } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { isWindows, loadFixture } from './test-utils.js'; if (!isWindows) { describe('Experimental Content Collections cache - render()', () => { diff --git a/packages/astro/test/experimental-content-collections.test.js b/packages/astro/test/experimental-content-collections.test.js index 68d0d8012cd4..6e4b88b2361f 100644 --- a/packages/astro/test/experimental-content-collections.test.js +++ b/packages/astro/test/experimental-content-collections.test.js @@ -1,10 +1,10 @@ -import * as devalue from 'devalue'; -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; -import { describe, before, after, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; +import * as devalue from 'devalue'; import testAdapter from './test-adapter.js'; import { preventNodeBuiltinDependencyPlugin } from './test-plugins.js'; +import { loadFixture } from './test-utils.js'; describe('Experimental Content Collections cache', () => { describe('Query', () => { diff --git a/packages/astro/test/featuresSupport.test.js b/packages/astro/test/featuresSupport.test.js index b87b0fc94d08..4387a702a33a 100644 --- a/packages/astro/test/featuresSupport.test.js +++ b/packages/astro/test/featuresSupport.test.js @@ -1,7 +1,7 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Adapter', () => { let fixture; diff --git a/packages/astro/test/fetch.test.js b/packages/astro/test/fetch.test.js index 846e0c8a38ab..b198f7b1f014 100644 --- a/packages/astro/test/fetch.test.js +++ b/packages/astro/test/fetch.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/fontsource.test.js b/packages/astro/test/fontsource.test.js index 41b50bd5e7fe..51c7a69d6ae8 100644 --- a/packages/astro/test/fontsource.test.js +++ b/packages/astro/test/fontsource.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/get-static-paths-pages.test.js b/packages/astro/test/get-static-paths-pages.test.js index b807310fcc0d..170e1d485ac9 100644 --- a/packages/astro/test/get-static-paths-pages.test.js +++ b/packages/astro/test/get-static-paths-pages.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/glob-pages-css.test.js b/packages/astro/test/glob-pages-css.test.js index 85813029f50c..07b427cb0dc8 100644 --- a/packages/astro/test/glob-pages-css.test.js +++ b/packages/astro/test/glob-pages-css.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/head-injection.test.js b/packages/astro/test/head-injection.test.js index fc27da0e4241..eb3ab77363a3 100644 --- a/packages/astro/test/head-injection.test.js +++ b/packages/astro/test/head-injection.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/hoisted-imports.test.js b/packages/astro/test/hoisted-imports.test.js index b30351378f6c..f7b8a3928215 100644 --- a/packages/astro/test/hoisted-imports.test.js +++ b/packages/astro/test/hoisted-imports.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; +import { loadFixture } from './test-utils.js'; describe('Hoisted Imports', () => { let fixture; diff --git a/packages/astro/test/html-component.test.js b/packages/astro/test/html-component.test.js index c0d67d43152a..535c01ce3ee8 100644 --- a/packages/astro/test/html-component.test.js +++ b/packages/astro/test/html-component.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/html-escape-complex.test.js b/packages/astro/test/html-escape-complex.test.js index f4f4e15907e2..fa6cb1f77f70 100644 --- a/packages/astro/test/html-escape-complex.test.js +++ b/packages/astro/test/html-escape-complex.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/html-escape.test.js b/packages/astro/test/html-escape.test.js index 61b03ca6f0a7..60033f2df798 100644 --- a/packages/astro/test/html-escape.test.js +++ b/packages/astro/test/html-escape.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/html-page.test.js b/packages/astro/test/html-page.test.js index e0533688d0c7..1f94aed40110 100644 --- a/packages/astro/test/html-page.test.js +++ b/packages/astro/test/html-page.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/html-slots.test.js b/packages/astro/test/html-slots.test.js index 61e11e37af2e..b49f270652b0 100644 --- a/packages/astro/test/html-slots.test.js +++ b/packages/astro/test/html-slots.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/hydration-race.test.js b/packages/astro/test/hydration-race.test.js index 66e791bca910..ac2af37232ba 100644 --- a/packages/astro/test/hydration-race.test.js +++ b/packages/astro/test/hydration-race.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index 3c9a19df6f9a..7287fc041c93 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -1,8 +1,8 @@ +import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import testAdapter from './test-adapter.js'; import { loadFixture } from './test-utils.js'; -import { describe, it, before, after } from 'node:test'; -import * as assert from 'node:assert/strict'; describe('astro:i18n virtual module', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/image-deletion.test.js b/packages/astro/test/image-deletion.test.js index d773a45b2e77..4283e8c06f3b 100644 --- a/packages/astro/test/image-deletion.test.js +++ b/packages/astro/test/image-deletion.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import { testImageService } from './test-image-service.js'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/import-ts-with-js.test.js b/packages/astro/test/import-ts-with-js.test.js index 2b72a61e0705..5a15c6813269 100644 --- a/packages/astro/test/import-ts-with-js.test.js +++ b/packages/astro/test/import-ts-with-js.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/impostor-mdx-file.test.js b/packages/astro/test/impostor-mdx-file.test.js index bb4dbf5f8494..98ef3ceac808 100644 --- a/packages/astro/test/impostor-mdx-file.test.js +++ b/packages/astro/test/impostor-mdx-file.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { isWindows, loadFixture } from './test-utils.js'; let fixture; diff --git a/packages/astro/test/integration-add-page-extension.test.js b/packages/astro/test/integration-add-page-extension.test.js index f1e97d00ef83..daf87fb807d9 100644 --- a/packages/astro/test/integration-add-page-extension.test.js +++ b/packages/astro/test/integration-add-page-extension.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/integration-server-setup.test.js b/packages/astro/test/integration-server-setup.test.js index 45f14d708f5c..fd6c2329a610 100644 --- a/packages/astro/test/integration-server-setup.test.js +++ b/packages/astro/test/integration-server-setup.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Integration server setup', () => { diff --git a/packages/astro/test/jsx.test.js b/packages/astro/test/jsx.test.js index 3b972a6eb0c3..c8da3de72bd9 100644 --- a/packages/astro/test/jsx.test.js +++ b/packages/astro/test/jsx.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/lazy-layout.test.js b/packages/astro/test/lazy-layout.test.js index 4be339bafbf6..a9f31756e424 100644 --- a/packages/astro/test/lazy-layout.test.js +++ b/packages/astro/test/lazy-layout.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/lit-element.test.js b/packages/astro/test/lit-element.test.js index 2ea5f13a94e0..efe16b943fc9 100644 --- a/packages/astro/test/lit-element.test.js +++ b/packages/astro/test/lit-element.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/markdown.test.js b/packages/astro/test/markdown.test.js index 1e78409ce8d3..654f9631d500 100644 --- a/packages/astro/test/markdown.test.js +++ b/packages/astro/test/markdown.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/middleware.test.js b/packages/astro/test/middleware.test.js index b5d77c091bf5..a2c73284d009 100644 --- a/packages/astro/test/middleware.test.js +++ b/packages/astro/test/middleware.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; -import * as cheerio from 'cheerio'; import { existsSync, readFileSync } from 'node:fs'; +import { after, before, describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; +import * as cheerio from 'cheerio'; import testAdapter from './test-adapter.js'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/minification-html.test.js b/packages/astro/test/minification-html.test.js index 6aefa98a52b3..fd890601d35e 100644 --- a/packages/astro/test/minification-html.test.js +++ b/packages/astro/test/minification-html.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { after, before, describe, it } from 'node:test'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; const NEW_LINES = /[\r\n]+/g; diff --git a/packages/astro/test/multiple-renderers.test.js b/packages/astro/test/multiple-renderers.test.js index ba55ac847009..06f13284a1b0 100644 --- a/packages/astro/test/multiple-renderers.test.js +++ b/packages/astro/test/multiple-renderers.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/non-ascii-path.test.js b/packages/astro/test/non-ascii-path.test.js index ada3749a85d1..e3e532be8758 100644 --- a/packages/astro/test/non-ascii-path.test.js +++ b/packages/astro/test/non-ascii-path.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/non-html-pages.test.js b/packages/astro/test/non-html-pages.test.js index f27787ef9609..2b8ed970f282 100644 --- a/packages/astro/test/non-html-pages.test.js +++ b/packages/astro/test/non-html-pages.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Non-HTML Pages', () => { diff --git a/packages/astro/test/partials.test.js b/packages/astro/test/partials.test.js index 84880781eca9..a78309375112 100644 --- a/packages/astro/test/partials.test.js +++ b/packages/astro/test/partials.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 { loadFixture } from './test-utils.js'; describe('Partials', () => { diff --git a/packages/astro/test/preact-compat-component.test.js b/packages/astro/test/preact-compat-component.test.js index d9dc9fb71764..c0a639dfbc66 100644 --- a/packages/astro/test/preact-compat-component.test.js +++ b/packages/astro/test/preact-compat-component.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 { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/preview-routing.test.js b/packages/astro/test/preview-routing.test.js index fe4a0d111f46..eed735c7684d 100644 --- a/packages/astro/test/preview-routing.test.js +++ b/packages/astro/test/preview-routing.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 { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/public-base-404.test.js b/packages/astro/test/public-base-404.test.js index 682f38b695c2..12c5ce14c6b4 100644 --- a/packages/astro/test/public-base-404.test.js +++ b/packages/astro/test/public-base-404.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 { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/redirects.test.js b/packages/astro/test/redirects.test.js index b3b0b0a559b4..443b82073404 100644 --- a/packages/astro/test/redirects.test.js +++ b/packages/astro/test/redirects.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { before, describe, it, after } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { after, before, describe, it } from 'node:test'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Astro.redirect', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/routing-priority.test.js b/packages/astro/test/routing-priority.test.js index b87c353dbad3..d4203595d8a9 100644 --- a/packages/astro/test/routing-priority.test.js +++ b/packages/astro/test/routing-priority.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 { load as cheerioLoad } from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/scoped-style-strategy.test.js b/packages/astro/test/scoped-style-strategy.test.js index 4d149dd9e24a..c1a76aabbf22 100644 --- a/packages/astro/test/scoped-style-strategy.test.js +++ b/packages/astro/test/scoped-style-strategy.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/set-html.test.js b/packages/astro/test/set-html.test.js index 1fe81fe51ba1..c3a100d0449e 100644 --- a/packages/astro/test/set-html.test.js +++ b/packages/astro/test/set-html.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 { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/solid-component.test.js b/packages/astro/test/solid-component.test.js index 870b0c1b6422..7043983d7a89 100644 --- a/packages/astro/test/solid-component.test.js +++ b/packages/astro/test/solid-component.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 { isWindows, loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/space-in-folder-name.test.js b/packages/astro/test/space-in-folder-name.test.js index f029c861db3a..08995d84eefb 100644 --- a/packages/astro/test/space-in-folder-name.test.js +++ b/packages/astro/test/space-in-folder-name.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 { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/special-chars-in-component-imports.test.js b/packages/astro/test/special-chars-in-component-imports.test.js index 40101132cd32..64301741adff 100644 --- a/packages/astro/test/special-chars-in-component-imports.test.js +++ b/packages/astro/test/special-chars-in-component-imports.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 { load as cheerioLoad } from 'cheerio'; import { isWindows, loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/ssr-adapter-build-config.test.js b/packages/astro/test/ssr-adapter-build-config.test.js index d1566f097d61..8c19c56ba67d 100644 --- a/packages/astro/test/ssr-adapter-build-config.test.js +++ b/packages/astro/test/ssr-adapter-build-config.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { before, describe, it } from 'node:test'; import { viteID } from '../dist/core/util.js'; +import { loadFixture } from './test-utils.js'; describe('Integration buildConfig hook', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-api-route.test.js b/packages/astro/test/ssr-api-route.test.js index d5fefb17a0e5..495381eac66a 100644 --- a/packages/astro/test/ssr-api-route.test.js +++ b/packages/astro/test/ssr-api-route.test.js @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; import net from 'node:net'; +import { after, before, describe, it } from 'node:test'; import testAdapter from './test-adapter.js'; import { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/ssr-assets.test.js b/packages/astro/test/ssr-assets.test.js index 9d900babe4a8..d56ad1686b32 100644 --- a/packages/astro/test/ssr-assets.test.js +++ b/packages/astro/test/ssr-assets.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { before, describe, it } from 'node:test'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('SSR Assets', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-dynamic.test.js b/packages/astro/test/ssr-dynamic.test.js index 36cf0aceddff..60b61335dad6 100644 --- a/packages/astro/test/ssr-dynamic.test.js +++ b/packages/astro/test/ssr-dynamic.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Dynamic pages in SSR', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-env.test.js b/packages/astro/test/ssr-env.test.js index 619495f3f017..7da190736768 100644 --- a/packages/astro/test/ssr-env.test.js +++ b/packages/astro/test/ssr-env.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('SSR Environment Variables', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-error-pages.test.js b/packages/astro/test/ssr-error-pages.test.js index 1ea7a52943b3..f62c507b53d8 100644 --- a/packages/astro/test/ssr-error-pages.test.js +++ b/packages/astro/test/ssr-error-pages.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { before, describe, it, after } from 'node:test'; -import { loadFixture } from './test-utils.js'; -import testAdapter from './test-adapter.js'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; +import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('404 and 500 pages', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/astro/test/ssr-hoisted-script.test.js b/packages/astro/test/ssr-hoisted-script.test.js index 271b19b940b8..6bd4642bb4a3 100644 --- a/packages/astro/test/ssr-hoisted-script.test.js +++ b/packages/astro/test/ssr-hoisted-script.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { after, describe, before, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; async function fetchHTML(fixture, path) { const app = await fixture.loadTestAdapterApp(); diff --git a/packages/astro/test/ssr-large-array.test.js b/packages/astro/test/ssr-large-array.test.js index c004660e9c4b..f8602446704f 100644 --- a/packages/astro/test/ssr-large-array.test.js +++ b/packages/astro/test/ssr-large-array.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('SSR with Large Array and client rendering', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-lit.test.js b/packages/astro/test/ssr-lit.test.js index edcc0b9b070c..40057cf218aa 100644 --- a/packages/astro/test/ssr-lit.test.js +++ b/packages/astro/test/ssr-lit.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Lit integration in SSR', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-locals.test.js b/packages/astro/test/ssr-locals.test.js index 2f0fa8d3564b..9fea1fed9bd6 100644 --- a/packages/astro/test/ssr-locals.test.js +++ b/packages/astro/test/ssr-locals.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('SSR Astro.locals from server', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-manifest.test.js b/packages/astro/test/ssr-manifest.test.js index 0a499b6b585f..eaab834689a1 100644 --- a/packages/astro/test/ssr-manifest.test.js +++ b/packages/astro/test/ssr-manifest.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; -import testAdapter from './test-adapter.js'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; +import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('astro:ssr-manifest', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-markdown.test.js b/packages/astro/test/ssr-markdown.test.js index 2d80ac7b722d..286891790316 100644 --- a/packages/astro/test/ssr-markdown.test.js +++ b/packages/astro/test/ssr-markdown.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Markdown pages in SSR', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-params.test.js b/packages/astro/test/ssr-params.test.js index df050f9e7616..c5d376fbfce0 100644 --- a/packages/astro/test/ssr-params.test.js +++ b/packages/astro/test/ssr-params.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Astro.params in SSR', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/astro/test/ssr-partytown.test.js b/packages/astro/test/ssr-partytown.test.js index 04e7abc23799..4910f3e51ba4 100644 --- a/packages/astro/test/ssr-partytown.test.js +++ b/packages/astro/test/ssr-partytown.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Using the Partytown integration in SSR', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-prerender-get-static-paths.test.js b/packages/astro/test/ssr-prerender-get-static-paths.test.js index 9a76c62a5350..999ab5a74734 100644 --- a/packages/astro/test/ssr-prerender-get-static-paths.test.js +++ b/packages/astro/test/ssr-prerender-get-static-paths.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { after, afterEach, describe, before, it } from 'node:test'; +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'; diff --git a/packages/astro/test/ssr-prerender.test.js b/packages/astro/test/ssr-prerender.test.js index 98678d681df7..2bf53cefafb2 100644 --- a/packages/astro/test/ssr-prerender.test.js +++ b/packages/astro/test/ssr-prerender.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('SSR: prerender', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-preview.test.js b/packages/astro/test/ssr-preview.test.js index c9c18044860c..50cefa69c7ab 100644 --- a/packages/astro/test/ssr-preview.test.js +++ b/packages/astro/test/ssr-preview.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; -import testAdapter from './test-adapter.js'; import { before, describe, it } from 'node:test'; +import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('SSR Preview', () => { /** @type {import('./test-utils').Fixture} */ let fixture; diff --git a/packages/astro/test/ssr-request.test.js b/packages/astro/test/ssr-request.test.js index 4569fe291f53..a78a10f25e9c 100644 --- a/packages/astro/test/ssr-request.test.js +++ b/packages/astro/test/ssr-request.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; +import { before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; -import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Using Astro.request in SSR', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-response.test.js b/packages/astro/test/ssr-response.test.js index 703ee76967fa..c3ddb2744f09 100644 --- a/packages/astro/test/ssr-response.test.js +++ b/packages/astro/test/ssr-response.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { before, describe, it } from 'node:test'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('Using Astro.response in SSR', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-scripts.test.js b/packages/astro/test/ssr-scripts.test.js index f1a213ea6f76..5afa2a25bc50 100644 --- a/packages/astro/test/ssr-scripts.test.js +++ b/packages/astro/test/ssr-scripts.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { before, describe, it } from 'node:test'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('SSR Hydrated component scripts', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/ssr-split-manifest.test.js b/packages/astro/test/ssr-split-manifest.test.js index 04cb1219ac68..2f66b367616f 100644 --- a/packages/astro/test/ssr-split-manifest.test.js +++ b/packages/astro/test/ssr-split-manifest.test.js @@ -1,11 +1,11 @@ import assert from 'node:assert/strict'; -import { describe, before, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; -import testAdapter from './test-adapter.js'; -import * as cheerio from 'cheerio'; -import { fileURLToPath } from 'node:url'; import { existsSync, readFileSync } from 'node:fs'; import { resolve } from 'node:path'; +import { before, describe, it } from 'node:test'; +import { fileURLToPath } from 'node:url'; +import * as cheerio from 'cheerio'; +import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('astro:ssr-manifest, split', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/astro/test/static-build-code-component.test.js b/packages/astro/test/static-build-code-component.test.js index 4bd4ca1a4234..d23d4115b229 100644 --- a/packages/astro/test/static-build-code-component.test.js +++ b/packages/astro/test/static-build-code-component.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Code component inside static build', () => { diff --git a/packages/astro/test/static-build-frameworks.test.js b/packages/astro/test/static-build-frameworks.test.js index 63df5c3797dd..8eb35bf7e150 100644 --- a/packages/astro/test/static-build-frameworks.test.js +++ b/packages/astro/test/static-build-frameworks.test.js @@ -1,7 +1,7 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; -import { loadFixture, isWindows } from './test-utils.js'; +import * as cheerio from 'cheerio'; +import { isWindows, loadFixture } from './test-utils.js'; describe('Static build - frameworks', () => { if (isWindows) { diff --git a/packages/astro/test/static-build.test.js b/packages/astro/test/static-build.test.js index 3d7a92dfa3a5..126e1011604d 100644 --- a/packages/astro/test/static-build.test.js +++ b/packages/astro/test/static-build.test.js @@ -1,8 +1,8 @@ -import { load as cheerioLoad } from 'cheerio'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; -import { loadFixture } from './test-utils.js'; +import { load as cheerioLoad } from 'cheerio'; import { Logger } from '../dist/core/logger/core.js'; +import { loadFixture } from './test-utils.js'; function addLeadingSlash(path) { return path.startsWith('/') ? path : '/' + path; diff --git a/packages/astro/test/streaming.test.js b/packages/astro/test/streaming.test.js index 074fde269e75..1cfe7f42f1c1 100644 --- a/packages/astro/test/streaming.test.js +++ b/packages/astro/test/streaming.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 testAdapter from './test-adapter.js'; import { isWindows, loadFixture, streamAsyncIterator } from './test-utils.js'; diff --git a/packages/astro/test/svelte-component.test.js b/packages/astro/test/svelte-component.test.js index b27c1fbf7cfe..16ccd0e0bc54 100644 --- a/packages/astro/test/svelte-component.test.js +++ b/packages/astro/test/svelte-component.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 { isWindows, loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/third-party-astro.test.js b/packages/astro/test/third-party-astro.test.js index 1a81af8a923e..7a6c91adec67 100644 --- a/packages/astro/test/third-party-astro.test.js +++ b/packages/astro/test/third-party-astro.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 { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/units/app/headers.test.js b/packages/astro/test/units/app/headers.test.js index e8ae33f53a1b..b13b760f4e97 100644 --- a/packages/astro/test/units/app/headers.test.js +++ b/packages/astro/test/units/app/headers.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { createOutgoingHttpHeaders } from '../../../dist/core/app/createOutgoingHttpHeaders.js'; describe('createOutgoingHttpHeaders', () => { diff --git a/packages/astro/test/units/assets/remote-pattern.test.js b/packages/astro/test/units/assets/remote-pattern.test.js index 316b81860098..8b2072a4c18f 100644 --- a/packages/astro/test/units/assets/remote-pattern.test.js +++ b/packages/astro/test/units/assets/remote-pattern.test.js @@ -1,11 +1,11 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { - matchProtocol, - matchPort, matchHostname, matchPathname, matchPattern, + matchPort, + matchProtocol, } from '../../../dist/assets/utils/remotePattern.js'; describe('astro/src/assets/utils/remotePattern', () => { diff --git a/packages/astro/test/units/build/static-build.test.js b/packages/astro/test/units/build/static-build.test.js index acc3395df3f2..487ebf10c6cd 100644 --- a/packages/astro/test/units/build/static-build.test.js +++ b/packages/astro/test/units/build/static-build.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { makeAstroPageEntryPointFileName } from '../../../dist/core/build/static-build.js'; describe('astro/src/core/build', () => { diff --git a/packages/astro/test/units/compile/invalid-css.test.js b/packages/astro/test/units/compile/invalid-css.test.js index b43fb8ff657e..73d52e5ec8c1 100644 --- a/packages/astro/test/units/compile/invalid-css.test.js +++ b/packages/astro/test/units/compile/invalid-css.test.js @@ -1,9 +1,9 @@ -import { resolveConfig } from 'vite'; -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import { pathToFileURL } from 'node:url'; +import { resolveConfig } from 'vite'; import { compile } from '../../../dist/core/compile/index.js'; import { AggregateError } from '../../../dist/core/errors/index.js'; -import { pathToFileURL } from 'node:url'; describe('astro/src/core/compile', () => { describe('Invalid CSS', () => { diff --git a/packages/astro/test/units/config/config-resolve.test.js b/packages/astro/test/units/config/config-resolve.test.js index 78b556200af2..b0c11be06543 100644 --- a/packages/astro/test/units/config/config-resolve.test.js +++ b/packages/astro/test/units/config/config-resolve.test.js @@ -1,8 +1,8 @@ +import * as assert from 'node:assert/strict'; import path from 'node:path'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; import { resolveConfig } from '../../../dist/core/config/index.js'; -import { describe, it } from 'node:test'; -import * as assert from 'node:assert/strict'; describe('resolveConfig', () => { it('resolves relative inline root correctly', async () => { diff --git a/packages/astro/test/units/config/config-server.test.js b/packages/astro/test/units/config/config-server.test.js index 816cc70355b5..4d7063498a91 100644 --- a/packages/astro/test/units/config/config-server.test.js +++ b/packages/astro/test/units/config/config-server.test.js @@ -1,8 +1,8 @@ +import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; import { flagsToAstroInlineConfig } from '../../../dist/cli/flags.js'; import { resolveConfig } from '../../../dist/core/config/index.js'; -import { describe, it } from 'node:test'; -import * as assert from 'node:assert/strict'; const cwd = fileURLToPath(new URL('../../fixtures/config-host/', import.meta.url)); diff --git a/packages/astro/test/units/config/config-tsconfig.test.js b/packages/astro/test/units/config/config-tsconfig.test.js index 0cd579257ec3..c6372cbe0766 100644 --- a/packages/astro/test/units/config/config-tsconfig.test.js +++ b/packages/astro/test/units/config/config-tsconfig.test.js @@ -1,6 +1,6 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; import * as path from 'node:path'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; import { loadTSConfig, updateTSConfigForFramework } from '../../../dist/core/config/index.js'; diff --git a/packages/astro/test/units/config/config-validate.test.js b/packages/astro/test/units/config/config-validate.test.js index 10a5c3482cf8..7bd54755a258 100644 --- a/packages/astro/test/units/config/config-validate.test.js +++ b/packages/astro/test/units/config/config-validate.test.js @@ -1,9 +1,9 @@ -import { z } from 'zod'; +import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import stripAnsi from 'strip-ansi'; -import { formatConfigErrorMessage } from '../../../dist/core/messages.js'; +import { z } from 'zod'; import { validateConfig } from '../../../dist/core/config/config.js'; -import { describe, it } from 'node:test'; -import * as assert from 'node:assert/strict'; +import { formatConfigErrorMessage } from '../../../dist/core/messages.js'; describe('Config Validation', () => { it('empty user config is valid', async () => { diff --git a/packages/astro/test/units/config/format.test.js b/packages/astro/test/units/config/format.test.js index fa65d502c17c..4c9e472ff34c 100644 --- a/packages/astro/test/units/config/format.test.js +++ b/packages/astro/test/units/config/format.test.js @@ -1,6 +1,6 @@ -import { fileURLToPath } from 'node:url'; -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import { fileURLToPath } from 'node:url'; import { createFs, runInContainer } from '../test-utils.js'; const root = new URL('../../fixtures/tailwindcss-ts/', import.meta.url); diff --git a/packages/astro/test/units/content-collections/error-map.test.js b/packages/astro/test/units/content-collections/error-map.test.js index 5e3f58733136..0595fd58a243 100644 --- a/packages/astro/test/units/content-collections/error-map.test.js +++ b/packages/astro/test/units/content-collections/error-map.test.js @@ -1,8 +1,8 @@ -import { z } from '../../../zod.mjs'; +import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { errorMap } from '../../../dist/content/index.js'; +import { z } from '../../../zod.mjs'; import { fixLineEndings } from '../../test-utils.js'; -import { describe, it } from 'node:test'; -import * as assert from 'node:assert/strict'; describe('Content Collections - error map', () => { it('Prefixes messages with object key', () => { diff --git a/packages/astro/test/units/content-collections/frontmatter.test.js b/packages/astro/test/units/content-collections/frontmatter.test.js index 2e161b81ff1e..260d561e4d65 100644 --- a/packages/astro/test/units/content-collections/frontmatter.test.js +++ b/packages/astro/test/units/content-collections/frontmatter.test.js @@ -1,7 +1,7 @@ -import { fileURLToPath } from 'node:url'; import nodeFS from 'node:fs'; import path from 'node:path'; import { describe, it } from 'node:test'; +import { fileURLToPath } from 'node:url'; import { attachContentServerListeners } from '../../../dist/content/index.js'; import { createFs, runInContainer, triggerFSEvent } from '../test-utils.js'; diff --git a/packages/astro/test/units/content-collections/get-entry-info.test.js b/packages/astro/test/units/content-collections/get-entry-info.test.js index 780dc9467a2d..769f3c0dc2d1 100644 --- a/packages/astro/test/units/content-collections/get-entry-info.test.js +++ b/packages/astro/test/units/content-collections/get-entry-info.test.js @@ -1,6 +1,6 @@ -import { getContentEntryIdAndSlug, getEntryCollectionName } from '../../../dist/content/utils.js'; -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import { getContentEntryIdAndSlug, getEntryCollectionName } from '../../../dist/content/utils.js'; describe('Content Collections - entry info', () => { const contentDir = new URL('src/content/', import.meta.url); diff --git a/packages/astro/test/units/content-collections/get-entry-type.test.js b/packages/astro/test/units/content-collections/get-entry-type.test.js index 96665d5e3cfc..2876e5bfc31b 100644 --- a/packages/astro/test/units/content-collections/get-entry-type.test.js +++ b/packages/astro/test/units/content-collections/get-entry-type.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; import { getEntryType } from '../../../dist/content/utils.js'; diff --git a/packages/astro/test/units/cookies/delete.test.js b/packages/astro/test/units/cookies/delete.test.js index e9e1bcd3c433..4b5f188e1a17 100644 --- a/packages/astro/test/units/cookies/delete.test.js +++ b/packages/astro/test/units/cookies/delete.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { AstroCookies } from '../../../dist/core/cookies/index.js'; import { apply as applyPolyfill } from '../../../dist/core/polyfill.js'; diff --git a/packages/astro/test/units/cookies/error.test.js b/packages/astro/test/units/cookies/error.test.js index cf53827166f9..027474424a2e 100644 --- a/packages/astro/test/units/cookies/error.test.js +++ b/packages/astro/test/units/cookies/error.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { AstroCookies } from '../../../dist/core/cookies/index.js'; import { apply as applyPolyfill } from '../../../dist/core/polyfill.js'; diff --git a/packages/astro/test/units/cookies/get.test.js b/packages/astro/test/units/cookies/get.test.js index d3d86260a6d5..8cf9b6e20f52 100644 --- a/packages/astro/test/units/cookies/get.test.js +++ b/packages/astro/test/units/cookies/get.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { AstroCookies } from '../../../dist/core/cookies/index.js'; import { apply as applyPolyfill } from '../../../dist/core/polyfill.js'; diff --git a/packages/astro/test/units/cookies/has.test.js b/packages/astro/test/units/cookies/has.test.js index 23346f917968..351893d1e044 100644 --- a/packages/astro/test/units/cookies/has.test.js +++ b/packages/astro/test/units/cookies/has.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { AstroCookies } from '../../../dist/core/cookies/index.js'; import { apply as applyPolyfill } from '../../../dist/core/polyfill.js'; diff --git a/packages/astro/test/units/cookies/set.test.js b/packages/astro/test/units/cookies/set.test.js index f7fd334d9810..120ff92bf64a 100644 --- a/packages/astro/test/units/cookies/set.test.js +++ b/packages/astro/test/units/cookies/set.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { AstroCookies } from '../../../dist/core/cookies/index.js'; import { apply as applyPolyfill } from '../../../dist/core/polyfill.js'; diff --git a/packages/astro/test/units/dev/base.test.js b/packages/astro/test/units/dev/base.test.js index a3006163b230..6a8f33fb7e92 100644 --- a/packages/astro/test/units/dev/base.test.js +++ b/packages/astro/test/units/dev/base.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; import { createFs, createRequestAndResponse, runInContainer } from '../test-utils.js'; diff --git a/packages/astro/test/units/dev/collections-mixed-content-errors.test.js b/packages/astro/test/units/dev/collections-mixed-content-errors.test.js index 26ea1334d01e..0086b51e83ac 100644 --- a/packages/astro/test/units/dev/collections-mixed-content-errors.test.js +++ b/packages/astro/test/units/dev/collections-mixed-content-errors.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; import _sync from '../../../dist/core/sync/index.js'; import { createFsWithFallback } from '../test-utils.js'; diff --git a/packages/astro/test/units/dev/collections-renderentry.test.js b/packages/astro/test/units/dev/collections-renderentry.test.js index cf36740270b4..4c3849577629 100644 --- a/packages/astro/test/units/dev/collections-renderentry.test.js +++ b/packages/astro/test/units/dev/collections-renderentry.test.js @@ -1,8 +1,8 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; -import * as cheerio from 'cheerio'; import os from 'node:os'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; +import * as cheerio from 'cheerio'; import { attachContentServerListeners } from '../../../dist/content/server-listeners.js'; import { createFsWithFallback, createRequestAndResponse, runInContainer } from '../test-utils.js'; diff --git a/packages/astro/test/units/dev/dev.test.js b/packages/astro/test/units/dev/dev.test.js index b89e18feb312..85f584e9c307 100644 --- a/packages/astro/test/units/dev/dev.test.js +++ b/packages/astro/test/units/dev/dev.test.js @@ -1,7 +1,7 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; -import * as cheerio from 'cheerio'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; +import * as cheerio from 'cheerio'; import { createFs, createRequestAndResponse, diff --git a/packages/astro/test/units/dev/head-injection.test.js b/packages/astro/test/units/dev/head-injection.test.js index 837fc45b9644..0bb7a30f8ea0 100644 --- a/packages/astro/test/units/dev/head-injection.test.js +++ b/packages/astro/test/units/dev/head-injection.test.js @@ -1,7 +1,7 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; -import * as cheerio from 'cheerio'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; +import * as cheerio from 'cheerio'; import { createFs, createRequestAndResponse, runInContainer } from '../test-utils.js'; const root = new URL('../../fixtures/alias/', import.meta.url); diff --git a/packages/astro/test/units/dev/hydration.test.js b/packages/astro/test/units/dev/hydration.test.js index 720e4b2f39dd..df48b757d15e 100644 --- a/packages/astro/test/units/dev/hydration.test.js +++ b/packages/astro/test/units/dev/hydration.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; import { createFs, createRequestAndResponse, runInContainer } from '../test-utils.js'; diff --git a/packages/astro/test/units/dev/restart.test.js b/packages/astro/test/units/dev/restart.test.js index 0fad93de4b9b..a2a858965dc5 100644 --- a/packages/astro/test/units/dev/restart.test.js +++ b/packages/astro/test/units/dev/restart.test.js @@ -1,7 +1,7 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; -import * as cheerio from 'cheerio'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; +import * as cheerio from 'cheerio'; import { createContainerWithAutomaticRestart, diff --git a/packages/astro/test/units/dev/styles.test.js b/packages/astro/test/units/dev/styles.test.js index a1ab6b94264a..3b674108d125 100644 --- a/packages/astro/test/units/dev/styles.test.js +++ b/packages/astro/test/units/dev/styles.test.js @@ -1,7 +1,7 @@ -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; -import { getStylesForURL } from '../../../dist/vite-plugin-astro-server/css.js'; +import { before, describe, it } from 'node:test'; import { viteID } from '../../../dist/core/util.js'; +import { getStylesForURL } from '../../../dist/vite-plugin-astro-server/css.js'; const root = new URL('../../fixtures/alias/', import.meta.url); diff --git a/packages/astro/test/units/i18n/astro_i18n.test.js b/packages/astro/test/units/i18n/astro_i18n.test.js index 0e8fdb4b5c89..6622308cc539 100644 --- a/packages/astro/test/units/i18n/astro_i18n.test.js +++ b/packages/astro/test/units/i18n/astro_i18n.test.js @@ -1,16 +1,16 @@ +import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import { MissingLocale } from '#astro/core/errors/errors-data'; +import { AstroError } from '#astro/core/errors/index'; +import { toRoutingStrategy } from '#astro/i18n/utils'; +import { validateConfig } from '../../../dist/core/config/config.js'; import { - getLocaleRelativeUrl, - getLocaleRelativeUrlList, getLocaleAbsoluteUrl, getLocaleAbsoluteUrlList, + getLocaleRelativeUrl, + getLocaleRelativeUrlList, } from '../../../dist/i18n/index.js'; import { parseLocale } from '../../../dist/i18n/utils.js'; -import { describe, it } from 'node:test'; -import * as assert from 'node:assert/strict'; -import { validateConfig } from '../../../dist/core/config/config.js'; -import { AstroError } from '#astro/core/errors/index'; -import { MissingLocale } from '#astro/core/errors/errors-data'; -import { toRoutingStrategy } from '#astro/i18n/utils'; describe('getLocaleRelativeUrl', () => { it('should correctly return the URL with the base', () => { diff --git a/packages/astro/test/units/integrations/api.test.js b/packages/astro/test/units/integrations/api.test.js index d4b0491c3b55..e05c4f9442cb 100644 --- a/packages/astro/test/units/integrations/api.test.js +++ b/packages/astro/test/units/integrations/api.test.js @@ -1,8 +1,8 @@ -import { runHookBuildSetup, runHookConfigSetup } from '../../../dist/integrations/index.js'; +import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { validateSupportedFeatures } from '../../../dist/integrations/astroFeaturesValidation.js'; +import { runHookBuildSetup, runHookConfigSetup } from '../../../dist/integrations/index.js'; import { defaultLogger } from '../test-utils.js'; -import { describe, it } from 'node:test'; -import * as assert from 'node:assert/strict'; describe('Integration API', () => { it('runHookBuildSetup should work', async () => { diff --git a/packages/astro/test/units/logger/locale.test.js b/packages/astro/test/units/logger/locale.test.js index ddeadfc81f7b..c427d022aad9 100644 --- a/packages/astro/test/units/logger/locale.test.js +++ b/packages/astro/test/units/logger/locale.test.js @@ -1,5 +1,5 @@ -import { describe, it, after } from 'node:test'; import * as assert from 'node:assert/strict'; +import { after, describe, it } from 'node:test'; const LOCALES = ['en_US', 'sv_SE', 'es_419.UTF-8', 'es_ES@euro', 'C']; diff --git a/packages/astro/test/units/render/chunk.test.js b/packages/astro/test/units/render/chunk.test.js index 035e98484ae8..f34e3d090867 100644 --- a/packages/astro/test/units/render/chunk.test.js +++ b/packages/astro/test/units/render/chunk.test.js @@ -1,7 +1,7 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; -import * as cheerio from 'cheerio'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; +import * as cheerio from 'cheerio'; import { createFs, createRequestAndResponse, runInContainer } from '../test-utils.js'; const root = new URL('../../fixtures/alias/', import.meta.url); diff --git a/packages/astro/test/units/render/components.test.js b/packages/astro/test/units/render/components.test.js index 7fa36e8642ef..c490cb19e3fb 100644 --- a/packages/astro/test/units/render/components.test.js +++ b/packages/astro/test/units/render/components.test.js @@ -1,7 +1,7 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; -import * as cheerio from 'cheerio'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; +import * as cheerio from 'cheerio'; import { createFs, createRequestAndResponse, runInContainer } from '../test-utils.js'; const root = new URL('../../fixtures/alias/', import.meta.url); diff --git a/packages/astro/test/units/render/head.test.js b/packages/astro/test/units/render/head.test.js index ce494336afa0..06fe0705adf4 100644 --- a/packages/astro/test/units/render/head.test.js +++ b/packages/astro/test/units/render/head.test.js @@ -1,17 +1,17 @@ -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; +import { RenderContext } from '../../../dist/core/render-context.js'; import { + Fragment, createComponent, + maybeRenderHead, render, renderComponent, - renderSlot, - maybeRenderHead, renderHead, - Fragment, + renderSlot, } from '../../../dist/runtime/server/index.js'; -import { RenderContext } from '../../../dist/core/render-context.js'; import { createBasicPipeline } from '../test-utils.js'; -import * as cheerio from 'cheerio'; const createAstroModule = (AstroComponent) => ({ default: AstroComponent }); diff --git a/packages/astro/test/units/render/jsx.test.js b/packages/astro/test/units/render/jsx.test.js index e2df9a60d50e..0f91ccfc9712 100644 --- a/packages/astro/test/units/render/jsx.test.js +++ b/packages/astro/test/units/render/jsx.test.js @@ -1,15 +1,15 @@ -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; +import { RenderContext } from '../../../dist/core/render-context.js'; +import { loadRenderer } from '../../../dist/core/render/index.js'; +import { jsx } from '../../../dist/jsx-runtime/index.js'; +import { createAstroJSXComponent, renderer as jsxRenderer } from '../../../dist/jsx/index.js'; import { createComponent, render, renderComponent, renderSlot, } from '../../../dist/runtime/server/index.js'; -import { jsx } from '../../../dist/jsx-runtime/index.js'; -import { loadRenderer } from '../../../dist/core/render/index.js'; -import { RenderContext } from '../../../dist/core/render-context.js'; -import { createAstroJSXComponent, renderer as jsxRenderer } from '../../../dist/jsx/index.js'; import { createBasicPipeline } from '../test-utils.js'; const createAstroModule = (AstroComponent) => ({ default: AstroComponent }); diff --git a/packages/astro/test/units/routing/endpoints.test.js b/packages/astro/test/units/routing/endpoints.test.js index c03a708028ab..cff44f1b45af 100644 --- a/packages/astro/test/units/routing/endpoints.test.js +++ b/packages/astro/test/units/routing/endpoints.test.js @@ -1,14 +1,14 @@ +import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; +import { fileURLToPath } from 'node:url'; +import { createContainer } from '../../../dist/core/dev/container.js'; +import testAdapter from '../../test-adapter.js'; import { createBasicSettings, createFs, createRequestAndResponse, defaultLogger, } from '../test-utils.js'; -import { fileURLToPath } from 'node:url'; -import { describe, it, before, after } from 'node:test'; -import * as assert from 'node:assert/strict'; -import { createContainer } from '../../../dist/core/dev/container.js'; -import testAdapter from '../../test-adapter.js'; const root = new URL('../../fixtures/api-routes/', import.meta.url); const fileSystem = { diff --git a/packages/astro/test/units/routing/manifest.test.js b/packages/astro/test/units/routing/manifest.test.js index 5e90c6c79b60..2e7ff9e7cf07 100644 --- a/packages/astro/test/units/routing/manifest.test.js +++ b/packages/astro/test/units/routing/manifest.test.js @@ -1,9 +1,9 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; +import { Logger } from '../../../dist/core/logger/core.js'; import { createRouteManifest } from '../../../dist/core/routing/manifest/create.js'; import { createBasicSettings, createFs } from '../test-utils.js'; -import { Logger } from '../../../dist/core/logger/core.js'; const root = new URL('../../fixtures/alias/', import.meta.url); diff --git a/packages/astro/test/units/routing/route-matching.test.js b/packages/astro/test/units/routing/route-matching.test.js index 01b1d000a1bb..b2f27d8c9f80 100644 --- a/packages/astro/test/units/routing/route-matching.test.js +++ b/packages/astro/test/units/routing/route-matching.test.js @@ -1,20 +1,20 @@ +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'; +import { createRouteManifest, matchAllRoutes } from '../../../dist/core/routing/index.js'; +import { getSortedPreloadedMatches } from '../../../dist/prerender/routing.js'; +import { DevPipeline } from '../../../dist/vite-plugin-astro-server/pipeline.js'; +import { createDevelopmentManifest } from '../../../dist/vite-plugin-astro-server/plugin.js'; +import testAdapter from '../../test-adapter.js'; import { createBasicSettings, createFs, createRequestAndResponse, defaultLogger, } from '../test-utils.js'; -import { createRouteManifest, matchAllRoutes } from '../../../dist/core/routing/index.js'; -import { fileURLToPath } from 'node:url'; -import { createViteLoader } from '../../../dist/core/module-loader/vite.js'; -import { describe, it, before, after } from 'node:test'; -import * as assert from 'node:assert/strict'; -import { createContainer } from '../../../dist/core/dev/container.js'; -import * as cheerio from 'cheerio'; -import testAdapter from '../../test-adapter.js'; -import { getSortedPreloadedMatches } from '../../../dist/prerender/routing.js'; -import { createDevelopmentManifest } from '../../../dist/vite-plugin-astro-server/plugin.js'; -import { DevPipeline } from '../../../dist/vite-plugin-astro-server/pipeline.js'; const root = new URL('../../fixtures/alias/', import.meta.url); const fileSystem = { diff --git a/packages/astro/test/units/routing/route-sanitization.test.js b/packages/astro/test/units/routing/route-sanitization.test.js index c2367055ab14..802418868173 100644 --- a/packages/astro/test/units/routing/route-sanitization.test.js +++ b/packages/astro/test/units/routing/route-sanitization.test.js @@ -1,15 +1,15 @@ +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 testAdapter from '../../test-adapter.js'; import { createBasicSettings, createFs, createRequestAndResponse, defaultLogger, } from '../test-utils.js'; -import { fileURLToPath } from 'node:url'; -import { describe, it, before, after } from 'node:test'; -import * as assert from 'node:assert/strict'; -import { createContainer } from '../../../dist/core/dev/container.js'; -import * as cheerio from 'cheerio'; -import testAdapter from '../../test-adapter.js'; const root = new URL('../../fixtures/alias/', import.meta.url); const fileSystem = { diff --git a/packages/astro/test/units/routing/trailing-slash.test.js b/packages/astro/test/units/routing/trailing-slash.test.js index 292b32ff5179..8bbc33f199fb 100644 --- a/packages/astro/test/units/routing/trailing-slash.test.js +++ b/packages/astro/test/units/routing/trailing-slash.test.js @@ -1,14 +1,14 @@ +import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; +import { fileURLToPath } from 'node:url'; +import { createContainer } from '../../../dist/core/dev/container.js'; +import testAdapter from '../../test-adapter.js'; import { createBasicSettings, createFs, createRequestAndResponse, defaultLogger, } from '../test-utils.js'; -import { fileURLToPath } from 'node:url'; -import { describe, it, before, after } from 'node:test'; -import * as assert from 'node:assert/strict'; -import { createContainer } from '../../../dist/core/dev/container.js'; -import testAdapter from '../../test-adapter.js'; const root = new URL('../../fixtures/api-routes/', import.meta.url); const fileSystem = { diff --git a/packages/astro/test/units/runtime/astro-global.test.js b/packages/astro/test/units/runtime/astro-global.test.js index a7959a4ec414..8c745c01d6ac 100644 --- a/packages/astro/test/units/runtime/astro-global.test.js +++ b/packages/astro/test/units/runtime/astro-global.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { createAstro } from '../../../dist/runtime/server/index.js'; describe('astro global', () => { diff --git a/packages/astro/test/units/vite-plugin-astro-server/controller.test.js b/packages/astro/test/units/vite-plugin-astro-server/controller.test.js index 345c2009dcf5..37fa4dfc42ce 100644 --- a/packages/astro/test/units/vite-plugin-astro-server/controller.test.js +++ b/packages/astro/test/units/vite-plugin-astro-server/controller.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { createLoader } from '../../../dist/core/module-loader/index.js'; import { createController, diff --git a/packages/astro/test/units/vite-plugin-astro-server/request.test.js b/packages/astro/test/units/vite-plugin-astro-server/request.test.js index 63d2d2a5f21c..dfbb5a1b8ee5 100644 --- a/packages/astro/test/units/vite-plugin-astro-server/request.test.js +++ b/packages/astro/test/units/vite-plugin-astro-server/request.test.js @@ -1,9 +1,11 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { createLoader } from '../../../dist/core/module-loader/index.js'; import { createRouteManifest } from '../../../dist/core/routing/index.js'; import { createComponent, render } from '../../../dist/runtime/server/index.js'; import { createController, handleRequest } from '../../../dist/vite-plugin-astro-server/index.js'; +import { DevPipeline } from '../../../dist/vite-plugin-astro-server/pipeline.js'; +import { createDevelopmentManifest } from '../../../dist/vite-plugin-astro-server/plugin.js'; import { createAstroModule, createBasicSettings, @@ -11,8 +13,6 @@ import { createRequestAndResponse, defaultLogger, } from '../test-utils.js'; -import { createDevelopmentManifest } from '../../../dist/vite-plugin-astro-server/plugin.js'; -import { DevPipeline } from '../../../dist/vite-plugin-astro-server/pipeline.js'; async function createDevPipeline(overrides = {}) { const settings = overrides.settings ?? (await createBasicSettings({ root: '/' })); diff --git a/packages/astro/test/units/vite-plugin-astro-server/response.test.js b/packages/astro/test/units/vite-plugin-astro-server/response.test.js index 42cd90e88cc4..fadaed99f4c2 100644 --- a/packages/astro/test/units/vite-plugin-astro-server/response.test.js +++ b/packages/astro/test/units/vite-plugin-astro-server/response.test.js @@ -1,14 +1,14 @@ +import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; +import { fileURLToPath } from 'node:url'; +import { createContainer } from '../../../dist/core/dev/container.js'; +import testAdapter from '../../test-adapter.js'; import { createBasicSettings, createFs, createRequestAndResponse, defaultLogger, } from '../test-utils.js'; -import { fileURLToPath } from 'node:url'; -import { describe, it, before, after } from 'node:test'; -import * as assert from 'node:assert/strict'; -import { createContainer } from '../../../dist/core/dev/container.js'; -import testAdapter from '../../test-adapter.js'; const root = new URL('../../fixtures/api-routes/', import.meta.url); const fileSystem = { diff --git a/packages/astro/test/units/vite-plugin-astro/compile.test.js b/packages/astro/test/units/vite-plugin-astro/compile.test.js index 08b6c2810a7d..dd779024b2a4 100644 --- a/packages/astro/test/units/vite-plugin-astro/compile.test.js +++ b/packages/astro/test/units/vite-plugin-astro/compile.test.js @@ -1,9 +1,9 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import { pathToFileURL } from 'node:url'; +import { init, parse } from 'es-module-lexer'; import { resolveConfig } from 'vite'; import { compileAstro } from '../../../dist/vite-plugin-astro/compile.js'; -import { init, parse } from 'es-module-lexer'; -import { pathToFileURL } from 'node:url'; const viteConfig = await resolveConfig({ configFile: false }, 'serve'); diff --git a/packages/astro/test/units/vite-plugin-astro/hmr.test.js b/packages/astro/test/units/vite-plugin-astro/hmr.test.js index f7f96819246c..22e17b6bdf7f 100644 --- a/packages/astro/test/units/vite-plugin-astro/hmr.test.js +++ b/packages/astro/test/units/vite-plugin-astro/hmr.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { isStyleOnlyChanged } from '../../../dist/vite-plugin-astro/hmr.js'; describe('isStyleOnlyChanged', () => { diff --git a/packages/astro/test/units/vite-plugin-scanner/scan.test.js b/packages/astro/test/units/vite-plugin-scanner/scan.test.js index d1e389de0c55..9b01c9f14a3c 100644 --- a/packages/astro/test/units/vite-plugin-scanner/scan.test.js +++ b/packages/astro/test/units/vite-plugin-scanner/scan.test.js @@ -1,5 +1,5 @@ -import { describe, it, before, after } from 'node:test'; import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { scan } from '../../../dist/vite-plugin-scanner/scan.js'; describe('astro scan', () => { diff --git a/packages/astro/test/view-transitions.test.js b/packages/astro/test/view-transitions.test.js index 17c1b4b8dc44..21d45f7fbdb5 100644 --- a/packages/astro/test/view-transitions.test.js +++ b/packages/astro/test/view-transitions.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 { loadFixture } from './test-utils.js'; diff --git a/packages/astro/test/vue-component.test.js b/packages/astro/test/vue-component.test.js index c2d753f89eca..c7770281f97c 100644 --- a/packages/astro/test/vue-component.test.js +++ b/packages/astro/test/vue-component.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 { isWindows, loadFixture } from './test-utils.js'; diff --git a/packages/create-astro/test/context.test.js b/packages/create-astro/test/context.test.js index ab8fbadd8261..48d2d4297643 100644 --- a/packages/create-astro/test/context.test.js +++ b/packages/create-astro/test/context.test.js @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; -import { describe, it } from 'node:test'; import os from 'node:os'; +import { describe, it } from 'node:test'; import { getContext } from '../dist/index.js'; describe('context', () => { it('no arguments', async () => { diff --git a/packages/create-astro/test/dependencies.test.js b/packages/create-astro/test/dependencies.test.js index 046e96591b91..e4eb3d1f415c 100644 --- a/packages/create-astro/test/dependencies.test.js +++ b/packages/create-astro/test/dependencies.test.js @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; -import { dependencies } from '../dist/index.js'; import { describe, it } from 'node:test'; +import { dependencies } from '../dist/index.js'; import { setup } from './utils.js'; describe('dependencies', () => { const fixture = setup(); diff --git a/packages/create-astro/test/git.test.js b/packages/create-astro/test/git.test.js index f1c8eba0e8ba..85854f0d59b4 100644 --- a/packages/create-astro/test/git.test.js +++ b/packages/create-astro/test/git.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; -import { mkdir, writeFile } from 'node:fs/promises'; import { rmSync } from 'node:fs'; +import { mkdir, writeFile } from 'node:fs/promises'; +import { after, before, describe, it } from 'node:test'; import { git } from '../dist/index.js'; import { setup } from './utils.js'; diff --git a/packages/create-astro/test/typescript.test.js b/packages/create-astro/test/typescript.test.js index 067957676e86..3d042c7c443e 100644 --- a/packages/create-astro/test/typescript.test.js +++ b/packages/create-astro/test/typescript.test.js @@ -1,10 +1,10 @@ import assert from 'node:assert/strict'; -import { describe, it, beforeEach } from 'node:test'; import fs from 'node:fs'; +import { beforeEach, describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; -import { typescript, setupTypeScript } from '../dist/index.js'; -import { setup, resetFixtures } from './utils.js'; +import { setupTypeScript, typescript } from '../dist/index.js'; +import { resetFixtures, setup } from './utils.js'; describe('typescript', async () => { const fixture = setup(); diff --git a/packages/create-astro/test/verify.test.js b/packages/create-astro/test/verify.test.js index 9ec7e49e91cd..ff335014517c 100644 --- a/packages/create-astro/test/verify.test.js +++ b/packages/create-astro/test/verify.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; -import { setup } from './utils.js'; import { verify } from '../dist/index.js'; +import { setup } from './utils.js'; describe('verify', async () => { const fixture = setup(); diff --git a/packages/integrations/lit/test/sass.test.js b/packages/integrations/lit/test/sass.test.js index 1f1ce19c5fd0..a6cbfae8bc43 100644 --- a/packages/integrations/lit/test/sass.test.js +++ b/packages/integrations/lit/test/sass.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; describe('check', () => { it('should be able to load sass', async () => { diff --git a/packages/integrations/lit/test/server.test.js b/packages/integrations/lit/test/server.test.js index 4b58715af2d5..b5f3cac9be41 100644 --- a/packages/integrations/lit/test/server.test.js +++ b/packages/integrations/lit/test/server.test.js @@ -1,10 +1,10 @@ -import { LitElement, html } from 'lit'; -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; +import { LitElement, html } from 'lit'; // Must come after lit import because @lit/reactive-element defines // globalThis.customElements which the server shim expects to be defined. import server from '../server.js'; -import * as cheerio from 'cheerio'; const { check, renderToStaticMarkup } = server; diff --git a/packages/integrations/markdoc/test/content-collections.test.js b/packages/integrations/markdoc/test/content-collections.test.js index cfd1c80c7e2c..ef4ebfceacbe 100644 --- a/packages/integrations/markdoc/test/content-collections.test.js +++ b/packages/integrations/markdoc/test/content-collections.test.js @@ -1,8 +1,8 @@ -import { parse as parseDevalue } from 'devalue'; -import { loadFixture, fixLineEndings } from '../../../astro/test/test-utils.js'; -import markdoc from '../dist/index.js'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; +import { parse as parseDevalue } from 'devalue'; +import { fixLineEndings, loadFixture } from '../../../astro/test/test-utils.js'; +import markdoc from '../dist/index.js'; function formatPost(post) { return { diff --git a/packages/integrations/markdoc/test/headings.test.js b/packages/integrations/markdoc/test/headings.test.js index b87f6408e60c..330d3356b216 100644 --- a/packages/integrations/markdoc/test/headings.test.js +++ b/packages/integrations/markdoc/test/headings.test.js @@ -1,7 +1,7 @@ -import { parseHTML } from 'linkedom'; -import { loadFixture } from '../../../astro/test/test-utils.js'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; +import { parseHTML } from 'linkedom'; +import { loadFixture } from '../../../astro/test/test-utils.js'; async function getFixture(name) { return await loadFixture({ diff --git a/packages/integrations/markdoc/test/image-assets.test.js b/packages/integrations/markdoc/test/image-assets.test.js index 880ee9b267d7..22534c60704b 100644 --- a/packages/integrations/markdoc/test/image-assets.test.js +++ b/packages/integrations/markdoc/test/image-assets.test.js @@ -1,7 +1,7 @@ -import { parseHTML } from 'linkedom'; -import { loadFixture } from '../../../astro/test/test-utils.js'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; +import { parseHTML } from 'linkedom'; +import { loadFixture } from '../../../astro/test/test-utils.js'; const root = new URL('./fixtures/image-assets/', import.meta.url); diff --git a/packages/integrations/markdoc/test/propagated-assets.test.js b/packages/integrations/markdoc/test/propagated-assets.test.js index 652c60014a41..a0768448f1d9 100644 --- a/packages/integrations/markdoc/test/propagated-assets.test.js +++ b/packages/integrations/markdoc/test/propagated-assets.test.js @@ -1,7 +1,7 @@ -import { parseHTML } from 'linkedom'; -import { loadFixture } from '../../../astro/test/test-utils.js'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; +import { parseHTML } from 'linkedom'; +import { loadFixture } from '../../../astro/test/test-utils.js'; describe('Markdoc - propagated assets', () => { let fixture; diff --git a/packages/integrations/markdoc/test/render-html.test.js b/packages/integrations/markdoc/test/render-html.test.js index d83a916071ce..785599ae57f6 100644 --- a/packages/integrations/markdoc/test/render-html.test.js +++ b/packages/integrations/markdoc/test/render-html.test.js @@ -1,7 +1,7 @@ -import { parseHTML } from 'linkedom'; -import { loadFixture } from '../../../astro/test/test-utils.js'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; +import { parseHTML } from 'linkedom'; +import { loadFixture } from '../../../astro/test/test-utils.js'; async function getFixture(name) { return await loadFixture({ diff --git a/packages/integrations/markdoc/test/render.test.js b/packages/integrations/markdoc/test/render.test.js index e5b8da74fab1..0960a980ce01 100644 --- a/packages/integrations/markdoc/test/render.test.js +++ b/packages/integrations/markdoc/test/render.test.js @@ -1,7 +1,7 @@ -import { parseHTML } from 'linkedom'; -import { loadFixture } from '../../../astro/test/test-utils.js'; import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; +import { parseHTML } from 'linkedom'; +import { loadFixture } from '../../../astro/test/test-utils.js'; async function getFixture(name) { return await loadFixture({ diff --git a/packages/integrations/markdoc/test/syntax-highlighting.test.js b/packages/integrations/markdoc/test/syntax-highlighting.test.js index 1d0f6127ba9d..bab309c87104 100644 --- a/packages/integrations/markdoc/test/syntax-highlighting.test.js +++ b/packages/integrations/markdoc/test/syntax-highlighting.test.js @@ -1,11 +1,11 @@ -import { parseHTML } from 'linkedom'; +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import Markdoc from '@markdoc/markdoc'; -import shiki from '../dist/extensions/shiki.js'; +import { isHTMLString } from 'astro/runtime/server/index.js'; +import { parseHTML } from 'linkedom'; import prism from '../dist/extensions/prism.js'; +import shiki from '../dist/extensions/shiki.js'; import { setupConfig } from '../dist/runtime.js'; -import { isHTMLString } from 'astro/runtime/server/index.js'; -import assert from 'node:assert/strict'; -import { describe, it } from 'node:test'; const entry = ` \`\`\`ts diff --git a/packages/integrations/markdoc/test/variables.test.js b/packages/integrations/markdoc/test/variables.test.js index c26ca3c45b7d..9873afcb77e2 100644 --- a/packages/integrations/markdoc/test/variables.test.js +++ b/packages/integrations/markdoc/test/variables.test.js @@ -1,8 +1,8 @@ +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; import markdoc from '../dist/index.js'; -import assert from 'node:assert/strict'; -import { after, before, describe, it } from 'node:test'; const root = new URL('./fixtures/variables/', import.meta.url); diff --git a/packages/integrations/mdx/test/css-head-mdx.test.js b/packages/integrations/mdx/test/css-head-mdx.test.js index 8b5764625086..5caab3d059b8 100644 --- a/packages/integrations/mdx/test/css-head-mdx.test.js +++ b/packages/integrations/mdx/test/css-head-mdx.test.js @@ -1,10 +1,10 @@ import mdx from '@astrojs/mdx'; -import { parseHTML } from 'linkedom'; -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; -import { loadFixture } from '../../../astro/test/test-utils.js'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; +import { parseHTML } from 'linkedom'; +import { loadFixture } from '../../../astro/test/test-utils.js'; describe('Head injection w/ MDX', () => { let fixture; diff --git a/packages/integrations/mdx/test/invalid-mdx-component.test.js b/packages/integrations/mdx/test/invalid-mdx-component.test.js index 4621b73da613..4e68fea647cb 100644 --- a/packages/integrations/mdx/test/invalid-mdx-component.test.js +++ b/packages/integrations/mdx/test/invalid-mdx-component.test.js @@ -1,5 +1,5 @@ -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from '../../../astro/test/test-utils.js'; import mdx from '../dist/index.js'; diff --git a/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js b/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js index c9f846a3ae22..e29efa45b58c 100644 --- a/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js +++ b/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js @@ -1,7 +1,7 @@ import mdx from '@astrojs/mdx'; -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-component.test.js b/packages/integrations/mdx/test/mdx-component.test.js index 3bb213001ed9..1983730e7ea0 100644 --- a/packages/integrations/mdx/test/mdx-component.test.js +++ b/packages/integrations/mdx/test/mdx-component.test.js @@ -1,7 +1,7 @@ import mdx from '@astrojs/mdx'; -import { describe, it, before, after } from 'node:test'; import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-escape.test.js b/packages/integrations/mdx/test/mdx-escape.test.js index f758dc50f81a..0d1200fe7de2 100644 --- a/packages/integrations/mdx/test/mdx-escape.test.js +++ b/packages/integrations/mdx/test/mdx-escape.test.js @@ -1,7 +1,7 @@ import mdx from '@astrojs/mdx'; -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-frontmatter-injection.test.js b/packages/integrations/mdx/test/mdx-frontmatter-injection.test.js index 0f8e9524f4a3..90ec45e4e88f 100644 --- a/packages/integrations/mdx/test/mdx-frontmatter-injection.test.js +++ b/packages/integrations/mdx/test/mdx-frontmatter-injection.test.js @@ -1,5 +1,5 @@ -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-frontmatter.test.js b/packages/integrations/mdx/test/mdx-frontmatter.test.js index 94ddc5e21968..3fcbf28e808f 100644 --- a/packages/integrations/mdx/test/mdx-frontmatter.test.js +++ b/packages/integrations/mdx/test/mdx-frontmatter.test.js @@ -1,7 +1,7 @@ import mdx from '@astrojs/mdx'; -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-get-headings.test.js b/packages/integrations/mdx/test/mdx-get-headings.test.js index 5e5b318ea469..29bb427ccd4b 100644 --- a/packages/integrations/mdx/test/mdx-get-headings.test.js +++ b/packages/integrations/mdx/test/mdx-get-headings.test.js @@ -2,8 +2,8 @@ import { rehypeHeadingIds } from '@astrojs/markdown-remark'; import mdx from '@astrojs/mdx'; import { visit } from 'unist-util-visit'; -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-get-static-paths.test.js b/packages/integrations/mdx/test/mdx-get-static-paths.test.js index 153ddad7cbe1..845676f8f2c5 100644 --- a/packages/integrations/mdx/test/mdx-get-static-paths.test.js +++ b/packages/integrations/mdx/test/mdx-get-static-paths.test.js @@ -1,9 +1,9 @@ import mdx from '@astrojs/mdx'; -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; -import { loadFixture } from '../../../astro/test/test-utils.js'; +import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; +import { loadFixture } from '../../../astro/test/test-utils.js'; const FIXTURE_ROOT = new URL('./fixtures/mdx-get-static-paths', import.meta.url); diff --git a/packages/integrations/mdx/test/mdx-images.test.js b/packages/integrations/mdx/test/mdx-images.test.js index e070f235864f..d4af271ec55f 100644 --- a/packages/integrations/mdx/test/mdx-images.test.js +++ b/packages/integrations/mdx/test/mdx-images.test.js @@ -1,5 +1,5 @@ -import { describe, it, before, after } from 'node:test'; import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-infinite-loop.test.js b/packages/integrations/mdx/test/mdx-infinite-loop.test.js index a13554fbe4ee..ed98d5c6d9e2 100644 --- a/packages/integrations/mdx/test/mdx-infinite-loop.test.js +++ b/packages/integrations/mdx/test/mdx-infinite-loop.test.js @@ -1,7 +1,7 @@ import mdx from '@astrojs/mdx'; -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from '../../../astro/test/test-utils.js'; describe('MDX Infinite Loop', () => { diff --git a/packages/integrations/mdx/test/mdx-math.test.js b/packages/integrations/mdx/test/mdx-math.test.js index cc6169c554c9..908a88e11878 100644 --- a/packages/integrations/mdx/test/mdx-math.test.js +++ b/packages/integrations/mdx/test/mdx-math.test.js @@ -1,11 +1,11 @@ -import mdx from '@astrojs/mdx'; -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import mdx from '@astrojs/mdx'; import { parseHTML } from 'linkedom'; -import { loadFixture } from '../../../astro/test/test-utils.js'; -import remarkMath from 'remark-math'; import rehypeMathjaxSvg from 'rehype-mathjax'; import rehypeMathjaxChtml from 'rehype-mathjax/chtml'; +import remarkMath from 'remark-math'; +import { loadFixture } from '../../../astro/test/test-utils.js'; const FIXTURE_ROOT = new URL('./fixtures/mdx-math/', import.meta.url); diff --git a/packages/integrations/mdx/test/mdx-namespace.test.js b/packages/integrations/mdx/test/mdx-namespace.test.js index 04c07817d435..13137e40e98c 100644 --- a/packages/integrations/mdx/test/mdx-namespace.test.js +++ b/packages/integrations/mdx/test/mdx-namespace.test.js @@ -1,5 +1,5 @@ -import { describe, it, before, after } from 'node:test'; import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-optimize.test.js b/packages/integrations/mdx/test/mdx-optimize.test.js index 7d9a68c95091..f504a49c9d53 100644 --- a/packages/integrations/mdx/test/mdx-optimize.test.js +++ b/packages/integrations/mdx/test/mdx-optimize.test.js @@ -1,5 +1,5 @@ -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-page.test.js b/packages/integrations/mdx/test/mdx-page.test.js index 6a97fb7366e8..7948de65312a 100644 --- a/packages/integrations/mdx/test/mdx-page.test.js +++ b/packages/integrations/mdx/test/mdx-page.test.js @@ -1,5 +1,5 @@ -import { describe, it, before, after } from 'node:test'; import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-plugins.test.js b/packages/integrations/mdx/test/mdx-plugins.test.js index ae98b48998de..1791acc5249e 100644 --- a/packages/integrations/mdx/test/mdx-plugins.test.js +++ b/packages/integrations/mdx/test/mdx-plugins.test.js @@ -1,11 +1,11 @@ import mdx from '@astrojs/mdx'; -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; +import { visit as estreeVisit } from 'estree-util-visit'; import { parseHTML } from 'linkedom'; -import { loadFixture } from '../../../astro/test/test-utils.js'; import remarkToc from 'remark-toc'; -import { visit as estreeVisit } from 'estree-util-visit'; +import { loadFixture } from '../../../astro/test/test-utils.js'; const FIXTURE_ROOT = new URL('./fixtures/mdx-plugins/', import.meta.url); const FILE = '/with-plugins/index.html'; diff --git a/packages/integrations/mdx/test/mdx-plus-react.test.js b/packages/integrations/mdx/test/mdx-plus-react.test.js index eb5955282984..08c0f118c077 100644 --- a/packages/integrations/mdx/test/mdx-plus-react.test.js +++ b/packages/integrations/mdx/test/mdx-plus-react.test.js @@ -1,5 +1,5 @@ -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-script-style-raw.test.js b/packages/integrations/mdx/test/mdx-script-style-raw.test.js index cac3e782306d..5b276f043e25 100644 --- a/packages/integrations/mdx/test/mdx-script-style-raw.test.js +++ b/packages/integrations/mdx/test/mdx-script-style-raw.test.js @@ -1,6 +1,6 @@ -import mdx from '@astrojs/mdx'; -import { describe, it, before, after } from 'node:test'; import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; +import mdx from '@astrojs/mdx'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-slots.test.js b/packages/integrations/mdx/test/mdx-slots.test.js index e5c5f77d4ae0..e8dc68e67f86 100644 --- a/packages/integrations/mdx/test/mdx-slots.test.js +++ b/packages/integrations/mdx/test/mdx-slots.test.js @@ -1,7 +1,7 @@ import mdx from '@astrojs/mdx'; -import { describe, it, before, after } from 'node:test'; import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js b/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js index e5ce04126744..662c1a0cdc0f 100644 --- a/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js +++ b/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js @@ -1,11 +1,11 @@ import mdx from '@astrojs/mdx'; -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; -import { loadFixture } from '../../../astro/test/test-utils.js'; -import shikiTwoslash from 'remark-shiki-twoslash'; import rehypePrettyCode from 'rehype-pretty-code'; +import shikiTwoslash from 'remark-shiki-twoslash'; +import { loadFixture } from '../../../astro/test/test-utils.js'; const FIXTURE_ROOT = new URL('./fixtures/mdx-syntax-hightlighting/', import.meta.url); diff --git a/packages/integrations/mdx/test/mdx-url-export.test.js b/packages/integrations/mdx/test/mdx-url-export.test.js index 6ab475070184..db7288bff27b 100644 --- a/packages/integrations/mdx/test/mdx-url-export.test.js +++ b/packages/integrations/mdx/test/mdx-url-export.test.js @@ -1,7 +1,7 @@ import mdx from '@astrojs/mdx'; -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from '../../../astro/test/test-utils.js'; describe('MDX url export', () => { diff --git a/packages/integrations/mdx/test/mdx-vite-env-vars.test.js b/packages/integrations/mdx/test/mdx-vite-env-vars.test.js index 0be5f735ffcd..1270fe5e60a5 100644 --- a/packages/integrations/mdx/test/mdx-vite-env-vars.test.js +++ b/packages/integrations/mdx/test/mdx-vite-env-vars.test.js @@ -1,5 +1,5 @@ -import { describe, it, before } from 'node:test'; import * as assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/remark-imgattr.test.js b/packages/integrations/mdx/test/remark-imgattr.test.js index 02f155fd4e3a..ebd9207b26ad 100644 --- a/packages/integrations/mdx/test/remark-imgattr.test.js +++ b/packages/integrations/mdx/test/remark-imgattr.test.js @@ -1,5 +1,5 @@ -import { describe, it, before, after } from 'node:test'; import * as assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/node/test/api-route.test.js b/packages/integrations/node/test/api-route.test.js index 9e0165cb9821..804a5ccf4797 100644 --- a/packages/integrations/node/test/api-route.test.js +++ b/packages/integrations/node/test/api-route.test.js @@ -1,8 +1,8 @@ -import nodejs from '../dist/index.js'; -import { loadFixture, createRequestAndResponse } from './test-utils.js'; -import crypto from 'node:crypto'; -import { describe, it, before, after } from 'node:test'; import * as assert from 'node:assert/strict'; +import crypto from 'node:crypto'; +import { after, before, describe, it } from 'node:test'; +import nodejs from '../dist/index.js'; +import { createRequestAndResponse, loadFixture } from './test-utils.js'; describe('API routes', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/node/test/assets.test.js b/packages/integrations/node/test/assets.test.js index bcd9bb4bd759..0b71f94cd6ce 100644 --- a/packages/integrations/node/test/assets.test.js +++ b/packages/integrations/node/test/assets.test.js @@ -1,8 +1,8 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import nodejs from '../dist/index.js'; import { loadFixture } from './test-utils.js'; -import * as cheerio from 'cheerio'; describe('Assets', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/node/test/bad-urls.test.js b/packages/integrations/node/test/bad-urls.test.js index 6d6c0a2e92c7..cdc0158ff919 100644 --- a/packages/integrations/node/test/bad-urls.test.js +++ b/packages/integrations/node/test/bad-urls.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import nodejs from '../dist/index.js'; import { loadFixture } from './test-utils.js'; diff --git a/packages/integrations/node/test/encoded.test.js b/packages/integrations/node/test/encoded.test.js index 15b5654b1f50..edc6ae78b037 100644 --- a/packages/integrations/node/test/encoded.test.js +++ b/packages/integrations/node/test/encoded.test.js @@ -1,7 +1,7 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import nodejs from '../dist/index.js'; -import { loadFixture, createRequestAndResponse } from './test-utils.js'; +import { createRequestAndResponse, loadFixture } from './test-utils.js'; describe('Encoded Pathname', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/node/test/errors.test.js b/packages/integrations/node/test/errors.test.js index c4212f0586b4..95bb1be85466 100644 --- a/packages/integrations/node/test/errors.test.js +++ b/packages/integrations/node/test/errors.test.js @@ -1,8 +1,8 @@ import assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import nodejs from '../dist/index.js'; import { loadFixture } from './test-utils.js'; -import * as cheerio from 'cheerio'; describe('Errors', () => { let fixture; diff --git a/packages/integrations/node/test/headers.test.js b/packages/integrations/node/test/headers.test.js index b74af99524b1..00b1766c799d 100644 --- a/packages/integrations/node/test/headers.test.js +++ b/packages/integrations/node/test/headers.test.js @@ -1,7 +1,7 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import nodejs from '../dist/index.js'; -import { loadFixture, createRequestAndResponse } from './test-utils.js'; +import { createRequestAndResponse, loadFixture } from './test-utils.js'; describe('Node Adapter Headers', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/node/test/image.test.js b/packages/integrations/node/test/image.test.js index b315c1a30169..c4758f96b265 100644 --- a/packages/integrations/node/test/image.test.js +++ b/packages/integrations/node/test/image.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import nodejs from '../dist/index.js'; import { loadFixture } from './test-utils.js'; diff --git a/packages/integrations/node/test/locals.test.js b/packages/integrations/node/test/locals.test.js index a310c729d883..6d2776079d6e 100644 --- a/packages/integrations/node/test/locals.test.js +++ b/packages/integrations/node/test/locals.test.js @@ -1,7 +1,7 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import nodejs from '../dist/index.js'; -import { loadFixture, createRequestAndResponse } from './test-utils.js'; +import { createRequestAndResponse, loadFixture } from './test-utils.js'; describe('API routes', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/node/test/node-middleware.test.js b/packages/integrations/node/test/node-middleware.test.js index 889f72315ea5..fa496e871f46 100644 --- a/packages/integrations/node/test/node-middleware.test.js +++ b/packages/integrations/node/test/node-middleware.test.js @@ -1,9 +1,9 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; -import nodejs from '../dist/index.js'; -import { loadFixture, waitServerListen } from './test-utils.js'; +import { after, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import express from 'express'; +import nodejs from '../dist/index.js'; +import { loadFixture, waitServerListen } from './test-utils.js'; /** * @typedef {import('../../../astro/test/test-utils').Fixture} Fixture diff --git a/packages/integrations/node/test/prerender-404-500.test.js b/packages/integrations/node/test/prerender-404-500.test.js index 4195db0ec639..afa23a151025 100644 --- a/packages/integrations/node/test/prerender-404-500.test.js +++ b/packages/integrations/node/test/prerender-404-500.test.js @@ -1,8 +1,8 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import nodejs from '../dist/index.js'; import { loadFixture, waitServerListen } from './test-utils.js'; -import * as cheerio from 'cheerio'; /** * @typedef {import('../../../astro/test/test-utils').Fixture} Fixture diff --git a/packages/integrations/node/test/prerender.test.js b/packages/integrations/node/test/prerender.test.js index de570511e8bf..bf34fc99ddfd 100644 --- a/packages/integrations/node/test/prerender.test.js +++ b/packages/integrations/node/test/prerender.test.js @@ -1,8 +1,8 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import nodejs from '../dist/index.js'; import { loadFixture, waitServerListen } from './test-utils.js'; -import * as cheerio from 'cheerio'; /** * @typedef {import('../../../astro/test/test-utils').Fixture} Fixture diff --git a/packages/integrations/node/test/url-protocol.test.js b/packages/integrations/node/test/url-protocol.test.js index 444d47ed5109..94d53104b9de 100644 --- a/packages/integrations/node/test/url-protocol.test.js +++ b/packages/integrations/node/test/url-protocol.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import { TLSSocket } from 'node:tls'; import nodejs from '../dist/index.js'; import { createRequestAndResponse, loadFixture } from './test-utils.js'; diff --git a/packages/integrations/node/test/well-known-locations.test.js b/packages/integrations/node/test/well-known-locations.test.js index 39d7ccedbd59..0951d6c27cc9 100644 --- a/packages/integrations/node/test/well-known-locations.test.js +++ b/packages/integrations/node/test/well-known-locations.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import nodejs from '../dist/index.js'; import { loadFixture } from './test-utils.js'; diff --git a/packages/integrations/react/test/react-component.test.js b/packages/integrations/react/test/react-component.test.js index 3e07c6d5907c..44dbb138fa4e 100644 --- a/packages/integrations/react/test/react-component.test.js +++ b/packages/integrations/react/test/react-component.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; import { isWindows, loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/sitemap/test/base-path.test.js b/packages/integrations/sitemap/test/base-path.test.js index dd80fd29acae..0417e4e2bf35 100644 --- a/packages/integrations/sitemap/test/base-path.test.js +++ b/packages/integrations/sitemap/test/base-path.test.js @@ -1,6 +1,6 @@ -import { loadFixture, readXML } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture, readXML } from './test-utils.js'; describe('URLs with base path', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/sitemap/test/dynamic-path.test.js b/packages/integrations/sitemap/test/dynamic-path.test.js index 851462ceb207..eab3b912c1bc 100644 --- a/packages/integrations/sitemap/test/dynamic-path.test.js +++ b/packages/integrations/sitemap/test/dynamic-path.test.js @@ -1,6 +1,6 @@ +import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; import { loadFixture, readXML } from './test-utils.js'; -import assert from 'node:assert/strict'; describe('Dynamic with rest parameter', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/sitemap/test/filter.test.js b/packages/integrations/sitemap/test/filter.test.js index 57faa47f7e86..adecb59e6c0e 100644 --- a/packages/integrations/sitemap/test/filter.test.js +++ b/packages/integrations/sitemap/test/filter.test.js @@ -1,7 +1,7 @@ -import { loadFixture, readXML } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; import { sitemap } from './fixtures/static/deps.mjs'; +import { loadFixture, readXML } from './test-utils.js'; describe('Filter support', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/sitemap/test/prefix.test.js b/packages/integrations/sitemap/test/prefix.test.js index fdd538d0f3cd..16ec44e9f3c4 100644 --- a/packages/integrations/sitemap/test/prefix.test.js +++ b/packages/integrations/sitemap/test/prefix.test.js @@ -1,7 +1,7 @@ -import { loadFixture, readXML } from './test-utils.js'; -import { sitemap } from './fixtures/static/deps.mjs'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { sitemap } from './fixtures/static/deps.mjs'; +import { loadFixture, readXML } from './test-utils.js'; describe('Prefix support', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/sitemap/test/routes.test.js b/packages/integrations/sitemap/test/routes.test.js index 326cb64ef996..00d6ccde305b 100644 --- a/packages/integrations/sitemap/test/routes.test.js +++ b/packages/integrations/sitemap/test/routes.test.js @@ -1,6 +1,6 @@ -import { loadFixture, readXML } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture, readXML } from './test-utils.js'; describe('routes', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/sitemap/test/ssr.test.js b/packages/integrations/sitemap/test/ssr.test.js index d4bbd5264244..b5c92698b3ba 100644 --- a/packages/integrations/sitemap/test/ssr.test.js +++ b/packages/integrations/sitemap/test/ssr.test.js @@ -1,6 +1,6 @@ -import { loadFixture, readXML } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture, readXML } from './test-utils.js'; describe('SSR support', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/sitemap/test/staticPaths.test.js b/packages/integrations/sitemap/test/staticPaths.test.js index 4054ad9304ad..abc687faf357 100644 --- a/packages/integrations/sitemap/test/staticPaths.test.js +++ b/packages/integrations/sitemap/test/staticPaths.test.js @@ -1,6 +1,6 @@ -import { loadFixture, readXML } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture, readXML } from './test-utils.js'; describe('getStaticPaths support', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/sitemap/test/trailing-slash.test.js b/packages/integrations/sitemap/test/trailing-slash.test.js index bdedf7687391..e0a6158fbe4d 100644 --- a/packages/integrations/sitemap/test/trailing-slash.test.js +++ b/packages/integrations/sitemap/test/trailing-slash.test.js @@ -1,6 +1,6 @@ -import { loadFixture, readXML } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture, readXML } from './test-utils.js'; describe('Trailing slash', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/tailwind/test/basic.test.js b/packages/integrations/tailwind/test/basic.test.js index 6e544eb8c70d..9921202aa4bb 100644 --- a/packages/integrations/tailwind/test/basic.test.js +++ b/packages/integrations/tailwind/test/basic.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import { loadFixture } from '../../../astro/test/test-utils.js'; describe('Basic', () => { diff --git a/packages/integrations/vercel/test/image.test.js b/packages/integrations/vercel/test/image.test.js index af99afab1a62..b82ac02bfdb8 100644 --- a/packages/integrations/vercel/test/image.test.js +++ b/packages/integrations/vercel/test/image.test.js @@ -1,6 +1,6 @@ -import * as cheerio from 'cheerio'; import assert from 'node:assert/strict'; import { after, before, describe, it } from 'node:test'; +import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Image', () => { diff --git a/packages/integrations/vercel/test/isr.test.js b/packages/integrations/vercel/test/isr.test.js index f6687e960b31..644d7e1f54a1 100644 --- a/packages/integrations/vercel/test/isr.test.js +++ b/packages/integrations/vercel/test/isr.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; describe('ISR', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/vercel/test/max-duration.test.js b/packages/integrations/vercel/test/max-duration.test.js index 188b4211dfa3..2a7698663f98 100644 --- a/packages/integrations/vercel/test/max-duration.test.js +++ b/packages/integrations/vercel/test/max-duration.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; describe('maxDuration', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/vercel/test/no-output.test.js b/packages/integrations/vercel/test/no-output.test.js index 31708754be11..34709804d0b8 100644 --- a/packages/integrations/vercel/test/no-output.test.js +++ b/packages/integrations/vercel/test/no-output.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; describe('Missing output config', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/vercel/test/prerendered-error-pages.test.js b/packages/integrations/vercel/test/prerendered-error-pages.test.js index d528972ecc27..5812c3364731 100644 --- a/packages/integrations/vercel/test/prerendered-error-pages.test.js +++ b/packages/integrations/vercel/test/prerendered-error-pages.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; describe('prerendered error pages routing', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/vercel/test/speed-insights.test.js b/packages/integrations/vercel/test/speed-insights.test.js index 783121600602..2ee9dcc3bf45 100644 --- a/packages/integrations/vercel/test/speed-insights.test.js +++ b/packages/integrations/vercel/test/speed-insights.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; describe('Vercel Speed Insights', () => { describe('output: server', () => { diff --git a/packages/integrations/vercel/test/split.test.js b/packages/integrations/vercel/test/split.test.js index 172c27775e15..fbd61aa9bfd1 100644 --- a/packages/integrations/vercel/test/split.test.js +++ b/packages/integrations/vercel/test/split.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; describe('build: split', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/vercel/test/static.test.js b/packages/integrations/vercel/test/static.test.js index 7547d2475a05..e007862d7263 100644 --- a/packages/integrations/vercel/test/static.test.js +++ b/packages/integrations/vercel/test/static.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; describe('static routing', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/vercel/test/streaming.test.js b/packages/integrations/vercel/test/streaming.test.js index 3d231478d0b6..a0172a7e6abb 100644 --- a/packages/integrations/vercel/test/streaming.test.js +++ b/packages/integrations/vercel/test/streaming.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; describe('streaming', () => { /** @type {import('./test-utils.js').Fixture} */ diff --git a/packages/integrations/vercel/test/web-analytics.test.js b/packages/integrations/vercel/test/web-analytics.test.js index 6b4efaedbcfd..d5056d0acb90 100644 --- a/packages/integrations/vercel/test/web-analytics.test.js +++ b/packages/integrations/vercel/test/web-analytics.test.js @@ -1,6 +1,6 @@ -import { loadFixture } from './test-utils.js'; import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; describe('Vercel Web Analytics', () => { describe('output: static', () => { diff --git a/packages/integrations/vue/test/app-entrypoint-css.test.js b/packages/integrations/vue/test/app-entrypoint-css.test.js index 692008349174..878aa8e486c3 100644 --- a/packages/integrations/vue/test/app-entrypoint-css.test.js +++ b/packages/integrations/vue/test/app-entrypoint-css.test.js @@ -1,7 +1,7 @@ -import { loadFixture } from './test-utils.js'; import * as assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; +import { loadFixture } from './test-utils.js'; describe('App Entrypoint CSS', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/vue/test/app-entrypoint.test.js b/packages/integrations/vue/test/app-entrypoint.test.js index 5c0437636654..c7fa828263ba 100644 --- a/packages/integrations/vue/test/app-entrypoint.test.js +++ b/packages/integrations/vue/test/app-entrypoint.test.js @@ -1,8 +1,8 @@ -import { loadFixture } from './test-utils.js'; import * as assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { load as cheerioLoad } from 'cheerio'; import { parseHTML } from 'linkedom'; +import { loadFixture } from './test-utils.js'; describe('App Entrypoint', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/vue/test/basics.test.js b/packages/integrations/vue/test/basics.test.js index 1f83e490f095..7db2deb37940 100644 --- a/packages/integrations/vue/test/basics.test.js +++ b/packages/integrations/vue/test/basics.test.js @@ -1,7 +1,7 @@ -import { loadFixture } from './test-utils.js'; import * as assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; +import { loadFixture } from './test-utils.js'; describe('Basics', () => { /** @type {import('./test-utils').Fixture} */ let fixture; diff --git a/packages/markdown/remark/test/autolinking.test.js b/packages/markdown/remark/test/autolinking.test.js index 76922e7c3731..966d5e30362e 100644 --- a/packages/markdown/remark/test/autolinking.test.js +++ b/packages/markdown/remark/test/autolinking.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import { createMarkdownProcessor } from '../dist/index.js'; describe('autolinking', () => { diff --git a/packages/markdown/remark/test/browser.test.js b/packages/markdown/remark/test/browser.test.js index c3831cca1590..824f6fa0becd 100644 --- a/packages/markdown/remark/test/browser.test.js +++ b/packages/markdown/remark/test/browser.test.js @@ -1,6 +1,6 @@ -import esbuild from 'esbuild'; import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; +import esbuild from 'esbuild'; describe('Bundle for browsers', async () => { it('esbuild browser build should work', async () => { diff --git a/packages/markdown/remark/test/entities.test.js b/packages/markdown/remark/test/entities.test.js index 83d95f5a1238..3c244c15abb4 100644 --- a/packages/markdown/remark/test/entities.test.js +++ b/packages/markdown/remark/test/entities.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import { createMarkdownProcessor } from '../dist/index.js'; describe('entities', async () => { diff --git a/packages/markdown/remark/test/plugins.test.js b/packages/markdown/remark/test/plugins.test.js index 4afc364c875b..dd0233baa491 100644 --- a/packages/markdown/remark/test/plugins.test.js +++ b/packages/markdown/remark/test/plugins.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; -import { createMarkdownProcessor } from '../dist/index.js'; import { fileURLToPath } from 'node:url'; +import { createMarkdownProcessor } from '../dist/index.js'; describe('plugins', () => { it('should be able to get file path when passing fileURL', async () => { diff --git a/packages/markdown/remark/test/remark-collect-images.test.js b/packages/markdown/remark/test/remark-collect-images.test.js index bc8c364680c1..cdfccf9c876e 100644 --- a/packages/markdown/remark/test/remark-collect-images.test.js +++ b/packages/markdown/remark/test/remark-collect-images.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, it, before } from 'node:test'; +import { before, describe, it } from 'node:test'; import { createMarkdownProcessor } from '../dist/index.js'; describe('collect images', async () => { diff --git a/packages/telemetry/test/index.test.js b/packages/telemetry/test/index.test.js index 678aa2f194b0..47d64198c282 100644 --- a/packages/telemetry/test/index.test.js +++ b/packages/telemetry/test/index.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { describe, it, before, after } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { AstroTelemetry } from '../dist/index.js'; function setup() { diff --git a/packages/underscore-redirects/test/astro.test.js b/packages/underscore-redirects/test/astro.test.js index 724ad97b1978..1d753449b152 100644 --- a/packages/underscore-redirects/test/astro.test.js +++ b/packages/underscore-redirects/test/astro.test.js @@ -1,6 +1,6 @@ -import { createRedirectsFromAstroRoutes } from '../dist/index.js'; import * as assert from 'node:assert/strict'; import { describe, it } from 'node:test'; +import { createRedirectsFromAstroRoutes } from '../dist/index.js'; describe('Astro', () => { const serverConfig = { diff --git a/packages/underscore-redirects/test/print.test.js b/packages/underscore-redirects/test/print.test.js index 3c3d0018e8ab..90c790bfd338 100644 --- a/packages/underscore-redirects/test/print.test.js +++ b/packages/underscore-redirects/test/print.test.js @@ -1,6 +1,6 @@ -import { Redirects } from '../dist/index.js'; import * as assert from 'node:assert/strict'; import { describe, it } from 'node:test'; +import { Redirects } from '../dist/index.js'; describe('Printing', () => { it('Formats long lines in a pretty way', () => { diff --git a/packages/underscore-redirects/test/weight.test.js b/packages/underscore-redirects/test/weight.test.js index 576b4c340f46..342851965337 100644 --- a/packages/underscore-redirects/test/weight.test.js +++ b/packages/underscore-redirects/test/weight.test.js @@ -1,6 +1,6 @@ -import { Redirects } from '../dist/index.js'; import * as assert from 'node:assert/strict'; import { describe, it } from 'node:test'; +import { Redirects } from '../dist/index.js'; describe('Weight', () => { it('Puts higher weighted definitions on top', () => { diff --git a/packages/upgrade/test/context.test.js b/packages/upgrade/test/context.test.js index 714a7b64ac43..bbc887c2ae3c 100644 --- a/packages/upgrade/test/context.test.js +++ b/packages/upgrade/test/context.test.js @@ -1,5 +1,5 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { getContext } from '../dist/index.js'; describe('context', () => { diff --git a/packages/upgrade/test/install.test.js b/packages/upgrade/test/install.test.js index a2a0e5144eae..4ceaa81c841f 100644 --- a/packages/upgrade/test/install.test.js +++ b/packages/upgrade/test/install.test.js @@ -1,7 +1,7 @@ -import { describe, it } from 'node:test'; import * as assert from 'node:assert/strict'; -import { setup } from './utils.js'; +import { describe, it } from 'node:test'; import { install } from '../dist/index.js'; +import { setup } from './utils.js'; describe('install', () => { const fixture = setup(); diff --git a/packages/upgrade/test/verify.test.js b/packages/upgrade/test/verify.test.js index 3b9d4b3bc12d..203e0fbf046f 100644 --- a/packages/upgrade/test/verify.test.js +++ b/packages/upgrade/test/verify.test.js @@ -1,5 +1,5 @@ -import { describe, it, beforeEach } from 'node:test'; import * as assert from 'node:assert/strict'; +import { beforeEach, describe, it } from 'node:test'; import { collectPackageInfo } from '../dist/index.js'; describe('collectPackageInfo', () => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a6e62986d847..f41b2321e808 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: .: dependencies: + '@biomejs/biome': + specifier: ^1.5.3 + version: 1.5.3 astro-benchmark: specifier: workspace:* version: link:benchmark @@ -5756,6 +5759,94 @@ packages: '@babel/helper-validator-identifier': 7.22.20 to-fast-properties: 2.0.0 + /@biomejs/biome@1.5.3: + resolution: {integrity: sha512-yvZCa/g3akwTaAQ7PCwPWDCkZs3Qa5ONg/fgOUT9e6wAWsPftCjLQFPXBeGxPK30yZSSpgEmRCfpGTmVbUjGgg==} + engines: {node: '>=14.*'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@biomejs/cli-darwin-arm64': 1.5.3 + '@biomejs/cli-darwin-x64': 1.5.3 + '@biomejs/cli-linux-arm64': 1.5.3 + '@biomejs/cli-linux-arm64-musl': 1.5.3 + '@biomejs/cli-linux-x64': 1.5.3 + '@biomejs/cli-linux-x64-musl': 1.5.3 + '@biomejs/cli-win32-arm64': 1.5.3 + '@biomejs/cli-win32-x64': 1.5.3 + dev: false + + /@biomejs/cli-darwin-arm64@1.5.3: + resolution: {integrity: sha512-ImU7mh1HghEDyqNmxEZBoMPr8SxekkZuYcs+gynKlNW+TALQs7swkERiBLkG9NR0K1B3/2uVzlvYowXrmlW8hw==} + engines: {node: '>=14.*'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@biomejs/cli-darwin-x64@1.5.3: + resolution: {integrity: sha512-vCdASqYnlpq/swErH7FD6nrFz0czFtK4k/iLgj0/+VmZVjineFPgevOb+Sr9vz0tk0GfdQO60bSpI74zU8M9Dw==} + engines: {node: '>=14.*'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@biomejs/cli-linux-arm64-musl@1.5.3: + resolution: {integrity: sha512-DYuMizUYUBYfS0IHGjDrOP1RGipqWfMGEvNEJ398zdtmCKLXaUvTimiox5dvx4X15mBK5M2m8wgWUgOP1giUpQ==} + engines: {node: '>=14.*'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@biomejs/cli-linux-arm64@1.5.3: + resolution: {integrity: sha512-cupBQv0sNF1OKqBfx7EDWMSsKwRrBUZfjXawT4s6hKV6ALq7p0QzWlxr/sDmbKMLOaLQtw2Qgu/77N9rm+f9Rg==} + engines: {node: '>=14.*'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@biomejs/cli-linux-x64-musl@1.5.3: + resolution: {integrity: sha512-UUHiAnlDqr2Y/LpvshBFhUYMWkl2/Jn+bi3U6jKuav0qWbbBKU/ByHgR4+NBxpKBYoCtWxhnmatfH1bpPIuZMw==} + engines: {node: '>=14.*'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@biomejs/cli-linux-x64@1.5.3: + resolution: {integrity: sha512-YQrSArQvcv4FYsk7Q91Yv4uuu5F8hJyORVcv3zsjCLGkjIjx2RhjYLpTL733SNL7v33GmOlZY0eFR1ko38tuUw==} + engines: {node: '>=14.*'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@biomejs/cli-win32-arm64@1.5.3: + resolution: {integrity: sha512-HxatYH7vf/kX9nrD+pDYuV2GI9GV8EFo6cfKkahAecTuZLPxryHx1WEfJthp5eNsE0+09STGkKIKjirP0ufaZA==} + engines: {node: '>=14.*'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@biomejs/cli-win32-x64@1.5.3: + resolution: {integrity: sha512-fMvbSouZEASU7mZH8SIJSANDm5OqsjgtVXlbUqxwed6BP7uuHRSs396Aqwh2+VoW8fwTpp6ybIUoC9FrzB0kyA==} + engines: {node: '>=14.*'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true + /@builder.io/partytown@0.8.1: resolution: {integrity: sha512-p4xhEtQCPe8YFJ8e7KT9RptnT+f4lvtbmXymbp1t0bLp+USkNMTxrRMNc3Dlr2w2fpxyX7uA0CyAeU3ju84O4A==} engines: {node: '>=18.0.0'} From cdfcbe5c9ddfdee2f9284f676940c4e21035bb03 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 21 Feb 2024 14:09:31 +0000 Subject: [PATCH 14/19] [ci] format --- biome.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/biome.json b/biome.json index d3d01f78d530..b46d0694f5f7 100644 --- a/biome.json +++ b/biome.json @@ -1,15 +1,15 @@ { - "$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", + "$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", "files": { "include": ["*.test.js"], "ignore": ["vendor"] }, - "organizeImports": { - "enabled": true - }, - "linter": { - "enabled": false - }, + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": false + }, "formatter": { "enabled": false } From 92b00ac97e4ec38f9293ef74308f7a1fce9beae4 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 21 Feb 2024 14:13:24 +0000 Subject: [PATCH 15/19] chore: ignore commit (#10181) --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 7cc4d8db7381..4e1332d659ba 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -4,3 +4,5 @@ 1335797903a57716e9a02b0ffd8ca636b3883c62 # Manually format .astro files in example projects (#3862) 59e8c71786fd1c154904b3fefa7d26d88f4d92d2 +# Change formatting (#10180) +062623438b5dfd66682a967edc7b7c91bd29e888 From 6343f6a438d790fa16a0dd268f4a51def4fa0f33 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 21 Feb 2024 14:27:00 +0000 Subject: [PATCH 16/19] Revert "Add option to prefix sitemap" (#10179) * Revert "Add option to prefix sitemap (#9846)" This reverts commit 9b78c992750cdb99c40a89a00ea2a0d1c00877d7. * changeset * feedabck * fix incorrect merging --- .changeset/slow-cats-argue.md | 7 ++ packages/integrations/sitemap/src/index.ts | 31 +++----- packages/integrations/sitemap/src/schema.ts | 7 -- .../integrations/sitemap/test/prefix.test.js | 72 ------------------- 4 files changed, 16 insertions(+), 101 deletions(-) create mode 100644 .changeset/slow-cats-argue.md delete mode 100644 packages/integrations/sitemap/test/prefix.test.js diff --git a/.changeset/slow-cats-argue.md b/.changeset/slow-cats-argue.md new file mode 100644 index 000000000000..a3ad7ca6885d --- /dev/null +++ b/.changeset/slow-cats-argue.md @@ -0,0 +1,7 @@ +--- +"@astrojs/sitemap": patch +--- + +Revert https://github.com/withastro/astro/pull/9846 + +The feature to customize the file name of the sitemap was reverted due to some internal issues with one of the dependencies. With an non-deterministic behaviour, the sitemap file was sometime emitted with incorrect syntax. diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 5d2a271d2cb9..11f19f5dea6e 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -1,14 +1,12 @@ import type { AstroConfig, AstroIntegration } from 'astro'; -import path, { resolve } from 'node:path'; +import path from 'node:path'; import { fileURLToPath } from 'node:url'; import type { EnumChangefreq, LinkItem as LinkItemBase, SitemapItemLoose } from 'sitemap'; -import { SitemapAndIndexStream, SitemapStream, streamToPromise } from 'sitemap'; +import { simpleSitemapAndIndex } from 'sitemap'; import { ZodError } from 'zod'; import { generateSitemap } from './generate-sitemap.js'; import { validateOptions } from './validate-options.js'; -import { createWriteStream } from 'node:fs'; -import { Readable } from 'node:stream'; export { EnumChangefreq as ChangeFreqEnum } from 'sitemap'; export type ChangeFreq = `${EnumChangefreq}`; @@ -35,8 +33,6 @@ export type SitemapOptions = lastmod?: Date; priority?: number; - prefix?: string; - // called for each sitemap item just before to save them on disk, sync or async serialize?(item: SitemapItem): SitemapItem | Promise | undefined; } @@ -48,6 +44,7 @@ function formatConfigErrorMessage(err: ZodError) { } const PKG_NAME = '@astrojs/sitemap'; +const OUTFILE = 'sitemap-index.xml'; const STATUS_CODE_PAGES = new Set(['404', '500']); function isStatusCodePage(pathname: string): boolean { @@ -80,8 +77,7 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { const opts = validateOptions(config.site, options); - const { filter, customPages, serialize, entryLimit, prefix = 'sitemap-' } = opts; - const OUTFILE = `${prefix}index.xml`; + const { filter, customPages, serialize, entryLimit } = opts; let finalSiteUrl: URL; if (config.site) { @@ -171,22 +167,13 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { } } const destDir = fileURLToPath(dir); - - const sms = new SitemapAndIndexStream({ + await simpleSitemapAndIndex({ + hostname: finalSiteUrl.href, + destinationDir: destDir, + sourceData: urlData, limit: entryLimit, - getSitemapStream: (i) => { - const sitemapStream = new SitemapStream({ hostname: finalSiteUrl.href }); - const fileName = `${prefix}${i}.xml`; - - const ws = sitemapStream.pipe(createWriteStream(resolve(destDir + fileName))); - - return [new URL(fileName, finalSiteUrl.href).toString(), sitemapStream, ws]; - }, + gzip: false, }); - - sms.pipe(createWriteStream(resolve(destDir + OUTFILE))); - await streamToPromise(Readable.from(urlData).pipe(sms)); - sms.end(); logger.info(`\`${OUTFILE}\` created at \`${path.relative(process.cwd(), destDir)}\``); } catch (err) { if (err instanceof ZodError) { diff --git a/packages/integrations/sitemap/src/schema.ts b/packages/integrations/sitemap/src/schema.ts index da629fc0c690..a7682e881a05 100644 --- a/packages/integrations/sitemap/src/schema.ts +++ b/packages/integrations/sitemap/src/schema.ts @@ -34,13 +34,6 @@ export const SitemapOptionsSchema = z changefreq: z.nativeEnum(ChangeFreq).optional(), lastmod: z.date().optional(), priority: z.number().min(0).max(1).optional(), - - prefix: z - .string() - .regex(/^[a-zA-Z\-_]+$/gm, { - message: 'Only English alphabet symbols, hyphen and underscore allowed', - }) - .optional(), }) .strict() .default(SITEMAP_CONFIG_DEFAULTS); diff --git a/packages/integrations/sitemap/test/prefix.test.js b/packages/integrations/sitemap/test/prefix.test.js deleted file mode 100644 index 16ec44e9f3c4..000000000000 --- a/packages/integrations/sitemap/test/prefix.test.js +++ /dev/null @@ -1,72 +0,0 @@ -import assert from 'node:assert/strict'; -import { before, describe, it } from 'node:test'; -import { sitemap } from './fixtures/static/deps.mjs'; -import { loadFixture, readXML } from './test-utils.js'; - -describe('Prefix support', () => { - /** @type {import('./test-utils.js').Fixture} */ - let fixture; - const prefix = 'test-'; - - describe('Static', () => { - before(async () => { - fixture = await loadFixture({ - root: './fixtures/static/', - integrations: [ - sitemap(), - sitemap({ - prefix, - }), - ], - }); - await fixture.build(); - }); - - it('Content is same', async () => { - const data = await readXML(fixture.readFile('/sitemap-0.xml')); - const prefixData = await readXML(fixture.readFile(`/${prefix}0.xml`)); - assert.deepEqual(prefixData, data); - }); - - it('Index file load correct sitemap', async () => { - const data = await readXML(fixture.readFile('/sitemap-index.xml')); - const sitemapUrl = data.sitemapindex.sitemap[0].loc[0]; - assert.strictEqual(sitemapUrl, 'http://example.com/sitemap-0.xml'); - - const prefixData = await readXML(fixture.readFile(`/${prefix}index.xml`)); - const prefixSitemapUrl = prefixData.sitemapindex.sitemap[0].loc[0]; - assert.strictEqual(prefixSitemapUrl, `http://example.com/${prefix}0.xml`); - }); - }); - - describe('SSR', () => { - before(async () => { - fixture = await loadFixture({ - root: './fixtures/ssr/', - integrations: [ - sitemap(), - sitemap({ - prefix, - }), - ], - }); - await fixture.build(); - }); - - it('Content is same', async () => { - const data = await readXML(fixture.readFile('/client/sitemap-0.xml')); - const prefixData = await readXML(fixture.readFile(`/client/${prefix}0.xml`)); - assert.deepEqual(prefixData, data); - }); - - it('Index file load correct sitemap', async () => { - const data = await readXML(fixture.readFile('/client/sitemap-index.xml')); - const sitemapUrl = data.sitemapindex.sitemap[0].loc[0]; - assert.strictEqual(sitemapUrl, 'http://example.com/sitemap-0.xml'); - - const prefixData = await readXML(fixture.readFile(`/client/${prefix}index.xml`)); - const prefixSitemapUrl = prefixData.sitemapindex.sitemap[0].loc[0]; - assert.strictEqual(prefixSitemapUrl, `http://example.com/${prefix}0.xml`); - }); - }); -}); From 891c26e92f7a9fc2f839ae1f04ff1a05a8cb4a03 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 21 Feb 2024 14:35:21 +0000 Subject: [PATCH 17/19] ci: fix regression of the commands (#10182) --- .github/workflows/ci.yml | 2 +- package.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88d5aaa4a7b0..acca6a0c119b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,7 +98,7 @@ jobs: run: pnpm run lint - name: Format Check - run: pnpm run format --check + run: pnpm run format:ci test: name: "Test: ${{ matrix.os }} (node@${{ matrix.NODE_VERSION }})" diff --git a/package.json b/package.json index b12affb58558..83cef9f4dba7 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,11 @@ "build:examples": "turbo run build --filter=\"@example/*\"", "dev": "turbo run dev --concurrency=40 --parallel --filter=astro --filter=create-astro --filter=\"@astrojs/*\" --filter=\"@benchmark/*\"", "format": "pnpm run format:code && pnpm run format:imports", - "format:ci": "pnpm run format:code && pnpm run format:imports", + "format:ci": "pnpm run format:code:check && pnpm run format:imports:check", "format:code": "prettier -w \"**/*\" --ignore-unknown --cache", + "format:code:check": "prettier -w \"**/*\" --ignore-unknown --cache --check", "format:imports": "biome check --apply .", + "format:imports:check": "biome ci .", "test": "turbo run test --concurrency=1 --filter=astro --filter=create-astro --filter=\"@astrojs/*\"", "test:match": "cd packages/astro && pnpm run test:match", "test:unit": "cd packages/astro && pnpm run test:unit", From 2c2519204a26a522cdaa4e17cac3aa4dbcb66056 Mon Sep 17 00:00:00 2001 From: "Houston (Bot)" <108291165+astrobot-houston@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:40:40 -0800 Subject: [PATCH 18/19] [ci] release (#10177) Co-authored-by: github-actions[bot] --- .changeset/loud-snakes-behave.md | 5 -- .changeset/slow-cats-argue.md | 7 --- .changeset/sour-ties-sparkle.md | 5 -- examples/basics/package.json | 2 +- examples/blog/package.json | 4 +- examples/component/package.json | 2 +- examples/framework-alpine/package.json | 2 +- examples/framework-lit/package.json | 2 +- examples/framework-multiple/package.json | 2 +- examples/framework-preact/package.json | 2 +- examples/framework-react/package.json | 2 +- examples/framework-solid/package.json | 2 +- examples/framework-svelte/package.json | 2 +- examples/framework-vue/package.json | 2 +- examples/hackernews/package.json | 2 +- examples/integration/package.json | 2 +- examples/middleware/package.json | 2 +- examples/minimal/package.json | 2 +- examples/non-html-pages/package.json | 2 +- examples/portfolio/package.json | 2 +- examples/ssr/package.json | 2 +- examples/starlog/package.json | 2 +- examples/view-transitions/package.json | 2 +- examples/with-markdoc/package.json | 2 +- examples/with-markdown-plugins/package.json | 2 +- examples/with-markdown-shiki/package.json | 2 +- 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 | 6 +++ packages/astro/package.json | 2 +- packages/integrations/sitemap/CHANGELOG.md | 10 ++++ packages/integrations/sitemap/package.json | 2 +- pnpm-lock.yaml | 56 ++++++++++----------- 35 files changed, 74 insertions(+), 75 deletions(-) delete mode 100644 .changeset/loud-snakes-behave.md delete mode 100644 .changeset/slow-cats-argue.md delete mode 100644 .changeset/sour-ties-sparkle.md diff --git a/.changeset/loud-snakes-behave.md b/.changeset/loud-snakes-behave.md deleted file mode 100644 index f9f077f6e0c3..000000000000 --- a/.changeset/loud-snakes-behave.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Fixes an issue with the `i18n.routing` types, where an internal transformation was causing the generation of incorrect types for integrations. diff --git a/.changeset/slow-cats-argue.md b/.changeset/slow-cats-argue.md deleted file mode 100644 index a3ad7ca6885d..000000000000 --- a/.changeset/slow-cats-argue.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"@astrojs/sitemap": patch ---- - -Revert https://github.com/withastro/astro/pull/9846 - -The feature to customize the file name of the sitemap was reverted due to some internal issues with one of the dependencies. With an non-deterministic behaviour, the sitemap file was sometime emitted with incorrect syntax. diff --git a/.changeset/sour-ties-sparkle.md b/.changeset/sour-ties-sparkle.md deleted file mode 100644 index 17088feae350..000000000000 --- a/.changeset/sour-ties-sparkle.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@astrojs/sitemap": patch ---- - -Fixes URL generation for routes that rest parameters and start with `/` diff --git a/examples/basics/package.json b/examples/basics/package.json index 1af476fc27f2..0862ea33853e 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.1" + "astro": "^4.4.2" } } diff --git a/examples/blog/package.json b/examples/blog/package.json index bb04d449ae33..2acf733d67b9 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/mdx": "^2.1.1", "@astrojs/rss": "^4.0.5", - "@astrojs/sitemap": "^3.1.0", - "astro": "^4.4.1" + "@astrojs/sitemap": "^3.1.1", + "astro": "^4.4.2" } } diff --git a/examples/component/package.json b/examples/component/package.json index 7b5c75756e74..c3c7bccb44ab 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^4.4.1" + "astro": "^4.4.2" }, "peerDependencies": { "astro": "^4.0.0" diff --git a/examples/framework-alpine/package.json b/examples/framework-alpine/package.json index e0ed476b4e07..b430bae77ba8 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -14,6 +14,6 @@ "@astrojs/alpinejs": "^0.4.0", "@types/alpinejs": "^3.13.5", "alpinejs": "^3.13.3", - "astro": "^4.4.1" + "astro": "^4.4.2" } } diff --git a/examples/framework-lit/package.json b/examples/framework-lit/package.json index df48b694cf67..0e55f8326df2 100644 --- a/examples/framework-lit/package.json +++ b/examples/framework-lit/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/lit": "^4.0.1", "@webcomponents/template-shadowroot": "^0.2.1", - "astro": "^4.4.1", + "astro": "^4.4.2", "lit": "^3.1.2" } } diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index 0bd249be1c81..528ec9c8b06d 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -16,7 +16,7 @@ "@astrojs/solid-js": "^4.0.1", "@astrojs/svelte": "^5.0.3", "@astrojs/vue": "^4.0.8", - "astro": "^4.4.1", + "astro": "^4.4.2", "preact": "^10.19.2", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index 8faa4f978e9a..b6c0b0386830 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/preact": "^3.1.0", "@preact/signals": "^1.2.1", - "astro": "^4.4.1", + "astro": "^4.4.2", "preact": "^10.19.2" } } diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index e7aa3ea0429e..fe50bef4c443 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -14,7 +14,7 @@ "@astrojs/react": "^3.0.10", "@types/react": "^18.2.37", "@types/react-dom": "^18.2.15", - "astro": "^4.4.1", + "astro": "^4.4.2", "react": "^18.2.0", "react-dom": "^18.2.0" } diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index b542af8a8a88..1a48585fc9bf 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/solid-js": "^4.0.1", - "astro": "^4.4.1", + "astro": "^4.4.2", "solid-js": "^1.8.5" } } diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index 53674d1ab8b0..6c8d9e471df6 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/svelte": "^5.0.3", - "astro": "^4.4.1", + "astro": "^4.4.2", "svelte": "^4.2.5" } } diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index 5a890f864ab8..256d04b2a2d3 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/vue": "^4.0.8", - "astro": "^4.4.1", + "astro": "^4.4.2", "vue": "^3.3.8" } } diff --git a/examples/hackernews/package.json b/examples/hackernews/package.json index 81873cea60cb..4fbe0c3a6b2d 100644 --- a/examples/hackernews/package.json +++ b/examples/hackernews/package.json @@ -12,6 +12,6 @@ }, "dependencies": { "@astrojs/node": "^8.2.0", - "astro": "^4.4.1" + "astro": "^4.4.2" } } diff --git a/examples/integration/package.json b/examples/integration/package.json index f0e7010ea73b..c0d976d209bd 100644 --- a/examples/integration/package.json +++ b/examples/integration/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^4.4.1" + "astro": "^4.4.2" }, "peerDependencies": { "astro": "^4.0.0" diff --git a/examples/middleware/package.json b/examples/middleware/package.json index 0bf01e5cc366..9a50f56d029c 100644 --- a/examples/middleware/package.json +++ b/examples/middleware/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@astrojs/node": "^8.2.0", - "astro": "^4.4.1", + "astro": "^4.4.2", "html-minifier": "^4.0.0" }, "devDependencies": { diff --git a/examples/minimal/package.json b/examples/minimal/package.json index 29cf0a82f36d..ebdf941cafde 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.1" + "astro": "^4.4.2" } } diff --git a/examples/non-html-pages/package.json b/examples/non-html-pages/package.json index 206c843bc54a..1d3ff23b9cf7 100644 --- a/examples/non-html-pages/package.json +++ b/examples/non-html-pages/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.1" + "astro": "^4.4.2" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index 63e5fc06a4eb..f215b1722d2b 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.1" + "astro": "^4.4.2" } } diff --git a/examples/ssr/package.json b/examples/ssr/package.json index 91167e75077f..ec7794f6dea3 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -14,7 +14,7 @@ "dependencies": { "@astrojs/node": "^8.2.0", "@astrojs/svelte": "^5.0.3", - "astro": "^4.4.1", + "astro": "^4.4.2", "svelte": "^4.2.5" } } diff --git a/examples/starlog/package.json b/examples/starlog/package.json index 304bd3eb40ac..ceee16be21d2 100644 --- a/examples/starlog/package.json +++ b/examples/starlog/package.json @@ -10,7 +10,7 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.1", + "astro": "^4.4.2", "sass": "^1.69.5", "sharp": "^0.32.6" } diff --git a/examples/view-transitions/package.json b/examples/view-transitions/package.json index eba4bb4061fa..92fae015e6bf 100644 --- a/examples/view-transitions/package.json +++ b/examples/view-transitions/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@astrojs/tailwind": "^5.1.0", "@astrojs/node": "^8.2.0", - "astro": "^4.4.1" + "astro": "^4.4.2" } } diff --git a/examples/with-markdoc/package.json b/examples/with-markdoc/package.json index 3a2ad4dc20c8..0f25c0461adc 100644 --- a/examples/with-markdoc/package.json +++ b/examples/with-markdoc/package.json @@ -12,6 +12,6 @@ }, "dependencies": { "@astrojs/markdoc": "^0.9.0", - "astro": "^4.4.1" + "astro": "^4.4.2" } } diff --git a/examples/with-markdown-plugins/package.json b/examples/with-markdown-plugins/package.json index 4e4b51729a01..df7b6fa9b46e 100644 --- a/examples/with-markdown-plugins/package.json +++ b/examples/with-markdown-plugins/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/markdown-remark": "^4.2.1", - "astro": "^4.4.1", + "astro": "^4.4.2", "hast-util-select": "^6.0.2", "rehype-autolink-headings": "^7.1.0", "rehype-slug": "^6.0.0", diff --git a/examples/with-markdown-shiki/package.json b/examples/with-markdown-shiki/package.json index 783fef8fa44e..25f2adf42c1b 100644 --- a/examples/with-markdown-shiki/package.json +++ b/examples/with-markdown-shiki/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.4.1" + "astro": "^4.4.2" } } diff --git a/examples/with-mdx/package.json b/examples/with-mdx/package.json index a931380ea1b0..88b924a068ea 100644 --- a/examples/with-mdx/package.json +++ b/examples/with-mdx/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/mdx": "^2.1.1", "@astrojs/preact": "^3.1.0", - "astro": "^4.4.1", + "astro": "^4.4.2", "preact": "^10.19.2" } } diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index 272b17ea9af0..05154417ce53 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/preact": "^3.1.0", "@nanostores/preact": "^0.5.0", - "astro": "^4.4.1", + "astro": "^4.4.2", "nanostores": "^0.9.5", "preact": "^10.19.2" } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index 7ecfff2cd0b2..6a97f648981e 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -14,7 +14,7 @@ "@astrojs/mdx": "^2.1.1", "@astrojs/tailwind": "^5.1.0", "@types/canvas-confetti": "^1.6.3", - "astro": "^4.4.1", + "astro": "^4.4.2", "autoprefixer": "^10.4.15", "canvas-confetti": "^1.9.1", "postcss": "^8.4.28", diff --git a/examples/with-vitest/package.json b/examples/with-vitest/package.json index 1f8c0775565e..f6497af7a957 100644 --- a/examples/with-vitest/package.json +++ b/examples/with-vitest/package.json @@ -12,7 +12,7 @@ "test": "vitest" }, "dependencies": { - "astro": "^4.4.1", + "astro": "^4.4.2", "vitest": "^1.2.2" } } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index 1a1daffbca74..68a46b3b9332 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,11 @@ # astro +## 4.4.2 + +### Patch Changes + +- [#10169](https://github.com/withastro/astro/pull/10169) [`a46249173edde66b03c19441144272baa8394fb4`](https://github.com/withastro/astro/commit/a46249173edde66b03c19441144272baa8394fb4) Thanks [@ematipico](https://github.com/ematipico)! - Fixes an issue with the `i18n.routing` types, where an internal transformation was causing the generation of incorrect types for integrations. + ## 4.4.1 ### Patch Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index fd36bbd592d7..25df2cdc0966 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "4.4.1", + "version": "4.4.2", "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/sitemap/CHANGELOG.md b/packages/integrations/sitemap/CHANGELOG.md index 3a275957b49f..c477f1fcfb7a 100644 --- a/packages/integrations/sitemap/CHANGELOG.md +++ b/packages/integrations/sitemap/CHANGELOG.md @@ -1,5 +1,15 @@ # @astrojs/sitemap +## 3.1.1 + +### Patch Changes + +- [#10179](https://github.com/withastro/astro/pull/10179) [`6343f6a438d790fa16a0dd268f4a51def4fa0f33`](https://github.com/withastro/astro/commit/6343f6a438d790fa16a0dd268f4a51def4fa0f33) Thanks [@ematipico](https://github.com/ematipico)! - Revert https://github.com/withastro/astro/pull/9846 + + The feature to customize the file name of the sitemap was reverted due to some internal issues with one of the dependencies. With an non-deterministic behaviour, the sitemap file was sometime emitted with incorrect syntax. + +- [#9975](https://github.com/withastro/astro/pull/9975) [`ec7d2ebbd96b8c2dfdadaf076bbf7953007536ed`](https://github.com/withastro/astro/commit/ec7d2ebbd96b8c2dfdadaf076bbf7953007536ed) Thanks [@moose96](https://github.com/moose96)! - Fixes URL generation for routes that rest parameters and start with `/` + ## 3.1.0 ### Minor Changes diff --git a/packages/integrations/sitemap/package.json b/packages/integrations/sitemap/package.json index e44836779a3d..cfdd92d56110 100644 --- a/packages/integrations/sitemap/package.json +++ b/packages/integrations/sitemap/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/sitemap", "description": "Generate a sitemap for your Astro site", - "version": "3.1.0", + "version": "3.1.1", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f41b2321e808..0aac945ceb74 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -134,7 +134,7 @@ importers: examples/basics: dependencies: astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/blog: @@ -146,16 +146,16 @@ importers: specifier: ^4.0.5 version: link:../../packages/astro-rss '@astrojs/sitemap': - specifier: ^3.1.0 + specifier: ^3.1.1 version: link:../../packages/integrations/sitemap astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/component: devDependencies: astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/framework-alpine: @@ -170,7 +170,7 @@ importers: specifier: ^3.13.3 version: 3.13.3 astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/framework-lit: @@ -182,7 +182,7 @@ importers: specifier: ^0.2.1 version: 0.2.1 astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro lit: specifier: ^3.1.2 @@ -206,7 +206,7 @@ importers: specifier: ^4.0.8 version: link:../../packages/integrations/vue astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro preact: specifier: ^10.19.2 @@ -236,7 +236,7 @@ importers: specifier: ^1.2.1 version: 1.2.1(preact@10.19.3) astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro preact: specifier: ^10.19.2 @@ -254,7 +254,7 @@ importers: specifier: ^18.2.15 version: 18.2.18 astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro react: specifier: ^18.2.0 @@ -269,7 +269,7 @@ importers: specifier: ^4.0.1 version: link:../../packages/integrations/solid astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro solid-js: specifier: ^1.8.5 @@ -281,7 +281,7 @@ importers: specifier: ^5.0.3 version: link:../../packages/integrations/svelte astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro svelte: specifier: ^4.2.5 @@ -293,7 +293,7 @@ importers: specifier: ^4.0.8 version: link:../../packages/integrations/vue astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro vue: specifier: ^3.3.8 @@ -305,13 +305,13 @@ importers: specifier: ^8.2.0 version: link:../../packages/integrations/node astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/integration: devDependencies: astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/middleware: @@ -320,7 +320,7 @@ importers: specifier: ^8.2.0 version: link:../../packages/integrations/node astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro html-minifier: specifier: ^4.0.0 @@ -333,19 +333,19 @@ importers: examples/minimal: dependencies: astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/non-html-pages: dependencies: astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/portfolio: dependencies: astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/ssr: @@ -357,7 +357,7 @@ importers: specifier: ^5.0.3 version: link:../../packages/integrations/svelte astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro svelte: specifier: ^4.2.5 @@ -366,7 +366,7 @@ importers: examples/starlog: dependencies: astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro sass: specifier: ^1.69.5 @@ -384,7 +384,7 @@ importers: specifier: ^5.1.0 version: link:../../packages/integrations/tailwind astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/with-markdoc: @@ -393,7 +393,7 @@ importers: specifier: ^0.9.0 version: link:../../packages/integrations/markdoc astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/with-markdown-plugins: @@ -402,7 +402,7 @@ importers: specifier: ^4.2.1 version: link:../../packages/markdown/remark astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro hast-util-select: specifier: ^6.0.2 @@ -423,7 +423,7 @@ importers: examples/with-markdown-shiki: dependencies: astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro examples/with-mdx: @@ -435,7 +435,7 @@ importers: specifier: ^3.1.0 version: link:../../packages/integrations/preact astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro preact: specifier: ^10.19.2 @@ -450,7 +450,7 @@ importers: specifier: ^0.5.0 version: 0.5.0(nanostores@0.9.5)(preact@10.19.3) astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro nanostores: specifier: ^0.9.5 @@ -471,7 +471,7 @@ importers: specifier: ^1.6.3 version: 1.6.4 astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro autoprefixer: specifier: ^10.4.15 @@ -489,7 +489,7 @@ importers: examples/with-vitest: dependencies: astro: - specifier: ^4.4.1 + specifier: ^4.4.2 version: link:../../packages/astro vitest: specifier: ^1.2.2 From 7c5fcd2fa817472f480bbfbbc11b9ed71a7210ab Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 22 Feb 2024 18:36:06 +0800 Subject: [PATCH 19/19] Improve `optimizeDeps.entries` to avoid server endpoints (#10143) --- .changeset/funny-bananas-switch.md | 5 +++++ packages/astro/src/core/create-vite.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/funny-bananas-switch.md diff --git a/.changeset/funny-bananas-switch.md b/.changeset/funny-bananas-switch.md new file mode 100644 index 000000000000..665c32804aa4 --- /dev/null +++ b/.changeset/funny-bananas-switch.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Improves the default `optimizeDeps.entries` Vite config to avoid globbing server endpoints, and respect the `srcDir` option diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index b2de6afb5c3b..662644fd3762 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -1,5 +1,6 @@ import nodeFs from 'node:fs'; import { fileURLToPath } from 'node:url'; +import glob from 'fast-glob'; import * as vite from 'vite'; import { crawlFrameworkPkgs } from 'vitefu'; import type { AstroSettings } from '../@types/astro.js'; @@ -103,6 +104,8 @@ export async function createVite( }, }); + const srcDirPattern = glob.convertPathToPattern(fileURLToPath(settings.config.srcDir)); + // Start with the Vite configuration that Astro core needs const commonConfig: vite.InlineConfig = { // Tell Vite not to combine config from vite.config.js with our provided inline config @@ -112,7 +115,13 @@ export async function createVite( customLogger: createViteLogger(logger, settings.config.vite.logLevel), appType: 'custom', optimizeDeps: { - entries: ['src/**/*'], + // Scan all files within `srcDir` except for known server-code (e.g endpoints) + entries: [ + `${srcDirPattern}!(pages)/**/*`, // All files except for pages + `${srcDirPattern}pages/**/!(*.js|*.mjs|*.ts|*.mts)`, // All pages except for endpoints + `${srcDirPattern}pages/**/_*.{js,mjs,ts,mts}`, // Remaining JS/TS files prefixed with `_` (not endpoints) + `${srcDirPattern}pages/**/_*/**/*.{js,mjs,ts,mts}`, // Remaining JS/TS files within directories prefixed with `_` (not endpoints) + ], exclude: ['astro', 'node-fetch'], }, plugins: [