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
@@ -1,67 +1,30 @@
1
- import { ActionHandler } from "../../actions/handler.js";
1
+ import { handleAction } from "../../actions/handler.js";
2
2
  import { FetchState as BaseFetchState } from "./fetch-state.js";
3
- import { CacheHandler } from "../cache/handler.js";
4
- import { appSymbol } from "../constants.js";
5
- import { I18n } from "../i18n/handler.js";
6
- import { AstroMiddleware } from "../middleware/astro-middleware.js";
7
- import { PagesHandler } from "../pages/handler.js";
3
+ import { handleCache } from "../cache/handler.js";
4
+ import { finalizeI18n, getI18n } from "../i18n/handler.js";
5
+ import { getAmbientManifest } from "../manifest/ambient.js";
6
+ import { handleMiddlewareWithErrorFallback } from "../middleware/astro-middleware.js";
7
+ import { handlePagesWithErrorFallback } from "../pages/handler.js";
8
8
  import { renderRedirect } from "../redirects/render.js";
9
- import { AstroHandler } from "../routing/handler.js";
9
+ import { handleRequest } from "../routing/handler.js";
10
10
  import { provideSession } from "../session/provider.js";
11
- import { TrailingSlashHandler } from "../routing/trailing-slash-handler.js";
12
- function getApp(request) {
13
- const app = Reflect.get(request, appSymbol);
14
- if (!app) {
15
- throw new Error(
16
- "FetchState(request) called on a request without an attached app. Ensure it runs inside Astro's request pipeline."
17
- );
18
- }
19
- return app;
20
- }
11
+ import { handleTrailingSlash } from "../routing/trailing-slash-handler.js";
21
12
  class FetchState extends BaseFetchState {
22
13
  constructor(request) {
23
- super(getApp(request).pipeline, request);
14
+ super(getAmbientManifest(), request);
24
15
  }
25
16
  }
26
- const astroHandlers = /* @__PURE__ */ new WeakMap();
27
17
  function astro(state) {
28
- const app = getApp(state.request);
29
- let handler = astroHandlers.get(app);
30
- if (!handler) {
31
- handler = new AstroHandler(app);
32
- astroHandlers.set(app, handler);
33
- }
34
- return handler.handle(state);
18
+ return handleRequest(state);
35
19
  }
36
- const trailingSlashHandlers = /* @__PURE__ */ new WeakMap();
37
20
  function trailingSlash(state) {
38
- const app = getApp(state.request);
39
- let handler = trailingSlashHandlers.get(app);
40
- if (!handler) {
41
- handler = new TrailingSlashHandler(app);
42
- trailingSlashHandlers.set(app, handler);
43
- }
44
- return handler.handle(state);
21
+ return handleTrailingSlash(state);
45
22
  }
46
- const middlewareInstances = /* @__PURE__ */ new WeakMap();
47
23
  function middleware(state, next) {
48
- const app = getApp(state.request);
49
- let mw = middlewareInstances.get(app);
50
- if (!mw) {
51
- mw = new AstroMiddleware(app.pipeline);
52
- middlewareInstances.set(app, mw);
53
- }
54
- return mw.handleWithErrorFallback(app, state, (s, _ctx) => next(s));
24
+ return handleMiddlewareWithErrorFallback(state, (s, _ctx) => next(s));
55
25
  }
56
- const pagesHandlers = /* @__PURE__ */ new WeakMap();
57
26
  function pages(state) {
58
- const app = getApp(state.request);
59
- let handler = pagesHandlers.get(app);
60
- if (!handler) {
61
- handler = new PagesHandler(app.pipeline);
62
- pagesHandlers.set(app, handler);
63
- }
64
- return handler.handleWithErrorFallback(app, state);
27
+ return handlePagesWithErrorFallback(state);
65
28
  }
66
29
  function sessions(state) {
67
30
  return provideSession(state);
@@ -72,40 +35,16 @@ function redirects(state) {
72
35
  }
73
36
  return void 0;
74
37
  }
