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