astro 6.1.2 → 6.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/actions/integration.js +2 -2
  2. package/dist/assets/utils/index.d.ts +1 -1
  3. package/dist/assets/utils/index.js +1 -9
  4. package/dist/assets/utils/vendor/image-size/utils/bit-reader.d.ts +2 -2
  5. package/dist/assets/utils/vendor/image-size/utils/bit-reader.js +5 -3
  6. package/dist/cli/add/index.js +37 -44
  7. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  8. package/dist/content/content-layer.js +3 -3
  9. package/dist/content/loaders/errors.d.ts +2 -2
  10. package/dist/content/loaders/errors.js +3 -0
  11. package/dist/content/loaders/glob.js +6 -2
  12. package/dist/content/mutable-data-store.js +26 -0
  13. package/dist/core/app/base.js +1 -1
  14. package/dist/core/app/dev/pipeline.js +4 -0
  15. package/dist/core/base-pipeline.d.ts +22 -35
  16. package/dist/core/base-pipeline.js +41 -8
  17. package/dist/core/build/generate.js +9 -1
  18. package/dist/core/build/pipeline.d.ts +3 -7
  19. package/dist/core/build/pipeline.js +30 -28
  20. package/dist/core/build/plugins/index.js +3 -1
  21. package/dist/core/build/plugins/plugin-chunk-imports.d.ts +10 -0
  22. package/dist/core/build/plugins/plugin-chunk-imports.js +38 -0
  23. package/dist/core/build/plugins/plugin-css.js +7 -2
  24. package/dist/core/config/schemas/refined-validators.d.ts +44 -0
  25. package/dist/core/config/schemas/refined-validators.js +168 -0
  26. package/dist/core/config/schemas/refined.js +28 -141
  27. package/dist/core/constants.js +1 -1
  28. package/dist/core/cookies/cookies.d.ts +1 -1
  29. package/dist/core/cookies/cookies.js +1 -0
  30. package/dist/core/dev/dev.js +1 -1
  31. package/dist/core/dev/restart.js +63 -68
  32. package/dist/core/messages/runtime.js +1 -1
  33. package/dist/core/render-context.d.ts +2 -2
  34. package/dist/core/render-context.js +20 -0
  35. package/dist/core/routing/create-manifest.js +12 -4
  36. package/dist/core/routing/default.d.ts +2 -3
  37. package/dist/core/routing/dev.js +0 -1
  38. package/dist/core/routing/helpers.d.ts +4 -2
  39. package/dist/core/routing/helpers.js +5 -3
  40. package/dist/integrations/features-validation.d.ts +3 -1
  41. package/dist/integrations/features-validation.js +2 -0
  42. package/dist/preferences/store.js +2 -1
  43. package/dist/prerender/routing.d.ts +1 -3
  44. package/dist/prerender/routing.js +1 -6
  45. package/dist/runtime/server/escape.d.ts +2 -1
  46. package/dist/runtime/server/escape.js +4 -5
  47. package/dist/runtime/server/transition.d.ts +2 -2
  48. package/dist/runtime/server/transition.js +4 -2
  49. package/dist/vite-plugin-app/pipeline.d.ts +4 -13
  50. package/dist/vite-plugin-app/pipeline.js +27 -12
  51. package/dist/vite-plugin-astro-server/base.d.ts +52 -0
  52. package/dist/vite-plugin-astro-server/base.js +66 -36
  53. package/dist/vite-plugin-astro-server/plugin.d.ts +0 -8
  54. package/dist/vite-plugin-astro-server/plugin.js +0 -107
  55. package/dist/vite-plugin-astro-server/trailing-slash.d.ts +34 -0
  56. package/dist/vite-plugin-astro-server/trailing-slash.js +24 -11
  57. package/dist/vite-plugin-head/index.js +40 -2
  58. package/dist/vite-plugin-hmr-reload/index.js +2 -2
  59. package/dist/vite-plugin-renderers/index.js +4 -3
  60. package/package.json +2 -2
@@ -3,26 +3,18 @@ import * as vite from "vite";
3
3
  import { globalContentLayer } from "../../content/instance.js";
4
4
  import { attachContentServerListeners } from "../../content/server-listeners.js";
5
5
  import { eventCliSession, telemetry } from "../../events/index.js";
6
+ import { runHookConfigDone, runHookConfigSetup } from "../../integrations/hooks.js";
6
7
  import { SETTINGS_FILE } from "../../preferences/constants.js";
