astro 7.2.2 → 7.2.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 (158) hide show
  1. package/dist/actions/handler.d.ts +6 -12
  2. package/dist/actions/handler.js +30 -40
  3. package/dist/actions/load.d.ts +12 -0
  4. package/dist/actions/load.js +55 -0
  5. package/dist/actions/runtime/entrypoints/server.js +5 -4
  6. package/dist/actions/runtime/server.js +8 -6
  7. package/dist/assets/fonts/providers/index.d.ts +1 -1
  8. package/dist/assets/fonts/providers/index.js +2 -12
  9. package/dist/assets/utils/vendor/image-size/types/heif.js +8 -3
  10. package/dist/assets/utils/vendor/image-size/types/icns.js +10 -2
  11. package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -2
  12. package/dist/assets/utils/vendor/image-size/types/jxl.js +5 -2
  13. package/dist/assets/utils/vendor/image-size/types/utils.d.ts +1 -1
  14. package/dist/assets/utils/vendor/image-size/types/utils.js +20 -6
  15. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  16. package/dist/container/environment.d.ts +20 -0
  17. package/dist/container/environment.js +106 -0
  18. package/dist/container/index.js +73 -37
  19. package/dist/content/content-layer.js +3 -3
  20. package/dist/content/data-store-writer.d.ts +7 -10
  21. package/dist/content/data-store-writer.js +62 -27
  22. package/dist/content/data-store.d.ts +20 -3
  23. package/dist/content/data-store.js +28 -7
  24. package/dist/content/mutable-data-store.js +15 -10
  25. package/dist/content/runtime.d.ts +3 -2
  26. package/dist/content/runtime.js +43 -26
  27. package/dist/core/app/app.d.ts +0 -2
  28. package/dist/core/app/app.js +0 -7
  29. package/dist/core/app/base.d.ts +32 -20
  30. package/dist/core/app/base.js +79 -73
  31. package/dist/core/app/dev-facade.d.ts +27 -0
  32. package/dist/core/app/dev-facade.js +51 -0
  33. package/dist/core/app/entrypoints/index.d.ts +0 -1
  34. package/dist/core/app/entrypoints/index.js +0 -2
  35. package/dist/core/app/entrypoints/virtual/dev.js +24 -19
  36. package/dist/core/app/node.js +13 -14
  37. package/dist/core/app/prepare-response.d.ts +1 -1
  38. package/dist/core/app/validate-headers.js +7 -3
  39. package/dist/core/build/app.d.ts +31 -6
  40. package/dist/core/build/app.js +31 -13
  41. package/dist/core/build/environment.d.ts +25 -0
  42. package/dist/core/build/environment.js +157 -0
  43. package/dist/core/cache/handler.d.ts +13 -7
  44. package/dist/core/cache/handler.js +55 -51
  45. package/dist/core/cache/provider.d.ts +4 -0
  46. package/dist/core/cache/provider.js +15 -0
  47. package/dist/core/constants.d.ts +0 -11
  48. package/dist/core/constants.js +1 -5
  49. package/dist/core/dev/dev.js +1 -1
  50. package/dist/core/environment/dev-nonrunnable.d.ts +6 -0
  51. package/dist/core/environment/dev-nonrunnable.js +170 -0
  52. package/dist/core/environment/index.d.ts +90 -0
  53. package/dist/core/environment/index.js +12 -0
  54. package/dist/core/environment/production.d.ts +6 -0
  55. package/dist/core/environment/production.js +117 -0
  56. package/dist/core/errors/build-handler.d.ts +5 -10
  57. package/dist/core/errors/build-handler.js +11 -17
  58. package/dist/core/errors/default-handler.d.ts +4 -9
  59. package/dist/core/errors/default-handler.js +92 -107
  60. package/dist/core/errors/dev-handler.d.ts +7 -11
  61. package/dist/core/errors/dev-handler.js +71 -69
  62. package/dist/core/errors/errors-data.d.ts +18 -0
  63. package/dist/core/errors/errors-data.js +7 -0
  64. package/dist/core/errors/handler.d.ts +22 -3
  65. package/dist/core/errors/handler.js +25 -0
  66. package/dist/core/fetch/default-handler.d.ts +15 -8
  67. package/dist/core/fetch/default-handler.js +12 -34
  68. package/dist/core/fetch/features.d.ts +23 -0
  69. package/dist/core/fetch/features.js +27 -0
  70. package/dist/core/fetch/fetch-state.d.ts +52 -7
  71. package/dist/core/fetch/fetch-state.js +99 -92
  72. package/dist/core/fetch/index.d.ts +9 -2
  73. package/dist/core/fetch/index.js +18 -79
  74. package/dist/core/fetch/vite-plugin.js +2 -1
  75. package/dist/core/i18n/domain.js +4 -11
  76. package/dist/core/i18n/handler.d.ts +28 -13
  77. package/dist/core/i18n/handler.js +100 -100
  78. package/dist/core/logger/manifest-logger.d.ts +31 -0
  79. package/dist/core/logger/manifest-logger.js +37 -0
  80. package/dist/core/manifest/ambient-source.d.ts +2 -0
  81. package/dist/core/manifest/ambient-source.js +4 -0
  82. package/dist/core/manifest/ambient.d.ts +16 -0
  83. package/dist/core/manifest/ambient.js +22 -0
  84. package/dist/core/manifest/derived.d.ts +3 -0
  85. package/dist/core/manifest/derived.js +10 -0
  86. package/dist/core/manifest/memo.d.ts +31 -0
  87. package/dist/core/manifest/memo.js +47 -0
  88. package/dist/core/messages/runtime.js +1 -1
  89. package/dist/core/middleware/astro-middleware.d.ts +25 -35
  90. package/dist/core/middleware/astro-middleware.js +61 -81
  91. package/dist/core/middleware/load.d.ts +19 -0
  92. package/dist/core/middleware/load.js +36 -0
  93. package/dist/core/middleware/sequence.js +15 -7
  94. package/dist/core/pages/handler.d.ts +18 -25
  95. package/dist/core/pages/handler.js +68 -84
  96. package/dist/core/redirects/render.js +3 -8
  97. package/dist/core/render/index.d.ts +0 -1
  98. package/dist/core/render/index.js +0 -2
  99. package/dist/core/render/route-cache.d.ts +6 -1
  100. package/dist/core/render/route-cache.js +11 -1
  101. package/dist/core/rewrites/handler.d.ts +4 -6
  102. package/dist/core/rewrites/handler.js +19 -20
  103. package/dist/core/routing/default.d.ts +2 -0
  104. package/dist/core/routing/default.js +7 -1
  105. package/dist/core/routing/dev.d.ts +1 -3
  106. package/dist/core/routing/dev.js +12 -5
  107. package/dist/core/routing/handler.d.ts +6 -16
  108. package/dist/core/routing/handler.js +126 -164
  109. package/dist/core/routing/helpers.d.ts +7 -1
  110. package/dist/core/routing/helpers.js +21 -0
  111. package/dist/core/routing/match-request.d.ts +10 -0
  112. package/dist/core/routing/match-request.js +46 -0
  113. package/dist/core/routing/route-table.d.ts +34 -0
  114. package/dist/core/routing/route-table.js +41 -0
  115. package/dist/core/routing/trailing-slash-handler.d.ts +4 -14
  116. package/dist/core/routing/trailing-slash-handler.js +39 -50
  117. package/dist/core/server-islands/mappings.d.ts +6 -0
  118. package/dist/core/server-islands/mappings.js +12 -0
  119. package/dist/core/session/driver.d.ts +4 -0
  120. package/dist/core/session/driver.js +14 -0
  121. package/dist/core/session/handler.d.ts +1 -1
  122. package/dist/core/session/handler.js +8 -8
  123. package/dist/core/session/provider-disabled.js +2 -2
  124. package/dist/entrypoints/prerender.js +5 -1
  125. package/dist/i18n/middleware.d.ts +4 -4
  126. package/dist/i18n/middleware.js +3 -3
  127. package/dist/manifest/serialized.d.ts +1 -0
  128. package/dist/manifest/serialized.js +9 -2
  129. package/dist/runtime/prerender/static-paths.d.ts +14 -2
  130. package/dist/runtime/prerender/static-paths.js +4 -3
  131. package/dist/types/public/config.d.ts +433 -241
  132. package/dist/vite-plugin-app/createAstroServerApp.js +22 -18
  133. package/dist/vite-plugin-app/environment.d.ts +18 -0
  134. package/dist/vite-plugin-app/environment.js +210 -0
  135. package/dist/vite-plugin-app/handle-request.d.ts +30 -0
  136. package/dist/vite-plugin-app/handle-request.js +129 -0
  137. package/dist/vite-plugin-app/index.d.ts +1 -1
  138. package/dist/vite-plugin-app/index.js +1 -1
  139. package/package.json +14 -7
  140. package/src/core/README.md +37 -0
  141. package/src/core/manifest/ambient-source.ts +9 -0
  142. package/src/types/README.md +5 -0
  143. package/dist/container/pipeline.d.ts +0 -14
  144. package/dist/container/pipeline.js +0 -78
  145. package/dist/core/app/dev/app.d.ts +0 -31
  146. package/dist/core/app/dev/app.js +0 -80
  147. package/dist/core/app/dev/pipeline.d.ts +0 -17
  148. package/dist/core/app/dev/pipeline.js +0 -133
  149. package/dist/core/app/pipeline.d.ts +0 -14
  150. package/dist/core/app/pipeline.js +0 -123
  151. package/dist/core/base-pipeline.d.ts +0 -183
  152. package/dist/core/base-pipeline.js +0 -293
  153. package/dist/core/build/pipeline.d.ts +0 -38
  154. package/dist/core/build/pipeline.js +0 -202
  155. package/dist/vite-plugin-app/app.d.ts +0 -62
  156. package/dist/vite-plugin-app/app.js +0 -237
  157. package/dist/vite-plugin-app/pipeline.d.ts +0 -25
  158. package/dist/vite-plugin-app/pipeline.js +0 -189
