astro 2.5.1 → 2.5.2
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/core/build/plugins/plugin-hoisted-scripts.js +30 -24
- package/dist/core/build/plugins/plugin-prerender.js +2 -2
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/index.js +2 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/core.js +1 -1
- package/dist/core/render/route-cache.js +1 -1
- package/dist/core/routing/manifest/create.js +3 -3
- package/dist/core/routing/validation.js +2 -2
- package/dist/prerender/metadata.d.ts +8 -0
- package/dist/prerender/metadata.js +20 -0
- package/dist/vite-plugin-astro-server/route.js +8 -0
- package/package.json +1 -1
|
@@ -33,33 +33,39 @@ function vitePluginHoistedScripts(settings, internals) {
|
|
|
33
33
|
if (((_a = settings.config.vite) == null ? void 0 : _a.build) && settings.config.vite.build.assetsInlineLimit !== void 0) {
|
|
34
34
|
assetInlineLimit = (_b = settings.config.vite) == null ? void 0 : _b.build.assetsInlineLimit;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
const considerInlining = /* @__PURE__ */ new Map();
|
|
37
|
+
const importedByOtherScripts = /* @__PURE__ */ new Set();
|
|
38
|
+
Object.entries(bundle).forEach(([id, output]) => {
|
|
37
39
|
if (output.type === "chunk" && output.facadeModuleId && virtualHoistedEntry(output.facadeModuleId)) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
40
|
+
considerInlining.set(id, output);
|
|
41
|
+
output.imports.forEach((imported) => importedByOtherScripts.add(imported));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
for (const [id, output] of considerInlining.entries()) {
|
|
45
|
+
const canBeInlined = importedByOtherScripts.has(output.fileName) === false && output.imports.length === 0 && output.dynamicImports.length === 0 && Buffer.byteLength(output.code) <= assetInlineLimit;
|
|
46
|
+
let removeFromBundle = false;
|
|
47
|
+
const facadeId = output.facadeModuleId;
|
|
48
|
+
const pages = internals.hoistedScriptIdToPagesMap.get(facadeId);
|
|
49
|
+
for (const pathname of pages) {
|
|
50
|
+
const vid = viteID(new URL("." + pathname, settings.config.root));
|
|
51
|
+
const pageInfo = getPageDataByViteID(internals, vid);
|
|
52
|
+
if (pageInfo) {
|
|
53
|
+
if (canBeInlined) {
|
|
54
|
+
pageInfo.hoistedScript = {
|
|
55
|
+
type: "inline",
|
|
56
|
+
value: output.code
|
|
57
|
+
};
|
|
58
|
+
removeFromBundle = true;
|
|
59
|
+
} else {
|
|
60
|
+
pageInfo.hoistedScript = {
|
|
61
|
+
type: "external",
|
|
62
|
+
value: id
|
|
63
|
+
};
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
}
|
|
67
|
+
if (removeFromBundle) {
|
|
68
|
+
delete bundle[id];
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { getPrerenderMetadata } from "../../../prerender/metadata.js";
|
|
2
3
|
import { extendManualChunks } from "./util.js";
|
|
3
4
|
function vitePluginPrerender(opts, internals) {
|
|
4
5
|
return {
|
|
@@ -6,13 +7,12 @@ function vitePluginPrerender(opts, internals) {
|
|
|
6
7
|
outputOptions(outputOptions) {
|
|
7
8
|
extendManualChunks(outputOptions, {
|
|
8
9
|
after(id, meta) {
|
|
9
|
-
var _a, _b, _c;
|
|
10
10
|
if (id.includes("astro/dist")) {
|
|
11
11
|
return "astro";
|
|
12
12
|
}
|
|
13
13
|
const pageInfo = internals.pagesByViteID.get(id);
|
|
14
14
|
if (pageInfo) {
|
|
15
|
-
if ((
|
|
15
|
+
if (getPrerenderMetadata(meta.getModuleInfo(id))) {
|
|
16
16
|
pageInfo.route.prerender = true;
|
|
17
17
|
return "prerender";
|
|
18
18
|
}
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -53,7 +53,7 @@ async function dev(settings, options) {
|
|
|
53
53
|
isRestart: options.isRestart
|
|
54
54
|
})
|
|
55
55
|
);
|
|
56
|
-
const currentVersion = "2.5.
|
|
56
|
+
const currentVersion = "2.5.2";
|
|
57
57
|
if (currentVersion.includes("-")) {
|
|
58
58
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
59
59
|
}
|
|
@@ -60,6 +60,7 @@ function createAPIContext({
|
|
|
60
60
|
return context;
|
|
61
61
|
}
|
|
62
62
|
async function callEndpoint(mod, env, ctx, logging, middleware) {
|
|
63
|
+
var _a;
|
|
63
64
|
const context = createAPIContext({
|
|
64
65
|
request: ctx.request,
|
|
65
66
|
params: ctx.params,
|
|
@@ -94,7 +95,7 @@ async function callEndpoint(mod, env, ctx, logging, middleware) {
|
|
|
94
95
|
response
|
|
95
96
|
};
|
|
96
97
|
}
|
|
97
|
-
if (env.ssr && !
|
|
98
|
+
if (env.ssr && !((_a = ctx.route) == null ? void 0 : _a.prerender)) {
|
|
98
99
|
if (response.hasOwnProperty("headers")) {
|
|
99
100
|
warn(
|
|
100
101
|
logging,
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
base,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "2.5.
|
|
50
|
+
const version = "2.5.2";
|
|
51
51
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
52
52
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
53
53
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -233,7 +233,7 @@ function printHelp({
|
|
|
233
233
|
message.push(
|
|
234
234
|
linebreak(),
|
|
235
235
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
236
|
-
`v${"2.5.
|
|
236
|
+
`v${"2.5.2"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
package/dist/core/render/core.js
CHANGED
|
@@ -52,7 +52,7 @@ async function getParamsAndProps(opts) {
|
|
|
52
52
|
routeCache.set(route, routeCacheEntry);
|
|
53
53
|
}
|
|
54
54
|
const matchedStaticPath = findPathItemByKey(routeCacheEntry.staticPaths, params, route);
|
|
55
|
-
if (!matchedStaticPath && (ssr ?
|
|
55
|
+
if (!matchedStaticPath && (ssr ? route.prerender : true)) {
|
|
56
56
|
return 0 /* NoMatchingStaticPath */;
|
|
57
57
|
}
|
|
58
58
|
pageProps = (matchedStaticPath == null ? void 0 : matchedStaticPath.props) ? { ...matchedStaticPath.props } : {};
|
|
@@ -11,7 +11,7 @@ async function callGetStaticPaths({
|
|
|
11
11
|
ssr
|
|
12
12
|
}) {
|
|
13
13
|
validateDynamicRouteModule(mod, { ssr, logging, route });
|
|
14
|
-
if (ssr && !
|
|
14
|
+
if (ssr && !route.prerender) {
|
|
15
15
|
return { staticPaths: Object.assign([], { keyed: /* @__PURE__ */ new Map() }) };
|
|
16
16
|
}
|
|
17
17
|
if (!mod.getStaticPaths) {
|
|
@@ -143,7 +143,7 @@ function createRouteManifest({ settings, cwd, fsMod }, logging) {
|
|
|
143
143
|
]);
|
|
144
144
|
const validEndpointExtensions = /* @__PURE__ */ new Set([".js", ".ts"]);
|
|
145
145
|
const localFs = fsMod ?? nodeFs;
|
|
146
|
-
const
|
|
146
|
+
const isPrerenderDefault = isHybridOutput(settings.config);
|
|
147
147
|
const foundInvalidFileExtensions = /* @__PURE__ */ new Set();
|
|
148
148
|
function walk(fs, dir, parentSegments, parentParams) {
|
|
149
149
|
let items = [];
|
|
@@ -233,7 +233,7 @@ function createRouteManifest({ settings, cwd, fsMod }, logging) {
|
|
|
233
233
|
component,
|
|
234
234
|
generate,
|
|
235
235
|
pathname: pathname || void 0,
|
|
236
|
-
prerender:
|
|
236
|
+
prerender: isPrerenderDefault
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
239
|
});
|
|
@@ -287,7 +287,7 @@ This route collides with: "${collision.component}".`
|
|
|
287
287
|
component,
|
|
288
288
|
generate,
|
|
289
289
|
pathname: pathname || void 0,
|
|
290
|
-
prerender:
|
|
290
|
+
prerender: isPrerenderDefault
|
|
291
291
|
});
|
|
292
292
|
});
|
|
293
293
|
return {
|
|
@@ -18,14 +18,14 @@ function validateDynamicRouteModule(mod, {
|
|
|
18
18
|
logging,
|
|
19
19
|
route
|
|
20
20
|
}) {
|
|
21
|
-
if (ssr && mod.getStaticPaths && !
|
|
21
|
+
if (ssr && mod.getStaticPaths && !route.prerender) {
|
|
22
22
|
warn(
|
|
23
23
|
logging,
|
|
24
24
|
"getStaticPaths",
|
|
25
25
|
`getStaticPaths() in ${bold(route.component)} is ignored when "output: server" is set.`
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
|
-
if ((!ssr ||
|
|
28
|
+
if ((!ssr || route.prerender) && !mod.getStaticPaths) {
|
|
29
29
|
throw new AstroError({
|
|
30
30
|
...AstroErrorData.GetStaticPathsRequired,
|
|
31
31
|
location: { file: route.component }
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ModuleInfo, ModuleLoader } from '../core/module-loader';
|
|
2
|
+
type GetPrerenderStatusParams = {
|
|
3
|
+
filePath: URL;
|
|
4
|
+
loader: ModuleLoader;
|
|
5
|
+
};
|
|
6
|
+
export declare function getPrerenderStatus({ filePath, loader, }: GetPrerenderStatusParams): boolean | undefined;
|
|
7
|
+
export declare function getPrerenderMetadata(moduleInfo: ModuleInfo): any;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { viteID } from "../core/util.js";
|
|
2
|
+
function getPrerenderStatus({
|
|
3
|
+
filePath,
|
|
4
|
+
loader
|
|
5
|
+
}) {
|
|
6
|
+
const fileID = viteID(filePath);
|
|
7
|
+
const moduleInfo = loader.getModuleInfo(fileID);
|
|
8
|
+
if (!moduleInfo)
|
|
9
|
+
return;
|
|
10
|
+
const prerenderStatus = getPrerenderMetadata(moduleInfo);
|
|
11
|
+
return prerenderStatus;
|
|
12
|
+
}
|
|
13
|
+
function getPrerenderMetadata(moduleInfo) {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
return (_c = (_b = (_a = moduleInfo == null ? void 0 : moduleInfo.meta) == null ? void 0 : _a.astro) == null ? void 0 : _b.pageOptions) == null ? void 0 : _c.prerender;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
getPrerenderMetadata,
|
|
19
|
+
getPrerenderStatus
|
|
20
|
+
};
|
|
@@ -9,6 +9,7 @@ import { preload, renderPage } from "../core/render/dev/index.js";
|
|
|
9
9
|
import { getParamsAndProps, GetParamsAndPropsError } from "../core/render/index.js";
|
|
10
10
|
import { createRequest } from "../core/request.js";
|
|
11
11
|
import { matchAllRoutes } from "../core/routing/index.js";
|
|
12
|
+
import { getPrerenderStatus } from "../prerender/metadata.js";
|
|
12
13
|
import { isHybridOutput } from "../prerender/utils.js";
|
|
13
14
|
import { log404 } from "./common.js";
|
|
14
15
|
import { handle404Response, writeSSRResult, writeWebResponse } from "./response.js";
|
|
@@ -22,6 +23,13 @@ async function matchRoute(pathname, env, manifest) {
|
|
|
22
23
|
for await (const maybeRoute of matches) {
|
|
23
24
|
const filePath = new URL(`./${maybeRoute.component}`, settings.config.root);
|
|
24
25
|
const preloadedComponent = await preload({ env, filePath });
|
|
26
|
+
const prerenderStatus = getPrerenderStatus({
|
|
27
|
+
filePath,
|
|
28
|
+
loader: env.loader
|
|
29
|
+
});
|
|
30
|
+
if (prerenderStatus !== void 0) {
|
|
31
|
+
maybeRoute.prerender = prerenderStatus;
|
|
32
|
+
}
|
|
25
33
|
const [, mod] = preloadedComponent;
|
|
26
34
|
const paramsAndPropsRes = await getParamsAndProps({
|
|
27
35
|
mod,
|