8
+ import { getPrerenderDefault } from "../../prerender/utils.js";
7
9
  import { createSettings, resolveConfig } from "../config/index.js";
8
- import { createNodeLogger } from "../logger/node.js";
10
+ import { createVite } from "../create-vite.js";
9
11
  import { collectErrorMetadata } from "../errors/dev/utils.js";
10
12
  import { isAstroConfigZodError } from "../errors/errors.js";
11
13
  import { createSafeError } from "../errors/index.js";
14
+ import { createNodeLogger } from "../logger/node.js";
12
15
  import { formatErrorMessage, warnIfCspWithShiki } from "../messages/runtime.js";
13
- import { createContainer, startContainer } from "./container.js";
14
- async function createRestartedContainer(container, settings) {
15
- const { logger, fs, inlineConfig } = container;
16
- const newContainer = await createContainer({
17
- isRestart: true,
18
- logger,
19
- settings,
20
- inlineConfig,
21
- fs
22
- });
23
- await startContainer(newContainer);
24
- return newContainer;
25
- }
16
+ import { createRoutesList } from "../routing/create-manifest.js";
17
+ import { createContainer } from "./container.js";
26
18
  const configRE = /.*astro.config.(?:mjs|mts|cjs|cts|js|ts)$/;
27
19
  function shouldRestartContainer({ settings, inlineConfig, restartInFlight }, changedFile) {
28
20
  if (restartInFlight) return false;
@@ -47,25 +39,41 @@ function shouldRestartContainer({ settings, inlineConfig, restartInFlight }, cha
47
39
  }
48
40
  return shouldRestart;
49
41
  }