75
- const actionHandlers = /* @__PURE__ */ new WeakMap();
76
38
  function actions(state) {
77
- const app = getApp(state.request);
78
- let handler = actionHandlers.get(app);
79
- if (!handler) {
80
- handler = new ActionHandler();
81
- actionHandlers.set(app, handler);
82
- }
83
- return handler.handle(state.getAPIContext(), state);
84
- }
85
- const i18nHandlers = /* @__PURE__ */ new WeakMap();
86
- function getI18n(app) {
87
- let handler = i18nHandlers.get(app);
88
- if (handler === void 0) {
89
- const config = app.manifest.i18n;
90
- handler = config && config.strategy !== "manual" ? new I18n(config, app.manifest.base, app.manifest.trailingSlash, app.manifest.buildFormat) : null;
91
- i18nHandlers.set(app, handler);
92
- }
93
- return handler;
39
+ return handleAction(state.getAPIContext(), state);
94
40
  }
95
41
  function i18n(state, response) {
96
- const handler = getI18n(getApp(state.request));
97
- if (!handler) return Promise.resolve(response);
98
- return handler.finalize(state, response);
42
+ const compiled = getI18n(state.manifest);
43
+ if (!compiled) return Promise.resolve(response);
44
+ return finalizeI18n(compiled, state, response);
99
45
  }
100
- const cacheHandlers = /* @__PURE__ */ new WeakMap();
101
46
  function cache(state, next) {
102
- const app = getApp(state.request);
103
- let handler = cacheHandlers.get(app);
104
- if (!handler) {
105
- handler = new CacheHandler(app);
106
- cacheHandlers.set(app, handler);
107
- }
108
- return handler.handle(state, next);
47
+ return handleCache(state, next);
109
48
  }
