astro 6.1.2 → 6.1.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/integration.js +2 -2
- package/dist/assets/utils/index.d.ts +1 -1
- package/dist/assets/utils/index.js +1 -9
- package/dist/assets/utils/vendor/image-size/utils/bit-reader.d.ts +2 -2
- package/dist/assets/utils/vendor/image-size/utils/bit-reader.js +5 -3
- package/dist/cli/add/index.js +37 -44
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/content/content-layer.js +3 -3
- package/dist/content/loaders/errors.d.ts +2 -2
- package/dist/content/loaders/errors.js +3 -0
- package/dist/content/loaders/glob.js +6 -2
- package/dist/content/mutable-data-store.js +26 -0
- package/dist/core/app/base.js +1 -1
- package/dist/core/app/dev/pipeline.js +4 -0
- package/dist/core/base-pipeline.d.ts +22 -35
- package/dist/core/base-pipeline.js +41 -8
- package/dist/core/build/generate.js +9 -1
- package/dist/core/build/pipeline.d.ts +3 -7
- package/dist/core/build/pipeline.js +30 -28
- package/dist/core/build/plugins/index.js +3 -1
- package/dist/core/build/plugins/plugin-chunk-imports.d.ts +10 -0
- package/dist/core/build/plugins/plugin-chunk-imports.js +38 -0
- package/dist/core/build/plugins/plugin-css.js +7 -2
- package/dist/core/config/schemas/refined-validators.d.ts +44 -0
- package/dist/core/config/schemas/refined-validators.js +168 -0
- package/dist/core/config/schemas/refined.js +28 -141
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.d.ts +1 -1
- package/dist/core/cookies/cookies.js +1 -0
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +63 -68
- package/dist/core/messages/runtime.js +1 -1
- package/dist/core/render-context.d.ts +2 -2
- package/dist/core/render-context.js +20 -0
- package/dist/core/routing/create-manifest.js +12 -4
- package/dist/core/routing/default.d.ts +2 -3
- package/dist/core/routing/dev.js +0 -1
- package/dist/core/routing/helpers.d.ts +4 -2
- package/dist/core/routing/helpers.js +5 -3
- package/dist/integrations/features-validation.d.ts +3 -1
- package/dist/integrations/features-validation.js +2 -0
- package/dist/preferences/store.js +2 -1
- package/dist/prerender/routing.d.ts +1 -3
- package/dist/prerender/routing.js +1 -6
- package/dist/runtime/server/escape.d.ts +2 -1
- package/dist/runtime/server/escape.js +4 -5
- package/dist/runtime/server/transition.d.ts +2 -2
- package/dist/runtime/server/transition.js +4 -2
- package/dist/vite-plugin-app/pipeline.d.ts +4 -13
- package/dist/vite-plugin-app/pipeline.js +27 -12
- package/dist/vite-plugin-astro-server/base.d.ts +52 -0
- package/dist/vite-plugin-astro-server/base.js +66 -36
- package/dist/vite-plugin-astro-server/plugin.d.ts +0 -8
- package/dist/vite-plugin-astro-server/plugin.js +0 -107
- package/dist/vite-plugin-astro-server/trailing-slash.d.ts +34 -0
- package/dist/vite-plugin-astro-server/trailing-slash.js +24 -11
- package/dist/vite-plugin-head/index.js +40 -2
- package/dist/vite-plugin-hmr-reload/index.js +2 -2
- package/dist/vite-plugin-renderers/index.js +4 -3
- package/package.json +2 -2
|
@@ -4,13 +4,31 @@ import { appendForwardSlash, prependForwardSlash } from "@astrojs/internal-helpe
|
|
|
4
4
|
import colors from "piccolore";
|
|
5
5
|
import { notFoundTemplate, subpathNotUsedTemplate } from "../template/4xx.js";
|
|
6
6
|
import { writeHtmlResponse } from "./response.js";
|
|
7
|
+
function resolveDevRoot(base, site) {
|
|
8
|
+
const effectiveBase = base || "/";
|
|
9
|
+
const siteUrl = site ? new URL(effectiveBase, site) : void 0;
|
|
10
|
+
const devRootURL = new URL(effectiveBase, "http://localhost");
|
|
11
|
+
const devRoot = siteUrl ? siteUrl.pathname : devRootURL.pathname;
|
|
12
|
+
const devRootReplacement = devRoot.endsWith("/") ? "/" : "";
|
|
13
|
+
return { devRoot, devRootReplacement };
|
|
14
|
+
}
|
|
15
|
+
function evaluateBaseRewrite(url, pathname, acceptHeader, devRoot, devRootReplacement) {
|
|
16
|
+
if (pathname.startsWith(devRoot)) {
|
|
17
|
+
let newUrl = url.replace(devRoot, devRootReplacement);
|
|
18
|
+
if (!newUrl.startsWith("/")) newUrl = prependForwardSlash(newUrl);
|
|
19
|
+
return { action: "rewrite", newUrl };
|
|
20
|
+
}
|
|
21
|
+
if (pathname === "/" || pathname === "/index.html") {
|
|
22
|
+
return { action: "not-found-subpath", pathname, devRoot };
|
|
23
|
+
}
|
|
24
|
+
if (acceptHeader?.includes("text/html")) {
|
|
25
|
+
return { action: "not-found", pathname };
|
|
26
|
+
}
|
|
27
|
+
return { action: "check-public" };
|
|
28
|
+
}
|
|
7
29
|
function baseMiddleware(settings, logger) {
|
|
8
30
|
const { config } = settings;
|
|
9
|
-
const
|
|
10
|
-
const site = config.site ? new URL(base, config.site) : void 0;
|
|
11
|
-
const devRootURL = new URL(base, "http://localhost");
|
|
12
|
-
const devRoot = site ? site.pathname : devRootURL.pathname;
|
|
13
|
-
const devRootReplacement = devRoot.endsWith("/") ? "/" : "";
|
|
31
|
+
const { devRoot, devRootReplacement } = resolveDevRoot(config.base, config.site);
|
|
14
32
|
return function devBaseMiddleware(req, res, next) {
|
|
15
33
|
const url = req.url;
|
|
16
34
|
let pathname;
|
|
@@ -19,40 +37,52 @@ function baseMiddleware(settings, logger) {
|
|
|
19
37
|
} catch (e) {
|
|
20
38
|
return next(e);
|
|
21
39
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
path.posix.relative(config.root.pathname, config.publicDir.pathname)
|
|
40
|
-
);
|
|
41
|
-
const expectedLocation = new URL(devRootURL.pathname + url, devRootURL).pathname;
|
|
42
|
-
logger.error(
|
|
43
|
-
"router",
|
|
44
|
-
`Request URLs for ${colors.bold(
|
|
45
|
-
publicDir
|
|
46
|
-
)} assets must also include your base. "${expectedLocation}" expected, but received "${url}".`
|
|
47
|
-
);
|
|
48
|
-
const html = subpathNotUsedTemplate(devRoot, pathname);
|
|
40
|
+
const decision = evaluateBaseRewrite(
|
|
41
|
+
url,
|
|
42
|
+
pathname,
|
|
43
|
+
req.headers.accept,
|
|
44
|
+
devRoot,
|
|
45
|
+
devRootReplacement
|
|
46
|
+
);
|
|
47
|
+
switch (decision.action) {
|
|
48
|
+
case "rewrite":
|
|
49
|
+
req.url = decision.newUrl;
|
|
50
|
+
return next();
|
|
51
|
+
case "not-found-subpath": {
|
|
52
|
+
const html = subpathNotUsedTemplate(decision.devRoot, decision.pathname);
|
|
53
|
+
return writeHtmlResponse(res, 404, html);
|
|
54
|
+
}
|
|
55
|
+
case "not-found": {
|
|
56
|
+
const html = notFoundTemplate(decision.pathname);
|
|
49
57
|
return writeHtmlResponse(res, 404, html);
|
|
50
|
-
} else {
|
|
51
|
-
next();
|
|
52
58
|
}
|
|
53
|
-
|
|
59
|
+
case "check-public": {
|
|
60
|
+
const publicPath = new URL("." + req.url, config.publicDir);
|
|
61
|
+
fs.stat(publicPath, (_err, stats) => {
|
|
62
|
+
if (stats) {
|
|
63
|
+
const publicDir = appendForwardSlash(
|
|
64
|
+
path.posix.relative(config.root.pathname, config.publicDir.pathname)
|
|
65
|
+
);
|
|
66
|
+
const devRootURL = new URL(devRoot, "http://localhost");
|
|
67
|
+
const expectedLocation = new URL(devRootURL.pathname + url, devRootURL).pathname;
|
|
68
|
+
logger.error(
|
|
69
|
+
"router",
|
|
70
|
+
`Request URLs for ${colors.bold(
|
|
71
|
+
publicDir
|
|
72
|
+
)} assets must also include your base. "${expectedLocation}" expected, but received "${url}".`
|
|
73
|
+
);
|
|
74
|
+
const html = subpathNotUsedTemplate(devRoot, pathname);
|
|
75
|
+
return writeHtmlResponse(res, 404, html);
|
|
76
|
+
} else {
|
|
77
|
+
next();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
54
82
|
};
|
|
55
83
|
}
|
|
56
84
|
export {
|
|
57
|
-
baseMiddleware
|
|
85
|
+
baseMiddleware,
|
|
86
|
+
evaluateBaseRewrite,
|
|
87
|
+
resolveDevRoot
|
|
58
88
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
|
-
import type { SSRManifest } from '../core/app/types.js';
|
|
3
2
|
import type { Logger } from '../core/logger/core.js';
|
|
4
3
|
import type { AstroSettings } from '../types/astro.js';
|
|
5
4
|
interface AstroPluginOptions {
|
|
@@ -7,11 +6,4 @@ interface AstroPluginOptions {
|
|
|
7
6
|
logger: Logger;
|
|
8
7
|
}
|
|
9
8
|
export default function createVitePluginAstroServer({ settings, logger, }: AstroPluginOptions): vite.Plugin;
|
|
10
|
-
/**
|
|
11
|
-
* It creates a `SSRManifest` from the `AstroSettings`.
|
|
12
|
-
*
|
|
13
|
-
* Renderers needs to be pulled out from the page module emitted during the build.
|
|
14
|
-
* @param settings
|
|
15
|
-
*/
|
|
16
|
-
export declare function createDevelopmentManifest(settings: AstroSettings): Promise<SSRManifest>;
|
|
17
9
|
export {};
|
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
import { IncomingMessage } from "node:http";
|
|
3
3
|
import { isRunnableDevEnvironment } from "vite";
|
|
4
|
-
import { toFallbackType } from "../core/app/common.js";
|
|
5
|
-
import { toRoutingStrategy } from "../core/app/entrypoints/index.js";
|
|
6
4
|
import { ASTRO_VITE_ENVIRONMENT_NAMES, devPrerenderMiddlewareSymbol } from "../core/constants.js";
|
|
7
|
-
import {
|
|
8
|
-
getAlgorithm,
|
|
9
|
-
getDirectives,
|
|
10
|
-
getScriptHashes,
|
|
11
|
-
getScriptResources,
|
|
12
|
-
getStrictDynamic,
|
|
13
|
-
getStyleHashes,
|
|
14
|
-
getStyleResources,
|
|
15
|
-
shouldTrackCspHashes
|
|
16
|
-
} from "../core/csp/common.js";
|
|
17
|
-
import { createKey, getEnvironmentKey, hasEnvironmentKey } from "../core/encryption.js";
|
|
18
5
|
import { getViteErrorPayload } from "../core/errors/dev/index.js";
|
|
19
6
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
20
|
-
import { NOOP_MIDDLEWARE_FN } from "../core/middleware/noop-middleware.js";
|
|
21
7
|
import { createViteLoader } from "../core/module-loader/index.js";
|
|
22
8
|
import { matchAllRoutes } from "../core/routing/match.js";
|
|
23
|
-
import { resolveMiddlewareMode } from "../integrations/adapter-utils.js";
|
|
24
9
|
import { SERIALIZED_MANIFEST_ID } from "../manifest/serialized.js";
|
|
25
10
|
import { ASTRO_DEV_SERVER_APP_ID } from "../vite-plugin-app/index.js";
|
|
26
11
|
import { baseMiddleware } from "./base.js";
|
|
@@ -30,7 +15,6 @@ import { setRouteError } from "./server-state.js";
|
|
|
30
15
|
import { routeGuardMiddleware } from "./route-guard.js";
|
|
31
16
|
import { secFetchMiddleware } from "./sec-fetch.js";
|
|
32
17
|
import { trailingSlashMiddleware } from "./trailing-slash.js";
|
|
33
|
-
import { sessionConfigToManifest } from "../core/session/utils.js";
|
|
34
18
|
function createVitePluginAstroServer({
|
|
35
19
|
settings,
|
|
36
20
|
logger
|
|
@@ -154,97 +138,6 @@ function createVitePluginAstroServer({
|
|
|
154
138
|
}
|
|
155
139
|
};
|
|
156
140
|
}
|
|
157
|
-
async function createDevelopmentManifest(settings) {
|
|
158
|
-
let i18nManifest;
|
|
159
|
-
let csp;
|
|
160
|
-
if (settings.config.i18n) {
|
|
161
|
-
i18nManifest = {
|
|
162
|
-
fallback: settings.config.i18n.fallback,
|
|
163
|
-
strategy: toRoutingStrategy(settings.config.i18n.routing, settings.config.i18n.domains),
|
|
164
|
-
defaultLocale: settings.config.i18n.defaultLocale,
|
|
165
|
-
locales: settings.config.i18n.locales,
|
|
166
|
-
domainLookupTable: {},
|
|
167
|
-
fallbackType: toFallbackType(settings.config.i18n.routing),
|
|
168
|
-
domains: settings.config.i18n.domains
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
if (shouldTrackCspHashes(settings.config.security.csp)) {
|
|
172
|
-
const styleHashes = [
|
|
173
|
-
...getStyleHashes(settings.config.security.csp),
|
|
174
|
-
...settings.injectedCsp.styleHashes
|
|
175
|
-
];
|
|
176
|
-
csp = {
|
|
177
|
-
cspDestination: settings.adapter?.adapterFeatures?.staticHeaders ? "adapter" : void 0,
|
|
178
|
-
scriptHashes: getScriptHashes(settings.config.security.csp),
|
|
179
|
-
scriptResources: getScriptResources(settings.config.security.csp),
|
|
180
|
-
styleHashes,
|
|
181
|
-
styleResources: getStyleResources(settings.config.security.csp),
|
|
182
|
-
algorithm: getAlgorithm(settings.config.security.csp),
|
|
183
|
-
directives: getDirectives(settings),
|
|
184
|
-
isStrictDynamic: getStrictDynamic(settings.config.security.csp)
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
rootDir: settings.config.root,
|
|
189
|
-
srcDir: settings.config.srcDir,
|
|
190
|
-
cacheDir: settings.config.cacheDir,
|
|
191
|
-
outDir: settings.config.outDir,
|
|
192
|
-
buildServerDir: settings.config.build.server,
|
|
193
|
-
buildClientDir: settings.config.build.client,
|
|
194
|
-
publicDir: settings.config.publicDir,
|
|
195
|
-
trailingSlash: settings.config.trailingSlash,
|
|
196
|
-
buildFormat: settings.config.build.format,
|
|
197
|
-
compressHTML: settings.config.compressHTML,
|
|
198
|
-
assetsDir: settings.config.build.assets,
|
|
199
|
-
serverLike: settings.buildOutput === "server",
|
|
200
|
-
middlewareMode: resolveMiddlewareMode(settings.adapter?.adapterFeatures),
|
|
201
|
-
assets: /* @__PURE__ */ new Set(),
|
|
202
|
-
entryModules: {},
|
|
203
|
-
routes: [],
|
|
204
|
-
adapterName: settings?.adapter?.name ?? "",
|
|
205
|
-
clientDirectives: settings.clientDirectives,
|
|
206
|
-
renderers: [],
|
|
207
|
-
base: settings.config.base,
|
|
208
|
-
userAssetsBase: settings.config?.vite?.base,
|
|
209
|
-
assetsPrefix: settings.config.build.assetsPrefix,
|
|
210
|
-
site: settings.config.site,
|
|
211
|
-
componentMetadata: /* @__PURE__ */ new Map(),
|
|
212
|
-
inlinedScripts: /* @__PURE__ */ new Map(),
|
|
213
|
-
i18n: i18nManifest,
|
|
214
|
-
checkOrigin: settings.config.security?.checkOrigin ?? false,
|
|
215
|
-
allowedDomains: settings.config.security?.allowedDomains,
|
|
216
|
-
actionBodySizeLimit: settings.config.security?.actionBodySizeLimit ? settings.config.security.actionBodySizeLimit : 1024 * 1024,
|
|
217
|
-
// 1mb default
|
|
218
|
-
serverIslandBodySizeLimit: settings.config.security?.serverIslandBodySizeLimit ? settings.config.security.serverIslandBodySizeLimit : 1024 * 1024,
|
|
219
|
-
// 1mb default
|
|
220
|
-
key: hasEnvironmentKey() ? getEnvironmentKey() : createKey(),
|
|
221
|
-
middleware() {
|
|
222
|
-
return {
|
|
223
|
-
onRequest: NOOP_MIDDLEWARE_FN
|
|
224
|
-
};
|
|
225
|
-
},
|
|
226
|
-
sessionConfig: sessionConfigToManifest(settings.config.session),
|
|
227
|
-
csp,
|
|
228
|
-
image: {
|
|
229
|
-
objectFit: settings.config.image.objectFit,
|
|
230
|
-
objectPosition: settings.config.image.objectPosition,
|
|
231
|
-
layout: settings.config.image.layout
|
|
232
|
-
},
|
|
233
|
-
devToolbar: {
|
|
234
|
-
enabled: settings.config.devToolbar.enabled && await settings.preferences.get("devToolbar.enabled"),
|
|
235
|
-
latestAstroVersion: settings.latestAstroVersion,
|
|
236
|
-
debugInfoOutput: "",
|
|
237
|
-
placement: settings.config.devToolbar.placement
|
|
238
|
-
},
|
|
239
|
-
logLevel: settings.logLevel,
|
|
240
|
-
shouldInjectCspMetaTags: false,
|
|
241
|
-
experimentalQueuedRendering: {
|
|
242
|
-
enabled: !!settings.config.experimental?.queuedRendering,
|
|
243
|
-
poolSize: settings.config.experimental?.queuedRendering?.poolSize ?? 1e3
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
141
|
export {
|
|
248
|
-
createDevelopmentManifest,
|
|
249
142
|
createVitePluginAstroServer as default
|
|
250
143
|
};
|
|
@@ -1,3 +1,37 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
2
|
import type { AstroSettings } from '../types/astro.js';
|
|
3
|
+
/**
|
|
4
|
+
* Outcome of the trailing-slash evaluation for a dev-server request.
|
|
5
|
+
*
|
|
6
|
+
* - **`next`** — The URL is acceptable. Pass the request through to the next
|
|
7
|
+
* middleware / route handler unchanged.
|
|
8
|
+
* - **`redirect`** — The URL contains duplicate trailing slashes (e.g.
|
|
9
|
+
* `/about//`). The client should be permanently redirected (301) to the
|
|
10
|
+
* collapsed form (`/about/`) so crawlers and browsers update their links.
|
|
11
|
+
* - **`reject`** — The URL's trailing-slash style conflicts with the project's
|
|
12
|
+
* `trailingSlash` config (`'always'` or `'never'`). The dev server responds
|
|
13
|
+
* with a 404 and a human-readable error page explaining the mismatch, giving
|
|
14
|
+
* the developer immediate feedback that their link is wrong before it reaches
|
|
15
|
+
* production.
|
|
16
|
+
*/
|
|
17
|
+
export type TrailingSlashDecision = {
|
|
18
|
+
action: 'next';
|
|
19
|
+
} | {
|
|
20
|
+
action: 'redirect';
|
|
21
|
+
status: 301;
|
|
22
|
+
location: string;
|
|
23
|
+
} | {
|
|
24
|
+
action: 'reject';
|
|
25
|
+
status: 404;
|
|
26
|
+
pathname: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Pure decision function for trailing-slash dev-server behavior.
|
|
30
|
+
*
|
|
31
|
+
* Evaluates a decoded `pathname`, the query-string portion (including leading
|
|
32
|
+
* `?`), and the project's `trailingSlash` config and returns the action the
|
|
33
|
+
* middleware should take. The middleware is responsible for translating the
|
|
34
|
+
* decision into an HTTP response.
|
|
35
|
+
*/
|
|
36
|
+
export declare function evaluateTrailingSlash(pathname: string, search: string, trailingSlash: 'always' | 'never' | 'ignore'): TrailingSlashDecision;
|
|
3
37
|
export declare function trailingSlashMiddleware(settings: AstroSettings): vite.Connect.NextHandleFunction;
|
|
@@ -5,6 +5,19 @@ import {
|
|
|
5
5
|
} from "@astrojs/internal-helpers/path";
|
|
6
6
|
import { trailingSlashMismatchTemplate } from "../template/4xx.js";
|
|
7
7
|
import { writeHtmlResponse, writeRedirectResponse } from "./response.js";
|
|
8
|
+
function evaluateTrailingSlash(pathname, search, trailingSlash) {
|
|
9
|
+
if (isInternalPath(pathname)) {
|
|
10
|
+
return { action: "next" };
|
|
11
|
+
}
|
|
12
|
+
const collapsed = collapseDuplicateTrailingSlashes(pathname, true);
|
|
13
|
+
if (pathname && collapsed !== pathname) {
|
|
14
|
+
return { action: "redirect", status: 301, location: `${collapsed}${search}` };
|
|
15
|
+
}
|
|
16
|
+
if (trailingSlash === "never" && pathname.endsWith("/") && pathname !== "/" || trailingSlash === "always" && !pathname.endsWith("/") && !hasFileExtension(pathname)) {
|
|
17
|
+
return { action: "reject", status: 404, pathname };
|
|
18
|
+
}
|
|
19
|
+
return { action: "next" };
|
|
20
|
+
}
|
|
8
21
|
function trailingSlashMiddleware(settings) {
|
|
9
22
|
const { trailingSlash } = settings.config;
|
|
10
23
|
return function devTrailingSlash(req, res, next) {
|
|
@@ -15,20 +28,20 @@ function trailingSlashMiddleware(settings) {
|
|
|
15
28
|
} catch (e) {
|
|
16
29
|
return next(e);
|
|
17
30
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
const decision = evaluateTrailingSlash(pathname, url.search, trailingSlash);
|
|
32
|
+
switch (decision.action) {
|
|
33
|
+
case "redirect":
|
|
34
|
+
return writeRedirectResponse(res, decision.status, decision.location);
|
|
35
|
+
case "reject": {
|
|
36
|
+
const html = trailingSlashMismatchTemplate(decision.pathname, trailingSlash);
|
|
37
|
+
return writeHtmlResponse(res, decision.status, html);
|
|
38
|
+
}
|
|
39
|
+
case "next":
|
|
40
|
+
return next();
|
|
28
41
|
}
|
|
29
|
-
return next();
|
|
30
42
|
};
|
|
31
43
|
}
|
|
32
44
|
export {
|
|
45
|
+
evaluateTrailingSlash,
|
|
33
46
|
trailingSlashMiddleware
|
|
34
47
|
};
|
|
@@ -6,8 +6,16 @@ import {
|
|
|
6
6
|
import { getTopLevelPageModuleInfos } from "../core/build/graph.js";
|
|
7
7
|
import { getAstroMetadata } from "../vite-plugin-astro/index.js";
|
|
8
8
|
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
9
|
+
const VIRTUAL_COMPONENT_METADATA = "virtual:astro:component-metadata";
|
|
10
|
+
const RESOLVED_VIRTUAL_COMPONENT_METADATA = `\0${VIRTUAL_COMPONENT_METADATA}`;
|
|
9
11
|
function configHeadVitePlugin() {
|
|
10
12
|
let environment;
|
|
13
|
+
function invalidateComponentMetadataModule() {
|
|
14
|
+
const virtualMod = environment.moduleGraph.getModuleById(RESOLVED_VIRTUAL_COMPONENT_METADATA);
|
|
15
|
+
if (virtualMod) {
|
|
16
|
+
environment.moduleGraph.invalidateModule(virtualMod);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
11
19
|
function buildImporterGraphFromEnvironment(seed) {
|
|
12
20
|
const queue = [seed];
|
|
13
21
|
const collected = /* @__PURE__ */ new Set();
|
|
@@ -46,15 +54,44 @@ function configHeadVitePlugin() {
|
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
56
|
}
|
|
57
|
+
invalidateComponentMetadataModule();
|
|
49
58
|
}
|
|
50
59
|
return {
|
|
51
60
|
name: "astro:head-metadata",
|
|
52
61
|
enforce: "pre",
|
|
53
62
|
apply: "serve",
|
|
54
|
-
configureServer(
|
|
55
|
-
environment =
|
|
63
|
+
configureServer(devServer) {
|
|
64
|
+
environment = devServer.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr];
|
|
65
|
+
devServer.watcher.on("add", invalidateComponentMetadataModule);
|
|
66
|
+
devServer.watcher.on("unlink", invalidateComponentMetadataModule);
|
|
67
|
+
devServer.watcher.on("change", invalidateComponentMetadataModule);
|
|
68
|
+
},
|
|
69
|
+
load(id) {
|
|
70
|
+
if (id !== RESOLVED_VIRTUAL_COMPONENT_METADATA) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const componentMetadataEntries = [];
|
|
74
|
+
for (const [moduleId, mod] of environment.moduleGraph.idToModuleMap) {
|
|
75
|
+
const info = this.getModuleInfo(moduleId) ?? (mod.id ? this.getModuleInfo(mod.id) : null);
|
|
76
|
+
if (!info) continue;
|
|
77
|
+
const astro = getAstroMetadata(info);
|
|
78
|
+
if (!astro) continue;
|
|
79
|
+
componentMetadataEntries.push([
|
|
80
|
+
moduleId,
|
|
81
|
+
{
|
|
82
|
+
containsHead: astro.containsHead,
|
|
83
|
+
propagation: astro.propagation
|
|
84
|
+
}
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
code: `export const componentMetadataEntries = ${JSON.stringify(componentMetadataEntries)};`
|
|
89
|
+
};
|
|
56
90
|
},
|
|
57
91
|
resolveId(source, importer) {
|
|
92
|
+
if (source === VIRTUAL_COMPONENT_METADATA) {
|
|
93
|
+
return RESOLVED_VIRTUAL_COMPONENT_METADATA;
|
|
94
|
+
}
|
|
58
95
|
if (importer) {
|
|
59
96
|
return this.resolve(source, importer, { skipSelf: true }).then((result) => {
|
|
60
97
|
if (result) {
|
|
@@ -81,6 +118,7 @@ function configHeadVitePlugin() {
|
|
|
81
118
|
if (hasHeadInjectComment(source)) {
|
|
82
119
|
propagateMetadata.call(this, id, "propagation", "in-tree");
|
|
83
120
|
}
|
|
121
|
+
invalidateComponentMetadataModule();
|
|
84
122
|
}
|
|
85
123
|
};
|
|
86
124
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
2
1
|
import { VIRTUAL_PAGE_RESOLVED_MODULE_ID } from "../vite-plugin-pages/const.js";
|
|
3
2
|
import { getDevCssModuleNameFromPageVirtualModuleName } from "../vite-plugin-css/util.js";
|
|
3
|
+
import { isAstroServerEnvironment } from "../environments.js";
|
|
4
4
|
function hmrReload() {
|
|
5
5
|
return {
|
|
6
6
|
name: "astro:hmr-reload",
|
|
@@ -8,7 +8,7 @@ function hmrReload() {
|
|
|
8
8
|
hotUpdate: {
|
|
9
9
|
order: "post",
|
|
10
10
|
handler({ modules, server, timestamp }) {
|
|
11
|
-
if (this.environment
|
|
11
|
+
if (!isAstroServerEnvironment(this.environment)) return;
|
|
12
12
|
let hasSsrOnlyModules = false;
|
|
13
13
|
const invalidatedModules = /* @__PURE__ */ new Set();
|
|
14
14
|
for (const mod of modules) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
2
|
-
import {
|
|
2
|
+
import { hasNonPrerenderedRoute } from "../core/routing/helpers.js";
|
|
3
3
|
const ASTRO_RENDERERS_MODULE_ID = "virtual:astro:renderers";
|
|
4
4
|
const RESOLVED_ASTRO_RENDERERS_MODULE_ID = `\0${ASTRO_RENDERERS_MODULE_ID}`;
|
|
5
5
|
function vitePluginRenderers(options) {
|
|
@@ -20,8 +20,9 @@ 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 && !options.serverIslandsState.hasIslands() && !
|
|
24
|
-
includeEndpoints: false
|
|
23
|
+
if (options.command === "build" && this.environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr && renderers.length > 0 && !options.serverIslandsState.hasIslands() && !hasNonPrerenderedRoute(options.routesList.routes, {
|
|
24
|
+
includeEndpoints: false,
|
|
25
|
+
includeExternal: true
|
|
25
26
|
})) {
|
|
26
27
|
return { code: `export const renderers = [];` };
|
|
27
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.4",
|
|
4
4
|
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "withastro",
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
"cheerio": "1.2.0",
|
|
176
176
|
"eol": "^0.10.0",
|
|
177
177
|
"expect-type": "^1.3.0",
|
|
178
|
-
"fs-fixture": "^2.
|
|
178
|
+
"fs-fixture": "^2.13.0",
|
|
179
179
|
"mdast-util-mdx": "^3.0.0",
|
|
180
180
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
181
181
|
"node-mocks-http": "^1.17.2",
|