50
- async function restartContainer(container) {
51
- const { logger, close, settings: existingSettings } = container;
42
+ async function restartContainerInPlace(container) {
43
+ const { logger, settings: existingSettings, inlineConfig, fs } = container;
52
44
  container.restartInFlight = true;
53
45
  try {
54
- const { astroConfig } = await resolveConfig(container.inlineConfig, "dev", container.fs);
55
- if (astroConfig.security.csp) {
56
- logger.warn(
57
- "config",
58
- "Astro's Content Security Policy (CSP) does not work in development mode. To verify your CSP implementation, build the project and run the preview server."
59
- );
60
- }
46
+ const { astroConfig } = await resolveConfig(inlineConfig, "dev", fs);
61
47
  warnIfCspWithShiki(astroConfig, logger);
62
- const settings = await createSettings(
48
+ let settings = await createSettings(
63
49
  astroConfig,
64
- container.inlineConfig.logLevel,
50
+ inlineConfig.logLevel,
65
51
  fileURLToPath(existingSettings.config.root)
66
52
  );
67
- await close();
68
- return await createRestartedContainer(container, settings);
53
+ settings = await runHookConfigSetup({ settings, command: "dev", logger, isRestart: true });
54
+ if (!settings.adapter?.adapterFeatures?.buildOutput) {
55
+ settings.buildOutput = getPrerenderDefault(settings.config) ? "static" : "server";
56
+ }
57
+ await runHookConfigDone({ settings, logger, command: "dev" });
58
+ const mode = inlineConfig?.mode ?? "development";
59
+ const {
60
+ server: { host, headers, allowedHosts }
61
+ } = settings.config;
62
+ const rendererClientEntries = settings.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
63
+ const routesList = await createRoutesList({ settings, fsMod: fs }, logger, { dev: true });
64
+ const address = container.viteServer.httpServer?.address();
65
+ const port = address !== null && typeof address === "object" ? address.port : void 0;
66
+ const newViteConfig = await createVite(
67
+ {
68
+ server: { host, headers, allowedHosts, port },
69
+ optimizeDeps: { include: rendererClientEntries }
70
+ },
71
+ { settings, logger, mode, command: "dev", fs, sync: false, routesList }
72
+ );
73
+ container.viteServer.config = await vite.resolveConfig(newViteConfig, "serve");
74
+ await container.viteServer.restart();
75
+ container.settings = settings;
76
+ return settings;
69
77
  } catch (_err) {
70
78
  const error = createSafeError(_err);
71
79
  if (!isAstroConfigZodError(_err)) {
@@ -74,16 +82,14 @@ async function restartContainer(container) {
74
82
  formatErrorMessage(collectErrorMetadata(error), logger.level() === "debug") + "\n"
75
83
  );
76
84
  }
77
- container.viteServer.environments.client.hot.send({
85
+ container.viteServer.environments?.client?.hot?.send({
78
86
  type: "error",
79
- err: {
80
- message: error.message,
81
- stack: error.stack || ""
82
- }
87
+ err: { message: error.message, stack: error.stack || "" }
83
88
  });
84
- container.restartInFlight = false;
85
89
  logger.error(null, "Continuing with previous valid configuration\n");
86
90
  return error;
91
+ } finally {
92
+ container.restartInFlight = false;
87
93
  }
88
94
  }
89
95
  async function createContainerWithAutomaticRestart({
@@ -92,12 +98,6 @@ async function createContainerWithAutomaticRestart({
92
98
  }) {
93
99
  const logger = createNodeLogger(inlineConfig ?? {});
94
100
  const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, "dev", fs);
95
- if (astroConfig.security.csp) {
96
- logger.warn(
97
- "config",
98
- "Astro's Content Security Policy (CSP) does not work in development mode. To verify your CSP implementation, build the project and run the preview server."
99
- );
100
- }
101
101
  warnIfCspWithShiki(astroConfig, logger);
102
102
  telemetry.record(eventCliSession("dev", userConfig));
103
103
  const settings = await createSettings(
@@ -119,7 +119,6 @@ async function createContainerWithAutomaticRestart({
119
119
  container: initialContainer,
120
120
  bindCLIShortcuts() {
121
121
  const customShortcuts = [
122
- // Disable default Vite shortcuts that don't work well with Astro
123
122
  { key: "r", description: "" },
124
123
  { key: "u", description: "" },
125
124
  { key: "c", description: "" }
@@ -139,42 +138,38 @@ async function createContainerWithAutomaticRestart({
139
138
  return restartComplete;
140
139
  }
141
140
  };
142
- async function handleServerRestart(logMsg = "", server) {
143
- logger.info(null, (logMsg + " Restarting...").trim());
144
- const container = restart.container;
145
- const result = await restartContainer(container);
146
- if (result instanceof Error) {
147
- resolveRestart(result);
148
- } else {
149
- restart.container = result;
150
- setupContainer();
151
- await attachContentServerListeners(restart.container);
152
- if (server) {
153
- server.resolvedUrls = result.viteServer.resolvedUrls;
154
- }
155
- resolveRestart(null);
156
- }
157
- restartComplete = new Promise((resolve) => {
158
- resolveRestart = resolve;
159
- });
160
- }
161
141
  function handleChangeRestart(logMsg) {
162
142
  return async function(changedFile) {
163
143
  if (shouldRestartContainer(restart.container, changedFile)) {
164
- handleServerRestart(logMsg);
144
+ logger.info(null, (logMsg + " Restarting...").trim());
145
+ const result = await restartContainerInPlace(restart.container);
146
+ if (result instanceof Error) {
147
+ resolveRestart(result);
148
+ } else {
149
+ setupContainer();
150
+ await attachContentServerListeners(restart.container);
151
+ resolveRestart(null);
152
+ }
153
+ restartComplete = new Promise((resolve) => {
154
+ resolveRestart = resolve;
155
+ });
165
156
  }
166
157
  };
167
158
  }
159
+ let changeHandler;
160
+ let unlinkHandler;
161
+ let addHandler;
168
162
  function setupContainer() {
169
163
  const watcher = restart.container.viteServer.watcher;
170
- watcher.on("change", handleChangeRestart("Configuration file updated."));
171
- watcher.on("unlink", handleChangeRestart("Configuration file removed."));
172
- watcher.on("add", handleChangeRestart("Configuration file added."));
173
- restart.container.viteServer.restart = async () => {
174
- if (!restart.container.restartInFlight) {
175
- await handleServerRestart("", restart.container.viteServer);
176
- }
177
- };
164
+ if (changeHandler) watcher.off("change", changeHandler);
165
+ if (unlinkHandler) watcher.off("unlink", unlinkHandler);
166
+ if (addHandler) watcher.off("add", addHandler);
167
+ changeHandler = handleChangeRestart("Configuration file updated.");
168
+ unlinkHandler = handleChangeRestart("Configuration file removed.");
169
+ addHandler = handleChangeRestart("Configuration file added.");
170
+ watcher.on("change", changeHandler);
171
+ watcher.on("unlink", unlinkHandler);
172
+ watcher.on("add", addHandler);
178
173
  }
179
174
  setupContainer();
180
175
  return restart;
@@ -276,7 +276,7 @@ function printHelp({
276
276
  message.push(
277
277
  linebreak(),
278
278
  ` ${bgGreen(black(` ${commandName} `))} ${green(
279
- `v${"6.1.2"}`
279
+ `v${"6.1.4"}`
280
280
  )} ${headline}`
281
281
  );
282
282
  }
@@ -1,6 +1,6 @@
1
1
  import type { ActionAPIContext } from '../actions/runtime/types.js';
2
2
  import type { ComponentInstance } from '../types/astro.js';
3
- import type { MiddlewareHandler, Props } from '../types/public/common.js';
3
+ import type { MiddlewareHandler, Params, Props } from '../types/public/common.js';
4
4
  import type { APIContext, AstroGlobal } from '../types/public/context.js';
5
5
  import type { RouteData, SSRResult } from '../types/public/internal.js';
6
6
  import type { ServerIslandMappings, SSRActions } from './app/types.js';
@@ -26,7 +26,7 @@ export declare class RenderContext {
26
26
  status: number;
27
27
  clientAddress: string | undefined;
28
28
  protected cookies: AstroCookies;
29
- params: import("../types/public/common.js").Params;
29
+ params: Params;
30
30
  protected url: URL;
31
31
  props: Props;
32
32
  partial: undefined | boolean;
@@ -38,6 +38,26 @@ import { AstroSession } from "./session/runtime.js";
38
38
  import { collapseDuplicateSlashes } from "@astrojs/internal-helpers/path";
39
39
  import { validateAndDecodePathname } from "./util/pathname.js";
40
40
  class RenderContext {
41
+ pipeline;
42
+ locals;
43
+ middleware;
44
+ actions;
45
+ serverIslands;
46
+ // It must be a DECODED pathname
47
+ pathname;
48
+ request;
49
+ routeData;
50
+ status;
51
+ clientAddress;
52
+ cookies;
53
+ params;
54
+ url;
55
+ props;
56
+ partial;
57
+ shouldInjectCspMetaTags;
58
+ session;
59
+ cache;
60
+ skipMiddleware;
41
61
  constructor(pipeline, locals, middleware, actions, serverIslands, pathname, request, routeData, status, clientAddress, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = RenderContext.#createNormalizedUrl(request.url), props = {}, partial = void 0, shouldInjectCspMetaTags = pipeline.manifest.shouldInjectCspMetaTags, session = void 0, cache, skipMiddleware = false) {
42
62
  this.pipeline = pipeline;
43
63
  this.locals = locals;
@@ -158,7 +158,11 @@ function createFileBasedRoutes({ settings, cwd, fsMod }, logger) {
158
158
  } else {
159
159
  const component = item.file;
160
160
  const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
161
- const trailingSlash = trailingSlashForPath(pathname, settings.config);
161
+ const trailingSlash = trailingSlashForPath(
162
+ pathname,
163
+ settings.config,
164
+ item.isPage ? "page" : "endpoint"
165
+ );
162
166
  const pattern = getPattern(segments, settings.config.base, trailingSlash);
163
167
  const route = joinSegments(segments);
164
168
  routes.push({
@@ -273,7 +277,11 @@ function createRoutesFromEntriesByDir(entriesByDir, settings, logger, pagesDirRe
273
277
  } else {
274
278
  const component = item.file;
275
279
  const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
276
- const trailingSlash = trailingSlashForPath(pathname, settings.config);
280
+ const trailingSlash = trailingSlashForPath(
281
+ pathname,
282
+ settings.config,
283
+ item.isPage ? "page" : "endpoint"
284
+ );
277
285
  const pattern = getPattern(segments, settings.config.base, trailingSlash);
278
286
  const route = joinSegments(segments);
279
287
  routes.push({
@@ -312,7 +320,7 @@ function groupEntriesByDir(entries) {
312
320
  }
313
321
  return entriesByDir;
314
322
  }
315
- const trailingSlashForPath = (pathname, config) => pathname && hasFileExtension(pathname) ? "never" : config.trailingSlash;
323
+ const trailingSlashForPath = (pathname, config, type) => type === "endpoint" && pathname && hasFileExtension(pathname) ? "never" : config.trailingSlash;
316
324
  function createInjectedRoutes({ settings, cwd }) {
317
325
  const { config } = settings;
318
326
  const prerender = getPrerenderDefault(config);
@@ -326,7 +334,7 @@ function createInjectedRoutes({ settings, cwd }) {
326
334
  });
327
335
  const type = resolved.endsWith(".astro") ? "page" : "endpoint";
328
336
  const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
329
- const trailingSlash = trailingSlashForPath(pathname, config);
337
+ const trailingSlash = trailingSlashForPath(pathname, config, type);
330
338
  const pattern = getPattern(segments, settings.config.base, trailingSlash);
331
339
  const params = segments.flat().filter((p) => p.dynamic).map((p) => p.content);
332
340
  const route = joinSegments(segments);
@@ -1,11 +1,10 @@
1
1
  import type { ComponentInstance } from '../../types/astro.js';
2
2
  import type { SSRManifest } from '../app/types.js';
3
- type DefaultRouteParams = {
3
+ export interface DefaultRouteParams {
4
4
  instance: ComponentInstance;
5
5
  matchesComponent(filePath: URL): boolean;
6
6
  route: string;
7
7
  component: string;
8
- };
8
+ }
9
9
  export declare const DEFAULT_COMPONENTS: string[];
10
10
  export declare function createDefaultRoutes(manifest: SSRManifest): DefaultRouteParams[];
11
- export {};
@@ -8,7 +8,6 @@ async function matchRoute(pathname, routesList, pipeline, manifest) {
8
8
  const { logger, routeCache } = pipeline;
9
9
  const matches = matchAllRoutes(pathname, routesList);
10
10
  const preloadedMatches = getSortedPreloadedMatches({
11
- pipeline,
12
11
  matches,
13
12
  manifest
14
13
  });
@@ -38,10 +38,12 @@ export declare function getCustom500Route(manifestData: RoutesList): RouteData |
38
38
  * `.html` suffix from pathnames that intentionally include it.
39
39
  */
40
40
  export declare function routeHasHtmlExtension(route: RouteData): boolean;
41
- export declare function hasNonPrerenderedProjectRoute(routes: Array<Pick<RouteData, 'type' | 'origin' | 'prerender'>>, options?: {
41
+ export declare function hasNonPrerenderedRoute(routes: Array<Pick<RouteData, 'type' | 'origin' | 'prerender'>>, options?: {
42
42
  includeEndpoints?: boolean;
43
+ includeExternal?: boolean;
43
44
  }): boolean;
44
- export declare function hasNonPrerenderedProjectRoute(routes: Array<Pick<IntegrationResolvedRoute, 'type' | 'origin' | 'isPrerendered'>>, options?: {
45
+ export declare function hasNonPrerenderedRoute(routes: Array<Pick<IntegrationResolvedRoute, 'type' | 'origin' | 'isPrerendered'>>, options?: {
45
46
  includeEndpoints?: boolean;
47
+ includeExternal?: boolean;
46
48
  }): boolean;
47
49
  export {};
@@ -30,19 +30,21 @@ function routeHasHtmlExtension(route) {
30
30
  (segment) => segment.some((part) => !part.dynamic && part.content.includes(".html"))
31
31
  );
32
32
  }
33
- function hasNonPrerenderedProjectRoute(routes, options) {
33
+ function hasNonPrerenderedRoute(routes, options) {
34
34
  const includeEndpoints = options?.includeEndpoints ?? true;
35
+ const includeExternal = options?.includeExternal ?? false;
35
36
  const routeTypes = includeEndpoints ? ["page", "endpoint"] : ["page"];
37
+ const origins = includeExternal ? ["project", "external"] : ["project"];
36
38
  return routes.some((route) => {
37
39
  const isPrerendered = "isPrerendered" in route ? route.isPrerendered : route.prerender;
38
- return routeTypes.includes(route.type) && route.origin === "project" && !isPrerendered;
40
+ return routeTypes.includes(route.type) && origins.includes(route.origin) && !isPrerendered;
39
41
  });
40
42
  }
41
43
  export {
42
44
  getCustom404Route,
43
45
  getCustom500Route,
44
46
  getFallbackRoute,
45
- hasNonPrerenderedProjectRoute,
47
+ hasNonPrerenderedRoute,
46
48
  routeHasHtmlExtension,
47
49
  routeIsFallback,
48
50
  routeIsRedirect
@@ -1,6 +1,6 @@
1
1
  import type { Logger } from '../core/logger/core.js';
2
2
  import type { AstroSettings } from '../types/astro.js';
3
- import type { AstroAdapterFeatureMap } from '../types/public/integrations.js';
3
+ import type { AdapterSupport, AdapterSupportsKind, AstroAdapterFeatureMap } from '../types/public/integrations.js';
4
4
  export declare const AdapterFeatureStability: {
5
5
  readonly STABLE: "stable";
6
6
  readonly DEPRECATED: "deprecated";
@@ -19,5 +19,7 @@ type ValidationResult = {
19
19
  *
20
20
  */
21
21
  export declare function validateSupportedFeatures(adapterName: string, featureMap: AstroAdapterFeatureMap, settings: AstroSettings, logger: Logger): ValidationResult;
22
+ export declare function unwrapSupportKind(supportKind?: AdapterSupport): AdapterSupportsKind | undefined;
23
+ export declare function getSupportMessage(supportKind: AdapterSupport): string | undefined;
22
24
  export declare function getAdapterStaticRecommendation(adapterName: string): string | undefined;
23
25
  export {};
@@ -132,5 +132,7 @@ function getAdapterStaticRecommendation(adapterName) {
132
132
  export {
133
133
  AdapterFeatureStability,
134
134
  getAdapterStaticRecommendation,
135
+ getSupportMessage,
136
+ unwrapSupportKind,
135
137
  validateSupportedFeatures
136
138
  };
@@ -4,11 +4,12 @@ import dget from "dlv";
4
4
  import { dset } from "dset";
5
5
  import { SETTINGS_FILE } from "./constants.js";
6
6
  class PreferenceStore {
7
+ dir;
8
+ file;
7
9
  constructor(dir, filename = SETTINGS_FILE) {
8
10
  this.dir = dir;
9
11
  this.file = path.join(this.dir, filename);
10
12
  }
11
- file;
12
13
  _store;
13
14
  get store() {
14
15
  if (this._store) return this._store;
@@ -1,11 +1,9 @@
1
1
  import type { RouteData, SSRManifest } from '../types/public/internal.js';
2
- import type { RunnablePipeline } from '../vite-plugin-app/pipeline.js';
3
2
  type GetSortedPreloadedMatchesParams = {
4
- pipeline: RunnablePipeline;
5
3
  matches: RouteData[];
6
4
  manifest: SSRManifest;
7
5
  };
8
- export declare function getSortedPreloadedMatches({ pipeline, matches, manifest, }: GetSortedPreloadedMatchesParams): PreloadAndSetPrerenderStatusResult[];
6
+ export declare function getSortedPreloadedMatches({ matches, manifest }: GetSortedPreloadedMatchesParams): PreloadAndSetPrerenderStatusResult[];
9
7
  type PreloadAndSetPrerenderStatusResult = {
10
8
  filePath: URL;
11
9
  route: RouteData;
@@ -1,12 +1,7 @@
1
1
  import { routeIsRedirect } from "../core/routing/helpers.js";
2
2
  import { routeComparator } from "../core/routing/priority.js";
3
- function getSortedPreloadedMatches({
4
- pipeline,
5
- matches,
6
- manifest
7
- }) {
3
+ function getSortedPreloadedMatches({ matches, manifest }) {
8
4
  return preloadAndSetPrerenderStatus({
9
- pipeline,
10
5
  matches,
11
6
  manifest
12
7
  }).sort((a, b) => routeComparator(a.route, b.route)).sort((a, b) => prioritizePrerenderedMatchesComparator(a.route, b.route));
@@ -1,12 +1,13 @@
1
1
  export declare const escapeHTML: (str: string) => string;
2
2
  export declare class HTMLBytes extends Uint8Array {
3
3
  }
4
+ declare const htmlStringSymbol: unique symbol;
4
5
  /**
5
6
  * A "blessed" extension of String that tells Astro that the string
6
7
  * has already been escaped. This helps prevent double-escaping of HTML.
7
8
  */
8
9
  export declare class HTMLString extends String {
9
- get [Symbol.toStringTag](): string;
10
+ [htmlStringSymbol]: boolean;
10
11
  }
11
12
  type BlessedType = string | HTMLBytes;
12
13
  /**
@@ -8,13 +8,12 @@ Object.defineProperty(HTMLBytes.prototype, Symbol.toStringTag, {
8
8
  return "HTMLBytes";
9
9
  }
10
10
  });
11
+ const htmlStringSymbol = /* @__PURE__ */ Symbol.for("astro:html-string");
11
12
  class HTMLString extends String {
12
- get [Symbol.toStringTag]() {
13
- return "HTMLString";
14
- }
13
+ [htmlStringSymbol] = true;
15
14
  }
16
15
  const markHTMLString = (value) => {
17
- if (value instanceof HTMLString) {
16
+ if (isHTMLString(value)) {
18
17
  return value;
19
18
  }
20
19
  if (typeof value === "string") {
@@ -23,7 +22,7 @@ const markHTMLString = (value) => {
23
22
  return value;
24
23
  };
25
24
  function isHTMLString(value) {
26
- return value instanceof HTMLString;
25
+ return !!value?.[htmlStringSymbol];
27
26
  }
28
27
  function markHTMLBytes(bytes) {
29
28
  return new HTMLBytes(bytes);
@@ -9,10 +9,10 @@ export declare function createAnimationScope(transitionName: string, animations:
9
9
  styles: string;
10
10
  };
11
11
  export declare class ViewTransitionStyleSheet {
12
- private scope;
13
- private name;
14
12
  private modern;
15
13
  private fallback;
14
+ private scope;
15
+ private name;
16
16
  constructor(scope: string, name: string);
17
17
  toString(): string;
18
18
  private layer;
@@ -68,12 +68,14 @@ function createAnimationScope(transitionName, animations) {
68
68
  return { scope, styles: sheet.toString().replaceAll('"', "") };
69
69
  }
70
70
  class ViewTransitionStyleSheet {
71
+ modern = [];
72
+ fallback = [];
73
+ scope;
74
+ name;
71
75
  constructor(scope, name) {
72
76
  this.scope = scope;
73
77
  this.name = name;
74
78
  }
75
- modern = [];
76
- fallback = [];
77
79
  toString() {
78
80
  const { scope, name } = this;
79
81
  const [modern, fallback] = [this.modern, this.fallback].map((rules) => rules.join(""));
@@ -1,26 +1,17 @@
1
1
  import { type HeadElements, Pipeline, type TryRewriteResult } from '../core/base-pipeline.js';
2
- import type { Logger } from '../core/logger/core.js';
3
2
  import type { ModuleLoader } from '../core/module-loader/index.js';
4
3
  import type { AstroSettings, ComponentInstance, RoutesList } from '../types/astro.js';
5
- import type { RewritePayload, RouteData, SSRLoadedRenderer, SSRManifest } from '../types/public/index.js';
4
+ import type { RewritePayload, RouteData, SSRLoadedRenderer } from '../types/public/index.js';
6
5
  /**
7
6
  * This Pipeline is used when the Vite SSR environment is runnable.
8
7
  */
9
8
  export declare class RunnablePipeline extends Pipeline {
10
- readonly loader: ModuleLoader;
11
- readonly logger: Logger;
12
- readonly manifest: SSRManifest;
13
- readonly settings: AstroSettings;
14
- readonly getDebugInfo: () => Promise<string>;
15
- readonly defaultRoutes: {
16
- instance: ComponentInstance;
17
- matchesComponent(filePath: URL): boolean;
18
- route: string;
19
- component: string;
20
- }[];
21
9
  getName(): string;
22
10
  renderers: SSRLoadedRenderer[];
23
11
  routesList: RoutesList | undefined;
12
+ readonly loader: ModuleLoader;
13
+ readonly settings: AstroSettings;
14
+ readonly getDebugInfo: () => Promise<string>;
24
15
  private constructor();
25
16
  static create(manifestData: RoutesList, { loader, logger, manifest, settings, getDebugInfo, }: Pick<RunnablePipeline, 'loader' | 'logger' | 'manifest' | 'settings' | 'getDebugInfo'>): RunnablePipeline;
26
17
  headElements(routeData: RouteData): Promise<HeadElements>;
@@ -5,7 +5,6 @@ import { enhanceViteSSRError } from "../core/errors/dev/index.js";
5
5
  import { AggregateError, CSSError, MarkdownError } from "../core/errors/index.js";
6
6
  import { RedirectComponentInstance } from "../core/redirects/index.js";
7
7
  import { loadRenderer } from "../core/render/index.js";
8
- import { createDefaultRoutes } from "../core/routing/default.js";
9
8
  import { routeIsRedirect } from "../core/routing/helpers.js";
10
9
  import { findRouteToRewrite } from "../core/routing/rewrite.js";
11
10
  import { isPage } from "../core/util.js";
@@ -16,17 +15,6 @@ import { newNodePool } from "../runtime/server/render/queue/pool.js";
16
15
  import { HTMLStringCache } from "../runtime/server/html-string-cache.js";
17
16
  import { queueRenderingEnabled } from "../core/app/manifest.js";
18
17
  class RunnablePipeline extends Pipeline {
19
- constructor(loader, logger, manifest, settings, getDebugInfo, defaultRoutes = createDefaultRoutes(manifest)) {
20
- const resolve = createResolve(loader, manifest.rootDir);
21
- const streaming = true;
22
- super(logger, manifest, "development", [], resolve, streaming);
23
- this.loader = loader;
24
- this.logger = logger;
25
- this.manifest = manifest;
26
- this.settings = settings;
27
- this.getDebugInfo = getDebugInfo;
28
- this.defaultRoutes = defaultRoutes;
29
- }
30
18
  getName() {
31
19
  return "RunnablePipeline";
32
20
  }
@@ -34,6 +22,33 @@ class RunnablePipeline extends Pipeline {
34
22
  // so it needs to be mutable here unlike in other environments
35
23
  renderers = new Array();
36
24
  routesList;
25
+ loader;
26
+ settings;
27
+ getDebugInfo;
28
+ constructor(loader, logger, manifest, settings, getDebugInfo, defaultRoutes) {
29
+ const resolve = createResolve(loader, manifest.rootDir);
30
+ const streaming = true;
31
+ super(
32
+ logger,
33
+ manifest,
34
+ "development",
35
+ [],
36
+ resolve,
37
+ streaming,
38
+ void 0,
39
+ void 0,
40
+ void 0,
41
+ void 0,
42
+ void 0,
43
+ void 0,
44
+ void 0,
45
+ void 0,
46
+ defaultRoutes
47
+ );
48
+ this.loader = loader;
49
+ this.settings = settings;
50
+ this.getDebugInfo = getDebugInfo;
51
+ }
37
52
  static create(manifestData, {
38
53
  loader,
39
54
  logger,
@@ -1,4 +1,56 @@
1
1
  import type * as vite from 'vite';
2
2
  import type { Logger } from '../core/logger/core.js';
3
3
  import type { AstroSettings } from '../types/astro.js';
4
+ /**
5
+ * Outcome of the base-URL evaluation for a dev-server request.
6
+ *
7
+ * - **`rewrite`** — The request URL starts with the configured `base` path.
8
+ * Strip the base prefix so downstream handlers see a root-relative URL
9
+ * (e.g. `/docs/about` → `/about` when `base: '/docs'`).
10
+ * - **`not-found-subpath`** — The user navigated to `/` or `/index.html` but
11
+ * the project has a non-root `base`. Respond with a 404 explaining that the
12
+ * site lives under the base path, so the developer knows to update the URL.
13
+ * - **`not-found`** — The URL doesn't start with the base and the browser
14
+ * expects HTML (`Accept: text/html`). Respond with a generic 404 page.
15
+ * - **`check-public`** — The URL doesn't match the base and the browser is
16
+ * requesting a non-HTML asset (image, script, font, etc.). The middleware
17
+ * must do an async `fs.stat` to decide whether the file exists in
18
+ * `publicDir` (and show a helpful base-path hint) or just pass through.
19
+ * This variant cannot be resolved purely.
20
+ */
21
+ export type BaseRewriteDecision = {
22
+ action: 'rewrite';
23
+ newUrl: string;
24
+ } | {
25
+ action: 'not-found-subpath';
26
+ pathname: string;
27
+ devRoot: string;
28
+ } | {
29
+ action: 'not-found';
30
+ pathname: string;
31
+ } | {
32
+ action: 'check-public';
33
+ };
34
+ /**
35
+ * Computes the `devRoot` path used to match and strip the base prefix.
36
+ *
37
+ * The `devRoot` is the pathname portion of the base URL (resolved against the
38
+ * `site` if present, otherwise against `http://localhost`). For example:
39
+ * - `base: '/docs'`, no site → `/docs`
40
+ * - `base: '/docs'`, `site: 'https://example.com'` → `/docs`
41
+ * - `base: '/'` → `/`
42
+ */
43
+ export declare function resolveDevRoot(base: string, site?: string): {
44
+ devRoot: string;
45
+ devRootReplacement: string;
46
+ };
47
+ /**
48
+ * Pure decision function for base-URL dev-server rewriting.
49
+ *
50
+ * Evaluates whether the incoming `url` starts with the project's `base` path
51
+ * and returns the action the middleware should take. The async `fs.stat` branch
52
+ * (checking `publicDir`) is represented as `check-public` and must be handled
53
+ * by the caller.
54
+ */
55
+ export declare function evaluateBaseRewrite(url: string, pathname: string, acceptHeader: string | undefined, devRoot: string, devRootReplacement: string): BaseRewriteDecision;
4
56
  export declare function baseMiddleware(settings: AstroSettings, logger: Logger): vite.Connect.NextHandleFunction;