astro 2.5.3 → 2.5.5
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/client-base.d.ts +27 -6
- package/client-image.d.ts +1 -1
- package/client.d.ts +0 -4
- package/dist/@types/astro.d.ts +0 -6
- package/dist/content/consts.d.ts +1 -2
- package/dist/content/consts.js +1 -8
- package/dist/content/runtime.js +47 -63
- package/dist/content/vite-plugin-content-assets.js +10 -26
- package/dist/content/vite-plugin-content-virtual-mod.js +56 -50
- package/dist/core/build/plugins/index.js +2 -0
- package/dist/core/build/plugins/plugin-pages.js +11 -17
- package/dist/core/build/plugins/plugin-renderers.d.ts +8 -0
- package/dist/core/build/plugins/plugin-renderers.js +54 -0
- package/dist/core/build/plugins/plugin-ssr.js +2 -0
- package/dist/core/build/static-build.js +3 -0
- package/dist/core/config/vite-load.js +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/index.js +0 -7
- package/dist/core/errors/errors-data.d.ts +0 -23
- package/dist/core/errors/errors-data.js +0 -26
- package/dist/core/messages.js +2 -2
- package/dist/core/render/core.d.ts +0 -9
- package/dist/core/render/core.js +1 -39
- package/dist/core/render/dev/vite.js +12 -7
- package/dist/core/render/result.js +5 -4
- package/dist/core/sync/index.js +1 -1
- package/dist/runtime/server/render/slot.d.ts +1 -1
- package/dist/runtime/server/render/util.js +2 -1
- package/dist/vite-plugin-head/index.js +1 -1
- package/dist/vite-plugin-markdown/content-entry-type.js +1 -6
- package/import-meta.d.ts +1 -8
- package/package.json +2 -1
- package/src/content/template/virtual-mod.mjs +1 -1
package/client-base.d.ts
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
/// <reference path="./import-meta.d.ts" />
|
|
2
2
|
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
4
|
+
declare namespace App {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
6
|
+
export interface Locals {}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface ImportMetaEnv {
|
|
10
|
+
/**
|
|
11
|
+
* The prefix for Astro-generated asset links if the build.assetsPrefix config option is set. This can be used to create asset links not handled by Astro.
|
|
12
|
+
*/
|
|
13
|
+
readonly ASSETS_PREFIX: string;
|
|
14
|
+
/**
|
|
15
|
+
* This is set to the site option specified in your project’s Astro config file.
|
|
16
|
+
*/
|
|
17
|
+
readonly SITE: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface ImportMeta {
|
|
21
|
+
/**
|
|
22
|
+
* Astro and Vite expose environment variables through `import.meta.env`. For a complete list of the environment variables available, see the two references below.
|
|
23
|
+
*
|
|
24
|
+
* - [Astro reference](https://docs.astro.build/en/guides/environment-variables/#default-environment-variables)
|
|
25
|
+
* - [Vite reference](https://vitejs.dev/guide/env-and-mode.html#env-variables)
|
|
26
|
+
*/
|
|
27
|
+
readonly env: ImportMetaEnv;
|
|
28
|
+
}
|
|
29
|
+
|
|
3
30
|
declare module 'astro:assets' {
|
|
4
31
|
// Exporting things one by one is a bit cumbersome, not sure if there's a better way - erika, 2023-02-03
|
|
5
32
|
type AstroAssets = {
|
|
@@ -387,9 +414,3 @@ declare module '*?inline' {
|
|
|
387
414
|
const src: string;
|
|
388
415
|
export default src;
|
|
389
416
|
}
|
|
390
|
-
|
|
391
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
392
|
-
declare namespace App {
|
|
393
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
394
|
-
export interface Locals {}
|
|
395
|
-
}
|
package/client-image.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// TODO: Merge this file with `client-base.d.ts` in 3.0, when the `astro:assets` feature isn't under a flag anymore.
|
|
4
4
|
|
|
5
|
-
type InputFormat = import('./dist/assets/types.js').
|
|
5
|
+
type InputFormat = import('./dist/assets/types.js').ImageInputFormat;
|
|
6
6
|
|
|
7
7
|
interface ImageMetadata {
|
|
8
8
|
src: string;
|
package/client.d.ts
CHANGED
package/dist/@types/astro.d.ts
CHANGED
|
@@ -1170,12 +1170,6 @@ export interface ContentEntryType {
|
|
|
1170
1170
|
entry: ContentEntryModule;
|
|
1171
1171
|
}): rollup.LoadResult | Promise<rollup.LoadResult>;
|
|
1172
1172
|
contentModuleTypes?: string;
|
|
1173
|
-
/**
|
|
1174
|
-
* Handle asset propagation for rendered content to avoid bleed.
|
|
1175
|
-
* Ex. MDX content can import styles and scripts, so `handlePropagation` should be true.
|
|
1176
|
-
* @default true
|
|
1177
|
-
*/
|
|
1178
|
-
handlePropagation?: boolean;
|
|
1179
1173
|
}
|
|
1180
1174
|
type GetContentEntryInfoReturnType = {
|
|
1181
1175
|
data: Record<string, unknown>;
|
package/dist/content/consts.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export declare const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
|
|
2
|
-
export declare const CONTENT_RENDER_FLAG = "astroRenderContent";
|
|
3
2
|
export declare const CONTENT_FLAG = "astroContentCollectionEntry";
|
|
4
3
|
export declare const DATA_FLAG = "astroDataCollectionEntry";
|
|
4
|
+
export declare const CONTENT_FLAGS: readonly ["astroContentCollectionEntry", "astroDataCollectionEntry", "astroPropagatedAssets"];
|
|
5
5
|
export declare const VIRTUAL_MODULE_ID = "astro:content";
|
|
6
6
|
export declare const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
|
|
7
7
|
export declare const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
|
|
8
8
|
export declare const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
|
|
9
|
-
export declare const CONTENT_FLAGS: readonly ["astroContentCollectionEntry", "astroRenderContent", "astroDataCollectionEntry", "astroPropagatedAssets"];
|
|
10
9
|
export declare const CONTENT_TYPES_FILE = "types.d.ts";
|
package/dist/content/consts.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
|
|
2
|
-
const CONTENT_RENDER_FLAG = "astroRenderContent";
|
|
3
2
|
const CONTENT_FLAG = "astroContentCollectionEntry";
|
|
4
3
|
const DATA_FLAG = "astroDataCollectionEntry";
|
|
4
|
+
const CONTENT_FLAGS = [CONTENT_FLAG, DATA_FLAG, PROPAGATED_ASSET_FLAG];
|
|
5
5
|
const VIRTUAL_MODULE_ID = "astro:content";
|
|
6
6
|
const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
|
|
7
7
|
const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
|
|
8
8
|
const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
|
|
9
|
-
const CONTENT_FLAGS = [
|
|
10
|
-
CONTENT_FLAG,
|
|
11
|
-
CONTENT_RENDER_FLAG,
|
|
12
|
-
DATA_FLAG,
|
|
13
|
-
PROPAGATED_ASSET_FLAG
|
|
14
|
-
];
|
|
15
9
|
const CONTENT_TYPES_FILE = "types.d.ts";
|
|
16
10
|
export {
|
|
17
11
|
CONTENT_FLAG,
|
|
18
12
|
CONTENT_FLAGS,
|
|
19
|
-
CONTENT_RENDER_FLAG,
|
|
20
13
|
CONTENT_TYPES_FILE,
|
|
21
14
|
DATA_FLAG,
|
|
22
15
|
LINKS_PLACEHOLDER,
|
package/dist/content/runtime.js
CHANGED
|
@@ -184,7 +184,7 @@ async function render({
|
|
|
184
184
|
id,
|
|
185
185
|
renderEntryImport
|
|
186
186
|
}) {
|
|
187
|
-
var _a
|
|
187
|
+
var _a;
|
|
188
188
|
const UnexpectedRenderError = new AstroError({
|
|
189
189
|
...AstroErrorData.UnknownContentCollectionError,
|
|
190
190
|
message: `Unexpected error while rendering ${String(collection)} \u2192 ${String(id)}.`
|
|
@@ -194,69 +194,53 @@ async function render({
|
|
|
194
194
|
const baseMod = await renderEntryImport();
|
|
195
195
|
if (baseMod == null || typeof baseMod !== "object")
|
|
196
196
|
throw UnexpectedRenderError;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (typeof getMod !== "function")
|
|
200
|
-
throw UnexpectedRenderError;
|
|
201
|
-
const propagationMod = await getMod();
|
|
202
|
-
if (propagationMod == null || typeof propagationMod !== "object")
|
|
203
|
-
throw UnexpectedRenderError;
|
|
204
|
-
const Content = createComponent({
|
|
205
|
-
factory(result, baseProps, slots) {
|
|
206
|
-
let styles = "", links = "", scripts = "";
|
|
207
|
-
if (Array.isArray(collectedStyles)) {
|
|
208
|
-
styles = collectedStyles.map((style) => {
|
|
209
|
-
return renderUniqueStylesheet(result, {
|
|
210
|
-
type: "inline",
|
|
211
|
-
content: style
|
|
212
|
-
});
|
|
213
|
-
}).join("");
|
|
214
|
-
}
|
|
215
|
-
if (Array.isArray(collectedLinks)) {
|
|
216
|
-
links = collectedLinks.map((link) => {
|
|
217
|
-
return renderUniqueStylesheet(result, {
|
|
218
|
-
type: "external",
|
|
219
|
-
src: prependForwardSlash(link)
|
|
220
|
-
});
|
|
221
|
-
}).join("");
|
|
222
|
-
}
|
|
223
|
-
if (Array.isArray(collectedScripts)) {
|
|
224
|
-
scripts = collectedScripts.map((script) => renderScriptElement(script)).join("");
|
|
225
|
-
}
|
|
226
|
-
let props = baseProps;
|
|
227
|
-
if (id.endsWith("mdx")) {
|
|
228
|
-
props = {
|
|
229
|
-
components: propagationMod.components ?? {},
|
|
230
|
-
...baseProps
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
return createHeadAndContent(
|
|
234
|
-
unescapeHTML(styles + links + scripts),
|
|
235
|
-
renderTemplate`${renderComponent(
|
|
236
|
-
result,
|
|
237
|
-
"Content",
|
|
238
|
-
propagationMod.Content,
|
|
239
|
-
props,
|
|
240
|
-
slots
|
|
241
|
-
)}`
|
|
242
|
-
);
|
|
243
|
-
},
|
|
244
|
-
propagation: "self"
|
|
245
|
-
});
|
|
246
|
-
return {
|
|
247
|
-
Content,
|
|
248
|
-
headings: ((_a = propagationMod.getHeadings) == null ? void 0 : _a.call(propagationMod)) ?? [],
|
|
249
|
-
remarkPluginFrontmatter: propagationMod.frontmatter ?? {}
|
|
250
|
-
};
|
|
251
|
-
} else if (baseMod.Content && typeof baseMod.Content === "function") {
|
|
252
|
-
return {
|
|
253
|
-
Content: baseMod.Content,
|
|
254
|
-
headings: ((_b = baseMod.getHeadings) == null ? void 0 : _b.call(baseMod)) ?? [],
|
|
255
|
-
remarkPluginFrontmatter: baseMod.frontmatter ?? {}
|
|
256
|
-
};
|
|
257
|
-
} else {
|
|
197
|
+
const { collectedStyles, collectedLinks, collectedScripts, getMod } = baseMod;
|
|
198
|
+
if (typeof getMod !== "function")
|
|
258
199
|
throw UnexpectedRenderError;
|
|
259
|
-
|
|
200
|
+
const mod = await getMod();
|
|
201
|
+
if (mod == null || typeof mod !== "object")
|
|
202
|
+
throw UnexpectedRenderError;
|
|
203
|
+
const Content = createComponent({
|
|
204
|
+
factory(result, baseProps, slots) {
|
|
205
|
+
let styles = "", links = "", scripts = "";
|
|
206
|
+
if (Array.isArray(collectedStyles)) {
|
|
207
|
+
styles = collectedStyles.map((style) => {
|
|
208
|
+
return renderUniqueStylesheet(result, {
|
|
209
|
+
type: "inline",
|
|
210
|
+
content: style
|
|
211
|
+
});
|
|
212
|
+
}).join("");
|
|
213
|
+
}
|
|
214
|
+
if (Array.isArray(collectedLinks)) {
|
|
215
|
+
links = collectedLinks.map((link) => {
|
|
216
|
+
return renderUniqueStylesheet(result, {
|
|
217
|
+
type: "external",
|
|
218
|
+
src: prependForwardSlash(link)
|
|
219
|
+
});
|
|
220
|
+
}).join("");
|
|
221
|
+
}
|
|
222
|
+
if (Array.isArray(collectedScripts)) {
|
|
223
|
+
scripts = collectedScripts.map((script) => renderScriptElement(script)).join("");
|
|
224
|
+
}
|
|
225
|
+
let props = baseProps;
|
|
226
|
+
if (id.endsWith("mdx")) {
|
|
227
|
+
props = {
|
|
228
|
+
components: mod.components ?? {},
|
|
229
|
+
...baseProps
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
return createHeadAndContent(
|
|
233
|
+
unescapeHTML(styles + links + scripts),
|
|
234
|
+
renderTemplate`${renderComponent(result, "Content", mod.Content, props, slots)}`
|
|
235
|
+
);
|
|
236
|
+
},
|
|
237
|
+
propagation: "self"
|
|
238
|
+
});
|
|
239
|
+
return {
|
|
240
|
+
Content,
|
|
241
|
+
headings: ((_a = mod.getHeadings) == null ? void 0 : _a.call(mod)) ?? [],
|
|
242
|
+
remarkPluginFrontmatter: mod.frontmatter ?? {}
|
|
243
|
+
};
|
|
260
244
|
}
|
|
261
245
|
function createReference({ lookupMap }) {
|
|
262
246
|
return function reference(collection) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
1
|
+
import { pathToFileURL } from "url";
|
|
3
2
|
import { moduleIsTopLevelPage, walkParentInfos } from "../core/build/graph.js";
|
|
4
3
|
import { getPageDataByViteID } from "../core/build/internal.js";
|
|
5
4
|
import { createViteLoader } from "../core/module-loader/vite.js";
|
|
@@ -7,13 +6,15 @@ import { joinPaths, prependForwardSlash } from "../core/path.js";
|
|
|
7
6
|
import { getStylesForURL } from "../core/render/dev/css.js";
|
|
8
7
|
import { getScriptsForURL } from "../core/render/dev/scripts.js";
|
|
9
8
|
import {
|
|
10
|
-
CONTENT_RENDER_FLAG,
|
|
11
9
|
LINKS_PLACEHOLDER,
|
|
12
10
|
PROPAGATED_ASSET_FLAG,
|
|
13
11
|
SCRIPTS_PLACEHOLDER,
|
|
14
12
|
STYLES_PLACEHOLDER
|
|
15
13
|
} from "./consts.js";
|
|
16
|
-
|
|
14
|
+
function isPropagatedAsset(viteId) {
|
|
15
|
+
const flags = new URLSearchParams(viteId.split("?")[1]);
|
|
16
|
+
return flags.has(PROPAGATED_ASSET_FLAG);
|
|
17
|
+
}
|
|
17
18
|
function astroContentAssetPropagationPlugin({
|
|
18
19
|
mode,
|
|
19
20
|
settings
|
|
@@ -21,21 +22,6 @@ function astroContentAssetPropagationPlugin({
|
|
|
21
22
|
let devModuleLoader;
|
|
22
23
|
return {
|
|
23
24
|
name: "astro:content-asset-propagation",
|
|
24
|
-
enforce: "pre",
|
|
25
|
-
async resolveId(id, importer, opts) {
|
|
26
|
-
if (hasContentFlag(id, CONTENT_RENDER_FLAG)) {
|
|
27
|
-
const base = id.split("?")[0];
|
|
28
|
-
for (const { extensions, handlePropagation = true } of settings.contentEntryTypes) {
|
|
29
|
-
if (handlePropagation && extensions.includes(extname(base))) {
|
|
30
|
-
return this.resolve(`${base}?${PROPAGATED_ASSET_FLAG}`, importer, {
|
|
31
|
-
skipSelf: true,
|
|
32
|
-
...opts
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return this.resolve(base, importer, { skipSelf: true, ...opts });
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
25
|
configureServer(server) {
|
|
40
26
|
if (mode === "dev") {
|
|
41
27
|
devModuleLoader = createViteLoader(server);
|
|
@@ -43,7 +29,7 @@ function astroContentAssetPropagationPlugin({
|
|
|
43
29
|
},
|
|
44
30
|
async transform(_, id, options) {
|
|
45
31
|
var _a;
|
|
46
|
-
if (
|
|
32
|
+
if (isPropagatedAsset(id)) {
|
|
47
33
|
const basePath = id.split("?")[0];
|
|
48
34
|
let stringifiedLinks, stringifiedStyles, stringifiedScripts;
|
|
49
35
|
if ((options == null ? void 0 : options.ssr) && devModuleLoader) {
|
|
@@ -69,14 +55,12 @@ function astroContentAssetPropagationPlugin({
|
|
|
69
55
|
stringifiedScripts = JSON.stringify(SCRIPTS_PLACEHOLDER);
|
|
70
56
|
}
|
|
71
57
|
const code = `
|
|
72
|
-
async function getMod() {
|
|
58
|
+
export async function getMod() {
|
|
73
59
|
return import(${JSON.stringify(basePath)});
|
|
74
60
|
}
|
|
75
|
-
const collectedLinks = ${stringifiedLinks};
|
|
76
|
-
const collectedStyles = ${stringifiedStyles};
|
|
77
|
-
const collectedScripts = ${stringifiedScripts};
|
|
78
|
-
const defaultMod = { __astroPropagation: true, getMod, collectedLinks, collectedStyles, collectedScripts };
|
|
79
|
-
export default defaultMod;
|
|
61
|
+
export const collectedLinks = ${stringifiedLinks};
|
|
62
|
+
export const collectedStyles = ${stringifiedStyles};
|
|
63
|
+
export const collectedScripts = ${stringifiedScripts};
|
|
80
64
|
`;
|
|
81
65
|
return { code, map: { mappings: "" } };
|
|
82
66
|
}
|
|
@@ -2,6 +2,7 @@ import glob from "fast-glob";
|
|
|
2
2
|
import fsMod from "node:fs";
|
|
3
3
|
import { extname } from "node:path";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
+
import pLimit from "p-limit";
|
|
5
6
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
6
7
|
import { rootRelativePath } from "../core/util.js";
|
|
7
8
|
import { VIRTUAL_MODULE_ID } from "./consts.js";
|
|
@@ -83,57 +84,62 @@ async function getStringifiedLookupMap({
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
...AstroErrorData.MixedContentDataCollectionError,
|
|
98
|
-
message: AstroErrorData.MixedContentDataCollectionError.message(collection)
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
if (entryType === "content") {
|
|
102
|
-
const contentEntryType = contentEntryConfigByExt.get(extname(filePath));
|
|
103
|
-
if (!contentEntryType)
|
|
87
|
+
const limit = pLimit(10);
|
|
88
|
+
const promises = [];
|
|
89
|
+
for (const filePath of contentGlob) {
|
|
90
|
+
promises.push(
|
|
91
|
+
limit(async () => {
|
|
92
|
+
var _a, _b, _c;
|
|
93
|
+
const entryType = getEntryType(filePath, contentPaths, contentEntryExts, dataEntryExts);
|
|
94
|
+
if (entryType !== "content" && entryType !== "data")
|
|
95
|
+
return;
|
|
96
|
+
const collection = getEntryCollectionName({ contentDir, entry: pathToFileURL(filePath) });
|
|
97
|
+
if (!collection)
|
|
104
98
|
throw UnexpectedLookupMapError;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
99
|
+
if (((_a = lookupMap[collection]) == null ? void 0 : _a.type) && lookupMap[collection].type !== entryType) {
|
|
100
|
+
throw new AstroError({
|
|
101
|
+
...AstroErrorData.MixedContentDataCollectionError,
|
|
102
|
+
message: AstroErrorData.MixedContentDataCollectionError.message(collection)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (entryType === "content") {
|
|
106
|
+
const contentEntryType = contentEntryConfigByExt.get(extname(filePath));
|
|
107
|
+
if (!contentEntryType)
|
|
108
|
+
throw UnexpectedLookupMapError;
|
|
109
|
+
const { id, slug: generatedSlug } = await getContentEntryIdAndSlug({
|
|
110
|
+
entry: pathToFileURL(filePath),
|
|
111
|
+
contentDir,
|
|
112
|
+
collection
|
|
113
|
+
});
|
|
114
|
+
const slug = await getEntrySlug({
|
|
115
|
+
id,
|
|
116
|
+
collection,
|
|
117
|
+
generatedSlug,
|
|
118
|
+
fs,
|
|
119
|
+
fileUrl: pathToFileURL(filePath),
|
|
120
|
+
contentEntryType
|
|
121
|
+
});
|
|
122
|
+
lookupMap[collection] = {
|
|
123
|
+
type: "content",
|
|
124
|
+
entries: {
|
|
125
|
+
...(_b = lookupMap[collection]) == null ? void 0 : _b.entries,
|
|
126
|
+
[slug]: rootRelativePath(root, filePath)
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
} else {
|
|
130
|
+
const id = getDataEntryId({ entry: pathToFileURL(filePath), contentDir, collection });
|
|
131
|
+
lookupMap[collection] = {
|
|
132
|
+
type: "data",
|
|
133
|
+
entries: {
|
|
134
|
+
...(_c = lookupMap[collection]) == null ? void 0 : _c.entries,
|
|
135
|
+
[id]: rootRelativePath(root, filePath)
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
await Promise.all(promises);
|
|
137
143
|
return JSON.stringify(lookupMap);
|
|
138
144
|
}
|
|
139
145
|
const UnexpectedLookupMapError = new AstroError({
|
|
@@ -9,12 +9,14 @@ import { pluginInternals } from "./plugin-internals.js";
|
|
|
9
9
|
import { pluginMiddleware } from "./plugin-middleware.js";
|
|
10
10
|
import { pluginPages } from "./plugin-pages.js";
|
|
11
11
|
import { pluginPrerender } from "./plugin-prerender.js";
|
|
12
|
+
import { pluginRenderers } from "./plugin-renderers.js";
|
|
12
13
|
import { pluginSSR } from "./plugin-ssr.js";
|
|
13
14
|
function registerAllPlugins({ internals, options, register }) {
|
|
14
15
|
register(pluginComponentEntry(internals));
|
|
15
16
|
register(pluginAliasResolve(internals));
|
|
16
17
|
register(pluginAnalyzer(internals));
|
|
17
18
|
register(pluginInternals(internals));
|
|
19
|
+
register(pluginRenderers(options, internals));
|
|
18
20
|
register(pluginMiddleware(options, internals));
|
|
19
21
|
register(pluginPages(options, internals));
|
|
20
22
|
register(pluginCSS(options, internals));
|
|
@@ -2,6 +2,7 @@ import { pagesVirtualModuleId, resolvedPagesVirtualModuleId } from "../../app/in
|
|
|
2
2
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
3
3
|
import { eachPageData } from "../internal.js";
|
|
4
4
|
import { MIDDLEWARE_MODULE_ID } from "./plugin-middleware.js";
|
|
5
|
+
import { RENDERERS_MODULE_ID } from "./plugin-renderers.js";
|
|
5
6
|
function vitePluginPages(opts, internals) {
|
|
6
7
|
return {
|
|
7
8
|
name: "@astro/plugin-build-pages",
|
|
@@ -18,8 +19,12 @@ function vitePluginPages(opts, internals) {
|
|
|
18
19
|
async load(id) {
|
|
19
20
|
if (id === resolvedPagesVirtualModuleId) {
|
|
20
21
|
let importMap = "";
|
|
21
|
-
|
|
22
|
+
const imports = [];
|
|
23
|
+
const exports = [];
|
|
24
|
+
const content = [];
|
|
22
25
|
let i = 0;
|
|
26
|
+
imports.push(`import { renderers } from "${RENDERERS_MODULE_ID}";`);
|
|
27
|
+
exports.push(`export { renderers };`);
|
|
23
28
|
for (const pageData of eachPageData(internals)) {
|
|
24
29
|
const variable = `_page${i}`;
|
|
25
30
|
imports.push(
|
|
@@ -28,23 +33,12 @@ function vitePluginPages(opts, internals) {
|
|
|
28
33
|
importMap += `[${JSON.stringify(pageData.component)}, ${variable}],`;
|
|
29
34
|
i++;
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const variable = `_renderer${i}`;
|
|
35
|
-
imports.unshift(`import ${variable} from '${renderer.serverEntrypoint}';`);
|
|
36
|
-
rendererItems += `Object.assign(${JSON.stringify(renderer)}, { ssr: ${variable} }),`;
|
|
37
|
-
i++;
|
|
36
|
+
if (opts.settings.config.experimental.middleware) {
|
|
37
|
+
imports.push(`import * as _middleware from "${MIDDLEWARE_MODULE_ID}";`);
|
|
38
|
+
exports.push(`export const middleware = _middleware;`);
|
|
38
39
|
}
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
${opts.settings.config.experimental.middleware ? `import * as _middleware from "${MIDDLEWARE_MODULE_ID}";` : ""}
|
|
42
|
-
|
|
43
|
-
export const pageMap = new Map([${importMap}]);
|
|
44
|
-
export const renderers = [${rendererItems}];
|
|
45
|
-
${opts.settings.config.experimental.middleware ? `export const middleware = _middleware;` : ""}
|
|
46
|
-
`;
|
|
47
|
-
return def;
|
|
40
|
+
content.push(`export const pageMap = new Map([${importMap}]);`);
|
|
41
|
+
return `${imports.join("\n")}${content.join("\n")}${exports.join("\n")}`;
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
44
|
};
|
|
@@ -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 RENDERERS_MODULE_ID = "@astro-renderers";
|
|
6
|
+
export declare const RESOLVED_RENDERERS_MODULE_ID: string;
|
|
7
|
+
export declare function vitePluginRenderers(opts: StaticBuildOptions, _internals: BuildInternals): VitePlugin;
|
|
8
|
+
export declare function pluginRenderers(opts: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { addRollupInput } from "../add-rollup-input.js";
|
|
2
|
+
const RENDERERS_MODULE_ID = "@astro-renderers";
|
|
3
|
+
const RESOLVED_RENDERERS_MODULE_ID = `\0${RENDERERS_MODULE_ID}`;
|
|
4
|
+
let inputs = /* @__PURE__ */ new Set();
|
|
5
|
+
function vitePluginRenderers(opts, _internals) {
|
|
6
|
+
return {
|
|
7
|
+
name: "@astro/plugin-renderers",
|
|
8
|
+
options(options) {
|
|
9
|
+
return addRollupInput(options, [RENDERERS_MODULE_ID]);
|
|
10
|
+
},
|
|
11
|
+
resolveId(id) {
|
|
12
|
+
if (id === RENDERERS_MODULE_ID) {
|
|
13
|
+
return RESOLVED_RENDERERS_MODULE_ID;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
async load(id) {
|
|
17
|
+
if (id === RESOLVED_RENDERERS_MODULE_ID) {
|
|
18
|
+
if (opts.settings.renderers.length > 0) {
|
|
19
|
+
const imports = [];
|
|
20
|
+
const exports = [];
|
|
21
|
+
let i = 0;
|
|
22
|
+
let rendererItems = "";
|
|
23
|
+
for (const renderer of opts.settings.renderers) {
|
|
24
|
+
const variable = `_renderer${i}`;
|
|
25
|
+
imports.push(`import ${variable} from '${renderer.serverEntrypoint}';`);
|
|
26
|
+
rendererItems += `Object.assign(${JSON.stringify(renderer)}, { ssr: ${variable} }),`;
|
|
27
|
+
i++;
|
|
28
|
+
}
|
|
29
|
+
exports.push(`export const renderers = [${rendererItems}];`);
|
|
30
|
+
return `${imports.join("\n")}
|
|
31
|
+
${exports.join("\n")}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function pluginRenderers(opts, internals) {
|
|
38
|
+
return {
|
|
39
|
+
build: "ssr",
|
|
40
|
+
hooks: {
|
|
41
|
+
"build:before": () => {
|
|
42
|
+
return {
|
|
43
|
+
vitePlugin: vitePluginRenderers(opts, internals)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
RENDERERS_MODULE_ID,
|
|
51
|
+
RESOLVED_RENDERERS_MODULE_ID,
|
|
52
|
+
pluginRenderers,
|
|
53
|
+
vitePluginRenderers
|
|
54
|
+
};
|
|
@@ -9,6 +9,7 @@ import { serializeRouteData } from "../../routing/index.js";
|
|
|
9
9
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
10
10
|
import { getOutFile, getOutFolder } from "../common.js";
|
|
11
11
|
import { cssOrder, mergeInlineCss } from "../internal.js";
|
|
12
|
+
import { RENDERERS_MODULE_ID } from "./plugin-renderers.js";
|
|
12
13
|
const virtualModuleId = "@astrojs-ssr-virtual-entry";
|
|
13
14
|
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
14
15
|
const manifestReplace = "@@ASTRO_MANIFEST_REPLACE@@";
|
|
@@ -33,6 +34,7 @@ function vitePluginSSR(internals, adapter, config) {
|
|
|
33
34
|
middleware = "middleware: _main.middleware";
|
|
34
35
|
}
|
|
35
36
|
return `import * as adapter from '${adapter.serverEntrypoint}';
|
|
37
|
+
import { renderers } from '${RENDERERS_MODULE_ID}';
|
|
36
38
|
import * as _main from '${pagesVirtualModuleId}';
|
|
37
39
|
import { deserializeManifest as _deserializeManifest } from 'astro/app';
|
|
38
40
|
import { _privateSetManifestDontUseThis } from 'astro:ssr-manifest';
|
|
@@ -25,6 +25,7 @@ import { trackPageData } from "./internal.js";
|
|
|
25
25
|
import { createPluginContainer } from "./plugin.js";
|
|
26
26
|
import { registerAllPlugins } from "./plugins/index.js";
|
|
27
27
|
import { RESOLVED_MIDDLEWARE_MODULE_ID } from "./plugins/plugin-middleware.js";
|
|
28
|
+
import { RESOLVED_RENDERERS_MODULE_ID } from "./plugins/plugin-renderers.js";
|
|
28
29
|
import { getTimeStat } from "./util.js";
|
|
29
30
|
async function viteBuild(opts) {
|
|
30
31
|
var _a, _b, _c;
|
|
@@ -132,6 +133,8 @@ async function ssrBuild(opts, internals, input, container) {
|
|
|
132
133
|
return opts.buildConfig.serverEntry;
|
|
133
134
|
} else if (chunkInfo.facadeModuleId === RESOLVED_MIDDLEWARE_MODULE_ID) {
|
|
134
135
|
return "middleware.mjs";
|
|
136
|
+
} else if (chunkInfo.facadeModuleId === RESOLVED_RENDERERS_MODULE_ID) {
|
|
137
|
+
return "renderers.mjs";
|
|
135
138
|
} else {
|
|
136
139
|
return "[name].mjs";
|
|
137
140
|
}
|
|
@@ -3,7 +3,7 @@ import * as vite from "vite";
|
|
|
3
3
|
import loadFallbackPlugin from "../../vite-plugin-load-fallback/index.js";
|
|
4
4
|
async function createViteLoader(root, fs) {
|
|
5
5
|
const viteServer = await vite.createServer({
|
|
6
|
-
server: { middlewareMode: true, hmr: false },
|
|
6
|
+
server: { middlewareMode: true, hmr: false, watch: { ignored: ["**"] } },
|
|
7
7
|
optimizeDeps: { disabled: true },
|
|
8
8
|
clearScreen: false,
|
|
9
9
|
appType: "custom",
|
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.5";
|
|
57
57
|
if (currentVersion.includes("-")) {
|
|
58
58
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
59
59
|
}
|
|
@@ -5,7 +5,6 @@ import { AstroCookies, attachToResponse } from "../cookies/index.js";
|
|
|
5
5
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
6
6
|
import { warn } from "../logger/core.js";
|
|
7
7
|
import { callMiddleware } from "../middleware/callMiddleware.js";
|
|
8
|
-
import { isValueSerializable } from "../render/core.js";
|
|
9
8
|
const clientAddressSymbol = Symbol.for("astro.clientAddress");
|
|
10
9
|
const clientLocalsSymbol = Symbol.for("astro.locals");
|
|
11
10
|
function createAPIContext({
|
|
@@ -76,12 +75,6 @@ async function callEndpoint(mod, env, ctx, logging, middleware) {
|
|
|
76
75
|
onRequest,
|
|
77
76
|
context,
|
|
78
77
|
async () => {
|
|
79
|
-
if (env.mode === "development" && !isValueSerializable(context.locals)) {
|
|
80
|
-
throw new AstroError({
|
|
81
|
-
...AstroErrorData.LocalsNotSerializable,
|
|
82
|
-
message: AstroErrorData.LocalsNotSerializable.message(ctx.pathname)
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
78
|
return await renderEndpoint(mod, context, env.ssr);
|
|
86
79
|
}
|
|
87
80
|
);
|
|
@@ -613,29 +613,6 @@ export declare const AstroErrorData: {
|
|
|
613
613
|
readonly message: "`locals` can only be assigned to an object. Other values like numbers, strings, etc. are not accepted.";
|
|
614
614
|
readonly hint: "If you tried to remove some information from the `locals` object, try to use `delete` or set the property to `undefined`.";
|
|
615
615
|
};
|
|
616
|
-
/**
|
|
617
|
-
* @docs
|
|
618
|
-
* @description
|
|
619
|
-
* Thrown in development mode when a user attempts to store something that is not serializable in `locals`.
|
|
620
|
-
*
|
|
621
|
-
* For example:
|
|
622
|
-
* ```ts
|
|
623
|
-
* import {defineMiddleware} from "astro/middleware";
|
|
624
|
-
* export const onRequest = defineMiddleware((context, next) => {
|
|
625
|
-
* context.locals = {
|
|
626
|
-
* foo() {
|
|
627
|
-
* alert("Hello world!")
|
|
628
|
-
* }
|
|
629
|
-
* };
|
|
630
|
-
* return next();
|
|
631
|
-
* });
|
|
632
|
-
* ```
|
|
633
|
-
*/
|
|
634
|
-
readonly LocalsNotSerializable: {
|
|
635
|
-
readonly title: "`Astro.locals` is not serializable";
|
|
636
|
-
readonly code: 3034;
|
|
637
|
-
readonly message: (href: string) => string;
|
|
638
|
-
};
|
|
639
616
|
/**
|
|
640
617
|
* @docs
|
|
641
618
|
* @see
|
|
@@ -627,32 +627,6 @@ Expected \`${defaultExpectedValue}\` value but got \`${suffix}\`.`;
|
|
|
627
627
|
message: "`locals` can only be assigned to an object. Other values like numbers, strings, etc. are not accepted.",
|
|
628
628
|
hint: "If you tried to remove some information from the `locals` object, try to use `delete` or set the property to `undefined`."
|
|
629
629
|
},
|
|
630
|
-
/**
|
|
631
|
-
* @docs
|
|
632
|
-
* @description
|
|
633
|
-
* Thrown in development mode when a user attempts to store something that is not serializable in `locals`.
|
|
634
|
-
*
|
|
635
|
-
* For example:
|
|
636
|
-
* ```ts
|
|
637
|
-
* import {defineMiddleware} from "astro/middleware";
|
|
638
|
-
* export const onRequest = defineMiddleware((context, next) => {
|
|
639
|
-
* context.locals = {
|
|
640
|
-
* foo() {
|
|
641
|
-
* alert("Hello world!")
|
|
642
|
-
* }
|
|
643
|
-
* };
|
|
644
|
-
* return next();
|
|
645
|
-
* });
|
|
646
|
-
* ```
|
|
647
|
-
*/
|
|
648
|
-
LocalsNotSerializable: {
|
|
649
|
-
title: "`Astro.locals` is not serializable",
|
|
650
|
-
code: 3034,
|
|
651
|
-
message: (href) => {
|
|
652
|
-
return `The information stored in \`Astro.locals\` for the path "${href}" is not serializable.
|
|
653
|
-
Make sure you store only serializable data.`;
|
|
654
|
-
}
|
|
655
|
-
},
|
|
656
630
|
// No headings here, that way Vite errors are merged with Astro ones in the docs, which makes more sense to users.
|
|
657
631
|
// Vite Errors - 4xxx
|
|
658
632
|
/**
|
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.5";
|
|
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.5"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
|
@@ -27,13 +27,4 @@ export type RenderPage = {
|
|
|
27
27
|
apiContext?: APIContext;
|
|
28
28
|
};
|
|
29
29
|
export declare function renderPage({ mod, renderContext, env, apiContext }: RenderPage): Promise<Response>;
|
|
30
|
-
/**
|
|
31
|
-
* Checks whether any value can is serializable.
|
|
32
|
-
*
|
|
33
|
-
* A serializable value contains plain values. For example, `Proxy`, `Set`, `Map`, functions, etc.
|
|
34
|
-
* are not serializable objects.
|
|
35
|
-
*
|
|
36
|
-
* @param object
|
|
37
|
-
*/
|
|
38
|
-
export declare function isValueSerializable(value: unknown): boolean;
|
|
39
30
|
export {};
|
package/dist/core/render/core.js
CHANGED
|
@@ -65,16 +65,7 @@ async function renderPage({ mod, renderContext, env, apiContext }) {
|
|
|
65
65
|
const Component = mod.default;
|
|
66
66
|
if (!Component)
|
|
67
67
|
throw new Error(`Expected an exported Astro component but received typeof ${typeof Component}`);
|
|
68
|
-
let locals = {};
|
|
69
|
-
if (apiContext) {
|
|
70
|
-
if (env.mode === "development" && !isValueSerializable(apiContext.locals)) {
|
|
71
|
-
throw new AstroError({
|
|
72
|
-
...AstroErrorData.LocalsNotSerializable,
|
|
73
|
-
message: AstroErrorData.LocalsNotSerializable.message(renderContext.pathname)
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
locals = apiContext.locals;
|
|
77
|
-
}
|
|
68
|
+
let locals = (apiContext == null ? void 0 : apiContext.locals) ?? {};
|
|
78
69
|
const result = createResult({
|
|
79
70
|
adapterName: env.adapterName,
|
|
80
71
|
links: renderContext.links,
|
|
@@ -113,38 +104,9 @@ async function renderPage({ mod, renderContext, env, apiContext }) {
|
|
|
113
104
|
}
|
|
114
105
|
return response;
|
|
115
106
|
}
|
|
116
|
-
function isValueSerializable(value) {
|
|
117
|
-
let type = typeof value;
|
|
118
|
-
let plainObject = true;
|
|
119
|
-
if (type === "object" && isPlainObject(value)) {
|
|
120
|
-
for (const [, nestedValue] of Object.entries(value)) {
|
|
121
|
-
if (!isValueSerializable(nestedValue)) {
|
|
122
|
-
plainObject = false;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
plainObject = false;
|
|
128
|
-
}
|
|
129
|
-
let result = value === null || type === "string" || type === "number" || type === "boolean" || Array.isArray(value) || plainObject;
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
132
|
-
function isPlainObject(value) {
|
|
133
|
-
if (typeof value !== "object" || value === null)
|
|
134
|
-
return false;
|
|
135
|
-
let proto = Object.getPrototypeOf(value);
|
|
136
|
-
if (proto === null)
|
|
137
|
-
return true;
|
|
138
|
-
let baseProto = proto;
|
|
139
|
-
while (Object.getPrototypeOf(baseProto) !== null) {
|
|
140
|
-
baseProto = Object.getPrototypeOf(baseProto);
|
|
141
|
-
}
|
|
142
|
-
return proto === baseProto;
|
|
143
|
-
}
|
|
144
107
|
export {
|
|
145
108
|
GetParamsAndPropsError,
|
|
146
109
|
getParamsAndProps,
|
|
147
110
|
getParamsAndPropsOrThrow,
|
|
148
|
-
isValueSerializable,
|
|
149
111
|
renderPage
|
|
150
112
|
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import npath from "path";
|
|
2
|
+
import { PROPAGATED_ASSET_FLAG } from "../../../content/consts.js";
|
|
2
3
|
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
|
|
3
4
|
import { unwrapId } from "../../util.js";
|
|
4
5
|
import { isCSSRequest } from "./util.js";
|
|
5
|
-
const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro",
|
|
6
|
+
const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS]);
|
|
6
7
|
const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
|
|
7
|
-
const ASTRO_PROPAGATED_ASSET_REGEX = /\?astroPropagatedAssets/;
|
|
8
8
|
async function* crawlGraph(loader, _id, isRootFile, scanned = /* @__PURE__ */ new Set()) {
|
|
9
9
|
const id = unwrapId(_id);
|
|
10
10
|
const importedModules = /* @__PURE__ */ new Set();
|
|
11
|
+
if (new URL(id, "file://").searchParams.has(PROPAGATED_ASSET_FLAG))
|
|
12
|
+
return;
|
|
11
13
|
const moduleEntriesForId = isRootFile ? (
|
|
12
14
|
// "getModulesByFile" pulls from a delayed module cache (fun implementation detail),
|
|
13
15
|
// So we can get up-to-date info on initial server load.
|
|
@@ -31,11 +33,14 @@ async function* crawlGraph(loader, _id, isRootFile, scanned = /* @__PURE__ */ ne
|
|
|
31
33
|
if (entryIsStyle && !isCSSRequest(importedModulePathname)) {
|
|
32
34
|
continue;
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
npath.extname(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if (fileExtensionsToSSR.has(
|
|
37
|
+
npath.extname(
|
|
38
|
+
// Use `id` instead of `pathname` to preserve query params.
|
|
39
|
+
// Should not SSR a module with an unexpected query param,
|
|
40
|
+
// like "?astroPropagatedAssets"
|
|
41
|
+
importedModule.id
|
|
42
|
+
)
|
|
43
|
+
)) {
|
|
39
44
|
const mod = loader.getModuleById(importedModule.id);
|
|
40
45
|
if (!(mod == null ? void 0 : mod.ssrModule)) {
|
|
41
46
|
try {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isHTMLString } from "../../runtime/server/escape.js";
|
|
1
2
|
import {
|
|
2
3
|
renderSlotToString,
|
|
3
4
|
stringifyChunk
|
|
@@ -69,10 +70,10 @@ class Slots {
|
|
|
69
70
|
const component = typeof slotValue === "function" ? await slotValue(result) : await slotValue;
|
|
70
71
|
const expression = getFunctionExpression(component);
|
|
71
72
|
if (expression) {
|
|
72
|
-
const slot = () => expression(...args);
|
|
73
|
-
return await renderSlotToString(result, slot).then(
|
|
74
|
-
|
|
75
|
-
);
|
|
73
|
+
const slot = async () => isHTMLString(await expression) ? expression : expression(...args);
|
|
74
|
+
return await renderSlotToString(result, slot).then((res) => {
|
|
75
|
+
return res != null ? String(res) : res;
|
|
76
|
+
});
|
|
76
77
|
}
|
|
77
78
|
if (typeof component === "function") {
|
|
78
79
|
return await renderJSX(result, component(...args)).then(
|
package/dist/core/sync/index.js
CHANGED
|
@@ -34,7 +34,7 @@ async function sync(settings, { logging, fs }) {
|
|
|
34
34
|
const tempViteServer = await createServer(
|
|
35
35
|
await createVite(
|
|
36
36
|
{
|
|
37
|
-
server: { middlewareMode: true, hmr: false },
|
|
37
|
+
server: { middlewareMode: true, hmr: false, watch: { ignored: ["**"] } },
|
|
38
38
|
optimizeDeps: { disabled: true },
|
|
39
39
|
ssr: { external: [] },
|
|
40
40
|
logLevel: "silent"
|
|
@@ -4,7 +4,7 @@ import type { RenderInstruction } from './types.js';
|
|
|
4
4
|
import { HTMLString } from '../escape.js';
|
|
5
5
|
type RenderTemplateResult = ReturnType<typeof renderTemplate>;
|
|
6
6
|
export type ComponentSlots = Record<string, ComponentSlotValue>;
|
|
7
|
-
export type ComponentSlotValue = (result: SSRResult) => RenderTemplateResult
|
|
7
|
+
export type ComponentSlotValue = (result: SSRResult) => RenderTemplateResult | Promise<RenderTemplateResult>;
|
|
8
8
|
declare const slotString: unique symbol;
|
|
9
9
|
export declare class SlotString extends HTMLString {
|
|
10
10
|
instructions: null | RenderInstruction[];
|
|
@@ -20,9 +20,10 @@ const toStyleString = (obj) => Object.entries(obj).map(([k, v]) => {
|
|
|
20
20
|
return `${k}:${v}`;
|
|
21
21
|
}).join(";");
|
|
22
22
|
function defineScriptVars(vars) {
|
|
23
|
+
var _a;
|
|
23
24
|
let output = "";
|
|
24
25
|
for (const [key, value] of Object.entries(vars)) {
|
|
25
|
-
output += `const ${toIdent(key)} = ${JSON.stringify(value).replace(
|
|
26
|
+
output += `const ${toIdent(key)} = ${(_a = JSON.stringify(value)) == null ? void 0 : _a.replace(
|
|
26
27
|
/<\/script>/g,
|
|
27
28
|
"\\x3C/script>"
|
|
28
29
|
)};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getTopLevelPages, walkParentInfos } from "../core/build/graph.js";
|
|
2
2
|
import { getAstroMetadata } from "../vite-plugin-astro/index.js";
|
|
3
|
-
const injectExp =
|
|
3
|
+
const injectExp = /^\/\/\s*astro-head-inject/;
|
|
4
4
|
function configHeadVitePlugin({
|
|
5
5
|
settings
|
|
6
6
|
}) {
|
|
@@ -10,9 +10,7 @@ const markdownContentEntryType = {
|
|
|
10
10
|
slug: parsed.data.slug,
|
|
11
11
|
rawData: parsed.matter
|
|
12
12
|
};
|
|
13
|
-
}
|
|
14
|
-
// We need to handle propagation for Markdown because they support layouts which will bring in styles.
|
|
15
|
-
handlePropagation: true
|
|
13
|
+
}
|
|
16
14
|
};
|
|
17
15
|
const mdxContentEntryType = {
|
|
18
16
|
extensions: [".mdx"],
|
|
@@ -25,9 +23,6 @@ const mdxContentEntryType = {
|
|
|
25
23
|
rawData: parsed.matter
|
|
26
24
|
};
|
|
27
25
|
},
|
|
28
|
-
// MDX can import scripts and styles,
|
|
29
|
-
// so wrap all MDX files with script / style propagation checks
|
|
30
|
-
handlePropagation: true,
|
|
31
26
|
contentModuleTypes: `declare module 'astro:content' {
|
|
32
27
|
interface Render {
|
|
33
28
|
'.mdx': Promise<{
|
package/import-meta.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// File vendored from Vite itself, as a workaround to https://github.com/vitejs/vite/
|
|
1
|
+
// File vendored from Vite itself, as a workaround to https://github.com/vitejs/vite/issues/13309 until Vite 5 comes out
|
|
2
2
|
|
|
3
3
|
// This file is an augmentation to the built-in ImportMeta interface
|
|
4
4
|
// Thus cannot contain any top-level imports
|
|
@@ -6,13 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
/* eslint-disable @typescript-eslint/consistent-type-imports */
|
|
8
8
|
|
|
9
|
-
// Duplicate of import('../src/node/importGlob').GlobOptions in order to
|
|
10
|
-
// avoid breaking the production client type. Because this file is referenced
|
|
11
|
-
// in vite/client.d.ts and in production src/node/importGlob.ts doesn't exist.
|
|
12
|
-
interface GlobOptions {
|
|
13
|
-
as?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
9
|
interface ImportMeta {
|
|
17
10
|
url: string;
|
|
18
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5",
|
|
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",
|
|
@@ -135,6 +135,7 @@
|
|
|
135
135
|
"magic-string": "^0.27.0",
|
|
136
136
|
"mime": "^3.0.0",
|
|
137
137
|
"ora": "^6.1.0",
|
|
138
|
+
"p-limit": "^4.0.0",
|
|
138
139
|
"path-to-regexp": "^6.2.1",
|
|
139
140
|
"preferred-pm": "^3.0.3",
|
|
140
141
|
"prompts": "^2.4.2",
|
|
@@ -46,7 +46,7 @@ function createGlobLookup(glob) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const renderEntryGlob = import.meta.glob('@@RENDER_ENTRY_GLOB_PATH@@', {
|
|
49
|
-
query: {
|
|
49
|
+
query: { astroPropagatedAssets: true },
|
|
50
50
|
});
|
|
51
51
|
const collectionToRenderEntryMap = createCollectionToGlobResultMap({
|
|
52
52
|
globResult: renderEntryGlob,
|