astro 2.5.0 → 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/content/types-generator.js +17 -9
- package/dist/core/app/index.js +2 -2
- package/dist/core/app/types.d.ts +3 -1
- package/dist/core/build/generate.js +3 -2
- package/dist/core/build/graph.js +1 -1
- package/dist/core/build/plugins/index.js +2 -0
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +30 -24
- package/dist/core/build/plugins/plugin-middleware.d.ts +8 -0
- package/dist/core/build/plugins/plugin-middleware.js +53 -0
- package/dist/core/build/plugins/plugin-pages.js +6 -10
- package/dist/core/build/plugins/plugin-prerender.js +4 -3
- package/dist/core/build/plugins/plugin-ssr.js +11 -19
- package/dist/core/build/static-build.js +3 -0
- package/dist/core/build/types.d.ts +3 -1
- 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 +8 -3
- 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
|
@@ -49,14 +49,22 @@ async function createContentTypesGenerator({
|
|
|
49
49
|
fs: {
|
|
50
50
|
readdir: fs.readdir.bind(fs),
|
|
51
51
|
readdirSync: fs.readdirSync.bind(fs)
|
|
52
|
-
}
|
|
52
|
+
},
|
|
53
|
+
onlyFiles: false,
|
|
54
|
+
objectMode: true
|
|
53
55
|
});
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
for (const entry of globResult) {
|
|
57
|
+
const entryURL = new URL(entry.path, contentPaths.contentDir);
|
|
58
|
+
if (entryURL.href.startsWith(contentPaths.config.url.href))
|
|
59
|
+
continue;
|
|
60
|
+
if (entry.dirent.isFile()) {
|
|
61
|
+
events.push({
|
|
62
|
+
type: { name: "add", entry: entryURL },
|
|
63
|
+
opts: { logLevel: "warn" }
|
|
64
|
+
});
|
|
65
|
+
} else if (entry.dirent.isDirectory()) {
|
|
66
|
+
events.push({ type: { name: "addDir", entry: entryURL }, opts: { logLevel: "warn" } });
|
|
67
|
+
}
|
|
60
68
|
}
|
|
61
69
|
await runEvents();
|
|
62
70
|
return { typesGenerated: true };
|
|
@@ -416,9 +424,9 @@ function warnNonexistentCollections({
|
|
|
416
424
|
warn(
|
|
417
425
|
logging,
|
|
418
426
|
"content",
|
|
419
|
-
|
|
427
|
+
`The ${JSON.stringify(
|
|
420
428
|
configuredCollection
|
|
421
|
-
)}
|
|
429
|
+
)} collection does not have an associated folder in your \`content\` directory. Make sure the folder exists, or check your content config for typos.`
|
|
422
430
|
);
|
|
423
431
|
}
|
|
424
432
|
}
|
package/dist/core/app/index.js
CHANGED
|
@@ -115,13 +115,13 @@ class App {
|
|
|
115
115
|
if (routeData.route === "/404") {
|
|
116
116
|
defaultStatus = 404;
|
|
117
117
|
}
|
|
118
|
-
let mod = this.#manifest.pageMap.get(routeData.component);
|
|
118
|
+
let mod = await this.#manifest.pageMap.get(routeData.component)();
|
|
119
119
|
if (routeData.type === "page") {
|
|
120
120
|
let response = await this.#renderPage(request, routeData, mod, defaultStatus);
|
|
121
121
|
if (response.status === 500) {
|
|
122
122
|
const fiveHundredRouteData = matchRoute("/500", this.#manifestData);
|
|
123
123
|
if (fiveHundredRouteData) {
|
|
124
|
-
mod = this.#manifest.pageMap.get(fiveHundredRouteData.component);
|
|
124
|
+
mod = await this.#manifest.pageMap.get(fiveHundredRouteData.component)();
|
|
125
125
|
try {
|
|
126
126
|
let fiveHundredResponse = await this.#renderPage(
|
|
127
127
|
request,
|
package/dist/core/app/types.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface RouteInfo {
|
|
|
24
24
|
export type SerializedRouteInfo = Omit<RouteInfo, 'routeData'> & {
|
|
25
25
|
routeData: SerializedRouteData;
|
|
26
26
|
};
|
|
27
|
+
type ImportComponentInstance = () => Promise<ComponentInstance>;
|
|
27
28
|
export interface SSRManifest {
|
|
28
29
|
adapterName: string;
|
|
29
30
|
routes: RouteInfo[];
|
|
@@ -31,7 +32,7 @@ export interface SSRManifest {
|
|
|
31
32
|
base?: string;
|
|
32
33
|
assetsPrefix?: string;
|
|
33
34
|
markdown: MarkdownRenderingOptions;
|
|
34
|
-
pageMap: Map<ComponentPath,
|
|
35
|
+
pageMap: Map<ComponentPath, ImportComponentInstance>;
|
|
35
36
|
renderers: SSRLoadedRenderer[];
|
|
36
37
|
/**
|
|
37
38
|
* Map of directive name (e.g. `load`) to the directive script code
|
|
@@ -49,3 +50,4 @@ export type SerializedSSRManifest = Omit<SSRManifest, 'routes' | 'assets' | 'com
|
|
|
49
50
|
clientDirectives: [string, string][];
|
|
50
51
|
};
|
|
51
52
|
export type AdapterCreateExports<T = any> = (manifest: SSRManifest, args?: T) => Record<string, any>;
|
|
53
|
+
export {};
|
|
@@ -115,13 +115,14 @@ async function generatePage(opts, internals, pageData, ssrEntry, builtPaths) {
|
|
|
115
115
|
const linkIds = [];
|
|
116
116
|
const scripts = (pageInfo == null ? void 0 : pageInfo.hoistedScript) ?? null;
|
|
117
117
|
const styles = pageData.styles.sort(cssOrder).map(({ sheet }) => sheet).reduce(mergeInlineCss, []);
|
|
118
|
-
const
|
|
118
|
+
const pageModulePromise = (_a = ssrEntry.pageMap) == null ? void 0 : _a.get(pageData.component);
|
|
119
119
|
const middleware = ssrEntry.middleware;
|
|
120
|
-
if (!
|
|
120
|
+
if (!pageModulePromise) {
|
|
121
121
|
throw new Error(
|
|
122
122
|
`Unable to find the module for ${pageData.component}. This is unexpected and likely a bug in Astro, please report.`
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
|
+
const pageModule = await pageModulePromise();
|
|
125
126
|
if (shouldSkipDraft(pageModule, opts.settings)) {
|
|
126
127
|
info(opts.logging, null, `${magenta("\u26A0\uFE0F")} Skipping draft ${pageData.route.component}`);
|
|
127
128
|
return;
|
package/dist/core/build/graph.js
CHANGED
|
@@ -25,7 +25,7 @@ function* walkParentInfos(id, ctx, until, depth = 0, order = 0, seen = /* @__PUR
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
function moduleIsTopLevelPage(info) {
|
|
28
|
-
return info.importers[0] === resolvedPagesVirtualModuleId;
|
|
28
|
+
return info.importers[0] === resolvedPagesVirtualModuleId || info.dynamicImporters[0] == resolvedPagesVirtualModuleId;
|
|
29
29
|
}
|
|
30
30
|
function* getTopLevelPages(id, ctx) {
|
|
31
31
|
for (const res of walkParentInfos(id, ctx)) {
|
|
@@ -6,6 +6,7 @@ import { pluginComponentEntry } from "./plugin-component-entry.js";
|
|
|
6
6
|
import { pluginCSS } from "./plugin-css.js";
|
|
7
7
|
import { pluginHoistedScripts } from "./plugin-hoisted-scripts.js";
|
|
8
8
|
import { pluginInternals } from "./plugin-internals.js";
|
|
9
|
+
import { pluginMiddleware } from "./plugin-middleware.js";
|
|
9
10
|
import { pluginPages } from "./plugin-pages.js";
|
|
10
11
|
import { pluginPrerender } from "./plugin-prerender.js";
|
|
11
12
|
import { pluginSSR } from "./plugin-ssr.js";
|
|
@@ -14,6 +15,7 @@ function registerAllPlugins({ internals, options, register }) {
|
|
|
14
15
|
register(pluginAliasResolve(internals));
|
|
15
16
|
register(pluginAnalyzer(internals));
|
|
16
17
|
register(pluginInternals(internals));
|
|
18
|
+
register(pluginMiddleware(options, internals));
|
|
17
19
|
register(pluginPages(options, internals));
|
|
18
20
|
register(pluginCSS(options, internals));
|
|
19
21
|
register(astroHeadBuildPlugin(options, internals));
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Plugin as VitePlugin } from 'vite';
|
|
2
|
+
import type { BuildInternals } from '../internal.js';
|
|
3
|
+
import type { AstroBuildPlugin } from '../plugin';
|
|
4
|
+
import type { StaticBuildOptions } from '../types';
|
|
5
|
+
export declare const MIDDLEWARE_MODULE_ID = "@astro-middleware";
|
|
6
|
+
export declare const RESOLVED_MIDDLEWARE_MODULE_ID = "\0@astro-middleware";
|
|
7
|
+
export declare function vitePluginMiddleware(opts: StaticBuildOptions, _internals: BuildInternals): VitePlugin;
|
|
8
|
+
export declare function pluginMiddleware(opts: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { MIDDLEWARE_PATH_SEGMENT_NAME } from "../../constants.js";
|
|
2
|
+
import { addRollupInput } from "../add-rollup-input.js";
|
|
3
|
+
const MIDDLEWARE_MODULE_ID = "@astro-middleware";
|
|
4
|
+
const RESOLVED_MIDDLEWARE_MODULE_ID = "\0@astro-middleware";
|
|
5
|
+
let inputs = /* @__PURE__ */ new Set();
|
|
6
|
+
function vitePluginMiddleware(opts, _internals) {
|
|
7
|
+
return {
|
|
8
|
+
name: "@astro/plugin-middleware",
|
|
9
|
+
options(options) {
|
|
10
|
+
if (opts.settings.config.experimental.middleware) {
|
|
11
|
+
return addRollupInput(options, [MIDDLEWARE_MODULE_ID]);
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
resolveId(id) {
|
|
15
|
+
if (id === MIDDLEWARE_MODULE_ID && opts.settings.config.experimental.middleware) {
|
|
16
|
+
return RESOLVED_MIDDLEWARE_MODULE_ID;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
async load(id) {
|
|
20
|
+
if (id === RESOLVED_MIDDLEWARE_MODULE_ID && opts.settings.config.experimental.middleware) {
|
|
21
|
+
const imports = [];
|
|
22
|
+
const exports = [];
|
|
23
|
+
let middlewareId = await this.resolve(
|
|
24
|
+
`${opts.settings.config.srcDir.pathname}/${MIDDLEWARE_PATH_SEGMENT_NAME}`
|
|
25
|
+
);
|
|
26
|
+
if (middlewareId) {
|
|
27
|
+
imports.push(`import { onRequest } from "${middlewareId.id}"`);
|
|
28
|
+
exports.push(`export { onRequest }`);
|
|
29
|
+
}
|
|
30
|
+
const result = [imports.join("\n"), exports.join("\n")];
|
|
31
|
+
return result.join("\n");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function pluginMiddleware(opts, internals) {
|
|
37
|
+
return {
|
|
38
|
+
build: "ssr",
|
|
39
|
+
hooks: {
|
|
40
|
+
"build:before": () => {
|
|
41
|
+
return {
|
|
42
|
+
vitePlugin: vitePluginMiddleware(opts, internals)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
MIDDLEWARE_MODULE_ID,
|
|
50
|
+
RESOLVED_MIDDLEWARE_MODULE_ID,
|
|
51
|
+
pluginMiddleware,
|
|
52
|
+
vitePluginMiddleware
|
|
53
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pagesVirtualModuleId, resolvedPagesVirtualModuleId } from "../../app/index.js";
|
|
2
|
-
import { MIDDLEWARE_PATH_SEGMENT_NAME } from "../../constants.js";
|
|
3
2
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
4
3
|
import { eachPageData } from "../internal.js";
|
|
4
|
+
import { MIDDLEWARE_MODULE_ID } from "./plugin-middleware.js";
|
|
5
5
|
function vitePluginPages(opts, internals) {
|
|
6
6
|
return {
|
|
7
7
|
name: "@astro/plugin-build-pages",
|
|
@@ -17,18 +17,14 @@ function vitePluginPages(opts, internals) {
|
|
|
17
17
|
},
|
|
18
18
|
async load(id) {
|
|
19
19
|
if (id === resolvedPagesVirtualModuleId) {
|
|
20
|
-
let middlewareId = null;
|
|
21
|
-
if (opts.settings.config.experimental.middleware) {
|
|
22
|
-
middlewareId = await this.resolve(
|
|
23
|
-
`${opts.settings.config.srcDir.pathname}/${MIDDLEWARE_PATH_SEGMENT_NAME}`
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
20
|
let importMap = "";
|
|
27
21
|
let imports = [];
|
|
28
22
|
let i = 0;
|
|
29
23
|
for (const pageData of eachPageData(internals)) {
|
|
30
24
|
const variable = `_page${i}`;
|
|
31
|
-
imports.push(
|
|
25
|
+
imports.push(
|
|
26
|
+
`const ${variable} = () => import(${JSON.stringify(pageData.moduleSpecifier)});`
|
|
27
|
+
);
|
|
32
28
|
importMap += `[${JSON.stringify(pageData.component)}, ${variable}],`;
|
|
33
29
|
i++;
|
|
34
30
|
}
|
|
@@ -42,11 +38,11 @@ function vitePluginPages(opts, internals) {
|
|
|
42
38
|
}
|
|
43
39
|
const def = `${imports.join("\n")}
|
|
44
40
|
|
|
45
|
-
${
|
|
41
|
+
${opts.settings.config.experimental.middleware ? `import * as _middleware from "${MIDDLEWARE_MODULE_ID}";` : ""}
|
|
46
42
|
|
|
47
43
|
export const pageMap = new Map([${importMap}]);
|
|
48
44
|
export const renderers = [${rendererItems}];
|
|
49
|
-
${
|
|
45
|
+
${opts.settings.config.experimental.middleware ? `export const middleware = _middleware;` : ""}
|
|
50
46
|
`;
|
|
51
47
|
return def;
|
|
52
48
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { getPrerenderMetadata } from "../../../prerender/metadata.js";
|
|
1
3
|
import { extendManualChunks } from "./util.js";
|
|
2
4
|
function vitePluginPrerender(opts, internals) {
|
|
3
5
|
return {
|
|
@@ -5,18 +7,17 @@ function vitePluginPrerender(opts, internals) {
|
|
|
5
7
|
outputOptions(outputOptions) {
|
|
6
8
|
extendManualChunks(outputOptions, {
|
|
7
9
|
after(id, meta) {
|
|
8
|
-
var _a, _b, _c;
|
|
9
10
|
if (id.includes("astro/dist")) {
|
|
10
11
|
return "astro";
|
|
11
12
|
}
|
|
12
13
|
const pageInfo = internals.pagesByViteID.get(id);
|
|
13
14
|
if (pageInfo) {
|
|
14
|
-
if ((
|
|
15
|
+
if (getPrerenderMetadata(meta.getModuleInfo(id))) {
|
|
15
16
|
pageInfo.route.prerender = true;
|
|
16
17
|
return "prerender";
|
|
17
18
|
}
|
|
18
19
|
pageInfo.route.prerender = false;
|
|
19
|
-
return `pages
|
|
20
|
+
return `pages/${path.basename(pageInfo.component)}`;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
});
|
|
@@ -8,7 +8,7 @@ import { joinPaths, prependForwardSlash } from "../../path.js";
|
|
|
8
8
|
import { serializeRouteData } from "../../routing/index.js";
|
|
9
9
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
10
10
|
import { getOutFile, getOutFolder } from "../common.js";
|
|
11
|
-
import { cssOrder,
|
|
11
|
+
import { cssOrder, mergeInlineCss } from "../internal.js";
|
|
12
12
|
const virtualModuleId = "@astrojs-ssr-virtual-entry";
|
|
13
13
|
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
14
14
|
const manifestReplace = "@@ASTRO_MANIFEST_REPLACE@@";
|
|
@@ -118,34 +118,26 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
118
118
|
return prependForwardSlash(joinPaths(settings.config.base, pth));
|
|
119
119
|
}
|
|
120
120
|
};
|
|
121
|
-
for (const
|
|
122
|
-
if (!
|
|
121
|
+
for (const route of opts.manifest.routes) {
|
|
122
|
+
if (!route.prerender)
|
|
123
123
|
continue;
|
|
124
|
-
if (!
|
|
124
|
+
if (!route.pathname)
|
|
125
125
|
continue;
|
|
126
|
-
const outFolder = getOutFolder(
|
|
127
|
-
|
|
128
|
-
pageData.route.pathname,
|
|
129
|
-
pageData.route.type
|
|
130
|
-
);
|
|
131
|
-
const outFile = getOutFile(
|
|
132
|
-
opts.settings.config,
|
|
133
|
-
outFolder,
|
|
134
|
-
pageData.route.pathname,
|
|
135
|
-
pageData.route.type
|
|
136
|
-
);
|
|
126
|
+
const outFolder = getOutFolder(opts.settings.config, route.pathname, route.type);
|
|
127
|
+
const outFile = getOutFile(opts.settings.config, outFolder, route.pathname, route.type);
|
|
137
128
|
const file = outFile.toString().replace(opts.settings.config.build.client.toString(), "");
|
|
138
129
|
routes.push({
|
|
139
130
|
file,
|
|
140
131
|
links: [],
|
|
141
132
|
scripts: [],
|
|
142
133
|
styles: [],
|
|
143
|
-
routeData: serializeRouteData(
|
|
134
|
+
routeData: serializeRouteData(route, settings.config.trailingSlash)
|
|
144
135
|
});
|
|
145
136
|
staticFiles.push(file);
|
|
146
137
|
}
|
|
147
|
-
for (const
|
|
148
|
-
|
|
138
|
+
for (const route of opts.manifest.routes) {
|
|
139
|
+
const pageData = internals.pagesByComponent.get(route.component);
|
|
140
|
+
if (route.prerender || !pageData)
|
|
149
141
|
continue;
|
|
150
142
|
const scripts = [];
|
|
151
143
|
if (pageData.hoistedScript) {
|
|
@@ -174,7 +166,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
174
166
|
...settings.scripts.filter((script) => script.stage === "head-inline").map(({ stage, content }) => ({ stage, children: content }))
|
|
175
167
|
],
|
|
176
168
|
styles,
|
|
177
|
-
routeData: serializeRouteData(
|
|
169
|
+
routeData: serializeRouteData(route, settings.config.trailingSlash)
|
|
178
170
|
});
|
|
179
171
|
}
|
|
180
172
|
if (!(BEFORE_HYDRATION_SCRIPT_ID in entryModules)) {
|
|
@@ -24,6 +24,7 @@ import { generatePages } from "./generate.js";
|
|
|
24
24
|
import { trackPageData } from "./internal.js";
|
|
25
25
|
import { createPluginContainer } from "./plugin.js";
|
|
26
26
|
import { registerAllPlugins } from "./plugins/index.js";
|
|
27
|
+
import { RESOLVED_MIDDLEWARE_MODULE_ID } from "./plugins/plugin-middleware.js";
|
|
27
28
|
import { getTimeStat } from "./util.js";
|
|
28
29
|
async function viteBuild(opts) {
|
|
29
30
|
var _a, _b, _c;
|
|
@@ -129,6 +130,8 @@ async function ssrBuild(opts, internals, input, container) {
|
|
|
129
130
|
entryFileNames(chunkInfo) {
|
|
130
131
|
if (chunkInfo.facadeModuleId === resolvedPagesVirtualModuleId) {
|
|
131
132
|
return opts.buildConfig.serverEntry;
|
|
133
|
+
} else if (chunkInfo.facadeModuleId === RESOLVED_MIDDLEWARE_MODULE_ID) {
|
|
134
|
+
return "middleware.mjs";
|
|
132
135
|
} else {
|
|
133
136
|
return "[name].mjs";
|
|
134
137
|
}
|
|
@@ -43,8 +43,9 @@ export interface StaticBuildOptions {
|
|
|
43
43
|
viteConfig: InlineConfig;
|
|
44
44
|
teardownCompiler: boolean;
|
|
45
45
|
}
|
|
46
|
+
type ImportComponentInstance = () => Promise<ComponentInstance>;
|
|
46
47
|
export interface SingleFileBuiltModule {
|
|
47
|
-
pageMap: Map<ComponentPath,
|
|
48
|
+
pageMap: Map<ComponentPath, ImportComponentInstance>;
|
|
48
49
|
middleware: AstroMiddlewareInstance<unknown>;
|
|
49
50
|
renderers: SSRLoadedRenderer[];
|
|
50
51
|
}
|
|
@@ -55,3 +56,4 @@ export type RollupOutput = Extract<Extract<ViteBuildReturn, Exclude<ViteBuildRet
|
|
|
55
56
|
export type OutputChunk = Extract<RollupOutput['output'][number], {
|
|
56
57
|
type: 'chunk';
|
|
57
58
|
}>;
|
|
59
|
+
export {};
|
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 {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bold } from "kleur/colors";
|
|
1
2
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
2
3
|
import { warn } from "../logger/core.js";
|
|
3
4
|
const VALID_PARAM_TYPES = ["string", "number", "undefined"];
|
|
@@ -17,10 +18,14 @@ function validateDynamicRouteModule(mod, {
|
|
|
17
18
|
logging,
|
|
18
19
|
route
|
|
19
20
|
}) {
|
|
20
|
-
if (ssr && mod.getStaticPaths && !
|
|
21
|
-
warn(
|
|
21
|
+
if (ssr && mod.getStaticPaths && !route.prerender) {
|
|
22
|
+
warn(
|
|
23
|
+
logging,
|
|
24
|
+
"getStaticPaths",
|
|
25
|
+
`getStaticPaths() in ${bold(route.component)} is ignored when "output: server" is set.`
|
|
26
|
+
);
|
|
22
27
|
}
|
|
23
|
-
if ((!ssr ||
|
|
28
|
+
if ((!ssr || route.prerender) && !mod.getStaticPaths) {
|
|
24
29
|
throw new AstroError({
|
|
25
30
|
...AstroErrorData.GetStaticPathsRequired,
|
|
26
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,
|