astro 6.0.6 → 6.0.8
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/runtime/server.d.ts +3 -1
- package/dist/actions/runtime/server.js +39 -8
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/content/content-layer.js +7 -4
- package/dist/core/app/entrypoints/node.d.ts +1 -1
- package/dist/core/app/entrypoints/node.js +9 -1
- package/dist/core/app/middlewares.d.ts +1 -0
- package/dist/core/app/middlewares.js +2 -1
- package/dist/core/app/node.d.ts +17 -0
- package/dist/core/app/node.js +1 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +4 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages/runtime.js +1 -1
- package/dist/core/render-context.js +7 -0
- package/dist/core/routing/match.js +8 -0
- package/dist/core/routing/rewrite.d.ts +9 -0
- package/dist/core/routing/rewrite.js +50 -24
- package/dist/core/server-islands/shared-state.d.ts +44 -0
- package/dist/core/server-islands/shared-state.js +96 -0
- package/dist/core/server-islands/vite-plugin-server-islands.d.ts +4 -1
- package/dist/core/server-islands/vite-plugin-server-islands.js +34 -60
- package/dist/i18n/middleware.js +14 -7
- package/dist/i18n/utils.d.ts +6 -0
- package/dist/i18n/utils.js +22 -0
- package/dist/manifest/serialized.js +11 -3
- package/dist/vite-plugin-astro-server/plugin.js +2 -2
- package/dist/vite-plugin-css/index.js +22 -0
- package/dist/vite-plugin-renderers/index.d.ts +2 -0
- package/dist/vite-plugin-renderers/index.js +1 -1
- package/package.json +1 -1
|
@@ -38,6 +38,8 @@ interface AstroActionContext {
|
|
|
38
38
|
export declare function getActionContext(context: APIContext): AstroActionContext;
|
|
39
39
|
export declare const ACTION_API_CONTEXT_SYMBOL: unique symbol;
|
|
40
40
|
/** Transform form data to an object based on a Zod schema. */
|
|
41
|
-
export declare function formDataToObject<T extends z.$ZodObject>(formData: FormData, schema: T
|
|
41
|
+
export declare function formDataToObject<T extends z.$ZodObject>(formData: FormData, schema: T,
|
|
42
|
+
/** @internal */
|
|
43
|
+
prefix?: string): Record<string, unknown>;
|
|
42
44
|
export declare function serializeActionResult(res: SafeResult<any, any>): SerializedActionResult;
|
|
43
45
|
export {};
|
|
@@ -206,29 +206,60 @@ function isActionAPIContext(ctx) {
|
|
|
206
206
|
const symbol = Reflect.get(ctx, ACTION_API_CONTEXT_SYMBOL);
|
|
207
207
|
return symbol === true;
|
|
208
208
|
}
|
|
209
|
-
function formDataToObject(formData, schema) {
|
|
210
|
-
const
|
|
209
|
+
function formDataToObject(formData, schema, prefix = "") {
|
|
210
|
+
const formKeys = [...formData.keys()];
|
|
211
|
+
const obj = schema._zod.def.catchall ? Object.fromEntries(
|
|
212
|
+
[...formData.entries()].filter(([k]) => k.startsWith(prefix)).map(([k, v]) => [k.slice(prefix.length), v])
|
|
213
|
+
) : {};
|
|
211
214
|
for (const [key, baseValidator] of Object.entries(schema._zod.def.shape)) {
|
|
215
|
+
const prefixedKey = prefix + key;
|
|
212
216
|
let validator = baseValidator;
|
|
213
217
|
while (validator instanceof z.$ZodOptional || validator instanceof z.$ZodNullable || validator instanceof z.$ZodDefault) {
|
|
214
|
-
if (validator instanceof z.$ZodDefault && !
|
|
218
|
+
if (validator instanceof z.$ZodDefault && !formDataHasKeyOrPrefix(formKeys, prefixedKey)) {
|
|
215
219
|
obj[key] = validator._zod.def.defaultValue instanceof Function ? validator._zod.def.defaultValue() : validator._zod.def.defaultValue;
|
|
216
220
|
}
|
|
217
221
|
validator = validator._zod.def.innerType;
|
|
218
222
|
}
|
|
219
|
-
|
|
223
|
+
while (validator instanceof z.$ZodPipe) {
|
|
224
|
+
validator = validator._zod.def.in;
|
|
225
|
+
}
|
|
226
|
+
if (validator instanceof z.$ZodDiscriminatedUnion) {
|
|
227
|
+
const typeKey = validator._zod.def.discriminator;
|
|
228
|
+
const typeValue = formData.get(prefixedKey + "." + typeKey);
|
|
229
|
+
if (typeof typeValue === "string") {
|
|
230
|
+
const match = validator._zod.def.options.find(
|
|
231
|
+
(option) => option.def.shape[typeKey].values.has(typeValue)
|
|
232
|
+
);
|
|
233
|
+
if (match) {
|
|
234
|
+
validator = match;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (validator instanceof z.$ZodObject) {
|
|
239
|
+
const nestedPrefix = prefixedKey + ".";
|
|
240
|
+
const hasNestedKeys = formKeys.some((k) => k.startsWith(nestedPrefix));
|
|
241
|
+
if (hasNestedKeys) {
|
|
242
|
+
obj[key] = formDataToObject(formData, validator, nestedPrefix);
|
|
243
|
+
} else if (!(key in obj)) {
|
|
244
|
+
obj[key] = baseValidator instanceof z.$ZodNullable ? null : void 0;
|
|
245
|
+
}
|
|
246
|
+
} else if (!formData.has(prefixedKey) && key in obj) {
|
|
220
247
|
continue;
|
|
221
248
|
} else if (validator instanceof z.$ZodBoolean) {
|
|
222
|
-
const val = formData.get(
|
|
223
|
-
obj[key] = val === "true" ? true : val === "false" ? false : formData.has(
|
|
249
|
+
const val = formData.get(prefixedKey);
|
|
250
|
+
obj[key] = val === "true" ? true : val === "false" ? false : formData.has(prefixedKey);
|
|
224
251
|
} else if (validator instanceof z.$ZodArray) {
|
|
225
|
-
obj[key] = handleFormDataGetAll(
|
|
252
|
+
obj[key] = handleFormDataGetAll(prefixedKey, formData, validator);
|
|
226
253
|
} else {
|
|
227
|
-
obj[key] = handleFormDataGet(
|
|
254
|
+
obj[key] = handleFormDataGet(prefixedKey, formData, validator, baseValidator);
|
|
228
255
|
}
|
|
229
256
|
}
|
|
230
257
|
return obj;
|
|
231
258
|
}
|
|
259
|
+
function formDataHasKeyOrPrefix(formKeys, key) {
|
|
260
|
+
const prefix = key + ".";
|
|
261
|
+
return formKeys.some((k) => k === key || k.startsWith(prefix));
|
|
262
|
+
}
|
|
232
263
|
function handleFormDataGetAll(key, formData, validator) {
|
|
233
264
|
const entries = Array.from(formData.getAll(key));
|
|
234
265
|
const elementValidator = validator._zod.def.element;
|
|
@@ -117,7 +117,10 @@ class ContentLayer {
|
|
|
117
117
|
});
|
|
118
118
|
return {
|
|
119
119
|
html: code,
|
|
120
|
-
metadata
|
|
120
|
+
metadata: {
|
|
121
|
+
...metadata,
|
|
122
|
+
imagePaths: (metadata.localImagePaths ?? []).concat(metadata.remoteImagePaths ?? [])
|
|
123
|
+
}
|
|
121
124
|
};
|
|
122
125
|
}
|
|
123
126
|
/**
|
|
@@ -189,7 +192,7 @@ ${contentConfig.error.message}`
|
|
|
189
192
|
logger.info("Content config changed");
|
|
190
193
|
shouldClear = true;
|
|
191
194
|
}
|
|
192
|
-
if (previousAstroVersion && previousAstroVersion !== "6.0.
|
|
195
|
+
if (previousAstroVersion && previousAstroVersion !== "6.0.8") {
|
|
193
196
|
logger.info("Astro version changed");
|
|
194
197
|
shouldClear = true;
|
|
195
198
|
}
|
|
@@ -197,8 +200,8 @@ ${contentConfig.error.message}`
|
|
|
197
200
|
logger.info("Clearing content store");
|
|
198
201
|
this.#store.clearAll();
|
|
199
202
|
}
|
|
200
|
-
if ("6.0.
|
|
201
|
-
this.#store.metaStore().set("astro-version", "6.0.
|
|
203
|
+
if ("6.0.8") {
|
|
204
|
+
this.#store.metaStore().set("astro-version", "6.0.8");
|
|
202
205
|
}
|
|
203
206
|
if (currentConfigDigest) {
|
|
204
207
|
this.#store.metaStore().set("content-config-digest", currentConfigDigest);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { NodeApp, loadApp, loadManifest, createRequest, writeResponse } from '../node.js';
|
|
1
|
+
export { NodeApp, loadApp, loadManifest, createRequest, writeResponse, getAbortControllerCleanup, } from '../node.js';
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NodeApp,
|
|
3
|
+
loadApp,
|
|
4
|
+
loadManifest,
|
|
5
|
+
createRequest,
|
|
6
|
+
writeResponse,
|
|
7
|
+
getAbortControllerCleanup
|
|
8
|
+
} from "../node.js";
|
|
2
9
|
export {
|
|
3
10
|
NodeApp,
|
|
4
11
|
createRequest,
|
|
12
|
+
getAbortControllerCleanup,
|
|
5
13
|
loadApp,
|
|
6
14
|
loadManifest,
|
|
7
15
|
writeResponse
|
package/dist/core/app/node.d.ts
CHANGED
|
@@ -90,6 +90,23 @@ export declare class NodeApp extends App {
|
|
|
90
90
|
*/
|
|
91
91
|
static writeResponse: typeof writeResponse;
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns the cleanup function for the AbortController and socket listeners created by `createRequest()`
|
|
95
|
+
* for the NodeJS IncomingMessage. This should only be called directly if the request is not
|
|
96
|
+
* being handled by Astro, i.e. if not calling `writeResponse()` after `createRequest()`.
|
|
97
|
+
* ```js
|
|
98
|
+
* import { createRequest, getAbortControllerCleanup } from 'astro/app/node';
|
|
99
|
+
* import { createServer } from 'node:http';
|
|
100
|
+
*
|
|
101
|
+
* const server = createServer(async (req, res) => {
|
|
102
|
+
* const request = createRequest(req);
|
|
103
|
+
* const cleanup = getAbortControllerCleanup(req);
|
|
104
|
+
* if (cleanup) cleanup();
|
|
105
|
+
* // can now safely call another handler
|
|
106
|
+
* })
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function getAbortControllerCleanup(req?: NodeRequest): (() => void) | undefined;
|
|
93
110
|
/** @deprecated This will be removed in a future major version. */
|
|
94
111
|
export declare function loadManifest(rootFolder: URL): Promise<SSRManifest>;
|
|
95
112
|
/** @deprecated This will be removed in a future major version. */
|
package/dist/core/app/node.js
CHANGED
package/dist/core/constants.js
CHANGED
package/dist/core/create-vite.js
CHANGED
|
@@ -43,6 +43,7 @@ import astroScriptsPageSSRPlugin from "../vite-plugin-scripts/page-ssr.js";
|
|
|
43
43
|
import { createViteLogger } from "./logger/vite.js";
|
|
44
44
|
import { vitePluginMiddleware } from "./middleware/vite-plugin.js";
|
|
45
45
|
import { joinPaths } from "./path.js";
|
|
46
|
+
import { ServerIslandsState } from "./server-islands/shared-state.js";
|
|
46
47
|
import { vitePluginServerIslands } from "./server-islands/vite-plugin-server-islands.js";
|
|
47
48
|
import { vitePluginCacheProvider } from "./cache/vite-plugin.js";
|
|
48
49
|
import { vitePluginSessionDriver } from "./session/vite-plugin.js";
|
|
@@ -80,6 +81,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
|
|
|
80
81
|
mode,
|
|
81
82
|
config: settings.config
|
|
82
83
|
});
|
|
84
|
+
const serverIslandsState = new ServerIslandsState();
|
|
83
85
|
validateEnvPrefixAgainstSchema(settings.config);
|
|
84
86
|
const commonConfig = {
|
|
85
87
|
// Tell Vite not to combine config from vite.config.js with our provided inline config
|
|
@@ -96,6 +98,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
|
|
|
96
98
|
vitePluginRenderers({
|
|
97
99
|
settings,
|
|
98
100
|
routesList,
|
|
101
|
+
serverIslandsState,
|
|
99
102
|
command: command === "dev" ? "serve" : "build"
|
|
100
103
|
}),
|
|
101
104
|
vitePluginStaticPaths(),
|
|
@@ -133,7 +136,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
|
|
|
133
136
|
vitePluginFileURL(),
|
|
134
137
|
astroInternationalization({ settings }),
|
|
135
138
|
vitePluginActions({ fs, settings }),
|
|
136
|
-
vitePluginServerIslands({ settings, logger }),
|
|
139
|
+
vitePluginServerIslands({ settings, logger, serverIslandsState }),
|
|
137
140
|
vitePluginSessionDriver({ settings }),
|
|
138
141
|
vitePluginCacheProvider({ settings }),
|
|
139
142
|
astroContainer(),
|
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 = "6.0.
|
|
29
|
+
const currentVersion = "6.0.8";
|
|
30
30
|
const isPrerelease = currentVersion.includes("-");
|
|
31
31
|
if (!isPrerelease) {
|
|
32
32
|
try {
|
|
@@ -4,6 +4,7 @@ import { getActionContext } from "../actions/runtime/server.js";
|
|
|
4
4
|
import { createCallAction, createGetActionResult, hasActionPayload } from "../actions/utils.js";
|
|
5
5
|
import {
|
|
6
6
|
computeCurrentLocale,
|
|
7
|
+
computeCurrentLocaleFromParams,
|
|
7
8
|
computePreferredLocale,
|
|
8
9
|
computePreferredLocaleList
|
|
9
10
|
} from "../i18n/utils.js";
|
|
@@ -737,6 +738,12 @@ class RenderContext {
|
|
|
737
738
|
}
|
|
738
739
|
pathname = pathname && !isRoute404or500(routeData) ? pathname : url.pathname;
|
|
739
740
|
computedLocale = computeCurrentLocale(pathname, locales, defaultLocale);
|
|
741
|
+
if (routeData.params.length > 0) {
|
|
742
|
+
const localeFromParams = computeCurrentLocaleFromParams(this.params, locales);
|
|
743
|
+
if (localeFromParams) {
|
|
744
|
+
computedLocale = localeFromParams;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
740
747
|
}
|
|
741
748
|
this.#currentLocale = computedLocale ?? fallbackTo;
|
|
742
749
|
return this.#currentLocale;
|
|
@@ -2,6 +2,14 @@ import { redirectIsExternal } from "../redirects/render.js";
|
|
|
2
2
|
import { SERVER_ISLAND_COMPONENT } from "../server-islands/endpoint.js";
|
|
3
3
|
import { isRoute404, isRoute500 } from "./internal/route-errors.js";
|
|
4
4
|
function matchRoute(pathname, manifest) {
|
|
5
|
+
if (isRoute404(pathname)) {
|
|
6
|
+
const errorRoute = manifest.routes.find((route) => isRoute404(route.route));
|
|
7
|
+
if (errorRoute) return errorRoute;
|
|
8
|
+
}
|
|
9
|
+
if (isRoute500(pathname)) {
|
|
10
|
+
const errorRoute = manifest.routes.find((route) => isRoute500(route.route));
|
|
11
|
+
if (errorRoute) return errorRoute;
|
|
12
|
+
}
|
|
5
13
|
return manifest.routes.find((route) => {
|
|
6
14
|
return route.pattern.test(pathname) || route.fallbackRoutes.some((fallbackRoute) => fallbackRoute.pattern.test(pathname));
|
|
7
15
|
});
|
|
@@ -34,4 +34,13 @@ export declare function findRouteToRewrite({ payload, routes, request, trailingS
|
|
|
34
34
|
export declare function copyRequest(newUrl: URL, oldRequest: Request, isPrerendered: boolean, logger: Logger, routePattern: string): Request;
|
|
35
35
|
export declare function setOriginPathname(request: Request, pathname: string, trailingSlash: AstroConfig['trailingSlash'], buildFormat: AstroConfig['build']['format']): void;
|
|
36
36
|
export declare function getOriginPathname(request: Request): string;
|
|
37
|
+
/**
|
|
38
|
+
* Pure function that normalizes a rewrite target pathname by stripping the base,
|
|
39
|
+
* handling trailing slashes, removing `.html` suffixes, and computing the final
|
|
40
|
+
* full URL pathname (with base re-prepended).
|
|
41
|
+
*/
|
|
42
|
+
export declare function normalizeRewritePathname(urlPathname: string, base: AstroConfig['base'], trailingSlash: AstroConfig['trailingSlash'], buildFormat: AstroConfig['build']['format']): {
|
|
43
|
+
pathname: string;
|
|
44
|
+
resolvedUrlPathname: string;
|
|
45
|
+
};
|
|
37
46
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { collapseDuplicateSlashes } from "@astrojs/internal-helpers/path";
|
|
1
2
|
import { shouldAppendForwardSlash } from "../build/util.js";
|
|
2
3
|
import { originPathnameSymbol } from "../constants.js";
|
|
3
4
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
} from "../path.js";
|
|
11
12
|
import { createRequest } from "../request.js";
|
|
12
13
|
import { DEFAULT_404_ROUTE } from "./internal/astro-designed-error-pages.js";
|
|
14
|
+
import { isRoute404, isRoute500 } from "./internal/route-errors.js";
|
|
13
15
|
function findRouteToRewrite({
|
|
14
16
|
payload,
|
|
15
17
|
routes,
|
|
@@ -25,34 +27,28 @@ function findRouteToRewrite({
|
|
|
25
27
|
} else if (payload instanceof Request) {
|
|
26
28
|
newUrl = new URL(payload.url);
|
|
27
29
|
} else {
|
|
28
|
-
newUrl = new URL(payload, new URL(request.url).origin);
|
|
30
|
+
newUrl = new URL(collapseDuplicateSlashes(payload), new URL(request.url).origin);
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const { pathname, resolvedUrlPathname } = normalizeRewritePathname(
|
|
33
|
+
newUrl.pathname,
|
|
34
|
+
base,
|
|
35
|
+
trailingSlash,
|
|
36
|
+
buildFormat
|
|
37
|
+
);
|
|
38
|
+
newUrl.pathname = resolvedUrlPathname;
|
|
39
|
+
const decodedPathname = decodeURI(pathname);
|
|
40
|
+
if (isRoute404(decodedPathname)) {
|
|
41
|
+
const errorRoute = routes.find((route) => route.route === "/404");
|
|
42
|
+
if (errorRoute) {
|
|
43
|
+
return { routeData: errorRoute, newUrl, pathname: decodedPathname };
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
if (buildFormat === "file") {
|
|
48
|
-
pathname = pathname.replace(/\.html$/, "");
|
|
49
|
-
}
|
|
50
|
-
if (base !== "/" && (pathname === "" || pathname === "/") && !shouldAppendSlash) {
|
|
51
|
-
newUrl.pathname = removeTrailingForwardSlash(base);
|
|
52
|
-
} else {
|
|
53
|
-
newUrl.pathname = joinPaths(...[base, pathname].filter(Boolean));
|
|
46
|
+
if (isRoute500(decodedPathname)) {
|
|
47
|
+
const errorRoute = routes.find((route) => route.route === "/500");
|
|
48
|
+
if (errorRoute) {
|
|
49
|
+
return { routeData: errorRoute, newUrl, pathname: decodedPathname };
|
|
50
|
+
}
|
|
54
51
|
}
|
|
55
|
-
const decodedPathname = decodeURI(pathname);
|
|
56
52
|
let foundRoute;
|
|
57
53
|
for (const route of routes) {
|
|
58
54
|
if (route.pattern.test(decodedPathname)) {
|
|
@@ -132,9 +128,39 @@ function getOriginPathname(request) {
|
|
|
132
128
|
}
|
|
133
129
|
return new URL(request.url).pathname;
|
|
134
130
|
}
|
|
131
|
+
function normalizeRewritePathname(urlPathname, base, trailingSlash, buildFormat) {
|
|
132
|
+
let pathname = collapseDuplicateSlashes(urlPathname);
|
|
133
|
+
const shouldAppendSlash = shouldAppendForwardSlash(trailingSlash, buildFormat);
|
|
134
|
+
if (base !== "/") {
|
|
135
|
+
const isBasePathRequest = urlPathname === base || urlPathname === removeTrailingForwardSlash(base);
|
|
136
|
+
if (isBasePathRequest) {
|
|
137
|
+
pathname = shouldAppendSlash ? "/" : "";
|
|
138
|
+
} else if (urlPathname.startsWith(base)) {
|
|
139
|
+
pathname = shouldAppendSlash ? appendForwardSlash(urlPathname) : removeTrailingForwardSlash(urlPathname);
|
|
140
|
+
pathname = pathname.slice(base.length);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!pathname.startsWith("/") && shouldAppendSlash && urlPathname.endsWith("/")) {
|
|
144
|
+
pathname = prependForwardSlash(pathname);
|
|
145
|
+
}
|
|
146
|
+
if (pathname === "/" && base !== "/" && !shouldAppendSlash) {
|
|
147
|
+
pathname = "";
|
|
148
|
+
}
|
|
149
|
+
if (buildFormat === "file") {
|
|
150
|
+
pathname = pathname.replace(/\.html$/, "");
|
|
151
|
+
}
|
|
152
|
+
let resolvedUrlPathname;
|
|
153
|
+
if (base !== "/" && (pathname === "" || pathname === "/") && !shouldAppendSlash) {
|
|
154
|
+
resolvedUrlPathname = removeTrailingForwardSlash(base);
|
|
155
|
+
} else {
|
|
156
|
+
resolvedUrlPathname = joinPaths(...[base, pathname].filter(Boolean));
|
|
157
|
+
}
|
|
158
|
+
return { pathname, resolvedUrlPathname };
|
|
159
|
+
}
|
|
135
160
|
export {
|
|
136
161
|
copyRequest,
|
|
137
162
|
findRouteToRewrite,
|
|
138
163
|
getOriginPathname,
|
|
164
|
+
normalizeRewritePathname,
|
|
139
165
|
setOriginPathname
|
|
140
166
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
type ServerIslandDiscovery = {
|
|
2
|
+
resolvedPath: string;
|
|
3
|
+
localName: string;
|
|
4
|
+
specifier: string;
|
|
5
|
+
importer: string;
|
|
6
|
+
};
|
|
7
|
+
type ServerIslandRecord = Omit<ServerIslandDiscovery, 'resolvedPath'> & {
|
|
8
|
+
islandName: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class ServerIslandsState {
|
|
11
|
+
private islandsByResolvedPath;
|
|
12
|
+
private resolvedPathByIslandName;
|
|
13
|
+
private referenceIdByResolvedPath;
|
|
14
|
+
hasIslands(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Record a discovered server island.
|
|
17
|
+
*
|
|
18
|
+
* Dedupe is based on `resolvedPath`: if the same resolved path is discovered
|
|
19
|
+
* again from a different importer/specifier, the first record is preserved.
|
|
20
|
+
* This keeps island names stable across repeated scans.
|
|
21
|
+
*/
|
|
22
|
+
discover(island: ServerIslandDiscovery): ServerIslandRecord;
|
|
23
|
+
getDiscoveredIslands(): Iterable<ServerIslandRecord>;
|
|
24
|
+
hasReferenceId(resolvedPath: string): boolean;
|
|
25
|
+
setReferenceId(resolvedPath: string, referenceId: string): void;
|
|
26
|
+
getDiscoveredIslandEntries(): Iterable<[string, ServerIslandRecord]>;
|
|
27
|
+
/**
|
|
28
|
+
* Build import-map source from discovered islands.
|
|
29
|
+
*
|
|
30
|
+
* Used by non-SSR build output and dev replacement paths where we can import
|
|
31
|
+
* directly from discovered component paths.
|
|
32
|
+
*/
|
|
33
|
+
createImportMapSourceFromDiscovered(toImportPath: (fileName: string) => string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Build import-map source from Rollup reference ids.
|
|
36
|
+
*
|
|
37
|
+
* Used by SSR build output: reference ids are resolved to final emitted chunk
|
|
38
|
+
* file names before generating import() mappings.
|
|
39
|
+
*/
|
|
40
|
+
createImportMapSourceFromReferences(resolveFileName: (referenceId: string) => string, toImportPath: (fileName: string) => string): string;
|
|
41
|
+
createNameMapSource(): string;
|
|
42
|
+
private createImportMapSource;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
class ServerIslandsState {
|
|
2
|
+
// Canonical source of discovered islands keyed by resolved component path.
|
|
3
|
+
islandsByResolvedPath = /* @__PURE__ */ new Map();
|
|
4
|
+
// Reverse lookup used to keep island names unique and stable.
|
|
5
|
+
resolvedPathByIslandName = /* @__PURE__ */ new Map();
|
|
6
|
+
// Rollup reference ids emitted for SSR chunks, keyed by resolved path.
|
|
7
|
+
referenceIdByResolvedPath = /* @__PURE__ */ new Map();
|
|
8
|
+
hasIslands() {
|
|
9
|
+
return this.islandsByResolvedPath.size > 0;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Record a discovered server island.
|
|
13
|
+
*
|
|
14
|
+
* Dedupe is based on `resolvedPath`: if the same resolved path is discovered
|
|
15
|
+
* again from a different importer/specifier, the first record is preserved.
|
|
16
|
+
* This keeps island names stable across repeated scans.
|
|
17
|
+
*/
|
|
18
|
+
discover(island) {
|
|
19
|
+
const { resolvedPath, ...discovery } = island;
|
|
20
|
+
const existing = this.islandsByResolvedPath.get(resolvedPath);
|
|
21
|
+
if (existing) {
|
|
22
|
+
return existing;
|
|
23
|
+
}
|
|
24
|
+
let name = island.localName;
|
|
25
|
+
let idx = 1;
|
|
26
|
+
while (this.resolvedPathByIslandName.has(name)) {
|
|
27
|
+
name += idx++;
|
|
28
|
+
}
|
|
29
|
+
const record = {
|
|
30
|
+
...discovery,
|
|
31
|
+
islandName: name
|
|
32
|
+
};
|
|
33
|
+
this.islandsByResolvedPath.set(resolvedPath, record);
|
|
34
|
+
this.resolvedPathByIslandName.set(name, resolvedPath);
|
|
35
|
+
return record;
|
|
36
|
+
}
|
|
37
|
+
getDiscoveredIslands() {
|
|
38
|
+
return this.islandsByResolvedPath.values();
|
|
39
|
+
}
|
|
40
|
+
hasReferenceId(resolvedPath) {
|
|
41
|
+
return this.referenceIdByResolvedPath.has(resolvedPath);
|
|
42
|
+
}
|
|
43
|
+
setReferenceId(resolvedPath, referenceId) {
|
|
44
|
+
this.referenceIdByResolvedPath.set(resolvedPath, referenceId);
|
|
45
|
+
}
|
|
46
|
+
getDiscoveredIslandEntries() {
|
|
47
|
+
return this.islandsByResolvedPath.entries();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build import-map source from discovered islands.
|
|
51
|
+
*
|
|
52
|
+
* Used by non-SSR build output and dev replacement paths where we can import
|
|
53
|
+
* directly from discovered component paths.
|
|
54
|
+
*/
|
|
55
|
+
createImportMapSourceFromDiscovered(toImportPath) {
|
|
56
|
+
const entries = Array.from(
|
|
57
|
+
this.islandsByResolvedPath,
|
|
58
|
+
([resolvedPath, island]) => [island.islandName, resolvedPath]
|
|
59
|
+
);
|
|
60
|
+
return this.createImportMapSource(entries, toImportPath);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Build import-map source from Rollup reference ids.
|
|
64
|
+
*
|
|
65
|
+
* Used by SSR build output: reference ids are resolved to final emitted chunk
|
|
66
|
+
* file names before generating import() mappings.
|
|
67
|
+
*/
|
|
68
|
+
createImportMapSourceFromReferences(resolveFileName, toImportPath) {
|
|
69
|
+
const entries = [];
|
|
70
|
+
for (const [resolvedPath, referenceId] of this.referenceIdByResolvedPath) {
|
|
71
|
+
const island = this.islandsByResolvedPath.get(resolvedPath);
|
|
72
|
+
if (!island) continue;
|
|
73
|
+
entries.push([island.islandName, resolveFileName(referenceId)]);
|
|
74
|
+
}
|
|
75
|
+
return this.createImportMapSource(entries, toImportPath);
|
|
76
|
+
}
|
|
77
|
+
createNameMapSource() {
|
|
78
|
+
const entries = Array.from(
|
|
79
|
+
this.islandsByResolvedPath,
|
|
80
|
+
([resolvedPath, island]) => [resolvedPath, island.islandName]
|
|
81
|
+
);
|
|
82
|
+
return `new Map(${JSON.stringify(entries, null, 2)})`;
|
|
83
|
+
}
|
|
84
|
+
createImportMapSource(entries, toImportPath) {
|
|
85
|
+
const mappings = Array.from(entries, ([islandName, fileName]) => {
|
|
86
|
+
const importPath = toImportPath(fileName);
|
|
87
|
+
return ` [${JSON.stringify(islandName)}, () => import(${JSON.stringify(importPath)})],`;
|
|
88
|
+
});
|
|
89
|
+
return `new Map([
|
|
90
|
+
${mappings.join("\n")}
|
|
91
|
+
])`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
ServerIslandsState
|
|
96
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Plugin as VitePlugin } from 'vite';
|
|
2
2
|
import type { AstroPluginOptions } from '../../types/astro.js';
|
|
3
|
+
import type { ServerIslandsState } from './shared-state.js';
|
|
3
4
|
export declare const SERVER_ISLAND_MANIFEST = "virtual:astro:server-island-manifest";
|
|
4
5
|
export declare const SERVER_ISLAND_MAP_MARKER = "$$server-islands-map$$";
|
|
5
|
-
export declare function vitePluginServerIslands({ settings }: AstroPluginOptions
|
|
6
|
+
export declare function vitePluginServerIslands({ settings, serverIslandsState, }: AstroPluginOptions & {
|
|
7
|
+
serverIslandsState: ServerIslandsState;
|
|
8
|
+
}): VitePlugin;
|
|
@@ -7,36 +7,22 @@ const serverIslandPlaceholderNameMap = "'$$server-islands-name-map$$'";
|
|
|
7
7
|
const SERVER_ISLAND_MAP_MARKER = "$$server-islands-map$$";
|
|
8
8
|
const serverIslandMapReplaceExp = /['"]\$\$server-islands-map\$\$['"]/g;
|
|
9
9
|
const serverIslandNameMapReplaceExp = /['"]\$\$server-islands-name-map\$\$['"]/g;
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
return `new Map([
|
|
16
|
-
${mappings.join("\n")}
|
|
17
|
-
])`;
|
|
18
|
-
}
|
|
19
|
-
function createNameMapSource(entries) {
|
|
20
|
-
return `new Map(${JSON.stringify(Array.from(entries), null, 2)})`;
|
|
21
|
-
}
|
|
22
|
-
function vitePluginServerIslands({ settings }) {
|
|
10
|
+
function vitePluginServerIslands({
|
|
11
|
+
settings,
|
|
12
|
+
serverIslandsState
|
|
13
|
+
}) {
|
|
23
14
|
let command = "serve";
|
|
24
15
|
let ssrEnvironment = null;
|
|
25
|
-
const serverIslandMap = /* @__PURE__ */ new Map();
|
|
26
|
-
const serverIslandNameMap = /* @__PURE__ */ new Map();
|
|
27
|
-
const serverIslandSourceMap = /* @__PURE__ */ new Map();
|
|
28
|
-
const referenceIdMap = /* @__PURE__ */ new Map();
|
|
29
16
|
function ensureServerIslandReferenceIds(ctx) {
|
|
30
|
-
for (const [resolvedPath,
|
|
31
|
-
if (
|
|
32
|
-
const source = serverIslandSourceMap.get(resolvedPath);
|
|
17
|
+
for (const [resolvedPath, island] of serverIslandsState.getDiscoveredIslandEntries()) {
|
|
18
|
+
if (serverIslandsState.hasReferenceId(resolvedPath)) continue;
|
|
33
19
|
const referenceId = ctx.emitFile({
|
|
34
20
|
type: "chunk",
|
|
35
|
-
id:
|
|
36
|
-
importer:
|
|
37
|
-
name: islandName
|
|
21
|
+
id: island.specifier,
|
|
22
|
+
importer: island.importer,
|
|
23
|
+
name: island.islandName
|
|
38
24
|
});
|
|
39
|
-
|
|
25
|
+
serverIslandsState.setReferenceId(resolvedPath, referenceId);
|
|
40
26
|
}
|
|
41
27
|
}
|
|
42
28
|
return {
|
|
@@ -86,33 +72,27 @@ export const serverIslandNameMap = ${serverIslandPlaceholderNameMap};`
|
|
|
86
72
|
const isBuildSsr = command === "build" && this.environment?.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr;
|
|
87
73
|
if (astro) {
|
|
88
74
|
for (const comp of astro.serverComponents) {
|
|
89
|
-
if (!
|
|
90
|
-
|
|
91
|
-
throw new AstroError(AstroErrorData.NoAdapterInstalledServerIslands);
|
|
92
|
-
}
|
|
93
|
-
let name = comp.localName;
|
|
94
|
-
let idx = 1;
|
|
95
|
-
while (serverIslandMap.has(name)) {
|
|
96
|
-
name += idx++;
|
|
97
|
-
}
|
|
98
|
-
serverIslandNameMap.set(comp.resolvedPath, name);
|
|
99
|
-
serverIslandMap.set(name, comp.resolvedPath);
|
|
100
|
-
serverIslandSourceMap.set(comp.resolvedPath, { id: comp.specifier, importer: id });
|
|
75
|
+
if (!settings.adapter) {
|
|
76
|
+
throw new AstroError(AstroErrorData.NoAdapterInstalledServerIslands);
|
|
101
77
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
78
|
+
const island = serverIslandsState.discover({
|
|
79
|
+
resolvedPath: comp.resolvedPath,
|
|
80
|
+
localName: comp.localName,
|
|
81
|
+
specifier: comp.specifier ?? comp.resolvedPath,
|
|
82
|
+
importer: id
|
|
83
|
+
});
|
|
84
|
+
if (isBuildSsr && !serverIslandsState.hasReferenceId(comp.resolvedPath)) {
|
|
105
85
|
const referenceId = this.emitFile({
|
|
106
86
|
type: "chunk",
|
|
107
|
-
id:
|
|
108
|
-
importer:
|
|
109
|
-
name: islandName
|
|
87
|
+
id: island.specifier,
|
|
88
|
+
importer: island.importer,
|
|
89
|
+
name: island.islandName
|
|
110
90
|
});
|
|
111
|
-
|
|
91
|
+
serverIslandsState.setReferenceId(comp.resolvedPath, referenceId);
|
|
112
92
|
}
|
|
113
93
|
}
|
|
114
94
|
}
|
|
115
|
-
if (
|
|
95
|
+
if (serverIslandsState.hasIslands() && ssrEnvironment) {
|
|
116
96
|
const mod = ssrEnvironment.moduleGraph.getModuleById(RESOLVED_SERVER_ISLAND_MANIFEST);
|
|
117
97
|
if (mod) {
|
|
118
98
|
ssrEnvironment.moduleGraph.invalidateModule(mod);
|
|
@@ -120,17 +100,16 @@ export const serverIslandNameMap = ${serverIslandPlaceholderNameMap};`
|
|
|
120
100
|
}
|
|
121
101
|
if (id === RESOLVED_SERVER_ISLAND_MANIFEST) {
|
|
122
102
|
if (command === "build" && settings.buildOutput) {
|
|
123
|
-
const hasServerIslands =
|
|
103
|
+
const hasServerIslands = serverIslandsState.hasIslands();
|
|
124
104
|
if (hasServerIslands && settings.buildOutput !== "server") {
|
|
125
105
|
throw new AstroError(AstroErrorData.NoAdapterInstalledServerIslands);
|
|
126
106
|
}
|
|
127
107
|
}
|
|
128
|
-
if (command !== "build" &&
|
|
129
|
-
const mapSource =
|
|
130
|
-
serverIslandMap,
|
|
108
|
+
if (command !== "build" && serverIslandsState.hasIslands()) {
|
|
109
|
+
const mapSource = serverIslandsState.createImportMapSourceFromDiscovered(
|
|
131
110
|
(fileName) => fileName
|
|
132
111
|
);
|
|
133
|
-
const nameMapSource = createNameMapSource(
|
|
112
|
+
const nameMapSource = serverIslandsState.createNameMapSource();
|
|
134
113
|
return {
|
|
135
114
|
code: `
|
|
136
115
|
export const serverIslandMap = ${mapSource};
|
|
@@ -150,21 +129,16 @@ export const serverIslandNameMap = ${serverIslandPlaceholderNameMap};`
|
|
|
150
129
|
if (envName === ASTRO_VITE_ENVIRONMENT_NAMES.ssr) {
|
|
151
130
|
const isRelativeChunk = !chunk.isEntry;
|
|
152
131
|
const dots = isRelativeChunk ? ".." : ".";
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const fileName = this.getFileName(referenceId);
|
|
156
|
-
const islandName = serverIslandNameMap.get(resolvedPath);
|
|
157
|
-
if (!islandName) continue;
|
|
158
|
-
mapEntries.push([islandName, fileName]);
|
|
159
|
-
}
|
|
160
|
-
mapSource = createServerIslandImportMapSource(
|
|
161
|
-
mapEntries,
|
|
132
|
+
mapSource = serverIslandsState.createImportMapSourceFromReferences(
|
|
133
|
+
(referenceId) => this.getFileName(referenceId),
|
|
162
134
|
(fileName) => `${dots}/${fileName}`
|
|
163
135
|
);
|
|
164
136
|
} else {
|
|
165
|
-
mapSource =
|
|
137
|
+
mapSource = serverIslandsState.createImportMapSourceFromDiscovered(
|
|
138
|
+
(fileName) => fileName
|
|
139
|
+
);
|
|
166
140
|
}
|
|
167
|
-
const nameMapSource = createNameMapSource(
|
|
141
|
+
const nameMapSource = serverIslandsState.createNameMapSource();
|
|
168
142
|
return {
|
|
169
143
|
code: code.replace(serverIslandMapReplaceExp, mapSource).replace(serverIslandNameMapReplaceExp, nameMapSource),
|
|
170
144
|
map: null
|
package/dist/i18n/middleware.js
CHANGED
|
@@ -48,15 +48,22 @@ function createI18nMiddleware(i18n, base, trailingSlash, format) {
|
|
|
48
48
|
return context.redirect(location, routeDecision.status);
|
|
49
49
|
}
|
|
50
50
|
case "notFound": {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
if (context.isPrerendered) {
|
|
52
|
+
const prerenderedRes = new Response(response.body, {
|
|
53
|
+
status: 404,
|
|
54
|
+
headers: response.headers
|
|
55
|
+
});
|
|
56
|
+
prerenderedRes.headers.set(REROUTE_DIRECTIVE_HEADER, "no");
|
|
57
|
+
if (routeDecision.location) {
|
|
58
|
+
prerenderedRes.headers.set("Location", routeDecision.location);
|
|
59
|
+
}
|
|
60
|
+
return prerenderedRes;
|
|
61
|
+
}
|
|
62
|
+
const headers = new Headers();
|
|
56
63
|
if (routeDecision.location) {
|
|
57
|
-
|
|
64
|
+
headers.set("Location", routeDecision.location);
|
|
58
65
|
}
|
|
59
|
-
return
|
|
66
|
+
return new Response(null, { status: 404, headers });
|
|
60
67
|
}
|
|
61
68
|
case "continue":
|
|
62
69
|
break;
|
package/dist/i18n/utils.d.ts
CHANGED
|
@@ -21,4 +21,10 @@ export declare function parseLocale(header: string): BrowserLocale[];
|
|
|
21
21
|
export declare function computePreferredLocale(request: Request, locales: Locales): string | undefined;
|
|
22
22
|
export declare function computePreferredLocaleList(request: Request, locales: Locales): string[];
|
|
23
23
|
export declare function computeCurrentLocale(pathname: string, locales: Locales, defaultLocale: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Check if any of the route's resolved param values match a configured locale.
|
|
26
|
+
* This handles dynamic routes like `[locale]` or `[...path]` where the locale
|
|
27
|
+
* isn't in a static segment of the route pathname.
|
|
28
|
+
*/
|
|
29
|
+
export declare function computeCurrentLocaleFromParams(params: Record<string, string | undefined>, locales: Locales): string | undefined;
|
|
24
30
|
export {};
|
package/dist/i18n/utils.js
CHANGED
|
@@ -134,8 +134,30 @@ function computeCurrentLocale(pathname, locales, defaultLocale) {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
+
function computeCurrentLocaleFromParams(params, locales) {
|
|
138
|
+
const byNormalizedCode = /* @__PURE__ */ new Map();
|
|
139
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
140
|
+
for (const locale of locales) {
|
|
141
|
+
if (typeof locale === "string") {
|
|
142
|
+
byNormalizedCode.set(normalizeTheLocale(locale), locale);
|
|
143
|
+
} else {
|
|
144
|
+
byPath.set(locale.path, locale.codes[0]);
|
|
145
|
+
for (const code of locale.codes) {
|
|
146
|
+
byNormalizedCode.set(normalizeTheLocale(code), code);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
for (const value of Object.values(params)) {
|
|
151
|
+
if (!value) continue;
|
|
152
|
+
const pathMatch = byPath.get(value);
|
|
153
|
+
if (pathMatch) return pathMatch;
|
|
154
|
+
const codeMatch = byNormalizedCode.get(normalizeTheLocale(value));
|
|
155
|
+
if (codeMatch) return codeMatch;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
137
158
|
export {
|
|
138
159
|
computeCurrentLocale,
|
|
160
|
+
computeCurrentLocaleFromParams,
|
|
139
161
|
computePreferredLocale,
|
|
140
162
|
computePreferredLocaleList,
|
|
141
163
|
parseLocale
|
|
@@ -34,6 +34,14 @@ function serializedManifestPlugin({
|
|
|
34
34
|
sync
|
|
35
35
|
}) {
|
|
36
36
|
const normalizedSrcDir = normalizePath(fileURLToPath(settings.config.srcDir));
|
|
37
|
+
let encodedKeyPromise;
|
|
38
|
+
function getEncodedKey() {
|
|
39
|
+
encodedKeyPromise ??= (async () => {
|
|
40
|
+
const key = hasEnvironmentKey() ? await getEnvironmentKey() : await createKey();
|
|
41
|
+
return encodeKey(key);
|
|
42
|
+
})();
|
|
43
|
+
return encodedKeyPromise;
|
|
44
|
+
}
|
|
37
45
|
function reloadManifest(path, server) {
|
|
38
46
|
if (path != null && normalizePath(path).startsWith(normalizedSrcDir)) {
|
|
39
47
|
const environment = server.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr];
|
|
@@ -67,7 +75,7 @@ function serializedManifestPlugin({
|
|
|
67
75
|
if (command === "build" && !sync) {
|
|
68
76
|
manifestData = `'${MANIFEST_REPLACE}'`;
|
|
69
77
|
} else {
|
|
70
|
-
const serialized = await createSerializedManifest(settings);
|
|
78
|
+
const serialized = await createSerializedManifest(settings, await getEncodedKey());
|
|
71
79
|
manifestData = JSON.stringify(serialized);
|
|
72
80
|
}
|
|
73
81
|
const hasCacheConfig = !!settings.config.experimental?.cache?.provider;
|
|
@@ -103,7 +111,7 @@ function serializedManifestPlugin({
|
|
|
103
111
|
}
|
|
104
112
|
};
|
|
105
113
|
}
|
|
106
|
-
async function createSerializedManifest(settings) {
|
|
114
|
+
async function createSerializedManifest(settings, encodedKey) {
|
|
107
115
|
let i18nManifest;
|
|
108
116
|
let csp;
|
|
109
117
|
if (settings.config.i18n) {
|
|
@@ -161,7 +169,7 @@ async function createSerializedManifest(settings) {
|
|
|
161
169
|
// 1mb default
|
|
162
170
|
serverIslandBodySizeLimit: settings.config.security?.serverIslandBodySizeLimit ? settings.config.security.serverIslandBodySizeLimit : 1024 * 1024,
|
|
163
171
|
// 1mb default
|
|
164
|
-
key: await encodeKey(hasEnvironmentKey() ? await getEnvironmentKey() : await createKey()),
|
|
172
|
+
key: encodedKey ?? await encodeKey(hasEnvironmentKey() ? await getEnvironmentKey() : await createKey()),
|
|
165
173
|
sessionConfig: sessionConfigToManifest(settings.config.session),
|
|
166
174
|
cacheConfig: cacheConfigToManifest(
|
|
167
175
|
settings.config.experimental?.cache,
|
|
@@ -19,7 +19,7 @@ import { getViteErrorPayload } from "../core/errors/dev/index.js";
|
|
|
19
19
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
20
20
|
import { NOOP_MIDDLEWARE_FN } from "../core/middleware/noop-middleware.js";
|
|
21
21
|
import { createViteLoader } from "../core/module-loader/index.js";
|
|
22
|
-
import {
|
|
22
|
+
import { matchAllRoutes } from "../core/routing/match.js";
|
|
23
23
|
import { resolveMiddlewareMode } from "../integrations/adapter-utils.js";
|
|
24
24
|
import { SERIALIZED_MANIFEST_ID } from "../manifest/serialized.js";
|
|
25
25
|
import { ASTRO_DEV_SERVER_APP_ID } from "../vite-plugin-app/index.js";
|
|
@@ -126,7 +126,7 @@ function createVitePluginAstroServer({
|
|
|
126
126
|
const { routes } = await prerenderHandler.environment.runner.import("virtual:astro:routes");
|
|
127
127
|
const routesList = { routes: routes.map((r) => r.routeData) };
|
|
128
128
|
const matches = matchAllRoutes(pathname, routesList);
|
|
129
|
-
if (!matches.some((route) => route.prerender
|
|
129
|
+
if (!matches.some((route) => route.prerender)) {
|
|
130
130
|
return next();
|
|
131
131
|
}
|
|
132
132
|
localStorage.run(request, () => {
|
|
@@ -18,6 +18,25 @@ import {
|
|
|
18
18
|
function getComponentFromVirtualModuleCssName(virtualModulePrefix, id) {
|
|
19
19
|
return id.slice(virtualModulePrefix.length).replace(new RegExp(ASTRO_CSS_EXTENSION_POST_PATTERN, "g"), ".");
|
|
20
20
|
}
|
|
21
|
+
async function ensureModulesLoaded(env, mod, seen = /* @__PURE__ */ new Set()) {
|
|
22
|
+
const id = mod.id ?? mod.url;
|
|
23
|
+
if (seen.has(id)) return;
|
|
24
|
+
seen.add(id);
|
|
25
|
+
for (const imp of mod.importedModules) {
|
|
26
|
+
if (!imp.id) continue;
|
|
27
|
+
if (seen.has(imp.id)) continue;
|
|
28
|
+
if (imp.id.includes(PROPAGATED_ASSET_QUERY_PARAM)) continue;
|
|
29
|
+
if (imp.id === RESOLVED_MODULE_DEV_CSS || imp.id === RESOLVED_MODULE_DEV_CSS_ALL || imp.id.startsWith(RESOLVED_MODULE_DEV_CSS_PREFIX))
|
|
30
|
+
continue;
|
|
31
|
+
if (!imp.transformResult) {
|
|
32
|
+
try {
|
|
33
|
+
await env.fetchModule(imp.id);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
await ensureModulesLoaded(env, imp, seen);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
21
40
|
function* collectCSSWithOrder(id, mod, seen = /* @__PURE__ */ new Set()) {
|
|
22
41
|
seen.add(id);
|
|
23
42
|
if (id.includes(PROPAGATED_ASSET_QUERY_PARAM)) {
|
|
@@ -98,6 +117,9 @@ function astroDevCssPlugin({ routesList, command }) {
|
|
|
98
117
|
code: "export const css = new Set()"
|
|
99
118
|
};
|
|
100
119
|
}
|
|
120
|
+
if (env) {
|
|
121
|
+
await ensureModulesLoaded(env, mod);
|
|
122
|
+
}
|
|
101
123
|
for (const collected of collectCSSWithOrder(componentPageId, mod)) {
|
|
102
124
|
if (!cssWithOrder.has(collected.idKey)) {
|
|
103
125
|
const content = cssContentCache.get(collected.id) || collected.content;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ConfigEnv, Plugin as VitePlugin } from 'vite';
|
|
2
|
+
import type { ServerIslandsState } from '../core/server-islands/shared-state.js';
|
|
2
3
|
import type { AstroSettings, RoutesList } from '../types/astro.js';
|
|
3
4
|
export declare const ASTRO_RENDERERS_MODULE_ID = "virtual:astro:renderers";
|
|
4
5
|
interface PluginOptions {
|
|
5
6
|
settings: AstroSettings;
|
|
6
7
|
routesList: RoutesList;
|
|
8
|
+
serverIslandsState: ServerIslandsState;
|
|
7
9
|
command: ConfigEnv['command'];
|
|
8
10
|
}
|
|
9
11
|
export default function vitePluginRenderers(options: PluginOptions): VitePlugin;
|
|
@@ -20,7 +20,7 @@ function vitePluginRenderers(options) {
|
|
|
20
20
|
id: new RegExp(`^${RESOLVED_ASTRO_RENDERERS_MODULE_ID}$`)
|
|
21
21
|
},
|
|
22
22
|
handler() {
|
|
23
|
-
if (options.command === "build" && this.environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr && renderers.length > 0 && !hasNonPrerenderedProjectRoute(options.routesList.routes, {
|
|
23
|
+
if (options.command === "build" && this.environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr && renderers.length > 0 && !options.serverIslandsState.hasIslands() && !hasNonPrerenderedProjectRoute(options.routesList.routes, {
|
|
24
24
|
includeEndpoints: false
|
|
25
25
|
})) {
|
|
26
26
|
return { code: `export const renderers = [];` };
|