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,27 @@
1
+ const FetchFeatures = {
2
+ redirects: 1 << 0,
3
+ sessions: 1 << 1,
4
+ actions: 1 << 2,
5
+ middleware: 1 << 3,
6
+ i18n: 1 << 4,
7
+ cache: 1 << 5
8
+ };
9
+ const ALL_FETCH_FEATURES = FetchFeatures.redirects | FetchFeatures.sessions | FetchFeatures.actions | FetchFeatures.middleware | FetchFeatures.i18n | FetchFeatures.cache;
10
+ const usedFeatures = /* @__PURE__ */ new WeakMap();
11
+ function markFeatureUsed(manifest, feature) {
12
+ const entry = usedFeatures.get(manifest);
13
+ if (entry) {
14
+ entry.bits |= feature;
15
+ } else {
16
+ usedFeatures.set(manifest, { bits: feature });
17
+ }
18
+ }
19
+ function getUsedFeatures(manifest) {
20
+ return usedFeatures.get(manifest)?.bits ?? 0;
21
+ }
22
+ export {
23
+ ALL_FETCH_FEATURES,
24
+ FetchFeatures,
25
+ getUsedFeatures,
26
+ markFeatureUsed
27
+ };
@@ -4,8 +4,33 @@ import type { Params, Props, RewritePayload } 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 { AstroCookies } from '../cookies/index.js';
7
- import { type Pipeline } from '../render/index.js';
8
- import type { ResolvedRenderOptions } from '../app/base.js';
7
+ import type { RenderErrorOptions, ResolvedRenderOptions } from '../app/base.js';
8
+ import type { SSRManifest } from '../app/types.js';
9
+ import { type RequestLogPayload } from '../environment/index.js';
10
+ import type { AstroLogger } from '../logger/core.js';
11
+ /**
12
+ * Per-render facade inputs passed by `BaseApp.render`'s fast path to the
13
+ * internal `FetchState` constructor and stored as plain state fields.
14
+ *
15
+ * MEMBERSHIP CLAMP: frozen at `{ streaming?, renderError?, logRequest? }`.
16
+ * Any addition must be facade-INSTANCE behavior — something a public
17
+ * overridable/reassignable method dispatches — never static or per-manifest
18
+ * data. This type is never exported from a public entrypoint;
19
+ * only `BaseApp.render` constructs it; only the `FetchState` constructor
20
+ * consumes it; it is never stored on a request, in a registry, or passed to
21
+ * any other function.
22
+ */
23
+ export interface FacadeHooks {
24
+ /** Overrides the environment's `defaultStreaming` for this render. */
25
+ streaming?: boolean;
26
+ /**
27
+ * Late-bound `app.renderError` dispatch for deep chain-internal error
28
+ * reroutes (preserves cloudflare's instance-property reassignment).
29
+ */
30
+ renderError?: (request: Request, options: RenderErrorOptions) => Promise<Response>;
31
+ /** Late-bound `app.logThisRequest` dispatch (dev request lines). */
32
+ logRequest?: (payload: RequestLogPayload) => void;
33
+ }
9
34
  /**
10
35
  * The public contract of {@link FetchState} exposed to user-land code
11
36
  * (custom fetch handlers, Hono middleware, etc.).
@@ -65,7 +90,27 @@ export declare function getFetchStateFromAPIContext(context: APIContext): FetchS
65
90
  */