110
49
  export {
111
50
  FetchState,
@@ -63,7 +63,8 @@ function vitePluginFetchable({ settings }) {
63
63
  }
64
64
  return {
65
65
  code: `import { DefaultFetchHandler } from 'astro/app/fetch/default-handler';
66
- export default new DefaultFetchHandler();`
66
+ export default new DefaultFetchHandler();
67
+ export const isDefaultFetchHandler = true;`
67
68
  };
68
69
  }
69
70
  }
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  appendForwardSlash,
3
- collapseDuplicateLeadingSlashes,
4
3
  joinPaths,
5
4
  prependForwardSlash,
6
- removeTrailingForwardSlash
5
+ removeTrailingForwardSlash,
6
+ stripRequestBase
7
7
  } from "@astrojs/internal-helpers/path";
8
8
  import { normalizeTheLocale } from "../../i18n/path.js";
9
9
  function computePathnameFromDomain(request, url, i18n, base, trailingSlash, logger, pathnameFromRequest) {
@@ -32,13 +32,13 @@ function computePathnameFromDomain(request, url, i18n, base, trailingSlash, logg
32
32
  }
33
33
  }
34
34
  if (locale) {
35
- const requestPathname = pathnameFromRequest ?? removeBase(url.pathname, base);
35
+ const requestPathname = pathnameFromRequest ?? stripRequestBase(url.pathname, base);
36
36
  pathname = prependForwardSlash(joinPaths(normalizeTheLocale(locale), requestPathname));
37
37
  if (trailingSlash === "always") {
38
38
  pathname = appendForwardSlash(pathname);
39
39
  } else if (trailingSlash === "never") {
40
40
  pathname = removeTrailingForwardSlash(pathname);
41
- } else if (requestPathname.endsWith("/")) {
41
+ } else if (url.pathname.endsWith("/")) {
42
42
  pathname = appendForwardSlash(pathname);
43
43
  }
44
44
  }
@@ -53,13 +53,6 @@ function computePathnameFromDomain(request, url, i18n, base, trailingSlash, logg
53
53
  }
54
54
  return pathname;
55
55
  }
56
- function removeBase(pathname, base) {
57
- pathname = collapseDuplicateLeadingSlashes(pathname);
58
- if (pathname.startsWith(base)) {
59
- return pathname.slice(removeTrailingForwardSlash(base).length + 1);
60
- }
61
- return pathname;
62
- }
63
56
  export {
64
57
  computePathnameFromDomain
65
58
  };
@@ -1,18 +1,33 @@
1
+ import { I18nRouter } from '../../i18n/router.js';
1
2
  import type { SSRManifest } from '../app/types.js';
2
3
  import type { FetchState } from '../fetch/fetch-state.js';
3
4
  /**
4
- * Post-processes a rendered `Response` against the app's i18n
5
- * configuration. This is the logic that previously ran as the internal
6
- * `createI18nMiddleware` middleware — lifted out of the middleware layer
7
- * so it runs as an explicit step in `AstroHandler.render` after the
8
- * middleware chain returns.
9
- *
10
- * Public entry points in `astro:i18n` (`createMiddleware`) preserve the
11
- * middleware-shaped API by wrapping an `I18n` instance in a
12
- * `MiddlewareHandler` closure.
5
+ * The compiled i18n configuration for a manifest: the config values plus the
6
+ * `I18nRouter` (with its inverted domain lookup table), compiled once and
7
+ * reused across requests.
13
8
  */
14
- export declare class I18n {
15
- #private;
16
- constructor(i18n: NonNullable<SSRManifest['i18n']>, base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash'], format: SSRManifest['buildFormat']);
17
- finalize(state: FetchState, response: Response): Promise<Response>;
9
+ export interface CompiledI18n {
10
+ config: NonNullable<SSRManifest['i18n']>;
11
+ base: SSRManifest['base'];
12
+ trailingSlash: SSRManifest['trailingSlash'];
13
+ format: SSRManifest['buildFormat'];
14
+ router: I18nRouter;
18
15
  }
16
+ /**
17
+ * Pure compile from explicit values — used by `astro:i18n`'s manual-mode
18
+ * middleware wrapper (`src/i18n/middleware.ts`), which receives the values as
19
+ * arguments rather than reading a manifest.
20
+ */
21
+ export declare function compileI18n(i18n: NonNullable<SSRManifest['i18n']>, base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash'], format: SSRManifest['buildFormat']): CompiledI18n;
22
+ /**
23
+ * The compiled i18n post-processor for a manifest, or `null` when i18n is
24
+ * unset or the routing strategy is `manual`.
25
+ */
26
+ export declare function getI18n(manifest: SSRManifest): CompiledI18n | null;
27
+ /**
28
+ * Post-processes a rendered `Response` against the compiled i18n
29
+ * configuration, as an explicit step in `handleRequest` after the middleware
30
+ * chain returns. The manual-strategy public API (`astro:i18n.middleware(...)`)
31
+ * wraps this in a middleware-shaped closure.
32
+ */
33
+ export declare function finalizeI18n(compiled: CompiledI18n, state: FetchState, response: Response): Promise<Response>;
@@ -1,116 +1,116 @@
1
1
  import { appendForwardSlash } from "@astrojs/internal-helpers/path";
2
2
  import { computeFallbackRoute } from "../../i18n/fallback.js";
3
3
  import { I18nRouter } from "../../i18n/router.js";
4
- import { PipelineFeatures } from "../base-pipeline.js";
4
+ import { markFeatureUsed, FetchFeatures } from "../fetch/features.js";
5
5
  import { shouldAppendForwardSlash } from "../build/util.js";
6
- class I18n {
7
- #i18n;
8
- #base;
9
- #trailingSlash;
10
- #format;
11
- #router;
12
- constructor(i18n, base, trailingSlash, format) {
13
- this.#i18n = i18n;
14
- this.#base = base;
15
- this.#trailingSlash = trailingSlash;
16
- this.#format = format;
17
- this.#router = new I18nRouter({
18
- strategy: i18n.strategy,
19
- defaultLocale: i18n.defaultLocale,
20
- locales: i18n.locales,
21
- base,
22
- domains: i18n.domainLookupTable ? Object.keys(i18n.domainLookupTable).reduce(
23
- (acc, domain) => {
24
- const locale = i18n.domainLookupTable[domain];
25
- if (!acc[domain]) {
26
- acc[domain] = [];
27
- }
28
- acc[domain].push(locale);
29
- return acc;
30
- },
31
- {}
32
- ) : void 0
33
- });
6
+ import { createManifestMemo } from "../manifest/memo.js";
7
+ function compileI18n(i18n, base, trailingSlash, format) {
8
+ const router = new I18nRouter({
9
+ strategy: i18n.strategy,
10
+ defaultLocale: i18n.defaultLocale,
11
+ locales: i18n.locales,
12
+ base,
13
+ domains: i18n.domainLookupTable ? Object.keys(i18n.domainLookupTable).reduce(
14
+ (acc, domain) => {
15
+ const locale = i18n.domainLookupTable[domain];
16
+ if (!acc[domain]) {
17
+ acc[domain] = [];
18
+ }
19
+ acc[domain].push(locale);
20
+ return acc;
21
+ },
22
+ {}
23
+ ) : void 0
24
+ });
25
+ return { config: i18n, base, trailingSlash, format, router };
26
+ }
27
+ const i18nMemo = createManifestMemo((manifest) => {
28
+ const config = manifest.i18n;
29
+ return config && config.strategy !== "manual" ? compileI18n(config, manifest.base, manifest.trailingSlash, manifest.buildFormat) : null;
30
+ });
31
+ function getI18n(manifest) {
32
+ return i18nMemo.get(manifest);
33
+ }
34
+ async function finalizeI18n(compiled, state, response) {
35
+ markFeatureUsed(state.manifest, FetchFeatures.i18n);
36
+ const i18n = compiled.config;
37
+ if (state.skipErrorReroute && typeof i18n.fallback === "undefined") {
38
+ return response;
34
39
  }
35
- async finalize(state, response) {
36
- state.pipeline.usedFeatures |= PipelineFeatures.i18n;
37
- const i18n = this.#i18n;
38
- if (state.skipErrorReroute && typeof i18n.fallback === "undefined") {
39
- return response;
40
- }
41
- if (state.responseRouteType !== "page" && state.responseRouteType !== "fallback") {
42
- return response;
40
+ if (state.responseRouteType !== "page" && state.responseRouteType !== "fallback") {
41
+ return response;
42
+ }
43
+ const url = state.url;
44
+ const currentLocale = state.computeCurrentLocale();
45
+ const isPrerendered = state.routeData.prerender;
46
+ const routerContext = {
47
+ currentLocale,
48
+ currentDomain: url.hostname,
49
+ routeType: state.responseRouteType,
50
+ isReroute: false
51
+ };
52
+ const routeDecision = compiled.router.match(url.pathname, routerContext);
53
+ switch (routeDecision.type) {
54
+ case "redirect": {
55
+ let location = routeDecision.location;
56
+ if (shouldAppendForwardSlash(compiled.trailingSlash, compiled.format)) {
57
+ location = appendForwardSlash(location);
58
+ }
59
+ return new Response(null, {
60
+ status: routeDecision.status ?? 302,
61
+ headers: { Location: location }
62
+ });
43
63
  }
44
- const url = state.url;
45
- const currentLocale = state.computeCurrentLocale();
46
- const isPrerendered = state.routeData.prerender;
47
- const routerContext = {
48
- currentLocale,
49
- currentDomain: url.hostname,
50
- routeType: state.responseRouteType,
51
- isReroute: false
52
- };
53
- const routeDecision = this.#router.match(url.pathname, routerContext);
54
- switch (routeDecision.type) {
55
- case "redirect": {
56
- let location = routeDecision.location;
57
- if (shouldAppendForwardSlash(this.#trailingSlash, this.#format)) {
58
- location = appendForwardSlash(location);
59
- }
60
- return new Response(null, {
61
- status: routeDecision.status ?? 302,
62
- headers: { Location: location }
64
+ case "notFound": {
65
+ if (isPrerendered) {
66
+ const prerenderedRes = new Response(response.body, {
67
+ status: 404,
68
+ headers: response.headers
63
69
  });
64
- }
65
- case "notFound": {
66
- if (isPrerendered) {
67
- const prerenderedRes = new Response(response.body, {
68
- status: 404,
69
- headers: response.headers
70
- });
71
- state.skipErrorReroute = true;
72
- if (routeDecision.location) {
73
- prerenderedRes.headers.set("Location", routeDecision.location);
74
- }
75
- return prerenderedRes;
76
- }
77
- const headers = new Headers();
70
+ state.skipErrorReroute = true;
78
71
  if (routeDecision.location) {
79
- headers.set("Location", routeDecision.location);
72
+ prerenderedRes.headers.set("Location", routeDecision.location);
80
73
  }
81
- return new Response(null, { status: 404, headers });
74
+ return prerenderedRes;
82
75
  }
83
- case "continue":
84
- break;
85
- }
86
- if (i18n.fallback && i18n.fallbackType) {
87
- const effectiveStatus = state.responseRouteType === "fallback" ? 404 : response.status;
88
- const fallbackDecision = computeFallbackRoute({
89
- pathname: url.pathname,
90
- responseStatus: effectiveStatus,
91
- currentLocale,
92
- fallback: i18n.fallback,
93
- fallbackType: i18n.fallbackType,
94
- locales: i18n.locales,
95
- defaultLocale: i18n.defaultLocale,
96
- strategy: i18n.strategy,
97
- base: this.#base
98
- });
99
- switch (fallbackDecision.type) {
100
- case "redirect":
101
- return new Response(null, {
102
- status: 302,
103
- headers: { Location: fallbackDecision.pathname + url.search }
104
- });
105
- case "rewrite":
106
- return await state.rewrite(fallbackDecision.pathname + url.search);
107
- case "none":
108
- break;
76
+ const headers = new Headers();
77
+ if (routeDecision.location) {
78
+ headers.set("Location", routeDecision.location);
109
79
  }
80
+ return new Response(null, { status: 404, headers });
81
+ }
82
+ case "continue":
83
+ break;
84
+ }
85
+ if (i18n.fallback && i18n.fallbackType) {
86
+ const effectiveStatus = state.responseRouteType === "fallback" ? 404 : response.status;
87
+ const fallbackDecision = computeFallbackRoute({
88
+ pathname: url.pathname,
89
+ responseStatus: effectiveStatus,
90
+ currentLocale,
91
+ fallback: i18n.fallback,
92
+ fallbackType: i18n.fallbackType,
93
+ locales: i18n.locales,
94
+ defaultLocale: i18n.defaultLocale,
95
+ strategy: i18n.strategy,
96
+ base: compiled.base
97
+ });
98
+ switch (fallbackDecision.type) {
99
+ case "redirect":
100
+ return new Response(null, {
101
+ status: 302,
102
+ headers: { Location: fallbackDecision.pathname + url.search }
103
+ });
104
+ case "rewrite":
105
+ return await state.rewrite(fallbackDecision.pathname + url.search);
106
+ case "none":
107
+ break;
110
108
  }
111
- return response;
112
109
  }
110
+ return response;
113
111
  }
114
112
  export {
115
- I18n
113
+ compileI18n,
114
+ finalizeI18n,
115
+ getI18n
116
116
  };
@@ -0,0 +1,31 @@
1
+ import type { SSRManifest } from '../app/types.js';
2
+ import type { AstroLogger } from './core.js';
3
+ /**
4
+ * One identity-stable logger per manifest. Created on first access as a
5
+ * console logger at `manifest.logLevel`.
6
+ *
7
+ * The instance is never replaced: `getResolvedLogger` swaps the
8
+ * destination in place via `AstroLogger.setDestination`, so every holder
9
+ * (state-captured logger, adapterLogger's retained options) writes to the
10
+ * new destination immediately.
11
+ */
12
+ export declare function getLogger(manifest: SSRManifest): AstroLogger;
13
+ /**
14
+ * Composition-time injection (dev server logger, DevApp console logger, an
15
+ * App facade constructed with a custom logger path, tests). Must be called
16
+ * before the first `getLogger()` read to take effect deterministically;
17
+ * replaces the stored instance either way.
18
+ */
19
+ export declare function setLogger(manifest: SSRManifest, logger: AstroLogger): void;
20
+ /**
21
+ * The manifest's logger with the user-configured destination (the
22
+ * `manifest.logger` thunk) resolved and applied via `setDestination` on the
23
+ * identity-stable logger. Memoized single-flight; awaited at request entry.
24
+ *
25
+ * Never rejects: a destination that fails to load is reported through the
26
+ * unswapped (console) logger, which stays in place — a broken custom
27
+ * destination cannot fail a request. Because the derivation always resolves,
28
+ * the memo's delete-on-rejection retry path never triggers: the thunk runs
29
+ * at most once per manifest.
30
+ */
31
+ export declare function getResolvedLogger(manifest: SSRManifest): Promise<AstroLogger>;
@@ -0,0 +1,37 @@
1
+ import { createAsyncManifestMemo } from "../manifest/memo.js";
2
+ import { createConsoleLogger } from "./impls/console.js";
3
+ const loggers = /* @__PURE__ */ new WeakMap();
4
+ function getLogger(manifest) {
5
+ let logger = loggers.get(manifest);
6
+ if (!logger) {
7
+ logger = createConsoleLogger({ level: manifest.logLevel });
8
+ loggers.set(manifest, logger);
9
+ }
10
+ return logger;
11
+ }
12
+ function setLogger(manifest, logger) {
13
+ loggers.set(manifest, logger);
14
+ }
15
+ const resolvedLogger = createAsyncManifestMemo(async (manifest) => {
16
+ const logger = getLogger(manifest);
17
+ try {
18
+ const destination = (await manifest.logger?.())?.default;
19
+ if (destination) {
20
+ logger.setDestination(destination);
21
+ }
22
+ } catch (error) {
23
+ logger.error(
24
+ "config",
25
+ "Failed to load the configured logger destination; continuing with the console logger.\n" + (error instanceof Error ? error.stack ?? error.message : String(error))
26
+ );
27
+ }
28
+ return logger;
29
+ });
30
+ function getResolvedLogger(manifest) {
31
+ return resolvedLogger.get(manifest);
32
+ }
33
+ export {
34
+ getLogger,
35
+ getResolvedLogger,
36
+ setLogger
37
+ };
@@ -0,0 +1,2 @@
1
+ import type { SSRManifest } from '../app/types.js';
2
+ export declare const manifest: SSRManifest | undefined;
@@ -0,0 +1,4 @@
1
+ const manifest = void 0;
2
+ export {
3
+ manifest
4
+ };
@@ -0,0 +1,16 @@
1
+ import type { SSRManifest } from '../app/types.js';
2
+ /**
3
+ * Registers a manifest for environments where `virtual:astro:manifest` cannot
4
+ * resolve (plain Node: unit tests, embedders). Internal API — deliberately not
5
+ * exported from any public entrypoint.
6
+ * Pass `undefined` to clear (test teardown).
7
+ */
8
+ export declare function setAmbientManifest(manifest: SSRManifest | undefined): void;
9
+ /**
10
+ * The ambient manifest: the explicitly registered one, else the virtual
11
+ * module's. Throws lazily when neither is available, so merely importing a
12
+ * module that uses this never fails — only actually handling a request does.
13
+ */
14
+ export declare function getAmbientManifest(): SSRManifest;
15
+ /** The ambient manifest if one is available, else `undefined`. Never throws. */
16
+ export declare function tryGetAmbientManifest(): SSRManifest | undefined;
@@ -0,0 +1,22 @@
1
+ import { NoManifestAvailable } from "../errors/errors-data.js";
2
+ import { AstroError } from "../errors/index.js";
3
+ import { manifest as viteManifest } from "#astro-internal/ambient-manifest";
4
+ let registered;
5
+ function setAmbientManifest(manifest) {
6
+ registered = manifest;
7
+ }
8
+ function getAmbientManifest() {
9
+ const manifest = registered ?? viteManifest;
10
+ if (!manifest) {
11
+ throw new AstroError(NoManifestAvailable);
12
+ }
13
+ return manifest;
14
+ }
15
+ function tryGetAmbientManifest() {
16
+ return registered ?? viteManifest;
17
+ }
18
+ export {
19
+ getAmbientManifest,
20
+ setAmbientManifest,
21
+ tryGetAmbientManifest
22
+ };
@@ -0,0 +1,3 @@
1
+ import type { SSRManifest } from '../app/types.js';
2
+ /** The manifest's `site` as a `URL` (used for `Astro.site`). */
3
+ export declare function getSite(manifest: SSRManifest): URL | undefined;
@@ -0,0 +1,10 @@
1
+ import { createManifestMemo } from "./memo.js";
2
+ const sites = createManifestMemo(
3
+ (manifest) => manifest.site ? new URL(manifest.site) : void 0
4
+ );
5
+ function getSite(manifest) {
6
+ return sites.get(manifest);
7
+ }
8
+ export {
9
+ getSite
10
+ };
@@ -0,0 +1,31 @@
1
+ import type { SSRManifest } from '../app/types.js';
2
+ /**
3
+ * Shared helpers for "derived once per process per manifest" memoization.
4
+ * Manifest-keyed WeakMaps are the sanctioned memoization primitive of the
5
+ * request core: each derivation lives in its owning module with its own memo —
6
+ * there is deliberately no central registry and no "get all derived state"
7
+ * function anywhere.
8
+ *
9
+ * Note: values are scoped per manifest OBJECT. Two `App`s constructed over the
10
+ * same manifest object (e.g. the cloudflare custom-fetch worker) share every
11
+ * memoized derivation.
12
+ */
13
+ export interface ManifestMemo<T> {
14
+ get(manifest: SSRManifest): T;
15
+ /** Whether a value is currently stored for the manifest (derived or set). */
16
+ has(manifest: SSRManifest): boolean;
17
+ /** Replaces the stored value atomically (HMR replacement). */
18
+ set(manifest: SSRManifest, value: T): void;
19
+ invalidate(manifest: SSRManifest): void;
20
+ }
21
+ export declare function createManifestMemo<T>(derive: (manifest: SSRManifest) => T): ManifestMemo<T>;
22
+ export interface AsyncManifestMemo<T> {
23
+ get(manifest: SSRManifest): Promise<T>;
24
+ invalidate(manifest: SSRManifest): void;
25
+ }
26
+ /**
27
+ * Caches the PROMISE (single-flight: concurrent callers share one derivation).
28
+ * On rejection the entry is DELETED so the next call retries a failed lazy
29
+ * resolve instead of caching the failure forever.
30
+ */
31
+ export declare function createAsyncManifestMemo<T>(derive: (manifest: SSRManifest) => Promise<T>): AsyncManifestMemo<T>;
@@ -0,0 +1,47 @@
1
+ function createManifestMemo(derive) {
2
+ const cache = /* @__PURE__ */ new WeakMap();
3
+ return {
4
+ get(manifest) {
5
+ if (cache.has(manifest)) {
6
+ return cache.get(manifest);
7
+ }
8
+ const value = derive(manifest);
9
+ cache.set(manifest, value);
10
+ return value;
11
+ },
12
+ has(manifest) {
13
+ return cache.has(manifest);
14
+ },
15
+ set(manifest, value) {
16
+ cache.set(manifest, value);
17
+ },
18
+ invalidate(manifest) {
19
+ cache.delete(manifest);
20
+ }
21
+ };
22
+ }
23
+ function createAsyncManifestMemo(derive) {
24
+ const cache = /* @__PURE__ */ new WeakMap();
25
+ return {
26
+ get(manifest) {
27
+ let promise = cache.get(manifest);
28
+ if (!promise) {
29
+ promise = derive(manifest);
30
+ cache.set(manifest, promise);
31
+ promise.catch(() => {
32
+ if (cache.get(manifest) === promise) {
33
+ cache.delete(manifest);
34
+ }
35
+ });
36
+ }
37
+ return promise;
38
+ },
39
+ invalidate(manifest) {
40
+ cache.delete(manifest);
41
+ }
42
+ };
43
+ }
44
+ export {
45
+ createAsyncManifestMemo,
46
+ createManifestMemo
47
+ };