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