@@ -0,0 +1,170 @@
1
+ import { stringifyForScript } from "../../runtime/server/escape.js";
2
+ import { ASTRO_VERSION } from "../constants.js";
3
+ import { getLogger } from "../logger/manifest-logger.js";
4
+ import { req } from "../messages/runtime.js";
5
+ import { RedirectSinglePageBuiltModule } from "../redirects/index.js";
6
+ import { createModuleScriptElement, createStylesheetElementSet } from "../render/ssr-element.js";
7
+ import { getDefaultRoutes } from "../routing/default.js";
8
+ import { findRouteToRewrite } from "../routing/rewrite.js";
9
+ import { getRouteTable } from "../routing/route-table.js";
10
+ async function getModuleForRoute(manifest, route) {
11
+ for (const defaultRoute of getDefaultRoutes(manifest)) {
12
+ if (route.component === defaultRoute.component) {
13
+ return {
14
+ page: () => Promise.resolve(defaultRoute.instance)
15
+ };
16
+ }
17
+ }
18
+ if (route.type === "redirect") {
19
+ return RedirectSinglePageBuiltModule;
20
+ } else {
21
+ if (manifest.pageMap) {
22
+ const importComponentInstance = manifest.pageMap.get(route.component);
23
+ if (!importComponentInstance) {
24
+ throw new Error(
25
+ `Unexpectedly unable to find a component instance for route ${route.route}`
26
+ );
27
+ }
28
+ return await importComponentInstance();
29
+ } else if (manifest.pageModule) {
30
+ return manifest.pageModule;
31
+ }
32
+ throw new Error(
33
+ "Astro couldn't find the correct page to render, probably because it wasn't correctly mapped for SSR usage. This is an internal error, please file an issue."
34
+ );
35
+ }
36
+ }
37
+ async function getComponentByRoute(manifest, routeData) {
38
+ try {
39
+ const module2 = await getModuleForRoute(manifest, routeData);
40
+ return module2.page();
41
+ } catch {
42
+ }
43
+ const url = new URL(routeData.component, manifest.rootDir);
44
+ const module = await import(
45
+ /* @vite-ignore */
46
+ url.toString()
47
+ );
48
+ return module;
49
+ }
50
+ function createNonRunnableEnvironment() {
51
+ return {
52
+ name: "dev-nonrunnable",
53
+ runtimeMode: "development",
54
+ // Dev always streams.
55
+ defaultStreaming: () => true,
56
+ async resolve(_manifest, specifier) {
57
+ if (specifier.startsWith("/")) {
58
+ return specifier;
59
+ } else {
60
+ return "/@id/" + specifier;
61
+ }
62
+ },
63
+ async headElements(manifest, routeData) {
64
+ const { componentMetadataEntries } = await import("virtual:astro:component-metadata");
65
+ for (const [id, entry] of componentMetadataEntries) {
66
+ manifest.componentMetadata.set(id, entry);
67
+ }
68
+ const { assetsPrefix, base } = manifest;
69
+ const routeInfo = manifest.routes.find((route) => route.routeData === routeData);
70
+ const links = /* @__PURE__ */ new Set();
71
+ const scripts = /* @__PURE__ */ new Set();
72
+ const styles = createStylesheetElementSet(routeInfo?.styles ?? [], base, assetsPrefix);
73
+ for (const script of routeInfo?.scripts ?? []) {
74
+ if ("stage" in script) {
75
+ if (script.stage === "head-inline") {
76
+ scripts.add({
77
+ props: {},
78
+ children: script.children
79
+ });
80
+ }
81
+ } else {
82
+ scripts.add(createModuleScriptElement(script));
83
+ }
84
+ }
85
+ scripts.add({
86
+ props: { type: "module", src: "/@vite/client" },
87
+ children: ""
88
+ });
89
+ if (manifest.devToolbar.enabled) {
90
+ scripts.add({
91
+ props: {
92
+ type: "module",
93
+ src: "/@id/astro/runtime/client/dev-toolbar/entrypoint.js"
94
+ },
95
+ children: ""
96
+ });
97
+ const additionalMetadata = {
98
+ root: manifest.rootDir.toString(),
99
+ version: ASTRO_VERSION,
100
+ latestAstroVersion: manifest.devToolbar.latestAstroVersion,
101
+ debugInfo: manifest.devToolbar.debugInfoOutput ?? "",
102
+ placement: manifest.devToolbar.placement
103
+ };
104
+ const children = `window.__astro_dev_toolbar__ = ${stringifyForScript(additionalMetadata)}`;
105
+ scripts.add({ props: {}, children });
106
+ }
107
+ const { devCSSMap } = await import("virtual:astro:dev-css-all");
108
+ const importer = devCSSMap.get(routeData.component);
109
+ let css = /* @__PURE__ */ new Set();
110
+ if (importer) {
111
+ const cssModule = await importer();
112
+ css = cssModule.css;
113
+ } else {
114
+ getLogger(manifest).warn(
115
+ "assets",
116
+ `Unable to find CSS for ${routeData.component}. This is likely a bug in Astro.`
117
+ );
118
+ }
119
+ for (const { id, url: src, content } of css) {
120
+ scripts.add({ props: { type: "module", src }, children: "" });
121
+ styles.add({ props: { "data-vite-dev-id": id }, children: content });
122
+ }
123
+ return { scripts, styles, links };
124
+ },
125
+ componentMetadata() {
126
+ },
127
+ getComponentByRoute,
128
+ getModuleForRoute,
129
+ async tryRewrite(manifest, payload, request) {
130
+ const { newUrl, pathname, routeData } = findRouteToRewrite({
131
+ payload,
132
+ request,
133
+ // The single fresh route table: HMR route updates are visible
134
+ // to rewrites at the same instant as every other consumer.
135
+ routes: getRouteTable(manifest).routes,
136
+ trailingSlash: manifest.trailingSlash,
137
+ buildFormat: manifest.buildFormat,
138
+ base: manifest.base,
139
+ outDir: manifest.serverLike ? manifest.buildClientDir : manifest.outDir
140
+ });
141
+ const componentInstance = await getComponentByRoute(manifest, routeData);
142
+ return { newUrl, pathname, componentInstance, routeData };
143
+ },
144
+ getRenderers(manifest) {
145
+ return manifest.renderers;
146
+ },
147
+ errorStrategy: "dev",
148
+ injectCspMetaTagsOnErrorPages: false,
149
+ logRequest(manifest, payload) {
150
+ const { pathname, method, statusCode, isRewrite, timeStart } = payload;
151
+ if (pathname === "/favicon.ico") {
152
+ return;
153
+ }
154
+ const reqTime = performance.now() - timeStart;
155
+ getLogger(manifest).info(
156
+ null,
157
+ req({
158
+ url: pathname,
159
+ method,
160
+ statusCode,
161
+ isRewrite,
162
+ reqTime
163
+ })
164
+ );
165
+ }
166
+ };
167
+ }
168
+ export {
169
+ createNonRunnableEnvironment
170
+ };
@@ -0,0 +1,90 @@
1
+ import type { ComponentInstance } from '../../types/astro.js';
2
+ import type { RewritePayload } from '../../types/public/common.js';
3
+ import type { RuntimeMode } from '../../types/public/config.js';
4
+ import type { RouteData, SSRLoadedRenderer, SSRManifest, SSRResult } from '../../types/public/internal.js';
5
+ import type { LogRequestPayload } from '../app/base.js';
6
+ import type { SinglePageBuiltModule } from '../build/types.js';
7
+ /**
8
+ * The scripts, styles and links a rendering environment injects into a page's
9
+ * head for a given route. (Rehomed here from the deleted Pipeline base class.)
10
+ */
11
+ export interface HeadElements extends Pick<SSRResult, 'scripts' | 'styles' | 'links'> {
12
+ }
13
+ /**
14
+ * The result of a successful `tryRewrite` environment call.
15
+ * (Rehomed here from the deleted Pipeline base class.)
16
+ */
17
+ export interface TryRewriteResult {
18
+ routeData: RouteData;
19
+ componentInstance: ComponentInstance;
20
+ newUrl: URL;
21
+ pathname: string;
22
+ }
23
+ /**
24
+ * The payload chain sites pass to request logging (`logRequestFromState`).
25
+ * `reqTime` is computed by the receiver (facade `logThisRequest` or the env
26
+ * record) from `timeStart`.
27
+ */
28
+ export type RequestLogPayload = Omit<LogRequestPayload, 'reqTime'> & {
29
+ timeStart: number;
30
+ };
31
+ /**
32
+ * The behavior that varies between rendering environments (production SSR,
33
+ * the two dev paths, build/prerender, the container), expressed as a plain
34
+ * record of functions and flags instead of a class hierarchy. Environments
35
+ * register their record for a manifest with `setEnvironment`; readers use
36
+ * `getEnvironment`, which falls back to the production record.
37
+ *
38
+ * When adding a member:
39
+ * - Only behavior that genuinely differs between environments belongs here
40
+ * (e.g. request logging: production is silent, dev prints request lines).
41
+ * If the build can emit it as data or a module thunk, put it on the
42
+ * manifest instead; only behavior needing live services goes here.
43
+ * - The record is stateless and shared. Mutable per-app state belongs in a
44
+ * manifest-keyed memo in the module that owns it, not here.
45
+ * - Members must not capture an App instance. Environment-private services
46
+ * captured at setup time (the dev ModuleLoader, BuildInternals) are fine —
47
+ * request handling can't reach them.
48
+ * - Behavior tied to one App instance — a public method a user may override
49
+ * on their app — cannot live here, because the record is shared by every
50
+ * app in the environment. The facade forwards that per request, via the
51
+ * hooks it passes to the FetchState constructor.
52
+ */
53
+ export interface RenderEnvironment {
54
+ /** Debug label. */
55
+ readonly name: string;
56
+ readonly runtimeMode: RuntimeMode;
57
+ /** Default streaming when the facade hooks don't specify a flag. */
58
+ defaultStreaming(manifest: SSRManifest): boolean;
59
+ resolve(manifest: SSRManifest, specifier: string): Promise<string>;
60
+ headElements(manifest: SSRManifest, routeData: RouteData): Promise<HeadElements> | HeadElements;
61
+ componentMetadata(manifest: SSRManifest, routeData: RouteData): Promise<SSRResult['componentMetadata']> | void;
62
+ getComponentByRoute(manifest: SSRManifest, routeData: RouteData): Promise<ComponentInstance>;
63
+ getModuleForRoute(manifest: SSRManifest, route: RouteData): Promise<SinglePageBuiltModule>;
64
+ tryRewrite(manifest: SSRManifest, payload: RewritePayload, request: Request): Promise<TryRewriteResult>;
65
+ /** Renderers for `createResult`. Sync — render sites read it without awaiting. */
66
+ getRenderers(manifest: SSRManifest): SSRLoadedRenderer[];
67
+ /** Which error-page strategy `renderErrorPage` dispatches to. */
68
+ readonly errorStrategy: 'default' | 'dev' | 'build';
69
+ /** Dev-only CSP meta-tag injection flag for error pages. */
70
+ readonly injectCspMetaTagsOnErrorPages: boolean;
71
+ /**
72
+ * Request logging as environment behavior: prod/build/container are
73
+ * no-ops; both dev environments emit the request lines. This is the
74
+ * fallback for states not built by a facade; the facade fast path's
75
+ * `hooks.logRequest` takes precedence so subclass overrides keep working.
76
+ * Computes `reqTime` from `payload.timeStart`.
77
+ */
78
+ logRequest(manifest: SSRManifest, payload: RequestLogPayload): void;
79
+ }
80
+ /**
81
+ * Registers the environment for a manifest. Idempotent; last registration wins
82
+ * (build may re-register after internals/options injection if it prefers).
83
+ */
84
+ export declare function setEnvironment(manifest: SSRManifest, env: RenderEnvironment): void;
85
+ /**
86
+ * The environment for a manifest. Defaults to the production (bundled)
87
+ * implementation, which is derivable from the manifest alone — so a bare
88
+ * `new FetchState(request)` in a bundled worker needs no registration.
89
+ */
90
+ export declare function getEnvironment(manifest: SSRManifest): RenderEnvironment;
@@ -0,0 +1,12 @@
1
+ import { productionEnvironment } from "./production.js";
2
+ const environments = /* @__PURE__ */ new WeakMap();
3
+ function setEnvironment(manifest, env) {
4
+ environments.set(manifest, env);
5
+ }
6
+ function getEnvironment(manifest) {
7
+ return environments.get(manifest) ?? productionEnvironment;
8
+ }
9
+ export {
10
+ getEnvironment,
11
+ setEnvironment
12
+ };
@@ -0,0 +1,6 @@
1
+ import type { RenderEnvironment } from './index.js';
2
+ /**
3
+ * The production / bundled environment — the default when nothing is
4
+ * registered. A stateless module constant derived from the manifest alone.
5
+ */
6
+ export declare const productionEnvironment: RenderEnvironment;
@@ -0,0 +1,117 @@
1
+ import { RedirectSinglePageBuiltModule } from "../redirects/index.js";
2
+ import {
3
+ createAssetLink,
4
+ createModuleScriptElement,
5
+ createStylesheetElementSet
6
+ } from "../render/ssr-element.js";
7
+ import { getDefaultRoutes } from "../routing/default.js";
8
+ import { getFallbackRoute, routeIsFallback, routeIsRedirect } from "../routing/helpers.js";
9
+ import { findRouteToRewrite } from "../routing/rewrite.js";
10
+ async function getModuleForRoute(manifest, route) {
11
+ for (const defaultRoute of getDefaultRoutes(manifest)) {
12
+ if (route.component === defaultRoute.component) {
13
+ return {
14
+ page: () => Promise.resolve(defaultRoute.instance)
15
+ };
16
+ }
17
+ }
18
+ let routeToProcess = route;
19
+ if (routeIsRedirect(route)) {
20
+ if (route.redirectRoute) {
21
+ routeToProcess = route.redirectRoute;
22
+ } else {
23
+ return RedirectSinglePageBuiltModule;
24
+ }
25
+ } else if (routeIsFallback(route)) {
26
+ routeToProcess = getFallbackRoute(route, manifest.routes);
27
+ }
28
+ if (manifest.pageMap) {
29
+ const importComponentInstance = manifest.pageMap.get(routeToProcess.component);
30
+ if (!importComponentInstance) {
31
+ throw new Error(`Unexpectedly unable to find a component instance for route ${route.route}`);
32
+ }
33
+ return await importComponentInstance();
34
+ } else if (manifest.pageModule) {
35
+ return manifest.pageModule;
36
+ }
37
+ throw new Error(
38
+ "Astro couldn't find the correct page to render, probably because it wasn't correctly mapped for SSR usage. This is an internal error, please file an issue."
39
+ );
40
+ }
41
+ async function getComponentByRoute(manifest, routeData) {
42
+ const module = await getModuleForRoute(manifest, routeData);
43
+ return module.page();
44
+ }
45
+ const productionEnvironment = {
46
+ name: "production",
47
+ runtimeMode: "production",
48
+ defaultStreaming: () => true,
49
+ async resolve(manifest, specifier) {
50
+ if (!(specifier in manifest.entryModules)) {
51
+ throw new Error(`Unable to resolve [${specifier}]`);
52
+ }
53
+ const bundlePath = manifest.entryModules[specifier];
54
+ if (bundlePath.startsWith("data:") || bundlePath.length === 0) {
55
+ return bundlePath;
56
+ } else {
57
+ return createAssetLink(bundlePath, manifest.base, manifest.assetsPrefix);
58
+ }
59
+ },
60
+ async headElements(manifest, routeData) {
61
+ const { assetsPrefix, base } = manifest;
62
+ const routeInfo = manifest.routes.find((route) => route.routeData.route === routeData.route);
63
+ const links = /* @__PURE__ */ new Set();
64
+ const scripts = /* @__PURE__ */ new Set();
65
+ const styles = createStylesheetElementSet(routeInfo?.styles ?? [], base, assetsPrefix);
66
+ for (const script of routeInfo?.scripts ?? []) {
67
+ if ("stage" in script) {
68
+ if (script.stage === "head-inline") {
69
+ scripts.add({
70
+ props: {},
71
+ children: script.children
72
+ });
73
+ }
74
+ } else {
75
+ scripts.add(createModuleScriptElement(script, base, assetsPrefix));
76
+ }
77
+ }
78
+ return { links, styles, scripts };
79
+ },
80
+ // The manifest's componentMetadata fallback stays in `createResult`.
81
+ componentMetadata() {
82
+ },
83
+ getComponentByRoute,
84
+ getModuleForRoute,
85
+ async tryRewrite(manifest, payload, request) {
86
+ const { newUrl, pathname, routeData } = findRouteToRewrite({
87
+ payload,
88
+ request,
89
+ // RAW manifest routes, NOT the derived route table: production
90
+ // manifests deliberately do not carry
91
+ // the default 404 route (`createRoutesList` ensures it in dev only),
92
+ // and `findRouteToRewrite` gives an existing `/404` list entry
93
+ // precedence over dynamic routes that also match the path — so the
94
+ // ensured table would let the synthetic default-404 entry shadow a
95
+ // catch-all route on an explicit rewrite to `/404`. The no-match
96
+ // fallback already returns `DEFAULT_404_ROUTE`, so the raw list loses
97
+ // nothing.
98
+ routes: manifest.routes.map((r) => r.routeData),
99
+ trailingSlash: manifest.trailingSlash,
100
+ buildFormat: manifest.buildFormat,
101
+ base: manifest.base,
102
+ outDir: manifest.serverLike ? manifest.buildClientDir : manifest.outDir
103
+ });
104
+ const componentInstance = await getComponentByRoute(manifest, routeData);
105
+ return { newUrl, pathname, componentInstance, routeData };
106
+ },
107
+ getRenderers(manifest) {
108
+ return manifest.renderers;
109
+ },
110
+ errorStrategy: "default",
111
+ injectCspMetaTagsOnErrorPages: false,
112
+ logRequest() {
113
+ }
114
+ };
115
+ export {
116
+ productionEnvironment
117
+ };
@@ -1,17 +1,12 @@
1
- import type { BaseApp, RenderErrorOptions } from '../app/base.js';
2
- import type { Pipeline } from '../base-pipeline.js';
3
- import type { ErrorHandler } from './handler.js';
1
+ import type { RenderErrorOptions } from '../app/base.js';
2
+ import type { SSRManifest } from '../app/types.js';
4
3
  /**
5
- * The error handler used during static build / prerendering.
4
+ * The error strategy used during static build / prerendering.
6
5
  *
7
6
  * - For 500 errors, returns the original response if present, otherwise
8
7
  * throws so the build surfaces the underlying error to the developer.
9
- * - For other errors (e.g. 404), delegates to `DefaultErrorHandler` with
8
+ * - For other errors (e.g. 404), delegates to `renderDefaultError` with
10
9
  * `prerenderedErrorPageFetch` cleared (the build pipeline can't fetch
11
10
  * prerendered pages the way production SSR can).
12
11
  */