66
91
  export declare class FetchState implements AstroFetchState {
67
92
  #private;
68
- pipeline: Pipeline;
93
+ /** The manifest — the single ambient source of static, build-time data. */
94
+ manifest: SSRManifest;
95
+ /** The manifest's identity-stable logger, captured once at construction. */
96
+ logger: AstroLogger;
97
+ /**
98
+ * Whether page renders stream. From the facade hooks on the fast path,
99
+ * else the environment's default.
100
+ */
101
+ streaming: boolean;
102
+ /**
103
+ * Internal facade hook: late-bound `app.renderError` dispatch. Undefined on
104
+ * bare and custom-handler paths — those fall through to the environment's
105
+ * error strategy (`renderErrorPage`).
106
+ */
107
+ renderError: ((request: Request, options: RenderErrorOptions) => Promise<Response>) | undefined;
108
+ /**
109
+ * Internal facade hook: late-bound `app.logThisRequest` dispatch. Undefined
110
+ * on bare and custom-handler paths — those fall through to the
111
+ * environment's `logRequest` behavior.
112
+ */
113
+ logRequest: ((payload: RequestLogPayload) => void) | undefined;
69
114
  /**
70
115
  * The request to render. Mutated during rewrites so subsequent renders
71
116
  * see the rewritten URL.
@@ -75,7 +120,7 @@ export declare class FetchState implements AstroFetchState {
75
120
  /**
76
121
  * The pathname to use for routing and rendering. Starts out as the raw,
77
122
  * base-stripped, decoded pathname from the request. May be further
78
- * normalized by `AstroHandler` after routeData is known (in dev, when
123
+ * normalized by `handleRequest` after routeData is known (in dev, when
79
124
  * the matched route has no `.html` extension, `.html` / `/index.html`
80
125
  * suffixes are stripped).
81
126
  */
@@ -102,7 +147,7 @@ export declare class FetchState implements AstroFetchState {
102
147
  response: Response | undefined;
103
148
  /**
104
149
  * Default HTTP status for the rendered response. Callers override
105
- * before rendering runs (e.g. `AstroHandler` sets this from
150
+ * before rendering runs (e.g. `handleRequest` sets this from
106
151
  * `BaseApp.getDefaultStatusCode`; error handlers set `404` / `500`).
107
152
  */
108
153
  status: number;
@@ -150,9 +195,9 @@ export declare class FetchState implements AstroFetchState {
150
195
  result: SSRResult | undefined;
151
196
  /** Initial props (from container/error handler). */
152
197
  initialProps: Props;
153
- constructor(pipeline: Pipeline, request: Request, options?: ResolvedRenderOptions);
198
+ constructor(manifest: SSRManifest, request: Request, options?: ResolvedRenderOptions, hooks?: FacadeHooks);
154
199
  /**
155
- * Triggers a rewrite. Delegates to the Rewrites handler.
200
+ * Triggers a rewrite. Delegates to the rewrites handler module.
156
201
  */
157
202
  rewrite(payload: RewritePayload): Promise<Response>;
158
203
  /**
@@ -1,20 +1,17 @@
1
1
  import colors from "piccolore";
2
2
  import {
3
- collapseDuplicateLeadingSlashes,
4
3
  collapseDuplicateSlashes,
5
4
  prependForwardSlash,
6
- removeTrailingForwardSlash
5
+ stripRequestBase
7
6
  } from "@astrojs/internal-helpers/path";
8
7
  import { deserializeActionResult } from "../../actions/runtime/client.js";
9
8
  import { createCallAction, createGetActionResult, hasActionPayload } from "../../actions/utils.js";
10
9
  import { AstroCookies } from "../cookies/index.js";
11
10
  import { Slots } from "../render/index.js";
12
11
  import {
13
- appSymbol,
14
12
  ASTRO_GENERATOR,
15
13
  fetchStateSymbol,
16
14
  originPathnameSymbol,
17
- pipelineSymbol,
18
15
  responseSentSymbol
19
16
  } from "../constants.js";
20
17
  import { normalizeCspResourceEntry, pushDirective } from "../csp/runtime.js";
@@ -27,7 +24,7 @@ import {
27
24
  computePreferredLocaleList as computePreferredLocaleListUtil
28
25
  } from "../../i18n/utils.js";
29
26
  import { getParams, getProps } from "../render/index.js";
30
- import { Rewrites } from "../rewrites/handler.js";
27
+ import { executeRewrite } from "../rewrites/handler.js";
31
28
  import { isRoute404or500, isRouteServerIsland } from "../routing/match.js";
32
29
  import { MultiLevelEncodingError, validateAndDecodePathname } from "../util/pathname.js";
33
30
  import { getOriginPathname, setOriginPathname } from "../routing/rewrite.js";
@@ -35,6 +32,12 @@ import { computePathnameFromDomain } from "../i18n/domain.js";
35
32
  import { getCustom404Route, routeHasHtmlExtension } from "../routing/helpers.js";
36
33
  import { getRenderOptions } from "../app/render-options.js";
37
34
  import { getFirstForwardedValue, validateForwardedHeaders } from "../app/validate-headers.js";
35
+ import { getEnvironment } from "../environment/index.js";
36
+ import { getLogger } from "../logger/manifest-logger.js";
37
+ import { getSite } from "../manifest/derived.js";
38
+ import { getRouteCache } from "../render/route-cache.js";
39
+ import { getRouteTable, matchAllRoutes, matchRoute } from "../routing/route-table.js";
40
+ import { getServerIslands } from "../server-islands/mappings.js";
38
41
  function getFetchStateFromAPIContext(context) {
39
42
  const state = context[fetchStateSymbol];
40
43
  if (!state) {
@@ -45,7 +48,27 @@ function getFetchStateFromAPIContext(context) {
45
48
  return state;
46
49
  }
47
50
  class FetchState {
48
- pipeline;
51
+ /** The manifest — the single ambient source of static, build-time data. */
52
+ manifest;
53
+ /** The manifest's identity-stable logger, captured once at construction. */
54
+ logger;
55
+ /**
56
+ * Whether page renders stream. From the facade hooks on the fast path,
57
+ * else the environment's default.
58
+ */
59
+ streaming;
60
+ /**
61
+ * Internal facade hook: late-bound `app.renderError` dispatch. Undefined on
62
+ * bare and custom-handler paths — those fall through to the environment's
63
+ * error strategy (`renderErrorPage`).
64
+ */
65
+ renderError;
66
+ /**
67
+ * Internal facade hook: late-bound `app.logThisRequest` dispatch. Undefined
68
+ * on bare and custom-handler paths — those fall through to the
69
+ * environment's `logRequest` behavior.
70
+ */
71
+ logRequest;
49
72
  /**
50
73
  * The request to render. Mutated during rewrites so subsequent renders
51
74
  * see the rewritten URL.
@@ -55,7 +78,7 @@ class FetchState {
55
78
  /**
56
79
  * The pathname to use for routing and rendering. Starts out as the raw,
57
80
  * base-stripped, decoded pathname from the request. May be further
58
- * normalized by `AstroHandler` after routeData is known (in dev, when
81
+ * normalized by `handleRequest` after routeData is known (in dev, when
59
82
  * the matched route has no `.html` extension, `.html` / `/index.html`
60
83
  * suffixes are stripped).
61
84
  */
@@ -82,7 +105,7 @@ class FetchState {
82
105
  response;
83
106
  /**
84
107
  * Default HTTP status for the rendered response. Callers override
85
- * before rendering runs (e.g. `AstroHandler` sets this from
108
+ * before rendering runs (e.g. `handleRequest` sets this from
86
109
  * `BaseApp.getDefaultStatusCode`; error handlers set `404` / `500`).
87
110
  */
88
111
  status = 200;
@@ -145,8 +168,6 @@ class FetchState {
145
168
  result;
146
169
  /** Initial props (from container/error handler). */
147
170
  initialProps = {};
148
- /** Rewrites handler instance. Lazy-initialized on first rewrite(). */
149
- #rewrites;
150
171
  /** Memoized Astro page partial. */
151
172
  #astroPagePartial;
152
173
  /**
@@ -162,8 +183,12 @@ class FetchState {
162
183
  #preferredLocale;
163
184
  /** Memoized preferred locale list. */
164
185
  #preferredLocaleList;
165
- constructor(pipeline, request, options) {
166
- this.pipeline = pipeline;
186
+ constructor(manifest, request, options, hooks) {
187
+ this.manifest = manifest;
188
+ this.logger = getLogger(manifest);
189
+ this.streaming = hooks?.streaming ?? getEnvironment(manifest).defaultStreaming(manifest);
190
+ this.renderError = hooks?.renderError;
191
+ this.logRequest = hooks?.logRequest;
167
192
  this.request = request;
168
193
  options ??= getRenderOptions(request);
169
194
  this.routeData = options?.routeData;
@@ -190,10 +215,10 @@ class FetchState {
190
215
  const domainPathname = computePathnameFromDomain(
191
216
  request,
192
217
  url,
193
- pipeline.manifest.i18n,
194
- pipeline.manifest.base,
195
- pipeline.manifest.trailingSlash,
196
- pipeline.logger,
218
+ manifest.i18n,
219
+ manifest.base,
220
+ manifest.trailingSlash,
221
+ this.logger,
197
222
  pathname
198
223
  );
199
224
  if (domainPathname) {
@@ -207,33 +232,31 @@ class FetchState {
207
232
  this.locals = options?.locals ?? {};
208
233
  this.url = url;
209
234
  this.cookies = new AstroCookies(request);
210
- if (pipeline.manifest.allowedDomains && pipeline.manifest.allowedDomains.length > 0 && !this.routeData?.prerender) {
235
+ if (manifest.allowedDomains && manifest.allowedDomains.length > 0 && !this.routeData?.prerender) {
211
236
  this.#applyForwardedHeaders();
212
237
  }
213
238
  if (!Reflect.get(this.request, originPathnameSymbol)) {
214
- setOriginPathname(
215
- this.request,
216
- this.pathname,
217
- pipeline.manifest.trailingSlash,
218
- pipeline.manifest.buildFormat
219
- );
239
+ setOriginPathname(this.request, this.pathname, manifest.trailingSlash, manifest.buildFormat);
220
240
  }
221
241
  this.#resolveRouteData();
222
242
  }
223
243
  /**
224
- * Triggers a rewrite. Delegates to the Rewrites handler.
244
+ * Triggers a rewrite. Delegates to the rewrites handler module.
225
245
  */
226
246
  rewrite(payload) {
227
- return (this.#rewrites ??= new Rewrites()).execute(this, payload);
247
+ return executeRewrite(this, payload);
228
248
  }
229
249
  /**
230
250
  * Creates the SSR result for the current page render.
231
251
  */
232
252
  async createResult(mod, ctx) {
233
- const pipeline = this.pipeline;
234
- const { clientDirectives, inlinedScripts, compressHTML, manifest, renderers, resolve } = pipeline;
253
+ const manifest = this.manifest;
254
+ const env = getEnvironment(manifest);
255
+ const { clientDirectives, inlinedScripts, compressHTML } = manifest;
256
+ const renderers = env.getRenderers(manifest);
257
+ const resolve = (specifier) => env.resolve(manifest, specifier);
235
258
  const routeData = this.routeData;
236
- const { links, scripts, styles } = await pipeline.headElements(routeData);
259
+ const { links, scripts, styles } = await env.headElements(manifest, routeData);
237
260
  const extraStyleHashes = [];
238
261
  const extraScriptHashes = [];
239
262
  const shouldInjectCspMetaTags = this.shouldInjectCspMetaTags ?? manifest.shouldInjectCspMetaTags;
@@ -246,7 +269,7 @@ class FetchState {
246
269
  extraScriptHashes.push(await generateCspDigest(script.children, cspAlgorithm));
247
270
  }
248
271
  }
249
- const componentMetadata = await pipeline.componentMetadata(routeData) ?? manifest.componentMetadata;
272
+ const componentMetadata = await env.componentMetadata(manifest, routeData) ?? manifest.componentMetadata;
250
273
  const headers = new Headers({ "Content-Type": "text/html" });
251
274
  const partial = typeof this.partial === "boolean" ? this.partial : Boolean(mod.partial);
252
275
  const actionResult = hasActionPayload(this.locals) ? deserializeActionResult(this.locals._actionPayload.actionResult) : void 0;
@@ -286,7 +309,7 @@ class FetchState {
286
309
  styles,
287
310
  actionResult,
288
311
  async getServerIslandNameMap() {
289
- const serverIslands = await pipeline.getServerIslands();
312
+ const serverIslands = await getServerIslands(manifest);
290
313
  return serverIslands.serverIslandNameMap ?? /* @__PURE__ */ new Map();
291
314
  },
292
315
  key: manifest.key,
@@ -355,11 +378,7 @@ class FetchState {
355
378
  Object.defineProperty(Astro, "slots", {
356
379
  get: () => {
357
380
  if (!_slots) {
358
- _slots = new Slots(
359
- result,
360
- slotValues,
361
- this.pipeline.logger
362
- );
381
+ _slots = new Slots(result, slotValues, this.logger);
363
382
  }
364
383
  return _slots;
365
384
  }
@@ -371,7 +390,7 @@ class FetchState {
371
390
  */
372
391
  createAstroPagePartial(result, apiContext) {
373
392
  const state = this;
374
- const { cookies, locals, params, pipeline, url } = this;
393
+ const { cookies, locals, params, logger, url } = this;
375
394
  const { response } = result;
376
395
  const redirect = (path, status = 302) => {
377
396
  if (state.request[responseSentSymbol]) {
@@ -408,7 +427,7 @@ class FetchState {
408
427
  rewrite,
409
428
  request: this.request,
410
429
  response,
411
- site: pipeline.site,
430
+ site: getSite(this.manifest),
412
431
  getActionResult: createGetActionResult(locals),
413
432
  get callAction() {
414
433
  return callAction;
@@ -423,13 +442,13 @@ class FetchState {
423
442
  get logger() {
424
443
  return {
425
444
  info(msg) {
426
- pipeline.logger.info(null, msg);
445
+ logger.info(null, msg);
427
446
  },
428
447
  warn(msg) {
429
- pipeline.logger.warn(null, msg);
448
+ logger.warn(null, msg);
430
449
  },
431
450
  error(msg) {
432
- pipeline.logger.error(null, msg);
451
+ logger.error(null, msg);
433
452
  }
434
453
  };
435
454
  }
@@ -438,7 +457,7 @@ class FetchState {
438
457
  return partial;
439
458
  }
440
459
  getClientAddress() {
441
- const { pipeline, clientAddress } = this;
460
+ const { clientAddress } = this;
442
461
  const routeData = this.routeData;
443
462
  if (routeData.prerender) {
444
463
  throw new AstroError({
@@ -449,10 +468,10 @@ class FetchState {
449
468
  if (clientAddress) {
450
469
  return clientAddress;
451
470
  }
452
- if (pipeline.adapterName) {
471
+ if (this.manifest.adapterName) {
453
472
  throw new AstroError({
454
473
  ...AstroErrorData.ClientAddressNotAvailable,
455
- message: AstroErrorData.ClientAddressNotAvailable.message(pipeline.adapterName)
474
+ message: AstroErrorData.ClientAddressNotAvailable.message(this.manifest.adapterName)
456
475
  });
457
476
  }
458
477
  throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable);
@@ -462,10 +481,9 @@ class FetchState {
462
481
  }
463
482
  getCsp() {
464
483
  const state = this;
465
- const { pipeline } = this;
466
- if (!pipeline.manifest.csp) {
467
- if (pipeline.runtimeMode === "production") {
468
- pipeline.logger.warn(
484
+ if (!this.manifest.csp) {
485
+ if (getEnvironment(this.manifest).runtimeMode === "production") {
486
+ this.logger.warn(
469
487
  "csp",
470
488
  `context.csp was used when rendering the route ${colors.green(state.routeData.route)}, but CSP was not configured. For more information, see https://docs.astro.build/en/reference/configuration-reference/#securitycsp`
471
489
  );
@@ -489,7 +507,7 @@ class FetchState {
489
507
  warnedFallback.add(key);
490
508
  const general = `${family}-src`;
491
509
  const specific = `${general}-${kind === "element" ? "elem" : "attr"}`;
492
- pipeline.logger.warn(
510
+ state.logger.warn(
493
511
  "csp",
494
512
  `A resource was added to \`${specific}\`, but \`${general}\` also defines custom resources (${defaultResources.join(
495
513
  " "
@@ -523,7 +541,7 @@ class FetchState {
523
541
  computeCurrentLocale() {
524
542
  const {
525
543
  url,
526
- pipeline: { i18n },
544
+ manifest: { i18n },
527
545
  routeData
528
546
  } = this;
529
547
  if (!i18n || !routeData) return;
@@ -567,7 +585,7 @@ class FetchState {
567
585
  }
568
586
  computePreferredLocale() {
569
587
  const {
570
- pipeline: { i18n },
588
+ manifest: { i18n },
571
589
  request
572
590
  } = this;
573
591
  if (!i18n) return;
@@ -575,7 +593,7 @@ class FetchState {
575
593
  }
576
594
  computePreferredLocaleList() {
577
595
  const {
578
- pipeline: { i18n },
596
+ manifest: { i18n },
579
597
  request
580
598
  } = this;
581
599
  if (!i18n) return;
@@ -589,7 +607,7 @@ class FetchState {
589
607
  async loadComponentInstance() {
590
608
  if (this.componentInstance) return this.componentInstance;
591
609
  if (this.#componentInstancePromise) return this.#componentInstancePromise;
592
- this.#componentInstancePromise = this.pipeline.getComponentByRoute(this.routeData).then((mod) => {
610
+ this.#componentInstancePromise = getEnvironment(this.manifest).getComponentByRoute(this.manifest, this.routeData).then((mod) => {
593
611
  this.componentInstance = mod;
594
612
  return mod;
595
613
  });
@@ -666,7 +684,7 @@ class FetchState {
666
684
  get() {
667
685
  if (!warned) {
668
686
  warned = true;
669
- state.pipeline.logger.warn(
687
+ state.logger.warn(
670
688
  "session",
671
689
  "`Astro.session` was accessed but no session storage is configured. Either configure the storage manually or use an adapter that provides session storage. For more information, see https://docs.astro.build/en/guides/sessions/"
672
690
  );
@@ -704,18 +722,20 @@ class FetchState {
704
722
  #stripHtmlExtension() {
705
723
  if (this.routeData && this.routeData.type === "page" && !routeHasHtmlExtension(this.routeData)) {
706
724
  this.pathname = this.pathname.replace(/\/index\.html$/, "/").replace(/\.html$/, "");
725
+ if (this.manifest.trailingSlash === "always" && this.pathname !== "" && !this.pathname.endsWith("/")) {
726
+ this.pathname += "/";
727
+ }
707
728
  }
708
729
  }
709
730
  #resolveRouteData() {
710
- const pipeline = this.pipeline;
711
731
  if (this.routeData) {
712
732
  this.#stripHtmlExtension();
713
733
  return;
714
734
  }
715
- const matched = pipeline.matchRoute(this.pathname);
716
- if (matched && matched.prerender && pipeline.manifest.serverLike) {
735
+ const matched = matchRoute(this.manifest, this.pathname);
736
+ if (matched && matched.prerender && this.manifest.serverLike) {
717
737
  if (matched.params.length > 0) {
718
- const allMatches = pipeline.matchAllRoutes(this.pathname);
738
+ const allMatches = matchAllRoutes(this.manifest, this.pathname);
719
739
  this.routeData = allMatches.find((r) => !r.prerender);
720
740
  } else {
721
741
  this.routeData = void 0;
@@ -723,37 +743,31 @@ class FetchState {
723
743
  } else {
724
744
  this.routeData = matched;
725
745
  }
726
- pipeline.logger.debug("router", "Astro matched the following route for " + this.request.url);
727
- pipeline.logger.debug("router", "RouteData:\n" + this.routeData);
746
+ this.logger.debug("router", "Astro matched the following route for " + this.request.url);
747
+ this.logger.debug("router", "RouteData:\n" + this.routeData);
728
748
  if (!this.routeData) {
729
- const custom404 = getCustom404Route(pipeline.manifestData);
749
+ const custom404 = getCustom404Route(getRouteTable(this.manifest));
730
750
  if (custom404 && !custom404.prerender) {
731
751
  this.routeData = custom404;
732
752
  }
733
753
  }
734
754
  if (!this.routeData) {
735
- pipeline.logger.debug("router", "Astro hasn't found routes that match " + this.request.url);
736
- pipeline.logger.debug("router", "Here's the available routes:\n", pipeline.manifestData);
755
+ this.logger.debug("router", "Astro hasn't found routes that match " + this.request.url);
756
+ this.logger.debug("router", "Here's the available routes:\n", getRouteTable(this.manifest));
737
757
  return;
738
758
  }
739
759
  this.#stripHtmlExtension();
740
760
  }
741
761
  /**
742
- * Strips the pipeline's base from a normalized request pathname and prepends
762
+ * Strips the manifest's base from a normalized request pathname and prepends
743
763
  * a forward slash.
744
764
  *
745
- * Mirrors `BaseApp.removeBase`, including the
746
- * `collapseDuplicateLeadingSlashes` fix that prevents middleware
747
- * authorization bypass when the URL starts with `//`.
765
+ * Mirrors `BaseApp.removeBase`: the router matches against this stripped path
766
+ * while middleware reads the un-stripped `context.url.pathname`, so both must
767
+ * strip the base identically.
748
768
  */
749
769
  #computePathname(normalizedPathname) {
750
- let pathname = collapseDuplicateLeadingSlashes(normalizedPathname);
751
- const base = this.pipeline.manifest.base;
752
- if (pathname.startsWith(base)) {
753
- const baseWithoutTrailingSlash = removeTrailingForwardSlash(base);
754
- pathname = pathname.slice(baseWithoutTrailingSlash.length + 1);
755
- }
756
- return prependForwardSlash(pathname);
770
+ return prependForwardSlash(stripRequestBase(normalizedPathname, this.manifest.base));
757
771
  }
758
772
  /**
759
773
  * Decodes and normalizes the public request pathname before deriving the
@@ -766,7 +780,7 @@ class FetchState {
766
780
  if (e instanceof MultiLevelEncodingError) {
767
781
  this.invalidEncoding = true;
768
782
  } else {
769
- this.pipeline.logger.error(null, e.toString());
783
+ this.logger.error(null, e.toString());
770
784
  }
771
785
  }
772
786
  return collapseDuplicateSlashes(pathname);
@@ -782,7 +796,7 @@ class FetchState {
782
796
  */
783
797
  #applyForwardedHeaders() {
784
798
  const headers = this.request.headers;
785
- const allowedDomains = this.pipeline.manifest.allowedDomains;
799
+ const allowedDomains = this.manifest.allowedDomains;
786
800
  const validated = validateForwardedHeaders(
787
801
  getFirstForwardedValue(headers.get("x-forwarded-proto") ?? void 0),
788
802
  getFirstForwardedValue(headers.get("x-forwarded-host") ?? void 0),
@@ -815,12 +829,7 @@ class FetchState {
815
829
  this.clientAddress = forwardedFor;
816
830
  }
817
831
  }
818
- const oldRequest = this.request;
819
- this.request = new Request(this.url, oldRequest);
820
- const app = Reflect.get(oldRequest, appSymbol);
821
- if (app !== void 0) {
822
- Reflect.set(this.request, appSymbol, app);
823
- }
832
+ this.request = new Request(this.url, this.request);
824
833
  }
825
834
  /**
826
835
  * Returns the resolved `props` for this render, computing them lazily
@@ -834,17 +843,16 @@ class FetchState {
834
843
  this.props = this.initialProps;
835
844
  return this.props;
836
845
  }
837
- const pipeline = this.pipeline;
838
846
  const mod = await this.loadComponentInstance();
839
847
  this.props = await getProps({
840
848
  mod,
841
849
  routeData: this.routeData,
842
- routeCache: pipeline.routeCache,
850
+ routeCache: getRouteCache(this.manifest),
843
851
  pathname: this.pathname,
844
- logger: pipeline.logger,
845
- serverLike: pipeline.manifest.serverLike,
846
- base: pipeline.manifest.base,
847
- trailingSlash: pipeline.manifest.trailingSlash
852
+ logger: this.logger,
853
+ serverLike: this.manifest.serverLike,
854
+ base: this.manifest.base,
855
+ trailingSlash: this.manifest.trailingSlash
848
856
  });
849
857
  return this.props;
850
858
  }
@@ -884,7 +892,7 @@ class FetchState {
884
892
  return state.computePreferredLocaleList();
885
893
  },
886
894
  request: this.request,
887
- site: this.pipeline.site,
895
+ site: getSite(this.manifest),
888
896
  url: this.url,
889
897
  get originPathname() {
890
898
  return getOriginPathname(state.request);
@@ -895,13 +903,13 @@ class FetchState {
895
903
  get logger() {
896
904
  return {
897
905
  info(msg) {
898
- state.pipeline.logger.info(null, msg);
906
+ state.logger.info(null, msg);
899
907
  },
900
908
  warn(msg) {
901
- state.pipeline.logger.warn(null, msg);
909
+ state.logger.warn(null, msg);
902
910
  },
903
911
  error(msg) {
904
- state.pipeline.logger.error(null, msg);
912
+ state.logger.error(null, msg);
905
913
  }
906
914
  };
907
915
  }
@@ -925,7 +933,6 @@ class FetchState {
925
933
  const rewrite = async (reroutePayload) => {
926
934
  return await state.rewrite(reroutePayload);
927
935
  };
928
- Reflect.set(actionApiContext, pipelineSymbol, this.pipeline);
929
936
  actionApiContext[fetchStateSymbol] = this;
930
937
  this.apiContext = Object.assign(actionApiContext, {
931
938
  props: this.props,
@@ -1,6 +1,12 @@
1
1
  import { FetchState as BaseFetchState } from './fetch-state.js';
2
2
  import type { AstroFetchState } from './fetch-state.js';
3
3
  export type { AstroFetchState };
4
+ /**
5
+ * The public per-request state, constructible from a bare `Request`.
6
+ * Static, build-time data comes from the ambient manifest — the manifest
7
+ * module bundled into every Astro-built server — so no app, pipeline, or
8
+ * request-attached handle is needed.
9
+ */
4
10
  export declare class FetchState extends BaseFetchState {
5
11
  constructor(request: Request);
6
12
  }
@@ -52,9 +58,10 @@ export declare function redirects(state: FetchState): Promise<Response> | undefi
52
58
  */
53
59
  export declare function actions(state: FetchState): Promise<Response | undefined> | undefined;
54
60
  /**
55
- * Post-processes a response against the app's i18n configuration.
61
+ * Post-processes a response against the manifest's i18n configuration.
56
62
  * Handles locale redirects, 404s for invalid locales, and fallback
57
- * routing. Returns the response unmodified if i18n is not configured.
63
+ * routing. Returns the response unmodified if i18n is not configured
64
+ * (or the routing strategy is `manual`).
58
65
  */
59
66
  export declare function i18n(state: FetchState, response: Response): Promise<Response>;
60
67
  /**