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,293 +0,0 @@
1
- import { NOOP_ACTIONS_MOD } from "../actions/noop-actions.js";
2
- import { createOriginCheckMiddleware } from "./app/origin-check.js";
3
- import { ActionNotFoundError } from "./errors/errors-data.js";
4
- import { AstroError } from "./errors/index.js";
5
- import { AstroLogger } from "./logger/core.js";
6
- import { NOOP_MIDDLEWARE_FN } from "./middleware/noop-middleware.js";
7
- import { sequence } from "./middleware/sequence.js";
8
- import { RedirectSinglePageBuiltModule } from "./redirects/index.js";
9
- import { RouteCache } from "./render/route-cache.js";
10
- import { createDefaultRoutes } from "./routing/default.js";
11
- import { ensure404Route } from "./routing/astro-designed-error-pages.js";
12
- import { Router } from "./routing/router.js";
13
- import { FORBIDDEN_PATH_KEYS } from "@astrojs/internal-helpers/object";
14
- const PipelineFeatures = {
15
- redirects: 1 << 0,
16
- sessions: 1 << 1,
17
- actions: 1 << 2,
18
- middleware: 1 << 3,
19
- i18n: 1 << 4,
20
- cache: 1 << 5
21
- };
22
- const ALL_PIPELINE_FEATURES = PipelineFeatures.redirects | PipelineFeatures.sessions | PipelineFeatures.actions | PipelineFeatures.middleware | PipelineFeatures.i18n | PipelineFeatures.cache;
23
- class Pipeline {
24
- internalMiddleware;
25
- resolvedMiddleware = void 0;
26
- resolvedLogger = false;
27
- resolvedActions = void 0;
28
- resolvedSessionDriver = void 0;
29
- resolvedCacheProvider = void 0;
30
- compiledCacheRoutes = void 0;
31
- /**
32
- * Bit mask of pipeline features activated by handler classes.
33
- * Each handler sets its bit via `|=`. Only meaningful when a
34
- * custom `src/fetch.ts` fetch handler is in use.
35
- */
36
- usedFeatures = 0;
37
- logger;
38
- manifest;
39
- /**
40
- * "development" or "production" only
41
- */
42
- runtimeMode;
43
- renderers;
44
- resolve;
45
- streaming;
46
- /**
47
- * Used to provide better error messages for `Astro.clientAddress`
48
- */
49
- adapterName;
50
- clientDirectives;
51
- inlinedScripts;
52
- compressHTML;
53
- i18n;
54
- middleware;
55
- routeCache;
56
- /**
57
- * Used for `Astro.site`.
58
- */
59
- site;
60
- /**
61
- * Array of built-in, internal, routes.
62
- * Used to find the route module
63
- */
64
- defaultRoutes;
65
- actions;
66
- sessionDriver;
67
- cacheProvider;
68
- cacheConfig;
69
- serverIslands;
70
- /** Route data derived from the manifest, used for route matching. */
71
- manifestData;
72
- /** Pattern-matching router built from manifestData. */
73
- #router;
74
- constructor(logger, manifest, runtimeMode, renderers, resolve, streaming, adapterName = manifest.adapterName, clientDirectives = manifest.clientDirectives, inlinedScripts = manifest.inlinedScripts, compressHTML = manifest.compressHTML, i18n = manifest.i18n, middleware = manifest.middleware, routeCache = new RouteCache(logger, runtimeMode), site = manifest.site ? new URL(manifest.site) : void 0, defaultRoutes = createDefaultRoutes(manifest), actions = manifest.actions, sessionDriver = manifest.sessionDriver, cacheProvider = manifest.cacheProvider, cacheConfig = manifest.cacheConfig, serverIslands = manifest.serverIslandMappings) {
75
- this.logger = logger;
76
- this.manifest = manifest;
77
- this.runtimeMode = runtimeMode;
78
- this.renderers = renderers;
79
- this.resolve = resolve;
80
- this.streaming = streaming;
81
- this.adapterName = adapterName;
82
- this.clientDirectives = clientDirectives;
83
- this.inlinedScripts = inlinedScripts;
84
- this.compressHTML = compressHTML;
85
- this.i18n = i18n;
86
- this.middleware = middleware;
87
- this.routeCache = routeCache;
88
- this.site = site;
89
- this.defaultRoutes = defaultRoutes;
90
- this.actions = actions;
91
- this.sessionDriver = sessionDriver;
92
- this.cacheProvider = cacheProvider;
93
- this.cacheConfig = cacheConfig;
94
- this.serverIslands = serverIslands;
95
- this.manifestData = { routes: (manifest.routes ?? []).map((route) => route.routeData) };
96
- ensure404Route(this.manifestData);
97
- this.#router = new Router(this.manifestData.routes, {
98
- base: manifest.base,
99
- trailingSlash: manifest.trailingSlash,
100
- buildFormat: manifest.buildFormat
101
- });
102
- this.internalMiddleware = [];
103
- }
104
- /**
105
- * Low-level route matching against the manifest routes. Returns the
106
- * matched `RouteData` or `undefined`. Does not filter prerendered
107
- * routes or check public assets — use `BaseApp.match()` for that.
108
- */
109
- matchRoute(pathname) {
110
- const match = this.#router.match(pathname, { allowWithoutBase: true });
111
- if (match.type !== "match") return void 0;
112
- return match.route;
113
- }
114
- /**
115
- * Returns all routes matching the given pathname, in priority order.
116
- * Used when the first match cannot serve the request (e.g. a
117
- * prerendered dynamic route that doesn't cover this specific path)
118
- * and the caller needs to try subsequent matches.
119
- */
120
- matchAllRoutes(pathname) {
121
- return this.#router.matchAll(pathname, { allowWithoutBase: true });
122
- }
123
- /**
124
- * Rebuilds the internal router after routes have been added or
125
- * removed (e.g. by the dev server on HMR).
126
- */
127
- rebuildRouter() {
128
- this.#router = new Router(this.manifestData.routes, {
129
- base: this.manifest.base,
130
- trailingSlash: this.manifest.trailingSlash,
131
- buildFormat: this.manifest.buildFormat
132
- });
133
- }
134
- /**
135
- * Resolves the middleware from the manifest, and returns the `onRequest` function. If `onRequest` isn't there,
136
- * it returns a no-op function
137
- */
138
- async getMiddleware() {
139
- if (this.resolvedMiddleware) {
140
- return this.resolvedMiddleware;
141
- }
142
- if (this.middleware) {
143
- const middlewareInstance = await this.middleware();
144
- const onRequest = middlewareInstance.onRequest ?? NOOP_MIDDLEWARE_FN;
145
- const internalMiddlewares = [onRequest];
146
- if (this.manifest.checkOrigin) {
147
- internalMiddlewares.unshift(createOriginCheckMiddleware());
148
- }
149
- this.resolvedMiddleware = sequence(...internalMiddlewares);
150
- return this.resolvedMiddleware;
151
- } else {
152
- this.resolvedMiddleware = NOOP_MIDDLEWARE_FN;
153
- return this.resolvedMiddleware;
154
- }
155
- }
156
- /**
157
- * Clears the cached middleware so it is re-resolved on the next request.
158
- * Called via HMR when middleware files change during development.
159
- */
160
- clearMiddleware() {
161
- this.resolvedMiddleware = void 0;
162
- }
163
- /**
164
- * Resolves the logger destination from the manifest and updates the pipeline logger.
165
- * If the user configured `logger`, the bundled logger factory is loaded
166
- * and replaces the default console destination. This is lazy and only resolves once.
167
- */
168
- async getLogger() {
169
- if (this.resolvedLogger) {
170
- return this.logger;
171
- }
172
- this.resolvedLogger = true;
173
- const destination = (await this.manifest.logger?.())?.default;
174
- if (destination) {
175
- this.logger = new AstroLogger({
176
- destination,
177
- level: this.manifest.logLevel
178
- });
179
- }
180
- return this.logger;
181
- }
182
- async getActions() {
183
- if (this.resolvedActions) {
184
- return this.resolvedActions;
185
- } else if (this.actions) {
186
- this.resolvedActions = await this.actions();
187
- return this.resolvedActions;
188
- }
189
- return NOOP_ACTIONS_MOD;
190
- }
191
- async getSessionDriver() {
192
- if (this.resolvedSessionDriver !== void 0) {
193
- return this.resolvedSessionDriver;
194
- }
195
- if (this.sessionDriver) {
196
- const driverModule = await this.sessionDriver();
197
- this.resolvedSessionDriver = driverModule?.default || null;
198
- return this.resolvedSessionDriver;
199
- }
200
- this.resolvedSessionDriver = null;
201
- return null;
202
- }
203
- async getCacheProvider() {
204
- if (this.resolvedCacheProvider !== void 0) {
205
- return this.resolvedCacheProvider;
206
- }
207
- if (this.cacheProvider) {
208
- const mod = await this.cacheProvider();
209
- const factory = mod?.default || null;
210
- this.resolvedCacheProvider = factory ? factory(this.cacheConfig?.options) : null;
211
- return this.resolvedCacheProvider;
212
- }
213
- this.resolvedCacheProvider = null;
214
- return null;
215
- }
216
- async getServerIslands() {
217
- if (this.serverIslands) {
218
- return this.serverIslands();
219
- }
220
- return {
221
- serverIslandMap: /* @__PURE__ */ new Map(),
222
- serverIslandNameMap: /* @__PURE__ */ new Map()
223
- };
224
- }
225
- async getAction(path) {
226
- const pathKeys = path.split(".").map((key) => decodeURIComponent(key));
227
- let { server } = await this.getActions();
228
- if (!server || !(typeof server === "object")) {
229
- throw new TypeError(
230
- `Expected \`server\` export in actions file to be an object. Received ${typeof server}.`
231
- );
232
- }
233
- for (const key of pathKeys) {
234
- if (typeof server === "function") {
235
- throw new AstroError({
236
- ...ActionNotFoundError,
237
- message: ActionNotFoundError.message(pathKeys.join("."))
238
- });
239
- }
240
- if (FORBIDDEN_PATH_KEYS.has(key)) {
241
- throw new AstroError({
242
- ...ActionNotFoundError,
243
- message: ActionNotFoundError.message(pathKeys.join("."))
244
- });
245
- }
246
- if (!Object.hasOwn(server, key)) {
247
- throw new AstroError({
248
- ...ActionNotFoundError,
249
- message: ActionNotFoundError.message(pathKeys.join("."))
250
- });
251
- }
252
- server = server[key];
253
- }
254
- if (typeof server !== "function") {
255
- throw new TypeError(
256
- `Expected handler for action ${pathKeys.join(".")} to be a function. Received ${typeof server}.`
257
- );
258
- }
259
- return server;
260
- }
261
- async getModuleForRoute(route) {
262
- for (const defaultRoute of this.defaultRoutes) {
263
- if (route.component === defaultRoute.component) {
264
- return {
265
- page: () => Promise.resolve(defaultRoute.instance)
266
- };
267
- }
268
- }
269
- if (route.type === "redirect") {
270
- return RedirectSinglePageBuiltModule;
271
- } else {
272
- if (this.manifest.pageMap) {
273
- const importComponentInstance = this.manifest.pageMap.get(route.component);
274
- if (!importComponentInstance) {
275
- throw new Error(
276
- `Unexpectedly unable to find a component instance for route ${route.route}`
277
- );
278
- }
279
- return await importComponentInstance();
280
- } else if (this.manifest.pageModule) {
281
- return this.manifest.pageModule;
282
- }
283
- throw new Error(
284
- "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."
285
- );
286
- }
287
- }
288
- }
289
- export {
290
- ALL_PIPELINE_FEATURES,
291
- Pipeline,
292
- PipelineFeatures
293
- };
@@ -1,38 +0,0 @@
1
- import type { ComponentInstance } from '../../types/astro.js';
2
- import type { RewritePayload } from '../../types/public/common.js';
3
- import type { RouteData, SSRResult } from '../../types/public/internal.js';
4
- import type { SSRManifest } from '../app/types.js';
5
- import type { TryRewriteResult } from '../base-pipeline.js';
6
- import { Pipeline } from '../base-pipeline.js';
7
- import { type DefaultRouteParams } from '../routing/default.js';
8
- import type { BuildInternals } from './internal.js';
9
- import type { SinglePageBuiltModule, StaticBuildOptions } from './types.js';
10
- /**
11
- * The build pipeline is responsible to gather the files emitted by the SSR build and generate the pages by executing these files.
12
- */
13
- export declare class BuildPipeline extends Pipeline {
14
- #private;
15
- internals: BuildInternals | undefined;
16
- options: StaticBuildOptions | undefined;
17
- readonly manifest: SSRManifest;
18
- readonly defaultRoutes: Array<DefaultRouteParams>;
19
- getName(): string;
20
- getSettings(): import("../../types/astro.js").AstroSettings;
21
- getOptions(): StaticBuildOptions;
22
- getInternals(): BuildInternals;
23
- private constructor();
24
- getRoutes(): RouteData[];
25
- static create({ manifest }: Pick<BuildPipeline, 'manifest'>): BuildPipeline;
26
- setInternals(internals: BuildInternals): void;
27
- setOptions(options: StaticBuildOptions): void;
28
- headElements(routeData: RouteData): Pick<SSRResult, 'scripts' | 'styles' | 'links'>;
29
- componentMetadata(): void;
30
- /**
31
- * It collects the routes to generate during the build.
32
- * It returns a map of page information and their relative entry point as a string.
33
- */
34
- retrieveRoutesToGenerate(): Set<RouteData>;
35
- getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
36
- getModuleForRoute(route: RouteData): Promise<SinglePageBuiltModule>;
37
- tryRewrite(payload: RewritePayload, request: Request): Promise<TryRewriteResult>;
38
- }
@@ -1,202 +0,0 @@
1
- import { VIRTUAL_PAGE_RESOLVED_MODULE_ID } from "../../vite-plugin-pages/const.js";
2
- import { getVirtualModulePageName } from "../../vite-plugin-pages/util.js";
3
- import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
4
- import { createConsoleLogger } from "../app/entrypoints/index.js";
5
- import { RedirectSinglePageBuiltModule } from "../redirects/component.js";
6
- import { Pipeline } from "../base-pipeline.js";
7
- import { createAssetLink, createStylesheetElementSet } from "../render/ssr-element.js";
8
- import { createDefaultRoutes } from "../routing/default.js";
9
- import { getFallbackRoute, routeIsFallback, routeIsRedirect } from "../routing/helpers.js";
10
- import { findRouteToRewrite } from "../routing/rewrite.js";
11
- import { cssOrder, mergeInlineCss, getPageData } from "./runtime.js";
12
- class BuildPipeline extends Pipeline {
13
- internals;
14
- options;
15
- manifest;
16
- defaultRoutes;
17
- getName() {
18
- return "BuildPipeline";
19
- }
20
- /**
21
- * This cache is needed to map a single `RouteData` to its file path.
22
- * @private
23
- */
24
- #routesByFilePath = /* @__PURE__ */ new WeakMap();
25
- getSettings() {
26
- if (!this.options) {
27
- throw new Error("No options defined");
28
- }
29
- return this.options.settings;
30
- }
31
- getOptions() {
32
- if (!this.options) {
33
- throw new Error("No options defined");
34
- }
35
- return this.options;
36
- }
37
- getInternals() {
38
- if (!this.internals) {
39
- throw new Error("No internals defined");
40
- }
41
- return this.internals;
42
- }
43
- constructor(manifest, defaultRoutes = createDefaultRoutes(manifest)) {
44
- const resolveCache = /* @__PURE__ */ new Map();
45
- async function resolve(specifier) {
46
- if (resolveCache.has(specifier)) {
47
- return resolveCache.get(specifier);
48
- }
49
- const hashedFilePath = manifest.entryModules[specifier];
50
- if (typeof hashedFilePath !== "string" || hashedFilePath === "") {
51
- if (specifier === BEFORE_HYDRATION_SCRIPT_ID) {
52
- resolveCache.set(specifier, "");
53
- return "";
54
- }
55
- throw new Error(`Cannot find the built path for ${specifier}`);
56
- }
57
- const assetLink = createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix);
58
- resolveCache.set(specifier, assetLink);
59
- return assetLink;
60
- }
61
- const logger = createConsoleLogger({ level: manifest.logLevel });
62
- super(logger, manifest, "production", manifest.renderers, resolve, manifest.serverLike);
63
- this.manifest = manifest;
64
- this.defaultRoutes = defaultRoutes;
65
- }
66
- getRoutes() {
67
- return this.getOptions().routesList.routes;
68
- }
69
- static create({ manifest }) {
70
- return new BuildPipeline(manifest);
71
- }
72
- setInternals(internals) {
73
- this.internals = internals;
74
- }
75
- setOptions(options) {
76
- this.options = options;
77
- }
78
- headElements(routeData) {
79
- const {
80
- manifest: { assetsPrefix, base }
81
- } = this;
82
- const settings = this.getSettings();
83
- const internals = this.getInternals();
84
- const links = /* @__PURE__ */ new Set();
85
- const pageBuildData = getPageData(internals, routeData.route, routeData.component);
86
- const scripts = /* @__PURE__ */ new Set();
87
- const sortedCssAssets = pageBuildData?.styles.sort(cssOrder).map(({ sheet }) => sheet).reduce(mergeInlineCss, []);
88
- const styles = createStylesheetElementSet(sortedCssAssets ?? [], base, assetsPrefix);
89
- if (settings.scripts.some((script) => script.stage === "page")) {
90
- const hashedFilePath = internals.entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID);
91
- if (typeof hashedFilePath !== "string") {
92
- throw new Error(`Cannot find the built path for ${PAGE_SCRIPT_ID}`);
93
- }
94
- const src = createAssetLink(hashedFilePath, base, assetsPrefix);
95
- scripts.add({
96
- props: { type: "module", src },
97
- children: ""
98
- });
99
- }
100
- for (const script of settings.scripts) {
101
- if (script.stage === "head-inline") {
102
- scripts.add({
103
- props: {},
104
- children: script.content
105
- });
106
- }
107
- }
108
- return { scripts, styles, links };
109
- }
110
- componentMetadata() {
111
- }
112
- /**
113
- * It collects the routes to generate during the build.
114
- * It returns a map of page information and their relative entry point as a string.
115
- */
116
- retrieveRoutesToGenerate() {
117
- const pages = /* @__PURE__ */ new Set();
118
- const defaultRouteComponents = new Set(this.defaultRoutes.map((route) => route.component));
119
- for (const { routeData } of this.manifest.routes) {
120
- if (routeIsRedirect(routeData)) {
121
- pages.add(routeData);
122
- continue;
123
- }
124
- if (routeIsFallback(routeData) && i18nHasFallback(this.manifest)) {
125
- pages.add(routeData);
126
- continue;
127
- }
128
- if (defaultRouteComponents.has(routeData.component)) {
129
- continue;
130
- }
131
- pages.add(routeData);
132
- const moduleSpecifier = getVirtualModulePageName(
133
- VIRTUAL_PAGE_RESOLVED_MODULE_ID,
134
- routeData.component
135
- );
136
- const filePath = this.internals?.entrySpecifierToBundleMap.get(moduleSpecifier);
137
- if (filePath) {
138
- this.#routesByFilePath.set(routeData, filePath);
139
- }
140
- }
141
- return pages;
142
- }
143
- async getComponentByRoute(routeData) {
144
- const module = await this.getModuleForRoute(routeData);
145
- return module.page();
146
- }
147
- async getModuleForRoute(route) {
148
- for (const defaultRoute of this.defaultRoutes) {
149
- if (route.component === defaultRoute.component) {
150
- return {
151
- page: () => Promise.resolve(defaultRoute.instance)
152
- };
153
- }
154
- }
155
- let routeToProcess = route;
156
- if (routeIsRedirect(route)) {
157
- if (route.redirectRoute) {
158
- routeToProcess = route.redirectRoute;
159
- } else {
160
- return RedirectSinglePageBuiltModule;
161
- }
162
- } else if (routeIsFallback(route)) {
163
- routeToProcess = getFallbackRoute(route, this.manifest.routes);
164
- }
165
- if (this.manifest.pageMap) {
166
- const importComponentInstance = this.manifest.pageMap.get(routeToProcess.component);
167
- if (!importComponentInstance) {
168
- throw new Error(
169
- `Unexpectedly unable to find a component instance for route ${route.route}`
170
- );
171
- }
172
- return await importComponentInstance();
173
- } else if (this.manifest.pageModule) {
174
- return this.manifest.pageModule;
175
- }
176
- throw new Error(
177
- "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."
178
- );
179
- }
180
- async tryRewrite(payload, request) {
181
- const { routeData, pathname, newUrl } = findRouteToRewrite({
182
- payload,
183
- request,
184
- routes: this.manifest.routes.map((routeInfo) => routeInfo.routeData),
185
- trailingSlash: this.manifest.trailingSlash,
186
- buildFormat: this.manifest.buildFormat,
187
- base: this.manifest.base,
188
- outDir: this.manifest.serverLike ? this.manifest.buildClientDir : this.manifest.outDir
189
- });
190
- const componentInstance = await this.getComponentByRoute(routeData);
191
- return { routeData, componentInstance, newUrl, pathname };
192
- }
193
- }
194
- function i18nHasFallback(manifest) {
195
- if (manifest.i18n && manifest.i18n.fallback) {
196
- return Object.keys(manifest.i18n.fallback).length > 0;
197
- }
198
- return false;
199
- }
200
- export {
201
- BuildPipeline
202
- };
@@ -1,62 +0,0 @@
1
- import type http from 'node:http';
2
- import { BaseApp } from '../core/app/entrypoints/index.js';
3
- import type { ErrorHandler } from '../core/errors/handler.js';
4
- import type { AstroLogger } from '../core/logger/core.js';
5
- import type { ModuleLoader } from '../core/module-loader/index.js';
6
- import type { AstroSettings, RoutesList } from '../types/astro.js';
7
- import type { RouteData, SSRManifest } from '../types/public/index.js';
8
- import type { DevServerController } from '../vite-plugin-astro-server/controller.js';
9
- import { RunnablePipeline } from './pipeline.js';
10
- import type { DevMatch, LogRequestPayload } from '../core/app/base.js';
11
- export declare class AstroServerApp extends BaseApp<RunnablePipeline> {
12
- #private;
13
- settings: AstroSettings;
14
- loader: ModuleLoader;
15
- manifestData: RoutesList;
16
- constructor(manifest: SSRManifest, streaming: boolean | undefined, logger: AstroLogger, manifestData: RoutesList, loader: ModuleLoader, settings: AstroSettings, getDebugInfo: () => Promise<string>);
17
- isDev(): boolean;
18
- /**
19
- * Updates the routes list when files change during development.
20
- * Called via HMR when new pages are added/removed.
21
- */
22
- updateRoutes(newRoutesList: RoutesList): void;
23
- /**
24
- * Clears the route cache so that getStaticPaths() is re-evaluated.
25
- * Called via HMR when content collection data changes.
26
- */
27
- clearRouteCache(): void;
28
- /**
29
- * Clears the cached middleware so it is re-resolved on the next request.
30
- * Called via HMR when middleware files change.
31
- */
32
- clearMiddleware(): void;
33
- /**
34
- * Clears the cached actions so they are re-resolved on the next request.
35
- * Called via HMR when action files change.
36
- */
37
- clearActions(): void;
38
- devMatch(pathname: string, { prerenderOnly }?: {
39
- prerenderOnly?: boolean;
40
- }): Promise<DevMatch | undefined>;
41
- static create(manifest: SSRManifest, routesList: RoutesList, logger: AstroLogger, loader: ModuleLoader, settings: AstroSettings, getDebugInfo: () => Promise<string>): Promise<AstroServerApp>;
42
- createPipeline(_streaming: boolean, manifest: SSRManifest, settings: AstroSettings, logger: AstroLogger, loader: ModuleLoader, manifestData: RoutesList, getDebugInfo: () => Promise<string>): RunnablePipeline;
43
- /**
44
- * Handle a request.
45
- * @returns The return value indicates whether or not the request was handled
46
- * by this handler. If the result is not `true`, then the request has not
47
- * been handled yet and other handlers can be run.
48
- */
49
- handleRequest({ controller, incomingRequest, incomingResponse, isHttps, prerenderOnly, }: HandleRequest): Promise<boolean>;
50
- match(request: Request, _allowPrerenderedRoutes: boolean): RouteData | undefined;
51
- protected createErrorHandler(): ErrorHandler;
52
- logRequest({ pathname, method, statusCode, isRewrite, reqTime }: LogRequestPayload): void;
53
- }
54
- type HandleRequest = {
55
- controller: DevServerController;
56
- incomingRequest: http.IncomingMessage;
57
- incomingResponse: http.ServerResponse;
58
- isHttps: boolean;
59
- /** When true, only handle prerendered routes. Returns false for SSR routes. */
60
- prerenderOnly?: boolean;
61
- };
62
- export {};