13
- export declare class BuildErrorHandler implements ErrorHandler {
14
- #private;
15
- constructor(app: BaseApp<Pipeline>);
16
- renderError(request: Request, options: RenderErrorOptions): Promise<Response>;
17
- }
12
+ export declare function renderBuildError(manifest: SSRManifest, request: Request, options: RenderErrorOptions): Promise<Response>;
@@ -1,22 +1,16 @@
1
- import { DefaultErrorHandler } from "./default-handler.js";
2
- class BuildErrorHandler {
3
- #default;
4
- constructor(app) {
5
- this.#default = new DefaultErrorHandler(app);
6
- }
7
- async renderError(request, options) {
8
- if (options.status === 500) {
9
- if (options.response) {
10
- return options.response;
11
- }
12
- throw options.error;
1
+ import { renderDefaultError } from "./default-handler.js";
2
+ async function renderBuildError(manifest, request, options) {
3
+ if (options.status === 500) {
4
+ if (options.response) {
5
+ return options.response;
13
6
  }
14
- return this.#default.renderError(request, {
15
- ...options,
16
- prerenderedErrorPageFetch: void 0
17
- });
7
+ throw options.error;
18
8
  }
9
+ return renderDefaultError(manifest, request, {
10
+ ...options,
11
+ prerenderedErrorPageFetch: void 0
12
+ });
19
13
  }
20
14
  export {
21
- BuildErrorHandler
15
+ renderBuildError
22
16
  };
@@ -1,14 +1,9 @@
1
- import type { BaseApp, RenderErrorOptions } from '../app/base.js';
2
- import type { Pipeline } from '../base-pipeline.js';
3
- import { type ErrorHandler } from './handler.js';
1
+ import type { RenderErrorOptions } from '../app/base.js';
2
+ import type { SSRManifest } from '../app/types.js';
4
3
  /**
5
- * The default error handler used in production SSR. Attempts to render the
4
+ * The default error strategy used in production SSR. Attempts to render the
6
5
  * matching error route (404.astro / 500.astro), falling back to a plain
7
6
  * response with the given status. Handles prerendered error pages via
8
7
  * `prerenderedErrorPageFetch`.
9
8
  */
10
- export declare class DefaultErrorHandler implements ErrorHandler {
11
- #private;
12
- constructor(app: BaseApp<Pipeline>);
13
- renderError(request: Request, { status, response: originalResponse, skipMiddleware, error, pathname, ...resolvedRenderOptions }: RenderErrorOptions): Promise<Response>;
14
- }
9
+ export declare function renderDefaultError(manifest: SSRManifest, request: Request, { status, response: originalResponse, skipMiddleware, error, pathname, ...resolvedRenderOptions }: RenderErrorOptions): Promise<Response>;