astro 6.0.4 → 6.0.6
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/bin/astro.mjs +2 -5
- package/dist/actions/integration.js +9 -6
- package/dist/assets/runtime.d.ts +2 -1
- package/dist/assets/runtime.js +15 -4
- package/dist/assets/utils/svg.js +25 -7
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/content/content-layer.js +3 -3
- package/dist/content/server-listeners.js +4 -0
- package/dist/content/types-generator.js +4 -1
- package/dist/core/app/base.js +2 -1
- package/dist/core/build/generate.js +92 -84
- package/dist/core/build/plugins/plugin-internals.js +12 -13
- package/dist/core/build/plugins/plugin-manifest.js +11 -5
- package/dist/core/build/static-build.js +9 -9
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages/runtime.js +1 -1
- package/dist/core/render/params-and-props.js +4 -6
- package/dist/core/render/ssr-element.js +26 -4
- package/dist/core/routing/helpers.d.ts +13 -0
- package/dist/core/routing/helpers.js +15 -0
- package/dist/core/server-islands/vite-plugin-server-islands.d.ts +1 -1
- package/dist/core/server-islands/vite-plugin-server-islands.js +59 -120
- package/dist/core/viteUtils.d.ts +7 -1
- package/dist/core/viteUtils.js +18 -1
- package/dist/manifest/serialized.d.ts +1 -1
- package/dist/manifest/serialized.js +4 -1
- package/dist/vite-plugin-astro/hmr.d.ts +3 -1
- package/dist/vite-plugin-astro/hmr.js +6 -2
- package/dist/vite-plugin-astro/index.js +1 -1
- package/dist/vite-plugin-astro-server/plugin.js +8 -12
- package/dist/vite-plugin-renderers/index.js +4 -6
- package/dist/vite-plugin-routes/index.js +3 -2
- package/dist/vite-plugin-scripts/index.js +1 -1
- package/package.json +4 -4
- package/templates/content/types.d.ts +3 -2
package/bin/astro.mjs
CHANGED
|
@@ -8,12 +8,9 @@ const CI_INSTRUCTIONS = {
|
|
|
8
8
|
VERCEL: 'https://vercel.com/docs/runtimes#official-runtimes/node-js/node-js-version',
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
// TODO: remove once Stackblitz supports Node 22
|
|
12
|
-
const IS_STACKBLITZ = !!process.versions.webcontainer;
|
|
13
|
-
|
|
14
11
|
// Hardcode supported Node.js version so we don't have to read differently in CJS & ESM.
|
|
15
|
-
const engines =
|
|
16
|
-
const skipSemverCheckIfAbove =
|
|
12
|
+
const engines = '>=22.12.0';
|
|
13
|
+
const skipSemverCheckIfAbove = 23;
|
|
17
14
|
|
|
18
15
|
/** `astro *` */
|
|
19
16
|
async function main() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AstroError } from "../core/errors/errors.js";
|
|
2
2
|
import { ActionsWithoutServerOutputError } from "../core/errors/errors-data.js";
|
|
3
|
+
import { hasNonPrerenderedProjectRoute } from "../core/routing/helpers.js";
|
|
3
4
|
import { viteID } from "../core/util.js";
|
|
4
5
|
import { ACTION_RPC_ROUTE_PATTERN, ACTIONS_TYPES_FILE, VIRTUAL_MODULE_ID } from "./consts.js";
|
|
5
6
|
function astroIntegrationActionsRouteHandler({
|
|
@@ -18,20 +19,22 @@ function astroIntegrationActionsRouteHandler({
|
|
|
18
19
|
});
|
|
19
20
|
},
|
|
20
21
|
"astro:config:done": async (params) => {
|
|
21
|
-
if (params.buildOutput === "static") {
|
|
22
|
-
const error = new AstroError(ActionsWithoutServerOutputError);
|
|
23
|
-
error.stack = void 0;
|
|
24
|
-
throw error;
|
|
25
|
-
}
|
|
26
22
|
const stringifiedActionsImport = JSON.stringify(
|
|
27
23
|
viteID(new URL(`./${filename}`, params.config.srcDir))
|
|
28
24
|
);
|
|
29
25
|
settings.injectedTypes.push({
|
|
30
26
|
filename: ACTIONS_TYPES_FILE,
|
|
31
27
|
content: `declare module "astro:actions" {
|
|
32
|
-
|
|
28
|
+
export const actions: typeof import(${stringifiedActionsImport})["server"];
|
|
33
29
|
}`
|
|
34
30
|
});
|
|
31
|
+
},
|
|
32
|
+
"astro:routes:resolved": ({ routes }) => {
|
|
33
|
+
if (!hasNonPrerenderedProjectRoute(routes)) {
|
|
34
|
+
const error = new AstroError(ActionsWithoutServerOutputError);
|
|
35
|
+
error.stack = void 0;
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
};
|
package/dist/assets/runtime.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ export interface SvgComponentProps {
|
|
|
3
3
|
meta: ImageMetadata;
|
|
4
4
|
attributes: Record<string, string>;
|
|
5
5
|
children: string;
|
|
6
|
+
styles: string[];
|
|
6
7
|
}
|
|
7
|
-
export declare function createSvgComponent({ meta, attributes, children }: SvgComponentProps): import("../runtime/server/index.js").AstroComponentFactory & ImageMetadata;
|
|
8
|
+
export declare function createSvgComponent({ meta, attributes, children, styles }: SvgComponentProps): import("../runtime/server/index.js").AstroComponentFactory & ImageMetadata;
|
|
8
9
|
type SvgAttributes = Record<string, any>;
|
|
9
10
|
export declare function dropAttributes(attributes: SvgAttributes): SvgAttributes;
|
|
10
11
|
export {};
|
package/dist/assets/runtime.js
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
+
import { generateCspDigest } from "../core/encryption.js";
|
|
1
2
|
import {
|
|
2
3
|
createComponent,
|
|
3
4
|
render,
|
|
4
5
|
spreadAttributes,
|
|
5
6
|
unescapeHTML
|
|
6
7
|
} from "../runtime/server/index.js";
|
|
7
|
-
function createSvgComponent({ meta, attributes, children }) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
function createSvgComponent({ meta, attributes, children, styles }) {
|
|
9
|
+
const hasStyles = styles.length > 0;
|
|
10
|
+
const Component = createComponent({
|
|
11
|
+
async factory(result, props) {
|
|
12
|
+
const normalizedProps = normalizeProps(attributes, props);
|
|
13
|
+
if (hasStyles && result.cspDestination) {
|
|
14
|
+
for (const style of styles) {
|
|
15
|
+
const hash = await generateCspDigest(style, result.cspAlgorithm);
|
|
16
|
+
result._metadata.extraStyleHashes.push(hash);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return render`<svg${spreadAttributes(normalizedProps)}>${unescapeHTML(children)}</svg>`;
|
|
20
|
+
},
|
|
21
|
+
propagation: hasStyles ? "self" : "none"
|
|
11
22
|
});
|
|
12
23
|
if (import.meta.env.DEV) {
|
|
13
24
|
makeNonEnumerable(Component);
|
package/dist/assets/utils/svg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { optimize } from "svgo";
|
|
2
|
-
import { parse, renderSync } from "ultrahtml";
|
|
2
|
+
import { ELEMENT_NODE, TEXT_NODE, parse, renderSync } from "ultrahtml";
|
|
3
3
|
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
|
4
4
|
import { dropAttributes } from "../runtime.js";
|
|
5
5
|
function parseSvg({
|
|
@@ -25,18 +25,31 @@ function parseSvg({
|
|
|
25
25
|
}
|
|
26
26
|
const root = parse(processedContents);
|
|
27
27
|
const svgNode = root.children.find(
|
|
28
|
-
({ name, type }) => type ===
|
|
28
|
+
({ name, type }) => type === ELEMENT_NODE && name === "svg"
|
|
29
29
|
);
|
|
30
30
|
if (!svgNode) {
|
|
31
31
|
throw new Error("SVG file does not contain an <svg> element");
|
|
32
32
|
}
|
|
33
33
|
const { attributes, children } = svgNode;
|
|
34
34
|
const body = renderSync({ ...root, children });
|
|
35
|
-
|
|
35
|
+
const styles = [];
|
|
36
|
+
for (const child of children) {
|
|
37
|
+
if (child.type === ELEMENT_NODE && child.name === "style") {
|
|
38
|
+
const textContent = child.children?.filter((c) => c.type === TEXT_NODE).map((c) => c.value).join("");
|
|
39
|
+
if (textContent) {
|
|
40
|
+
styles.push(textContent);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { attributes, body, styles };
|
|
36
45
|
}
|
|
37
46
|
function makeSvgComponent(meta, contents, svgoConfig) {
|
|
38
47
|
const file = typeof contents === "string" ? contents : contents.toString("utf-8");
|
|
39
|
-
const {
|
|
48
|
+
const {
|
|
49
|
+
attributes,
|
|
50
|
+
body: children,
|
|
51
|
+
styles
|
|
52
|
+
} = parseSvg({
|
|
40
53
|
path: meta.fsPath,
|
|
41
54
|
contents: file,
|
|
42
55
|
svgoConfig
|
|
@@ -44,19 +57,24 @@ function makeSvgComponent(meta, contents, svgoConfig) {
|
|
|
44
57
|
const props = {
|
|
45
58
|
meta,
|
|
46
59
|
attributes: dropAttributes(attributes),
|
|
47
|
-
children
|
|
60
|
+
children,
|
|
61
|
+
styles
|
|
48
62
|
};
|
|
49
63
|
return `import { createSvgComponent } from 'astro/assets/runtime';
|
|
50
64
|
export default createSvgComponent(${JSON.stringify(props)})`;
|
|
51
65
|
}
|
|
52
66
|
function parseSvgComponentData(meta, contents, svgoConfig) {
|
|
53
67
|
const file = typeof contents === "string" ? contents : contents.toString("utf-8");
|
|
54
|
-
const {
|
|
68
|
+
const {
|
|
69
|
+
attributes,
|
|
70
|
+
body: children,
|
|
71
|
+
styles
|
|
72
|
+
} = parseSvg({
|
|
55
73
|
path: meta.fsPath,
|
|
56
74
|
contents: file,
|
|
57
75
|
svgoConfig
|
|
58
76
|
});
|
|
59
|
-
return { attributes: dropAttributes(attributes), children };
|
|
77
|
+
return { attributes: dropAttributes(attributes), children, styles };
|
|
60
78
|
}
|
|
61
79
|
export {
|
|
62
80
|
makeSvgComponent,
|
|
@@ -189,7 +189,7 @@ ${contentConfig.error.message}`
|
|
|
189
189
|
logger.info("Content config changed");
|
|
190
190
|
shouldClear = true;
|
|
191
191
|
}
|
|
192
|
-
if (previousAstroVersion && previousAstroVersion !== "6.0.
|
|
192
|
+
if (previousAstroVersion && previousAstroVersion !== "6.0.6") {
|
|
193
193
|
logger.info("Astro version changed");
|
|
194
194
|
shouldClear = true;
|
|
195
195
|
}
|
|
@@ -197,8 +197,8 @@ ${contentConfig.error.message}`
|
|
|
197
197
|
logger.info("Clearing content store");
|
|
198
198
|
this.#store.clearAll();
|
|
199
199
|
}
|
|
200
|
-
if ("6.0.
|
|
201
|
-
this.#store.metaStore().set("astro-version", "6.0.
|
|
200
|
+
if ("6.0.6") {
|
|
201
|
+
this.#store.metaStore().set("astro-version", "6.0.6");
|
|
202
202
|
}
|
|
203
203
|
if (currentConfigDigest) {
|
|
204
204
|
this.#store.metaStore().set("content-config-digest", currentConfigDigest);
|
|
@@ -6,6 +6,10 @@ async function attachContentServerListeners({
|
|
|
6
6
|
logger,
|
|
7
7
|
settings
|
|
8
8
|
}) {
|
|
9
|
+
const maxListeners = viteServer.watcher.getMaxListeners();
|
|
10
|
+
if (maxListeners !== 0 && maxListeners < 50) {
|
|
11
|
+
viteServer.watcher.setMaxListeners(50);
|
|
12
|
+
}
|
|
9
13
|
const contentGenerator = await createContentTypesGenerator({
|
|
10
14
|
fs,
|
|
11
15
|
settings,
|
|
@@ -463,7 +463,10 @@ async function generateJSONSchema(fsMod, collectionConfig, collectionKey, collec
|
|
|
463
463
|
ctx.jsonSchema.type = "string";
|
|
464
464
|
ctx.jsonSchema.format = "date-time";
|
|
465
465
|
}
|
|
466
|
-
}
|
|
466
|
+
},
|
|
467
|
+
// Collection schemas are used for parsing collection input, so we need to tell Zod to use the
|
|
468
|
+
// input shape when generating a JSON schema.
|
|
469
|
+
io: "input"
|
|
467
470
|
});
|
|
468
471
|
const schemaStr = JSON.stringify(schema, null, 2);
|
|
469
472
|
const schemaJsonPath = new URL(
|
package/dist/core/app/base.js
CHANGED
|
@@ -32,6 +32,7 @@ import { AstroIntegrationLogger, Logger } from "../logger/core.js";
|
|
|
32
32
|
import { RenderContext } from "../render-context.js";
|
|
33
33
|
import { redirectTemplate } from "../routing/3xx.js";
|
|
34
34
|
import { ensure404Route } from "../routing/astro-designed-error-pages.js";
|
|
35
|
+
import { routeHasHtmlExtension } from "../routing/helpers.js";
|
|
35
36
|
import { matchRoute } from "../routing/match.js";
|
|
36
37
|
import { applyCacheHeaders } from "../cache/runtime/cache.js";
|
|
37
38
|
import { Router } from "../routing/router.js";
|
|
@@ -303,7 +304,7 @@ class BaseApp {
|
|
|
303
304
|
});
|
|
304
305
|
}
|
|
305
306
|
let pathname = this.getPathnameFromRequest(request);
|
|
306
|
-
if (this.isDev()) {
|
|
307
|
+
if (this.isDev() && !routeHasHtmlExtension(routeData)) {
|
|
307
308
|
pathname = pathname.replace(/\/index\.html$/, "/").replace(/\.html$/, "");
|
|
308
309
|
}
|
|
309
310
|
const defaultStatus = this.getDefaultStatusCode(routeData, pathname);
|
|
@@ -61,102 +61,106 @@ async function generatePages(options, internals, prerenderOutputDir) {
|
|
|
61
61
|
const verb = ssr ? "prerendering" : "generating";
|
|
62
62
|
logger.info("SKIP_FORMAT", `
|
|
63
63
|
${colors.bgGreen(colors.black(` ${verb} static routes `))}`);
|
|
64
|
-
const pathsWithRoutes = await prerenderer.getStaticPaths();
|
|
65
64
|
const routeToHeaders = /* @__PURE__ */ new Map();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
65
|
+
let staticImageList = getStaticImageList();
|
|
66
|
+
try {
|
|
67
|
+
const pathsWithRoutes = await prerenderer.getStaticPaths();
|
|
68
|
+
const hasI18nDomains = ssr && options.settings.config.i18n?.domains && Object.keys(options.settings.config.i18n.domains).length > 0;
|
|
69
|
+
const { config } = options.settings;
|
|
70
|
+
const builtPaths = /* @__PURE__ */ new Set();
|
|
71
|
+
const filteredPaths = pathsWithRoutes.filter(({ pathname, route }) => {
|
|
72
|
+
if (hasI18nDomains && route.prerender) {
|
|
73
|
+
throw new AstroError({
|
|
74
|
+
...AstroErrorData.NoPrerenderedRoutesWithDomains,
|
|
75
|
+
message: AstroErrorData.NoPrerenderedRoutesWithDomains.message(route.component)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const normalized = removeTrailingForwardSlash(pathname);
|
|
79
|
+
if (!builtPaths.has(normalized)) {
|
|
80
|
+
builtPaths.add(normalized);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
const matchedRoute = matchRoute(decodeURI(pathname), options.routesList);
|
|
84
|
+
if (!matchedRoute) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (matchedRoute === route) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
if (config.prerenderConflictBehavior === "error") {
|
|
91
|
+
throw new AstroError({
|
|
92
|
+
...AstroErrorData.PrerenderRouteConflict,
|
|
93
|
+
message: AstroErrorData.PrerenderRouteConflict.message(
|
|
94
|
+
matchedRoute.route,
|
|
95
|
+
route.route,
|
|
96
|
+
normalized
|
|
97
|
+
),
|
|
98
|
+
hint: AstroErrorData.PrerenderRouteConflict.hint(matchedRoute.route, route.route)
|
|
99
|
+
});
|
|
100
|
+
} else if (config.prerenderConflictBehavior === "warn") {
|
|
101
|
+
const msg = AstroErrorData.PrerenderRouteConflict.message(
|
|
92
102
|
matchedRoute.route,
|
|
93
103
|
route.route,
|
|
94
104
|
normalized
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
() => generatePathWithPrerenderer(
|
|
118
|
-
prerenderer,
|
|
119
|
-
pathname,
|
|
120
|
-
route,
|
|
121
|
-
options,
|
|
122
|
-
routeToHeaders,
|
|
123
|
-
logger
|
|
105
|
+
);
|
|
106
|
+
logger.warn("build", msg);
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
});
|
|
110
|
+
if (config.build.concurrency > 1) {
|
|
111
|
+
const limit = PLimit(config.build.concurrency);
|
|
112
|
+
const BATCH_SIZE = 1e5;
|
|
113
|
+
for (let i = 0; i < filteredPaths.length; i += BATCH_SIZE) {
|
|
114
|
+
const batch = filteredPaths.slice(i, i + BATCH_SIZE);
|
|
115
|
+
const promises = [];
|
|
116
|
+
for (const { pathname, route } of batch) {
|
|
117
|
+
promises.push(
|
|
118
|
+
limit(
|
|
119
|
+
() => generatePathWithPrerenderer(
|
|
120
|
+
prerenderer,
|
|
121
|
+
pathname,
|
|
122
|
+
route,
|
|
123
|
+
options,
|
|
124
|
+
routeToHeaders,
|
|
125
|
+
logger
|
|
126
|
+
)
|
|
124
127
|
)
|
|
125
|
-
)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
await Promise.all(promises);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
for (const { pathname, route } of filteredPaths) {
|
|
134
|
+
await generatePathWithPrerenderer(
|
|
135
|
+
prerenderer,
|
|
136
|
+
pathname,
|
|
137
|
+
route,
|
|
138
|
+
options,
|
|
139
|
+
routeToHeaders,
|
|
140
|
+
logger
|
|
126
141
|
);
|
|
127
142
|
}
|
|
128
|
-
await Promise.all(promises);
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
for (const { pathname, route } of filteredPaths) {
|
|
132
|
-
await generatePathWithPrerenderer(
|
|
133
|
-
prerenderer,
|
|
134
|
-
pathname,
|
|
135
|
-
route,
|
|
136
|
-
options,
|
|
137
|
-
routeToHeaders,
|
|
138
|
-
logger
|
|
139
|
-
);
|
|
140
143
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
for (const { route: generatedRoute } of filteredPaths) {
|
|
145
|
+
if (generatedRoute.distURL && generatedRoute.distURL.length > 0) {
|
|
146
|
+
for (const pageData of Object.values(options.allPages)) {
|
|
147
|
+
if (pageData.route.route === generatedRoute.route && pageData.route.component === generatedRoute.component) {
|
|
148
|
+
pageData.route.distURL = generatedRoute.distURL;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
148
151
|
}
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
staticImageList = getStaticImageList();
|
|
155
|
+
if (prerenderer.collectStaticImages) {
|
|
156
|
+
const adapterImages = await prerenderer.collectStaticImages();
|
|
157
|
+
for (const [path, entry] of adapterImages) {
|
|
158
|
+
staticImageList.set(path, entry);
|
|
159
|
+
}
|
|
157
160
|
}
|
|
161
|
+
} finally {
|
|
162
|
+
await prerenderer.teardown?.();
|
|
158
163
|
}
|
|
159
|
-
await prerenderer.teardown?.();
|
|
160
164
|
logger.info(
|
|
161
165
|
null,
|
|
162
166
|
colors.green(`\u2713 Completed in ${getTimeStat(generatePagesTimer, performance.now())}.
|
|
@@ -328,7 +332,11 @@ function getUrlForPath(pathname, base, origin, format, trailingSlash, routeType)
|
|
|
328
332
|
}
|
|
329
333
|
let buildPathname;
|
|
330
334
|
if (pathname === "/" || pathname === "") {
|
|
331
|
-
|
|
335
|
+
if (format === "file") {
|
|
336
|
+
buildPathname = joinPaths(base, "index.html");
|
|
337
|
+
} else {
|
|
338
|
+
buildPathname = collapseDuplicateTrailingSlashes(base + ending, trailingSlash !== "never");
|
|
339
|
+
}
|
|
332
340
|
} else if (routeType === "endpoint") {
|
|
333
341
|
const buildPathRelative = removeLeadingForwardSlash(pathname);
|
|
334
342
|
buildPathname = joinPaths(base, buildPathRelative);
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { normalizeEntryId } from "./plugin-component-entry.js";
|
|
2
2
|
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../../constants.js";
|
|
3
|
+
function getRollupInputAsSet(rollupInput) {
|
|
4
|
+
if (Array.isArray(rollupInput)) {
|
|
5
|
+
return new Set(rollupInput);
|
|
6
|
+
} else if (typeof rollupInput === "string") {
|
|
7
|
+
return /* @__PURE__ */ new Set([rollupInput]);
|
|
8
|
+
} else if (rollupInput && typeof rollupInput === "object") {
|
|
9
|
+
return new Set(Object.values(rollupInput));
|
|
10
|
+
} else {
|
|
11
|
+
return /* @__PURE__ */ new Set();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
3
14
|
function pluginInternals(options, internals) {
|
|
4
|
-
let input;
|
|
5
15
|
return {
|
|
6
16
|
name: "@astro/plugin-build-internals",
|
|
7
17
|
applyToEnvironment(environment) {
|
|
@@ -27,19 +37,8 @@ function pluginInternals(options, internals) {
|
|
|
27
37
|
};
|
|
28
38
|
}
|
|
29
39
|
},
|
|
30
|
-
configResolved(config) {
|
|
31
|
-
const rollupInput = config.build?.rollupOptions?.input;
|
|
32
|
-
if (Array.isArray(rollupInput)) {
|
|
33
|
-
input = new Set(rollupInput);
|
|
34
|
-
} else if (typeof rollupInput === "string") {
|
|
35
|
-
input = /* @__PURE__ */ new Set([rollupInput]);
|
|
36
|
-
} else if (rollupInput && typeof rollupInput === "object") {
|
|
37
|
-
input = new Set(Object.values(rollupInput));
|
|
38
|
-
} else {
|
|
39
|
-
input = /* @__PURE__ */ new Set();
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
40
|
async generateBundle(_options, bundle) {
|
|
41
|
+
const input = getRollupInputAsSet(this.environment?.config.build.rollupOptions.input);
|
|
43
42
|
const promises = [];
|
|
44
43
|
const mapping = /* @__PURE__ */ new Map();
|
|
45
44
|
const allInput = /* @__PURE__ */ new Set([...input, ...internals.clientInput]);
|
|
@@ -81,13 +81,19 @@ async function buildManifest(opts, internals, staticFiles, encodedKey) {
|
|
|
81
81
|
const { settings } = opts;
|
|
82
82
|
const routes = [];
|
|
83
83
|
const domainLookupTable = {};
|
|
84
|
-
const
|
|
85
|
-
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
86
|
-
staticFiles.push(entryModules[PAGE_SCRIPT_ID]);
|
|
87
|
-
}
|
|
84
|
+
const rawEntryModules = Object.fromEntries(internals.entrySpecifierToBundleMap.entries());
|
|
88
85
|
const assetQueryParams = settings.adapter?.client?.assetQueryParams;
|
|
89
86
|
const assetQueryString = assetQueryParams ? assetQueryParams.toString() : void 0;
|
|
90
87
|
const appendAssetQuery = (pth) => assetQueryString ? `${pth}?${assetQueryString}` : pth;
|
|
88
|
+
const entryModules = Object.fromEntries(
|
|
89
|
+
Object.entries(rawEntryModules).map(([key, value]) => [
|
|
90
|
+
key,
|
|
91
|
+
value ? appendAssetQuery(value) : value
|
|
92
|
+
])
|
|
93
|
+
);
|
|
94
|
+
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
95
|
+
staticFiles.push(rawEntryModules[PAGE_SCRIPT_ID]);
|
|
96
|
+
}
|
|
91
97
|
const prefixAssetPath = (pth) => {
|
|
92
98
|
let result = "";
|
|
93
99
|
if (settings.config.build.assetsPrefix) {
|
|
@@ -118,7 +124,7 @@ async function buildManifest(opts, internals, staticFiles, encodedKey) {
|
|
|
118
124
|
if (!pageData) continue;
|
|
119
125
|
const scripts = [];
|
|
120
126
|
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
121
|
-
const src =
|
|
127
|
+
const src = rawEntryModules[PAGE_SCRIPT_ID];
|
|
122
128
|
scripts.push({
|
|
123
129
|
type: "external",
|
|
124
130
|
value: appendAssetQuery(src)
|
|
@@ -34,7 +34,7 @@ import { encodeName, getTimeStat, viteBuildReturnToRollupOutputs } from "./util.
|
|
|
34
34
|
import { NOOP_MODULE_ID } from "./plugins/plugin-noop.js";
|
|
35
35
|
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../constants.js";
|
|
36
36
|
import { getSSRAssets } from "./internal.js";
|
|
37
|
-
import {
|
|
37
|
+
import { SERVER_ISLAND_MAP_MARKER } from "../server-islands/vite-plugin-server-islands.js";
|
|
38
38
|
const PRERENDER_ENTRY_FILENAME_PREFIX = "prerender-entry";
|
|
39
39
|
function extractRelevantChunks(outputs, prerender) {
|
|
40
40
|
const extracted = [];
|
|
@@ -43,7 +43,7 @@ function extractRelevantChunks(outputs, prerender) {
|
|
|
43
43
|
if (chunk.type === "asset") continue;
|
|
44
44
|
const needsContentInjection = chunk.code.includes(LINKS_PLACEHOLDER);
|
|
45
45
|
const needsManifestInjection = chunk.moduleIds.includes(SERIALIZED_MANIFEST_RESOLVED_ID);
|
|
46
|
-
const needsServerIslandInjection = chunk.code.includes(
|
|
46
|
+
const needsServerIslandInjection = chunk.code.includes(SERVER_ISLAND_MAP_MARKER);
|
|
47
47
|
if (needsContentInjection || needsManifestInjection || needsServerIslandInjection) {
|
|
48
48
|
extracted.push({
|
|
49
49
|
fileName: chunk.fileName,
|
|
@@ -218,6 +218,13 @@ async function buildEnvironments(opts, internals) {
|
|
|
218
218
|
// This takes precedence over platform plugin fallbacks (e.g., Cloudflare)
|
|
219
219
|
builder: {
|
|
220
220
|
async buildApp(builder2) {
|
|
221
|
+
settings.timer.start("Prerender build");
|
|
222
|
+
let prerenderOutput = await builder2.build(builder2.environments.prerender);
|
|
223
|
+
settings.timer.end("Prerender build");
|
|
224
|
+
extractPrerenderEntryFileName(internals, prerenderOutput);
|
|
225
|
+
const prerenderOutputs = viteBuildReturnToRollupOutputs(prerenderOutput);
|
|
226
|
+
const prerenderChunks = extractRelevantChunks(prerenderOutputs, true);
|
|
227
|
+
prerenderOutput = void 0;
|
|
221
228
|
let ssrChunks = [];
|
|
222
229
|
if (settings.buildOutput !== "static") {
|
|
223
230
|
settings.timer.start("SSR build");
|
|
@@ -229,13 +236,6 @@ async function buildEnvironments(opts, internals) {
|
|
|
229
236
|
ssrChunks = extractRelevantChunks(ssrOutputs, false);
|
|
230
237
|
ssrOutput = void 0;
|
|
231
238
|
}
|
|
232
|
-
settings.timer.start("Prerender build");
|
|
233
|
-
let prerenderOutput = await builder2.build(builder2.environments.prerender);
|
|
234
|
-
settings.timer.end("Prerender build");
|
|
235
|
-
extractPrerenderEntryFileName(internals, prerenderOutput);
|
|
236
|
-
const prerenderOutputs = viteBuildReturnToRollupOutputs(prerenderOutput);
|
|
237
|
-
const prerenderChunks = extractRelevantChunks(prerenderOutputs, true);
|
|
238
|
-
prerenderOutput = void 0;
|
|
239
239
|
const ssrPlugins = builder2.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr]?.config.plugins ?? [];
|
|
240
240
|
buildPostHooks = ssrPlugins.map(
|
|
241
241
|
(plugin) => typeof plugin.api?.buildPostHook === "function" ? plugin.api.buildPostHook : void 0
|
package/dist/core/constants.js
CHANGED
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.6";
|
|
30
30
|
const isPrerelease = currentVersion.includes("-");
|
|
31
31
|
if (!isPrerelease) {
|
|
32
32
|
try {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_404_COMPONENT } from "../constants.js";
|
|
2
2
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
3
|
-
import { routeIsFallback, routeIsRedirect } from "../routing/helpers.js";
|
|
3
|
+
import { routeHasHtmlExtension, routeIsFallback, routeIsRedirect } from "../routing/helpers.js";
|
|
4
4
|
import { callGetStaticPaths, findPathItemByKey } from "./route-cache.js";
|
|
5
5
|
async function getProps(opts) {
|
|
6
6
|
const {
|
|
@@ -44,11 +44,9 @@ async function getProps(opts) {
|
|
|
44
44
|
}
|
|
45
45
|
function getParams(route, pathname) {
|
|
46
46
|
if (!route.params.length) return {};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
const paramsMatch = route.pattern.exec(path) || route.fallbackRoutes.map((fallbackRoute) => fallbackRoute.pattern.exec(path)).find((x) => x);
|
|
47
|
+
const path = pathname.endsWith(".html") && !routeHasHtmlExtension(route) ? pathname.slice(0, -5) : pathname;
|
|
48
|
+
const allPatterns = [route, ...route.fallbackRoutes].map((r) => r.pattern);
|
|
49
|
+
const paramsMatch = allPatterns.map((pattern) => pattern.exec(path)).find((x) => x);
|
|
52
50
|
if (!paramsMatch) return {};
|
|
53
51
|
const params = {};
|
|
54
52
|
route.params.forEach((key, i) => {
|
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
import { getAssetsPrefix } from "../../assets/utils/getAssetsPrefix.js";
|
|
2
2
|
import { fileExtension, joinPaths, prependForwardSlash, slash } from "../../core/path.js";
|
|
3
|
+
const URL_PARSE_BASE = "https://astro.build";
|
|
4
|
+
function splitAssetPath(path) {
|
|
5
|
+
const parsed = new URL(path, URL_PARSE_BASE);
|
|
6
|
+
const isAbsolute = URL.canParse(path);
|
|
7
|
+
const pathname = !isAbsolute && !path.startsWith("/") ? parsed.pathname.slice(1) : parsed.pathname;
|
|
8
|
+
return {
|
|
9
|
+
pathname,
|
|
10
|
+
suffix: `${parsed.search}${parsed.hash}`
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function appendQueryParams(path, queryParams) {
|
|
14
|
+
const queryString = queryParams.toString();
|
|
15
|
+
if (!queryString) {
|
|
16
|
+
return path;
|
|
17
|
+
}
|
|
18
|
+
const hashIndex = path.indexOf("#");
|
|
19
|
+
const basePath = hashIndex === -1 ? path : path.slice(0, hashIndex);
|
|
20
|
+
const hash = hashIndex === -1 ? "" : path.slice(hashIndex);
|
|
21
|
+
const separator = basePath.includes("?") ? "&" : "?";
|
|
22
|
+
return `${basePath}${separator}${queryString}${hash}`;
|
|
23
|
+
}
|
|
3
24
|
function createAssetLink(href, base, assetsPrefix, queryParams) {
|
|
25
|
+
const { pathname, suffix } = splitAssetPath(href);
|
|
4
26
|
let url = "";
|
|
5
27
|
if (assetsPrefix) {
|
|
6
|
-
const pf = getAssetsPrefix(fileExtension(
|
|
7
|
-
url = joinPaths(pf, slash(
|
|
28
|
+
const pf = getAssetsPrefix(fileExtension(pathname), assetsPrefix);
|
|
29
|
+
url = joinPaths(pf, slash(pathname)) + suffix;
|
|
8
30
|
} else if (base) {
|
|
9
|
-
url = prependForwardSlash(joinPaths(base, slash(
|
|
31
|
+
url = prependForwardSlash(joinPaths(base, slash(pathname))) + suffix;
|
|
10
32
|
} else {
|
|
11
33
|
url = href;
|
|
12
34
|
}
|
|
13
35
|
if (queryParams) {
|
|
14
|
-
url
|
|
36
|
+
url = appendQueryParams(url, queryParams);
|
|
15
37
|
}
|
|
16
38
|
return url;
|
|
17
39
|
}
|