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.
- package/dist/actions/handler.d.ts +6 -12
- package/dist/actions/handler.js +30 -40
- package/dist/actions/load.d.ts +12 -0
- package/dist/actions/load.js +55 -0
- package/dist/actions/runtime/entrypoints/server.js +5 -4
- package/dist/actions/runtime/server.js +8 -6
- package/dist/assets/fonts/providers/index.d.ts +1 -1
- package/dist/assets/fonts/providers/index.js +2 -12
- package/dist/assets/utils/vendor/image-size/types/heif.js +8 -3
- package/dist/assets/utils/vendor/image-size/types/icns.js +10 -2
- package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -2
- package/dist/assets/utils/vendor/image-size/types/jxl.js +5 -2
- package/dist/assets/utils/vendor/image-size/types/utils.d.ts +1 -1
- package/dist/assets/utils/vendor/image-size/types/utils.js +20 -6
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/container/environment.d.ts +20 -0
- package/dist/container/environment.js +106 -0
- package/dist/container/index.js +73 -37
- package/dist/content/content-layer.js +3 -3
- package/dist/content/data-store-writer.d.ts +7 -10
- package/dist/content/data-store-writer.js +62 -27
- package/dist/content/data-store.d.ts +20 -3
- package/dist/content/data-store.js +28 -7
- package/dist/content/mutable-data-store.js +15 -10
- package/dist/content/runtime.d.ts +3 -2
- package/dist/content/runtime.js +43 -26
- package/dist/core/app/app.d.ts +0 -2
- package/dist/core/app/app.js +0 -7
- package/dist/core/app/base.d.ts +32 -20
- package/dist/core/app/base.js +79 -73
- package/dist/core/app/dev-facade.d.ts +27 -0
- package/dist/core/app/dev-facade.js +51 -0
- package/dist/core/app/entrypoints/index.d.ts +0 -1
- package/dist/core/app/entrypoints/index.js +0 -2
- package/dist/core/app/entrypoints/virtual/dev.js +24 -19
- package/dist/core/app/node.js +13 -14
- package/dist/core/app/prepare-response.d.ts +1 -1
- package/dist/core/app/validate-headers.js +7 -3
- package/dist/core/build/app.d.ts +31 -6
- package/dist/core/build/app.js +31 -13
- package/dist/core/build/environment.d.ts +25 -0
- package/dist/core/build/environment.js +157 -0
- package/dist/core/cache/handler.d.ts +13 -7
- package/dist/core/cache/handler.js +55 -51
- package/dist/core/cache/provider.d.ts +4 -0
- package/dist/core/cache/provider.js +15 -0
- package/dist/core/constants.d.ts +0 -11
- package/dist/core/constants.js +1 -5
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/environment/dev-nonrunnable.d.ts +6 -0
- package/dist/core/environment/dev-nonrunnable.js +170 -0
- package/dist/core/environment/index.d.ts +90 -0
- package/dist/core/environment/index.js +12 -0
- package/dist/core/environment/production.d.ts +6 -0
- package/dist/core/environment/production.js +117 -0
- package/dist/core/errors/build-handler.d.ts +5 -10
- package/dist/core/errors/build-handler.js +11 -17
- package/dist/core/errors/default-handler.d.ts +4 -9
- package/dist/core/errors/default-handler.js +92 -107
- package/dist/core/errors/dev-handler.d.ts +7 -11
- package/dist/core/errors/dev-handler.js +71 -69
- package/dist/core/errors/errors-data.d.ts +18 -0
- package/dist/core/errors/errors-data.js +7 -0
- package/dist/core/errors/handler.d.ts +22 -3
- package/dist/core/errors/handler.js +25 -0
- package/dist/core/fetch/default-handler.d.ts +15 -8
- package/dist/core/fetch/default-handler.js +12 -34
- package/dist/core/fetch/features.d.ts +23 -0
- package/dist/core/fetch/features.js +27 -0
- package/dist/core/fetch/fetch-state.d.ts +52 -7
- package/dist/core/fetch/fetch-state.js +99 -92
- package/dist/core/fetch/index.d.ts +9 -2
- package/dist/core/fetch/index.js +18 -79
- package/dist/core/fetch/vite-plugin.js +2 -1
- package/dist/core/i18n/domain.js +4 -11
- package/dist/core/i18n/handler.d.ts +28 -13
- package/dist/core/i18n/handler.js +100 -100
- package/dist/core/logger/manifest-logger.d.ts +31 -0
- package/dist/core/logger/manifest-logger.js +37 -0
- package/dist/core/manifest/ambient-source.d.ts +2 -0
- package/dist/core/manifest/ambient-source.js +4 -0
- package/dist/core/manifest/ambient.d.ts +16 -0
- package/dist/core/manifest/ambient.js +22 -0
- package/dist/core/manifest/derived.d.ts +3 -0
- package/dist/core/manifest/derived.js +10 -0
- package/dist/core/manifest/memo.d.ts +31 -0
- package/dist/core/manifest/memo.js +47 -0
- package/dist/core/messages/runtime.js +1 -1
- package/dist/core/middleware/astro-middleware.d.ts +25 -35
- package/dist/core/middleware/astro-middleware.js +61 -81
- package/dist/core/middleware/load.d.ts +19 -0
- package/dist/core/middleware/load.js +36 -0
- package/dist/core/middleware/sequence.js +15 -7
- package/dist/core/pages/handler.d.ts +18 -25
- package/dist/core/pages/handler.js +68 -84
- package/dist/core/redirects/render.js +3 -8
- package/dist/core/render/index.d.ts +0 -1
- package/dist/core/render/index.js +0 -2
- package/dist/core/render/route-cache.d.ts +6 -1
- package/dist/core/render/route-cache.js +11 -1
- package/dist/core/rewrites/handler.d.ts +4 -6
- package/dist/core/rewrites/handler.js +19 -20
- package/dist/core/routing/default.d.ts +2 -0
- package/dist/core/routing/default.js +7 -1
- package/dist/core/routing/dev.d.ts +1 -3
- package/dist/core/routing/dev.js +12 -5
- package/dist/core/routing/handler.d.ts +6 -16
- package/dist/core/routing/handler.js +126 -164
- package/dist/core/routing/helpers.d.ts +7 -1
- package/dist/core/routing/helpers.js +21 -0
- package/dist/core/routing/match-request.d.ts +10 -0
- package/dist/core/routing/match-request.js +46 -0
- package/dist/core/routing/route-table.d.ts +34 -0
- package/dist/core/routing/route-table.js +41 -0
- package/dist/core/routing/trailing-slash-handler.d.ts +4 -14
- package/dist/core/routing/trailing-slash-handler.js +39 -50
- package/dist/core/server-islands/mappings.d.ts +6 -0
- package/dist/core/server-islands/mappings.js +12 -0
- package/dist/core/session/driver.d.ts +4 -0
- package/dist/core/session/driver.js +14 -0
- package/dist/core/session/handler.d.ts +1 -1
- package/dist/core/session/handler.js +8 -8
- package/dist/core/session/provider-disabled.js +2 -2
- package/dist/entrypoints/prerender.js +5 -1
- package/dist/i18n/middleware.d.ts +4 -4
- package/dist/i18n/middleware.js +3 -3
- package/dist/manifest/serialized.d.ts +1 -0
- package/dist/manifest/serialized.js +9 -2
- package/dist/runtime/prerender/static-paths.d.ts +14 -2
- package/dist/runtime/prerender/static-paths.js +4 -3
- package/dist/types/public/config.d.ts +433 -241
- package/dist/vite-plugin-app/createAstroServerApp.js +22 -18
- package/dist/vite-plugin-app/environment.d.ts +18 -0
- package/dist/vite-plugin-app/environment.js +210 -0
- package/dist/vite-plugin-app/handle-request.d.ts +30 -0
- package/dist/vite-plugin-app/handle-request.js +129 -0
- package/dist/vite-plugin-app/index.d.ts +1 -1
- package/dist/vite-plugin-app/index.js +1 -1
- package/package.json +14 -7
- package/src/core/README.md +37 -0
- package/src/core/manifest/ambient-source.ts +9 -0
- package/src/types/README.md +5 -0
- package/dist/container/pipeline.d.ts +0 -14
- package/dist/container/pipeline.js +0 -78
- package/dist/core/app/dev/app.d.ts +0 -31
- package/dist/core/app/dev/app.js +0 -80
- package/dist/core/app/dev/pipeline.d.ts +0 -17
- package/dist/core/app/dev/pipeline.js +0 -133
- package/dist/core/app/pipeline.d.ts +0 -14
- package/dist/core/app/pipeline.js +0 -123
- package/dist/core/base-pipeline.d.ts +0 -183
- package/dist/core/base-pipeline.js +0 -293
- package/dist/core/build/pipeline.d.ts +0 -38
- package/dist/core/build/pipeline.js +0 -202
- package/dist/vite-plugin-app/app.d.ts +0 -62
- package/dist/vite-plugin-app/app.js +0 -237
- package/dist/vite-plugin-app/pipeline.d.ts +0 -25
- package/dist/vite-plugin-app/pipeline.js +0 -189
package/dist/core/app/node.js
CHANGED
|
@@ -19,12 +19,7 @@ function createRequestFromNodeRequest(req, {
|
|
|
19
19
|
const isEncrypted = "encrypted" in req.socket && req.socket.encrypted;
|
|
20
20
|
const protocol = isEncrypted ? "https" : "http";
|
|
21
21
|
const hostname = typeof req.headers.host === "string" ? req.headers.host : typeof req.headers[":authority"] === "string" ? req.headers[":authority"] : serverPort ? `localhost:${serverPort}` : "localhost";
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
url = new URL(`${protocol}://${hostname}${req.url}`);
|
|
25
|
-
} catch {
|
|
26
|
-
url = new URL(`${protocol}://${hostname}`);
|
|
27
|
-
}
|
|
22
|
+
const url = buildRequestUrl(protocol, hostname, req.url, serverPort);
|
|
28
23
|
const options = {
|
|
29
24
|
method: req.method || "GET",
|
|
30
25
|
headers: makeRequestHeaders(req),
|
|
@@ -80,14 +75,7 @@ function createRequest(req, {
|
|
|
80
75
|
);
|
|
81
76
|
const hostname = validated.host ?? validatedHostname ?? "localhost";
|
|
82
77
|
const port = validated.port ?? (!validated.host && !validatedHostname && serverPort ? String(serverPort) : void 0);
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
const hostnamePort = getHostnamePort(hostname, port);
|
|
86
|
-
url = new URL(`${protocol}://${hostnamePort}${req.url}`);
|
|
87
|
-
} catch {
|
|
88
|
-
const hostnamePort = getHostnamePort(hostname, port);
|
|
89
|
-
url = new URL(`${protocol}://${hostnamePort}`);
|
|
90
|
-
}
|
|
78
|
+
const url = buildRequestUrl(protocol, getHostnamePort(hostname, port), req.url, serverPort);
|
|
91
79
|
const options = {
|
|
92
80
|
method: req.method || "GET",
|
|
93
81
|
headers: makeRequestHeaders(req),
|
|
@@ -245,6 +233,17 @@ function getHostnamePort(hostname, port) {
|
|
|
245
233
|
const hostnamePort = portInHostname ? hostname : `${hostname}${port ? `:${port}` : ""}`;
|
|
246
234
|
return hostnamePort;
|
|
247
235
|
}
|
|
236
|
+
function buildRequestUrl(protocol, hostnamePort, requestPath, serverPort) {
|
|
237
|
+
const path = requestPath ?? "";
|
|
238
|
+
if (URL.canParse(`${protocol}://${hostnamePort}${path}`)) {
|
|
239
|
+
return new URL(`${protocol}://${hostnamePort}${path}`);
|
|
240
|
+
}
|
|
241
|
+
if (URL.canParse(`${protocol}://${hostnamePort}`)) {
|
|
242
|
+
return new URL(`${protocol}://${hostnamePort}`);
|
|
243
|
+
}
|
|
244
|
+
const fallbackHost = serverPort ? `localhost:${serverPort}` : "localhost";
|
|
245
|
+
return new URL(`${protocol}://${fallbackHost}`);
|
|
246
|
+
}
|
|
248
247
|
function makeRequestHeaders(req) {
|
|
249
248
|
const headers = new Headers();
|
|
250
249
|
for (const [name, value] of Object.entries(req.headers)) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* and marks the response as sent.
|
|
4
4
|
*
|
|
5
5
|
* This is a pure function with no dependencies on the app; it is shared by
|
|
6
|
-
* `
|
|
6
|
+
* `handleRequest` and the various error handlers.
|
|
7
7
|
*/
|
|
8
8
|
export declare function prepareResponse(response: Response, { addCookieHeader }: {
|
|
9
9
|
addCookieHeader: boolean;
|
|
@@ -9,6 +9,7 @@ function sanitizeHost(hostname) {
|
|
|
9
9
|
}
|
|
10
10
|
function parseHost(host) {
|
|
11
11
|
const parts = host.split(":");
|
|
12
|
+
if (parts.length > 2) return void 0;
|
|
12
13
|
return {
|
|
13
14
|
hostname: parts[0],
|
|
14
15
|
port: parts[1]
|
|
@@ -28,7 +29,9 @@ function validateHost(host, protocol, allowedDomains) {
|
|
|
28
29
|
if (!allowedDomains || allowedDomains.length === 0) return void 0;
|
|
29
30
|
const sanitized = sanitizeHost(host);
|
|
30
31
|
if (!sanitized) return void 0;
|
|
31
|
-
const
|
|
32
|
+
const parsed = parseHost(sanitized);
|
|
33
|
+
if (!parsed) return void 0;
|
|
34
|
+
const { hostname, port } = parsed;
|
|
32
35
|
if (matchesAllowedDomains(hostname, protocol, port, allowedDomains)) {
|
|
33
36
|
return sanitized;
|
|
34
37
|
}
|
|
@@ -67,8 +70,9 @@ function validateForwardedHeaders(forwardedProtocol, forwardedHost, forwardedPor
|
|
|
67
70
|
if (forwardedHost && forwardedHost.length > 0 && allowedDomains && allowedDomains.length > 0) {
|
|
68
71
|
const protoForValidation = result.protocol || "https";
|
|
69
72
|
const sanitized = sanitizeHost(forwardedHost);
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
const parsed = sanitized ? parseHost(sanitized) : void 0;
|
|
74
|
+
if (sanitized && parsed) {
|
|
75
|
+
const { hostname, port: portFromHost } = parsed;
|
|
72
76
|
const portForValidation = result.port || portFromHost;
|
|
73
77
|
if (matchesAllowedDomains(hostname, protoForValidation, portForValidation, allowedDomains)) {
|
|
74
78
|
result.host = sanitized;
|
package/dist/core/build/app.d.ts
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
1
|
import { BaseApp } from '../app/entrypoints/index.js';
|
|
2
|
+
import type { LogRequestPayload } from '../app/base.js';
|
|
2
3
|
import type { SSRManifest } from '../app/types.js';
|
|
4
|
+
import type { ComponentInstance } from '../../types/astro.js';
|
|
5
|
+
import type { RouteData } from '../../types/public/internal.js';
|
|
6
|
+
import { type RouteCache } from '../render/route-cache.js';
|
|
7
|
+
import type { BuildEnvironmentSlots } from './environment.js';
|
|
3
8
|
import type { BuildInternals } from './internal.js';
|
|
4
|
-
import { BuildPipeline } from './pipeline.js';
|
|
5
9
|
import type { StaticBuildOptions } from './types.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The build / prerender facade: a thin shell over the
|
|
12
|
+
* build environment record. The two-phase init state (`setInternals` /
|
|
13
|
+
* `setOptions`, injected by `createDefaultPrerenderer.setup()` after the
|
|
14
|
+
* prerender bundle import) lives in the `BuildEnvironmentSlots` closure
|
|
15
|
+
* created by the prerender entrypoint; the facade only forwards across the
|
|
16
|
+
* bundle boundary into those slots.
|
|
17
|
+
*/
|
|
18
|
+
export declare class BuildApp extends BaseApp {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(manifest: SSRManifest, buildEnv: BuildEnvironmentSlots);
|
|
10
21
|
isDev(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Streaming falls through to the environment default
|
|
24
|
+
* (`manifest.serverLike` for the build environment) — we can skip
|
|
25
|
+
* streaming in SSG for performance, as writing strings is faster.
|
|
26
|
+
*/
|
|
27
|
+
protected resolveStreaming(): boolean | undefined;
|
|
11
28
|
setInternals(internals: BuildInternals): void;
|
|
12
29
|
setOptions(options: StaticBuildOptions): void;
|
|
13
30
|
getOptions(): StaticBuildOptions;
|
|
14
31
|
getSettings(): import("../../types/astro.js").AstroSettings;
|
|
15
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Route cache and component loader for `StaticPaths`. Defined on the app
|
|
34
|
+
* (rather than reached through the functional core at the call site) so
|
|
35
|
+
* they execute inside the prerender bundle's module graph: the default
|
|
36
|
+
* prerenderer constructs `StaticPaths` from a different bundle, whose
|
|
37
|
+
* copies of the core modules hold separate per-manifest state.
|
|
38
|
+
*/
|
|
39
|
+
get routeCache(): RouteCache;
|
|
40
|
+
getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
|
|
16
41
|
logRequest(_options: LogRequestPayload): void;
|
|
17
42
|
}
|
package/dist/core/build/app.js
CHANGED
|
@@ -1,31 +1,49 @@
|
|
|
1
1
|
import { BaseApp } from "../app/entrypoints/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { getEnvironment } from "../environment/index.js";
|
|
3
|
+
import { getRouteCache } from "../render/route-cache.js";
|
|
4
4
|
class BuildApp extends BaseApp {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
#buildEnv;
|
|
6
|
+
constructor(manifest, buildEnv) {
|
|
7
|
+
super(manifest);
|
|
8
|
+
this.#buildEnv = buildEnv;
|
|
9
9
|
}
|
|
10
10
|
isDev() {
|
|
11
11
|
return true;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Streaming falls through to the environment default
|
|
15
|
+
* (`manifest.serverLike` for the build environment) — we can skip
|
|
16
|
+
* streaming in SSG for performance, as writing strings is faster.
|
|
17
|
+
*/
|
|
18
|
+
resolveStreaming() {
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
13
21
|
setInternals(internals) {
|
|
14
|
-
this.
|
|
22
|
+
this.#buildEnv.setInternals(internals);
|
|
15
23
|
}
|
|
16
24
|
setOptions(options) {
|
|
17
|
-
this.
|
|
25
|
+
this.#buildEnv.setOptions(options);
|
|
18
26
|
this.logger.setDestination(options.logger.options.destination);
|
|
19
27
|
this.resetAdapterLogger();
|
|
20
28
|
}
|
|
21
29
|
getOptions() {
|
|
22
|
-
return this.
|
|
30
|
+
return this.#buildEnv.getOptions();
|
|
23
31
|
}
|
|
24
32
|
getSettings() {
|
|
25
|
-
return this.
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
return this.#buildEnv.getSettings();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Route cache and component loader for `StaticPaths`. Defined on the app
|
|
37
|
+
* (rather than reached through the functional core at the call site) so
|
|
38
|
+
* they execute inside the prerender bundle's module graph: the default
|
|
39
|
+
* prerenderer constructs `StaticPaths` from a different bundle, whose
|
|
40
|
+
* copies of the core modules hold separate per-manifest state.
|
|
41
|
+
*/
|
|
42
|
+
get routeCache() {
|
|
43
|
+
return getRouteCache(this.manifest);
|
|
44
|
+
}
|
|
45
|
+
getComponentByRoute(routeData) {
|
|
46
|
+
return getEnvironment(this.manifest).getComponentByRoute(this.manifest, routeData);
|
|
29
47
|
}
|
|
30
48
|
logRequest(_options) {
|
|
31
49
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AstroSettings } from '../../types/astro.js';
|
|
2
|
+
import type { RenderEnvironment } from '../environment/index.js';
|
|
3
|
+
import type { BuildInternals } from './internal.js';
|
|
4
|
+
import type { StaticBuildOptions } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* The build / prerender environment record and its mutable closure slots.
|
|
7
|
+
* The build has a two-phase initialization: the prerender bundle is imported
|
|
8
|
+
* first, and `createDefaultPrerenderer.setup()` injects `BuildInternals` /
|
|
9
|
+
* `StaticBuildOptions` afterwards through the facade. The slots live in this
|
|
10
|
+
* closure; accessors throw before injection, and the environment functions
|
|
11
|
+
* close over the same slots.
|
|
12
|
+
*/
|
|
13
|
+
export interface BuildEnvironmentSlots {
|
|
14
|
+
/** The build `RenderEnvironment`; its functions close over the slots below. */
|
|
15
|
+
env: RenderEnvironment;
|
|
16
|
+
setInternals(internals: BuildInternals): void;
|
|
17
|
+
setOptions(options: StaticBuildOptions): void;
|
|
18
|
+
/** Throws `No internals defined` before injection. */
|
|
19
|
+
getInternals(): BuildInternals;
|
|
20
|
+
/** Throws `No options defined` before injection. */
|
|
21
|
+
getOptions(): StaticBuildOptions;
|
|
22
|
+
/** Throws `No options defined` before injection. */
|
|
23
|
+
getSettings(): AstroSettings;
|
|
24
|
+
}
|
|
25
|
+
export declare function createBuildEnvironment(): BuildEnvironmentSlots;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
2
|
+
import { RedirectSinglePageBuiltModule } from "../redirects/index.js";
|
|
3
|
+
import { createAssetLink, createStylesheetElementSet } from "../render/ssr-element.js";
|
|
4
|
+
import { getDefaultRoutes } from "../routing/default.js";
|
|
5
|
+
import { getFallbackRoute, routeIsFallback, routeIsRedirect } from "../routing/helpers.js";
|
|
6
|
+
import { findRouteToRewrite } from "../routing/rewrite.js";
|
|
7
|
+
import { cssOrder, getPageData, mergeInlineCss } from "./runtime.js";
|
|
8
|
+
async function getModuleForRoute(manifest, route) {
|
|
9
|
+
for (const defaultRoute of getDefaultRoutes(manifest)) {
|
|
10
|
+
if (route.component === defaultRoute.component) {
|
|
11
|
+
return {
|
|
12
|
+
page: () => Promise.resolve(defaultRoute.instance)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
let routeToProcess = route;
|
|
17
|
+
if (routeIsRedirect(route)) {
|
|
18
|
+
if (route.redirectRoute) {
|
|
19
|
+
routeToProcess = route.redirectRoute;
|
|
20
|
+
} else {
|
|
21
|
+
return RedirectSinglePageBuiltModule;
|
|
22
|
+
}
|
|
23
|
+
} else if (routeIsFallback(route)) {
|
|
24
|
+
routeToProcess = getFallbackRoute(route, manifest.routes);
|
|
25
|
+
}
|
|
26
|
+
if (manifest.pageMap) {
|
|
27
|
+
const importComponentInstance = manifest.pageMap.get(routeToProcess.component);
|
|
28
|
+
if (!importComponentInstance) {
|
|
29
|
+
throw new Error(`Unexpectedly unable to find a component instance for route ${route.route}`);
|
|
30
|
+
}
|
|
31
|
+
return await importComponentInstance();
|
|
32
|
+
} else if (manifest.pageModule) {
|
|
33
|
+
return manifest.pageModule;
|
|
34
|
+
}
|
|
35
|
+
throw new Error(
|
|
36
|
+
"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."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
async function getComponentByRoute(manifest, routeData) {
|
|
40
|
+
const module = await getModuleForRoute(manifest, routeData);
|
|
41
|
+
return module.page();
|
|
42
|
+
}
|
|
43
|
+
function createBuildEnvironment() {
|
|
44
|
+
let internals;
|
|
45
|
+
let options;
|
|
46
|
+
function getInternals() {
|
|
47
|
+
if (!internals) {
|
|
48
|
+
throw new Error("No internals defined");
|
|
49
|
+
}
|
|
50
|
+
return internals;
|
|
51
|
+
}
|
|
52
|
+
function getOptions() {
|
|
53
|
+
if (!options) {
|
|
54
|
+
throw new Error("No options defined");
|
|
55
|
+
}
|
|
56
|
+
return options;
|
|
57
|
+
}
|
|
58
|
+
function getSettings() {
|
|
59
|
+
return getOptions().settings;
|
|
60
|
+
}
|
|
61
|
+
const resolveCache = /* @__PURE__ */ new Map();
|
|
62
|
+
const env = {
|
|
63
|
+
name: "build",
|
|
64
|
+
runtimeMode: "production",
|
|
65
|
+
// We can skip streaming in SSG for performance as writing as strings is
|
|
66
|
+
// faster.
|
|
67
|
+
defaultStreaming: (manifest) => manifest.serverLike,
|
|
68
|
+
async resolve(manifest, specifier) {
|
|
69
|
+
if (resolveCache.has(specifier)) {
|
|
70
|
+
return resolveCache.get(specifier);
|
|
71
|
+
}
|
|
72
|
+
const hashedFilePath = manifest.entryModules[specifier];
|
|
73
|
+
if (typeof hashedFilePath !== "string" || hashedFilePath === "") {
|
|
74
|
+
if (specifier === BEFORE_HYDRATION_SCRIPT_ID) {
|
|
75
|
+
resolveCache.set(specifier, "");
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
throw new Error(`Cannot find the built path for ${specifier}`);
|
|
79
|
+
}
|
|
80
|
+
const assetLink = createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix);
|
|
81
|
+
resolveCache.set(specifier, assetLink);
|
|
82
|
+
return assetLink;
|
|
83
|
+
},
|
|
84
|
+
headElements(manifest, routeData) {
|
|
85
|
+
const { assetsPrefix, base } = manifest;
|
|
86
|
+
const settings = getSettings();
|
|
87
|
+
const buildInternals = getInternals();
|
|
88
|
+
const links = /* @__PURE__ */ new Set();
|
|
89
|
+
const pageBuildData = getPageData(buildInternals, routeData.route, routeData.component);
|
|
90
|
+
const scripts = /* @__PURE__ */ new Set();
|
|
91
|
+
const sortedCssAssets = pageBuildData?.styles.sort(cssOrder).map(({ sheet }) => sheet).reduce(mergeInlineCss, []);
|
|
92
|
+
const styles = createStylesheetElementSet(sortedCssAssets ?? [], base, assetsPrefix);
|
|
93
|
+
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
94
|
+
const hashedFilePath = buildInternals.entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID);
|
|
95
|
+
if (typeof hashedFilePath !== "string") {
|
|
96
|
+
throw new Error(`Cannot find the built path for ${PAGE_SCRIPT_ID}`);
|
|
97
|
+
}
|
|
98
|
+
const src = createAssetLink(hashedFilePath, base, assetsPrefix);
|
|
99
|
+
scripts.add({
|
|
100
|
+
props: { type: "module", src },
|
|
101
|
+
children: ""
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
for (const script of settings.scripts) {
|
|
105
|
+
if (script.stage === "head-inline") {
|
|
106
|
+
scripts.add({
|
|
107
|
+
props: {},
|
|
108
|
+
children: script.content
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { scripts, styles, links };
|
|
113
|
+
},
|
|
114
|
+
componentMetadata() {
|
|
115
|
+
},
|
|
116
|
+
getComponentByRoute,
|
|
117
|
+
getModuleForRoute,
|
|
118
|
+
async tryRewrite(manifest, payload, request) {
|
|
119
|
+
const { routeData, pathname, newUrl } = findRouteToRewrite({
|
|
120
|
+
payload,
|
|
121
|
+
request,
|
|
122
|
+
// RAW manifest routes, exactly like `BuildPipeline.tryRewrite` — see
|
|
123
|
+
// the production environment's tryRewrite for why the derived
|
|
124
|
+
// (ensured-404) table is NOT observably identical here.
|
|
125
|
+
routes: manifest.routes.map((r) => r.routeData),
|
|
126
|
+
trailingSlash: manifest.trailingSlash,
|
|
127
|
+
buildFormat: manifest.buildFormat,
|
|
128
|
+
base: manifest.base,
|
|
129
|
+
outDir: manifest.serverLike ? manifest.buildClientDir : manifest.outDir
|
|
130
|
+
});
|
|
131
|
+
const componentInstance = await getComponentByRoute(manifest, routeData);
|
|
132
|
+
return { routeData, componentInstance, newUrl, pathname };
|
|
133
|
+
},
|
|
134
|
+
getRenderers(manifest) {
|
|
135
|
+
return manifest.renderers;
|
|
136
|
+
},
|
|
137
|
+
errorStrategy: "build",
|
|
138
|
+
injectCspMetaTagsOnErrorPages: false,
|
|
139
|
+
logRequest() {
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
env,
|
|
144
|
+
setInternals(value) {
|
|
145
|
+
internals = value;
|
|
146
|
+
},
|
|
147
|
+
setOptions(value) {
|
|
148
|
+
options = value;
|
|
149
|
+
},
|
|
150
|
+
getInternals,
|
|
151
|
+
getOptions,
|
|
152
|
+
getSettings
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
export {
|
|
156
|
+
createBuildEnvironment
|
|
157
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { BaseApp } from '../app/base.js';
|
|
2
1
|
import type { FetchState } from '../fetch/fetch-state.js';
|
|
3
|
-
import type {
|
|
2
|
+
import type { SSRManifest } from '../app/types.js';
|
|
3
|
+
import { type CompiledCacheRoute } from './runtime/route-matching.js';
|
|
4
4
|
/**
|
|
5
5
|
* Registers a cache provider on the given `FetchState`. When
|
|
6
6
|
* `state.resolve('cache')` is first called, the appropriate cache
|
|
@@ -22,8 +22,14 @@ export declare function provideCache(state: FetchState): Promise<void> | void;
|
|
|
22
22
|
* Cache headers (`CDN-Cache-Control`, `Cache-Tag`) are stripped from
|
|
23
23
|
* the final response after the runtime provider has read them.
|
|
24
24
|
*/
|
|
25
|
-
export declare
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
export declare function handleCache(state: FetchState, next: () => Promise<Response>): Promise<Response>;
|
|
26
|
+
/**
|
|
27
|
+
* Config-level cache routes compiled from `manifest.cacheConfig`, derived
|
|
28
|
+
* lazily on the first cache-seeded request.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCompiledCacheRoutes(manifest: SSRManifest): CompiledCacheRoute[];
|
|
31
|
+
/**
|
|
32
|
+
* Internal raw setter — exists only so the transitional `Pipeline` bridge can
|
|
33
|
+
* expose `compiledCacheRoutes` as a get/set pair.
|
|
34
|
+
*/
|
|
35
|
+
export declare function setCompiledCacheRoutes(manifest: SSRManifest, routes: CompiledCacheRoute[]): void;
|
|
@@ -1,38 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { markFeatureUsed, FetchFeatures } from "../fetch/features.js";
|
|
2
|
+
import { getEnvironment } from "../environment/index.js";
|
|
3
|
+
import { createManifestMemo } from "../manifest/memo.js";
|
|
4
|
+
import { getCacheProvider } from "./provider.js";
|
|
2
5
|
import { AstroCache, applyCacheHeaders } from "./runtime/cache.js";
|
|
3
6
|
import { NoopAstroCache, DisabledAstroCache } from "./runtime/noop.js";
|
|
4
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
compileCacheRoutes,
|
|
9
|
+
matchCacheRoute
|
|
10
|
+
} from "./runtime/route-matching.js";
|
|
5
11
|
const CACHE_KEY = "cache";
|
|
6
12
|
function provideCache(state) {
|
|
7
|
-
const
|
|
8
|
-
if (!
|
|
13
|
+
const manifest = state.manifest;
|
|
14
|
+
if (!manifest.cacheConfig) {
|
|
9
15
|
state.provide(CACHE_KEY, {
|
|
10
|
-
create: () => new DisabledAstroCache(
|
|
16
|
+
create: () => new DisabledAstroCache(state.logger)
|
|
11
17
|
});
|
|
12
18
|
return;
|
|
13
19
|
}
|
|
14
|
-
if (
|
|
20
|
+
if (getEnvironment(manifest).runtimeMode === "development") {
|
|
15
21
|
state.provide(CACHE_KEY, {
|
|
16
22
|
create: () => new NoopAstroCache()
|
|
17
23
|
});
|
|
18
24
|
return;
|
|
19
25
|
}
|
|
20
|
-
return provideCacheAsync(state,
|
|
26
|
+
return provideCacheAsync(state, manifest);
|
|
21
27
|
}
|
|
22
|
-
async function provideCacheAsync(state,
|
|
23
|
-
const cacheProvider = await
|
|
28
|
+
async function provideCacheAsync(state, manifest) {
|
|
29
|
+
const cacheProvider = await getCacheProvider(manifest);
|
|
24
30
|
state.provide(CACHE_KEY, {
|
|
25
31
|
create() {
|
|
26
32
|
const cache = new AstroCache(cacheProvider);
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
pipeline.compiledCacheRoutes = compileCacheRoutes(
|
|
30
|
-
pipeline.cacheConfig.routes,
|
|
31
|
-
pipeline.manifest.base,
|
|
32
|
-
pipeline.manifest.trailingSlash
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
const matched = matchCacheRoute(state.pathname, pipeline.compiledCacheRoutes);
|
|
33
|
+
if (manifest.cacheConfig?.routes) {
|
|
34
|
+
const matched = matchCacheRoute(state.pathname, getCompiledCacheRoutes(manifest));
|
|
36
35
|
if (matched) {
|
|
37
36
|
cache.set(matched);
|
|
38
37
|
}
|
|
@@ -41,41 +40,46 @@ async function provideCacheAsync(state, pipeline) {
|
|
|
41
40
|
}
|
|
42
41
|
});
|
|
43
42
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
async function handleCache(state, next) {
|
|
44
|
+
markFeatureUsed(state.manifest, FetchFeatures.cache);
|
|
45
|
+
if (!state.manifest.cacheProvider) {
|
|
46
|
+
return next();
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
response2.headers.delete("CDN-Cache-Control");
|
|
70
|
-
response2.headers.delete("Cache-Tag");
|
|
71
|
-
return response2;
|
|
72
|
-
}
|
|
73
|
-
const response = await next();
|
|
74
|
-
applyCacheHeaders(cache, response, state.request);
|
|
75
|
-
return response;
|
|
48
|
+
const cache = state.resolve(CACHE_KEY);
|
|
49
|
+
const cacheProvider = await getCacheProvider(state.manifest);
|
|
50
|
+
if (cacheProvider?.onRequest) {
|
|
51
|
+
const response2 = await cacheProvider.onRequest(
|
|
52
|
+
{
|
|
53
|
+
request: state.request,
|
|
54
|
+
url: new URL(state.request.url),
|
|
55
|
+
waitUntil: state.renderOptions.waitUntil
|
|
56
|
+
},
|
|
57
|
+
async () => {
|
|
58
|
+
const res = await next();
|
|
59
|
+
applyCacheHeaders(cache, res, state.request);
|
|
60
|
+
return res;
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
response2.headers.delete("CDN-Cache-Control");
|
|
64
|
+
response2.headers.delete("Cache-Tag");
|
|
65
|
+
return response2;
|
|
76
66
|
}
|
|
67
|
+
const response = await next();
|
|
68
|
+
applyCacheHeaders(cache, response, state.request);
|
|
69
|
+
return response;
|
|
70
|
+
}
|
|
71
|
+
const compiledCacheRoutesMemo = createManifestMemo(
|
|
72
|
+
(manifest) => manifest.cacheConfig?.routes ? compileCacheRoutes(manifest.cacheConfig.routes, manifest.base, manifest.trailingSlash) : []
|
|
73
|
+
);
|
|
74
|
+
function getCompiledCacheRoutes(manifest) {
|
|
75
|
+
return compiledCacheRoutesMemo.get(manifest);
|
|
76
|
+
}
|
|
77
|
+
function setCompiledCacheRoutes(manifest, routes) {
|
|
78
|
+
compiledCacheRoutesMemo.set(manifest, routes);
|
|
77
79
|
}
|
|
78
80
|
export {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
getCompiledCacheRoutes,
|
|
82
|
+
handleCache,
|
|
83
|
+
provideCache,
|
|
84
|
+
setCompiledCacheRoutes
|
|
81
85
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SSRManifest } from '../app/types.js';
|
|
2
|
+
import type { CacheProvider } from './types.js';
|
|
3
|
+
/** Resolves the cache provider from the manifest, `null` when none. */
|
|
4
|
+
export declare function getCacheProvider(manifest: SSRManifest): Promise<CacheProvider | null>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createAsyncManifestMemo } from "../manifest/memo.js";
|
|
2
|
+
const cacheProviderMemo = createAsyncManifestMemo(async (manifest) => {
|
|
3
|
+
if (manifest.cacheProvider) {
|
|
4
|
+
const mod = await manifest.cacheProvider();
|
|
5
|
+
const factory = mod?.default || null;
|
|
6
|
+
return factory ? factory(manifest.cacheConfig?.options) : null;
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
});
|
|
10
|
+
function getCacheProvider(manifest) {
|
|
11
|
+
return cacheProviderMemo.get(manifest);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
getCacheProvider
|
|
15
|
+
};
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -32,10 +32,6 @@ export declare const clientLocalsSymbol: unique symbol;
|
|
|
32
32
|
* Use this symbol to set and retrieve the original pathname of a request. This is useful when working with redirects and rewrites
|
|
33
33
|
*/
|
|
34
34
|
export declare const originPathnameSymbol: unique symbol;
|
|
35
|
-
/**
|
|
36
|
-
* Use this symbol to set and retrieve the pipeline.
|
|
37
|
-
*/
|
|
38
|
-
export declare const pipelineSymbol: unique symbol;
|
|
39
35
|
/**
|
|
40
36
|
* Use this symbol to stash the active `FetchState` on an `APIContext`
|
|
41
37
|
* (or `ActionAPIContext`). Consumed by internal shims that need access
|
|
@@ -44,13 +40,6 @@ export declare const pipelineSymbol: unique symbol;
|
|
|
44
40
|
* `src/i18n/middleware.ts`.
|
|
45
41
|
*/
|
|
46
42
|
export declare const fetchStateSymbol: unique symbol;
|
|
47
|
-
/**
|
|
48
|
-
* Use this symbol to stash the `BaseApp` on an incoming `Request` at the
|
|
49
|
-
* top of the pipeline. Fetch handlers loaded from `virtual:astro:fetchable`
|
|
50
|
-
* (including `DefaultFetchHandler`) read it to find the app associated
|
|
51
|
-
* with the current request without needing App passed to their constructor.
|
|
52
|
-
*/
|
|
53
|
-
export declare const appSymbol: unique symbol;
|
|
54
43
|
/**
|
|
55
44
|
* Use this symbol to opt into handling prerender routes in Astro core dev middleware.
|
|
56
45
|
*/
|
package/dist/core/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const ASTRO_VERSION = "7.2.
|
|
1
|
+
const ASTRO_VERSION = "7.2.4";
|
|
2
2
|
const ASTRO_GENERATOR = `Astro v${ASTRO_VERSION}`;
|
|
3
3
|
const ASTRO_ERROR_HEADER = "X-Astro-Error";
|
|
4
4
|
const DEFAULT_404_COMPONENT = "astro-default-404.astro";
|
|
@@ -7,9 +7,7 @@ const REROUTABLE_STATUS_CODES = [404, 500];
|
|
|
7
7
|
const clientAddressSymbol = /* @__PURE__ */ Symbol.for("astro.clientAddress");
|
|
8
8
|
const clientLocalsSymbol = /* @__PURE__ */ Symbol.for("astro.locals");
|
|
9
9
|
const originPathnameSymbol = /* @__PURE__ */ Symbol.for("astro.originPathname");
|
|
10
|
-
const pipelineSymbol = /* @__PURE__ */ Symbol.for("astro.pipeline");
|
|
11
10
|
const fetchStateSymbol = /* @__PURE__ */ Symbol.for("astro.fetchState");
|
|
12
|
-
const appSymbol = /* @__PURE__ */ Symbol.for("astro.app");
|
|
13
11
|
const devPrerenderMiddlewareSymbol = /* @__PURE__ */ Symbol.for("astro.devPrerenderMiddleware");
|
|
14
12
|
const nodeRequestAbortControllerCleanupSymbol = /* @__PURE__ */ Symbol.for(
|
|
15
13
|
"astro.nodeRequestAbortControllerCleanup"
|
|
@@ -50,13 +48,11 @@ export {
|
|
|
50
48
|
REDIRECT_STATUS_CODES,
|
|
51
49
|
REROUTABLE_STATUS_CODES,
|
|
52
50
|
SUPPORTED_MARKDOWN_FILE_EXTENSIONS,
|
|
53
|
-
appSymbol,
|
|
54
51
|
clientAddressSymbol,
|
|
55
52
|
clientLocalsSymbol,
|
|
56
53
|
devPrerenderMiddlewareSymbol,
|
|
57
54
|
fetchStateSymbol,
|
|
58
55
|
nodeRequestAbortControllerCleanupSymbol,
|
|
59
56
|
originPathnameSymbol,
|
|
60
|
-
pipelineSymbol,
|
|
61
57
|
responseSentSymbol
|
|
62
58
|
};
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -26,7 +26,7 @@ async function dev(inlineConfig) {
|
|
|
26
26
|
await telemetry.record([]);
|
|
27
27
|
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
28
28
|
const logger = restart.container.logger;
|
|
29
|
-
const currentVersion = "7.2.
|
|
29
|
+
const currentVersion = "7.2.4";
|
|
30
30
|
const isPrerelease = currentVersion.includes("-");
|
|
31
31
|
if (!isPrerelease) {
|
|
32
32
|
try {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RenderEnvironment } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The non-runnable dev environment (workerd and other adapters whose requests
|
|
4
|
+
* run outside Vite's module runner). Registered by the dev virtual entrypoint.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createNonRunnableEnvironment(): RenderEnvironment;
|