astro 2.0.17 → 2.1.0
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/README.md +3 -3
- package/client-base.d.ts +27 -0
- package/client-image.d.ts +48 -0
- package/components/Image.astro +28 -0
- package/dist/@types/astro.d.ts +101 -1
- package/dist/assets/consts.d.ts +4 -0
- package/dist/assets/consts.js +20 -0
- package/dist/assets/image-endpoint.d.ts +5 -0
- package/dist/assets/image-endpoint.js +50 -0
- package/dist/assets/index.d.ts +4 -0
- package/dist/assets/index.js +10 -0
- package/dist/assets/internal.d.ts +36 -0
- package/dist/assets/internal.js +70 -0
- package/dist/assets/services/service.d.ts +71 -0
- package/dist/assets/services/service.js +88 -0
- package/dist/assets/services/sharp.d.ts +3 -0
- package/dist/assets/services/sharp.js +57 -0
- package/dist/assets/services/squoosh.d.ts +3 -0
- package/dist/assets/services/squoosh.js +56 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_enc.d.js +11 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +1628 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +1850 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/codecs.d.ts +158 -0
- package/dist/assets/services/vendor/squoosh/codecs.js +284 -0
- package/dist/assets/services/vendor/squoosh/copy-wasm.d.ts +1 -0
- package/dist/assets/services/vendor/squoosh/copy-wasm.js +24 -0
- package/dist/assets/services/vendor/squoosh/emscripten-types.d.js +0 -0
- package/dist/assets/services/vendor/squoosh/emscripten-utils.d.ts +9 -0
- package/dist/assets/services/vendor/squoosh/emscripten-utils.js +33 -0
- package/dist/assets/services/vendor/squoosh/image-pool.d.ts +4 -0
- package/dist/assets/services/vendor/squoosh/image-pool.js +94 -0
- package/dist/assets/services/vendor/squoosh/image.d.ts +14 -0
- package/dist/assets/services/vendor/squoosh/image.js +27 -0
- package/dist/assets/services/vendor/squoosh/image_data.d.ts +9 -0
- package/dist/assets/services/vendor/squoosh/image_data.js +22 -0
- package/dist/assets/services/vendor/squoosh/impl.d.ts +22 -0
- package/dist/assets/services/vendor/squoosh/impl.js +110 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_enc.d.js +11 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +1631 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +1737 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng.d.ts +10 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng.js +89 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng_bg.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.d.ts +15 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +138 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_png_bg.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/resize/squoosh_resize.d.ts +15 -0
- package/dist/assets/services/vendor/squoosh/resize/squoosh_resize.js +95 -0
- package/dist/assets/services/vendor/squoosh/resize/squoosh_resize_bg.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/rotate/rotate.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/utils/execOnce.d.ts +1 -0
- package/dist/assets/services/vendor/squoosh/utils/execOnce.js +14 -0
- package/dist/assets/services/vendor/squoosh/utils/workerPool.d.ts +22 -0
- package/dist/assets/services/vendor/squoosh/utils/workerPool.js +95 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_enc.d.js +4 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +1473 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +1640 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.wasm +0 -0
- package/dist/assets/types.d.ts +119 -0
- package/dist/assets/types.js +0 -0
- package/dist/assets/utils/etag.d.ts +12 -0
- package/dist/assets/utils/etag.js +28 -0
- package/dist/assets/utils/metadata.d.ts +6 -0
- package/dist/assets/utils/metadata.js +30 -0
- package/dist/assets/utils/queryParams.d.ts +2 -0
- package/dist/assets/utils/queryParams.js +16 -0
- package/dist/assets/utils/transformToPath.d.ts +2 -0
- package/dist/assets/utils/transformToPath.js +17 -0
- package/dist/assets/vite-plugin-assets.d.ts +5 -0
- package/dist/assets/vite-plugin-assets.js +187 -0
- package/dist/cli/check/index.d.ts +81 -2
- package/dist/cli/check/index.js +190 -44
- package/dist/cli/index.js +39 -16
- package/dist/cli/telemetry.js +1 -1
- package/dist/content/consts.d.ts +0 -1
- package/dist/content/consts.js +1 -3
- package/dist/content/internal.d.ts +7 -0
- package/dist/content/internal.js +27 -5
- package/dist/content/template/virtual-mod.d.mts +1 -0
- package/dist/content/types-generator.js +25 -10
- package/dist/content/utils.d.ts +16 -13
- package/dist/content/utils.js +29 -6
- package/dist/content/vite-plugin-content-assets.d.ts +3 -1
- package/dist/content/vite-plugin-content-assets.js +10 -6
- package/dist/content/vite-plugin-content-imports.js +54 -27
- package/dist/content/vite-plugin-content-virtual-mod.js +7 -4
- package/dist/core/add/index.js +2 -1
- package/dist/core/app/index.js +104 -134
- package/dist/core/build/generate.js +30 -5
- package/dist/core/build/index.d.ts +2 -0
- package/dist/core/build/index.js +16 -0
- package/dist/core/build/plugins/plugin-ssr.js +3 -5
- package/dist/core/config/config.js +2 -1
- package/dist/core/config/schema.d.ts +64 -8
- package/dist/core/config/schema.js +17 -3
- package/dist/core/config/settings.js +4 -2
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.js +36 -68
- package/dist/core/create-vite.js +5 -1
- package/dist/core/dev/dev.d.ts +2 -2
- package/dist/core/dev/dev.js +24 -4
- package/dist/core/errors/dev/vite.js +6 -1
- package/dist/core/errors/errors-data.d.ts +17 -1
- package/dist/core/errors/errors-data.js +16 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/path.d.ts +1 -0
- package/dist/core/path.js +4 -0
- package/dist/core/preview/index.d.ts +3 -1
- package/dist/core/preview/index.js +16 -1
- package/dist/core/render/dev/css.js +2 -2
- package/dist/core/render/dev/environment.js +1 -5
- package/dist/core/render/environment.js +1 -2
- package/dist/core/render/result.js +13 -35
- package/dist/core/sync/index.d.ts +18 -5
- package/dist/core/sync/index.js +13 -1
- package/dist/integrations/index.js +12 -1
- package/dist/runtime/server/render/component.js +1 -1
- package/dist/runtime/server/response.js +11 -30
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/plugin.js +1 -1
- package/dist/vite-plugin-env/index.js +4 -4
- package/dist/vite-plugin-inject-env-ts/index.js +17 -2
- package/dist/vite-plugin-markdown/content-entry-type.d.ts +7 -0
- package/dist/vite-plugin-markdown/content-entry-type.js +39 -0
- package/dist/vite-plugin-markdown/index.js +70 -4
- package/dist/vite-plugin-ssr-manifest/index.d.ts +2 -0
- package/dist/vite-plugin-ssr-manifest/index.js +25 -0
- package/package.json +26 -9
- package/src/content/template/types.d.ts +18 -9
- package/src/content/template/virtual-mod.mjs +6 -0
- package/tsconfigs/base.json +6 -1
package/dist/content/utils.js
CHANGED
|
@@ -6,7 +6,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
6
6
|
import { normalizePath } from "vite";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
9
|
-
import {
|
|
9
|
+
import { CONTENT_TYPES_FILE } from "./consts.js";
|
|
10
10
|
const collectionConfigParser = z.object({
|
|
11
11
|
schema: z.any().optional()
|
|
12
12
|
});
|
|
@@ -23,14 +23,29 @@ const contentConfigParser = z.object({
|
|
|
23
23
|
const msg = {
|
|
24
24
|
collectionConfigMissing: (collection) => `${collection} does not have a config. We suggest adding one for type safety!`
|
|
25
25
|
};
|
|
26
|
+
function extractFrontmatterAssets(data) {
|
|
27
|
+
function findAssets(potentialAssets) {
|
|
28
|
+
return Object.values(potentialAssets).reduce((acc, curr) => {
|
|
29
|
+
if (typeof curr === "object") {
|
|
30
|
+
if (curr.__astro === true) {
|
|
31
|
+
acc.push(curr);
|
|
32
|
+
} else {
|
|
33
|
+
acc.push(...findAssets(curr));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return acc;
|
|
37
|
+
}, []);
|
|
38
|
+
}
|
|
39
|
+
return findAssets(data).map((asset) => asset.src);
|
|
40
|
+
}
|
|
26
41
|
function getEntrySlug({
|
|
27
42
|
id,
|
|
28
43
|
collection,
|
|
29
44
|
slug,
|
|
30
|
-
|
|
45
|
+
unvalidatedSlug
|
|
31
46
|
}) {
|
|
32
47
|
try {
|
|
33
|
-
return z.string().default(slug).parse(
|
|
48
|
+
return z.string().default(slug).parse(unvalidatedSlug);
|
|
34
49
|
} catch {
|
|
35
50
|
throw new AstroError({
|
|
36
51
|
...AstroErrorData.InvalidContentEntrySlugError,
|
|
@@ -39,7 +54,7 @@ function getEntrySlug({
|
|
|
39
54
|
}
|
|
40
55
|
}
|
|
41
56
|
async function getEntryData(entry, collectionConfig) {
|
|
42
|
-
let { slug, ...data } = entry.
|
|
57
|
+
let { slug, ...data } = entry.unvalidatedData;
|
|
43
58
|
if (collectionConfig.schema) {
|
|
44
59
|
if (typeof collectionConfig.schema === "object" && !("safeParseAsync" in collectionConfig.schema)) {
|
|
45
60
|
throw new AstroError({
|
|
@@ -55,7 +70,9 @@ async function getEntryData(entry, collectionConfig) {
|
|
|
55
70
|
message: AstroErrorData.ContentSchemaContainsSlugError.message(entry.collection)
|
|
56
71
|
});
|
|
57
72
|
}
|
|
58
|
-
const parsed = await collectionConfig.schema.safeParseAsync(entry.
|
|
73
|
+
const parsed = await collectionConfig.schema.safeParseAsync(entry.unvalidatedData, {
|
|
74
|
+
errorMap
|
|
75
|
+
});
|
|
59
76
|
if (parsed.success) {
|
|
60
77
|
data = parsed.data;
|
|
61
78
|
} else {
|
|
@@ -80,6 +97,9 @@ async function getEntryData(entry, collectionConfig) {
|
|
|
80
97
|
}
|
|
81
98
|
return data;
|
|
82
99
|
}
|
|
100
|
+
function getContentEntryExts(settings) {
|
|
101
|
+
return settings.contentEntryTypes.map((t) => t.extensions).flat();
|
|
102
|
+
}
|
|
83
103
|
class NoCollectionError extends Error {
|
|
84
104
|
}
|
|
85
105
|
function getEntryInfo({
|
|
@@ -103,7 +123,7 @@ function getEntryInfo({
|
|
|
103
123
|
};
|
|
104
124
|
return res;
|
|
105
125
|
}
|
|
106
|
-
function getEntryType(entryPath, paths) {
|
|
126
|
+
function getEntryType(entryPath, paths, contentFileExts) {
|
|
107
127
|
const { ext, base } = path.parse(entryPath);
|
|
108
128
|
const fileUrl = pathToFileURL(entryPath);
|
|
109
129
|
if (hasUnderscoreBelowContentDirectoryPath(fileUrl, paths.contentDir) || isOnIgnoreList(base)) {
|
|
@@ -216,6 +236,7 @@ function getContentPaths({ srcDir, root }, fs = fsMod) {
|
|
|
216
236
|
return {
|
|
217
237
|
cacheDir: new URL(".astro/", root),
|
|
218
238
|
contentDir: new URL("./content/", srcDir),
|
|
239
|
+
assetsDir: new URL("./assets/", srcDir),
|
|
219
240
|
typesTemplate: new URL("types.d.ts", templateDir),
|
|
220
241
|
virtualModTemplate: new URL("virtual-mod.mjs", templateDir),
|
|
221
242
|
config: configStats
|
|
@@ -237,6 +258,8 @@ export {
|
|
|
237
258
|
collectionConfigParser,
|
|
238
259
|
contentConfigParser,
|
|
239
260
|
contentObservable,
|
|
261
|
+
extractFrontmatterAssets,
|
|
262
|
+
getContentEntryExts,
|
|
240
263
|
getContentPaths,
|
|
241
264
|
getDotAstroTypeReference,
|
|
242
265
|
getEntryData,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
+
import { AstroSettings } from '../@types/astro.js';
|
|
2
3
|
import { BuildInternals } from '../core/build/internal.js';
|
|
3
4
|
import { AstroBuildPlugin } from '../core/build/plugin.js';
|
|
4
5
|
import type { StaticBuildOptions } from '../core/build/types';
|
|
5
|
-
export declare function astroContentAssetPropagationPlugin({ mode }: {
|
|
6
|
+
export declare function astroContentAssetPropagationPlugin({ mode, settings, }: {
|
|
6
7
|
mode: string;
|
|
8
|
+
settings: AstroSettings;
|
|
7
9
|
}): Plugin;
|
|
8
10
|
export declare function astroConfigBuildPlugin(options: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -7,18 +7,22 @@ import { prependForwardSlash } from "../core/path.js";
|
|
|
7
7
|
import { getStylesForURL } from "../core/render/dev/css.js";
|
|
8
8
|
import { getScriptsForURL } from "../core/render/dev/scripts.js";
|
|
9
9
|
import {
|
|
10
|
-
contentFileExts,
|
|
11
10
|
LINKS_PLACEHOLDER,
|
|
12
11
|
PROPAGATED_ASSET_FLAG,
|
|
13
12
|
SCRIPTS_PLACEHOLDER,
|
|
14
13
|
STYLES_PLACEHOLDER
|
|
15
14
|
} from "./consts.js";
|
|
16
|
-
|
|
15
|
+
import { getContentEntryExts } from "./utils.js";
|
|
16
|
+
function isPropagatedAsset(viteId, contentEntryExts) {
|
|
17
17
|
const url = new URL(viteId, "file://");
|
|
18
|
-
return url.searchParams.has(PROPAGATED_ASSET_FLAG) &&
|
|
18
|
+
return url.searchParams.has(PROPAGATED_ASSET_FLAG) && contentEntryExts.some((ext) => url.pathname.endsWith(ext));
|
|
19
19
|
}
|
|
20
|
-
function astroContentAssetPropagationPlugin({
|
|
20
|
+
function astroContentAssetPropagationPlugin({
|
|
21
|
+
mode,
|
|
22
|
+
settings
|
|
23
|
+
}) {
|
|
21
24
|
let devModuleLoader;
|
|
25
|
+
const contentEntryExts = getContentEntryExts(settings);
|
|
22
26
|
return {
|
|
23
27
|
name: "astro:content-asset-propagation",
|
|
24
28
|
enforce: "pre",
|
|
@@ -28,7 +32,7 @@ function astroContentAssetPropagationPlugin({ mode }) {
|
|
|
28
32
|
}
|
|
29
33
|
},
|
|
30
34
|
load(id) {
|
|
31
|
-
if (isPropagatedAsset(id)) {
|
|
35
|
+
if (isPropagatedAsset(id, contentEntryExts)) {
|
|
32
36
|
const basePath = id.split("?")[0];
|
|
33
37
|
const code = `
|
|
34
38
|
export async function getMod() {
|
|
@@ -45,7 +49,7 @@ function astroContentAssetPropagationPlugin({ mode }) {
|
|
|
45
49
|
var _a;
|
|
46
50
|
if (!(options == null ? void 0 : options.ssr))
|
|
47
51
|
return;
|
|
48
|
-
if (devModuleLoader && isPropagatedAsset(id)) {
|
|
52
|
+
if (devModuleLoader && isPropagatedAsset(id, contentEntryExts)) {
|
|
49
53
|
const basePath = id.split("?")[0];
|
|
50
54
|
if (!((_a = devModuleLoader.getModuleById(basePath)) == null ? void 0 : _a.ssrModule)) {
|
|
51
55
|
await devModuleLoader.import(basePath);
|
|
@@ -1,32 +1,42 @@
|
|
|
1
1
|
import * as devalue from "devalue";
|
|
2
|
+
import { extname } from "node:path";
|
|
2
3
|
import { pathToFileURL } from "url";
|
|
4
|
+
import { normalizePath } from "vite";
|
|
3
5
|
import { AstroErrorData } from "../core/errors/errors-data.js";
|
|
4
6
|
import { AstroError } from "../core/errors/errors.js";
|
|
5
7
|
import { escapeViteEnvReferences, getFileInfo } from "../vite-plugin-utils/index.js";
|
|
6
|
-
import {
|
|
8
|
+
import { CONTENT_FLAG } from "./consts.js";
|
|
7
9
|
import {
|
|
10
|
+
extractFrontmatterAssets,
|
|
11
|
+
getContentEntryExts,
|
|
8
12
|
getContentPaths,
|
|
9
13
|
getEntryData,
|
|
10
14
|
getEntryInfo,
|
|
11
15
|
getEntrySlug,
|
|
12
16
|
getEntryType,
|
|
13
|
-
globalContentConfigObserver
|
|
14
|
-
parseFrontmatter
|
|
17
|
+
globalContentConfigObserver
|
|
15
18
|
} from "./utils.js";
|
|
16
|
-
function isContentFlagImport(viteId) {
|
|
17
|
-
const {
|
|
18
|
-
return searchParams.has(CONTENT_FLAG) &&
|
|
19
|
+
function isContentFlagImport(viteId, contentEntryExts) {
|
|
20
|
+
const { searchParams, pathname } = new URL(viteId, "file://");
|
|
21
|
+
return searchParams.has(CONTENT_FLAG) && contentEntryExts.some((ext) => pathname.endsWith(ext));
|
|
19
22
|
}
|
|
20
23
|
function astroContentImportPlugin({
|
|
21
24
|
fs,
|
|
22
25
|
settings
|
|
23
26
|
}) {
|
|
24
27
|
const contentPaths = getContentPaths(settings.config, fs);
|
|
28
|
+
const contentEntryExts = getContentEntryExts(settings);
|
|
29
|
+
const contentEntryExtToParser = /* @__PURE__ */ new Map();
|
|
30
|
+
for (const entryType of settings.contentEntryTypes) {
|
|
31
|
+
for (const ext of entryType.extensions) {
|
|
32
|
+
contentEntryExtToParser.set(ext, entryType);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
25
35
|
return {
|
|
26
36
|
name: "astro:content-imports",
|
|
27
37
|
async load(id) {
|
|
28
38
|
const { fileId } = getFileInfo(id, settings.config);
|
|
29
|
-
if (isContentFlagImport(id)) {
|
|
39
|
+
if (isContentFlagImport(id, contentEntryExts)) {
|
|
30
40
|
const observable = globalContentConfigObserver.get();
|
|
31
41
|
if (observable.status === "init") {
|
|
32
42
|
throw new AstroError({
|
|
@@ -52,31 +62,48 @@ function astroContentImportPlugin({
|
|
|
52
62
|
});
|
|
53
63
|
}
|
|
54
64
|
const rawContents = await fs.promises.readFile(fileId, "utf-8");
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
const fileExt = extname(fileId);
|
|
66
|
+
if (!contentEntryExtToParser.has(fileExt)) {
|
|
67
|
+
throw new AstroError({
|
|
68
|
+
...AstroErrorData.UnknownContentCollectionError,
|
|
69
|
+
message: `No parser found for content entry ${JSON.stringify(
|
|
70
|
+
fileId
|
|
71
|
+
)}. Did you apply an integration for this file type?`
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const contentEntryParser = contentEntryExtToParser.get(fileExt);
|
|
75
|
+
const info = await contentEntryParser.getEntryInfo({
|
|
76
|
+
fileUrl: pathToFileURL(fileId),
|
|
77
|
+
contents: rawContents
|
|
78
|
+
});
|
|
79
|
+
const generatedInfo = getEntryInfo({
|
|
61
80
|
entry: pathToFileURL(fileId),
|
|
62
81
|
contentDir: contentPaths.contentDir
|
|
63
82
|
});
|
|
64
|
-
if (
|
|
83
|
+
if (generatedInfo instanceof Error)
|
|
65
84
|
return;
|
|
66
|
-
const _internal = { filePath: fileId, rawData };
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
85
|
+
const _internal = { filePath: fileId, rawData: info.rawData };
|
|
86
|
+
const slug = getEntrySlug({ ...generatedInfo, unvalidatedSlug: info.slug });
|
|
87
|
+
const collectionConfig = contentConfig == null ? void 0 : contentConfig.collections[generatedInfo.collection];
|
|
88
|
+
const data = collectionConfig ? await getEntryData(
|
|
89
|
+
{ ...generatedInfo, _internal, unvalidatedData: info.data },
|
|
90
|
+
collectionConfig
|
|
91
|
+
) : info.data;
|
|
92
|
+
const images = extractFrontmatterAssets(data).map(
|
|
93
|
+
(image) => `'${image}': await import('${normalizePath(image)}'),`
|
|
94
|
+
);
|
|
71
95
|
const code = escapeViteEnvReferences(`
|
|
72
|
-
export const id = ${JSON.stringify(
|
|
73
|
-
export const collection = ${JSON.stringify(
|
|
96
|
+
export const id = ${JSON.stringify(generatedInfo.id)};
|
|
97
|
+
export const collection = ${JSON.stringify(generatedInfo.collection)};
|
|
74
98
|
export const slug = ${JSON.stringify(slug)};
|
|
75
|
-
export const body = ${JSON.stringify(body)};
|
|
99
|
+
export const body = ${JSON.stringify(info.body)};
|
|
100
|
+
const frontmatterImages = {
|
|
101
|
+
${images.join("\n")}
|
|
102
|
+
}
|
|
76
103
|
export const data = ${devalue.uneval(data)};
|
|
77
104
|
export const _internal = {
|
|
78
|
-
filePath: ${JSON.stringify(
|
|
79
|
-
rawData: ${JSON.stringify(rawData)},
|
|
105
|
+
filePath: ${JSON.stringify(_internal.filePath)},
|
|
106
|
+
rawData: ${JSON.stringify(_internal.rawData)},
|
|
80
107
|
};
|
|
81
108
|
`);
|
|
82
109
|
return { code };
|
|
@@ -84,9 +111,9 @@ export const _internal = {
|
|
|
84
111
|
},
|
|
85
112
|
configureServer(viteServer) {
|
|
86
113
|
viteServer.watcher.on("all", async (event, entry) => {
|
|
87
|
-
if (["add", "unlink", "change"].includes(event) && getEntryType(entry, contentPaths) === "config") {
|
|
114
|
+
if (["add", "unlink", "change"].includes(event) && getEntryType(entry, contentPaths, contentEntryExts) === "config") {
|
|
88
115
|
for (const modUrl of viteServer.moduleGraph.urlToModuleMap.keys()) {
|
|
89
|
-
if (isContentFlagImport(modUrl)) {
|
|
116
|
+
if (isContentFlagImport(modUrl, contentEntryExts)) {
|
|
90
117
|
const mod = await viteServer.moduleGraph.getModuleByUrl(modUrl);
|
|
91
118
|
if (mod) {
|
|
92
119
|
viteServer.moduleGraph.invalidateModule(mod);
|
|
@@ -97,7 +124,7 @@ export const _internal = {
|
|
|
97
124
|
});
|
|
98
125
|
},
|
|
99
126
|
async transform(code, id) {
|
|
100
|
-
if (isContentFlagImport(id)) {
|
|
127
|
+
if (isContentFlagImport(id, contentEntryExts)) {
|
|
101
128
|
return { code: escapeViteEnvReferences(code) };
|
|
102
129
|
}
|
|
103
130
|
}
|
|
@@ -2,8 +2,8 @@ import fsMod from "node:fs";
|
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { normalizePath } from "vite";
|
|
4
4
|
import { appendForwardSlash, prependForwardSlash } from "../core/path.js";
|
|
5
|
-
import {
|
|
6
|
-
import { getContentPaths } from "./utils.js";
|
|
5
|
+
import { VIRTUAL_MODULE_ID } from "./consts.js";
|
|
6
|
+
import { getContentEntryExts, getContentPaths } from "./utils.js";
|
|
7
7
|
function astroContentVirtualModPlugin({
|
|
8
8
|
settings
|
|
9
9
|
}) {
|
|
@@ -15,8 +15,11 @@ function astroContentVirtualModPlugin({
|
|
|
15
15
|
)
|
|
16
16
|
)
|
|
17
17
|
);
|
|
18
|
-
const
|
|
19
|
-
const
|
|
18
|
+
const contentEntryExts = getContentEntryExts(settings);
|
|
19
|
+
const assetsDir = settings.config.experimental.assets ? contentPaths.assetsDir.toString() : "undefined";
|
|
20
|
+
const extGlob = contentEntryExts.length === 1 ? contentEntryExts[0] : `{${contentEntryExts.join(",")}}`;
|
|
21
|
+
const entryGlob = `${relContentDir}**/*${extGlob}`;
|
|
22
|
+
const virtualModContents = fsMod.readFileSync(contentPaths.virtualModTemplate, "utf-8").replace("@@CONTENT_DIR@@", relContentDir).replace("@@ASSETS_DIR@@", assetsDir).replace("@@ENTRY_GLOB_PATH@@", entryGlob).replace("@@RENDER_ENTRY_GLOB_PATH@@", entryGlob);
|
|
20
23
|
const astroContentVirtualModuleId = "\0" + VIRTUAL_MODULE_ID;
|
|
21
24
|
return {
|
|
22
25
|
name: "astro-content-virtual-mod-plugin",
|
package/dist/core/add/index.js
CHANGED
|
@@ -421,7 +421,8 @@ async function updateAstroConfig({
|
|
|
421
421
|
let output = await generate(ast);
|
|
422
422
|
const comment = "// https://astro.build/config";
|
|
423
423
|
const defaultExport = "export default defineConfig";
|
|
424
|
-
output = output.replace(`
|
|
424
|
+
output = output.replace(`
|
|
425
|
+
${comment}`, "");
|
|
425
426
|
output = output.replace(`${defaultExport}`, `
|
|
426
427
|
${comment}
|
|
427
428
|
${defaultExport}`);
|
package/dist/core/app/index.js
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
var __accessCheck = (obj, member, msg) => {
|
|
2
|
-
if (!member.has(obj))
|
|
3
|
-
throw TypeError("Cannot " + msg);
|
|
4
|
-
};
|
|
5
|
-
var __privateGet = (obj, member, getter) => {
|
|
6
|
-
__accessCheck(obj, member, "read from private field");
|
|
7
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
8
|
-
};
|
|
9
|
-
var __privateAdd = (obj, member, value) => {
|
|
10
|
-
if (member.has(obj))
|
|
11
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
12
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
-
};
|
|
14
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
15
|
-
__accessCheck(obj, member, "write to private field");
|
|
16
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
|
-
return value;
|
|
18
|
-
};
|
|
19
|
-
var __privateMethod = (obj, member, method) => {
|
|
20
|
-
__accessCheck(obj, member, "access private method");
|
|
21
|
-
return method;
|
|
22
|
-
};
|
|
23
|
-
var _env, _manifest, _manifestData, _routeDataToRouteInfo, _encoder, _logging, _base, _baseWithoutTrailingSlash, _renderPage, renderPage_fn, _callEndpoint, callEndpoint_fn;
|
|
24
1
|
import mime from "mime";
|
|
25
2
|
import { attachToResponse, getSetCookiesFromResponse } from "../cookies/index.js";
|
|
26
3
|
import { call as callEndpoint } from "../endpoint/index.js";
|
|
@@ -42,28 +19,26 @@ import { deserializeManifest } from "./common.js";
|
|
|
42
19
|
const pagesVirtualModuleId = "@astrojs-pages-virtual-entry";
|
|
43
20
|
const resolvedPagesVirtualModuleId = "\0" + pagesVirtualModuleId;
|
|
44
21
|
class App {
|
|
22
|
+
#env;
|
|
23
|
+
#manifest;
|
|
24
|
+
#manifestData;
|
|
25
|
+
#routeDataToRouteInfo;
|
|
26
|
+
#encoder = new TextEncoder();
|
|
27
|
+
#logging = {
|
|
28
|
+
dest: consoleLogDestination,
|
|
29
|
+
level: "info"
|
|
30
|
+
};
|
|
31
|
+
#base;
|
|
32
|
+
#baseWithoutTrailingSlash;
|
|
45
33
|
constructor(manifest, streaming = true) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
__privateAdd(this, _env, void 0);
|
|
49
|
-
__privateAdd(this, _manifest, void 0);
|
|
50
|
-
__privateAdd(this, _manifestData, void 0);
|
|
51
|
-
__privateAdd(this, _routeDataToRouteInfo, void 0);
|
|
52
|
-
__privateAdd(this, _encoder, new TextEncoder());
|
|
53
|
-
__privateAdd(this, _logging, {
|
|
54
|
-
dest: consoleLogDestination,
|
|
55
|
-
level: "info"
|
|
56
|
-
});
|
|
57
|
-
__privateAdd(this, _base, void 0);
|
|
58
|
-
__privateAdd(this, _baseWithoutTrailingSlash, void 0);
|
|
59
|
-
__privateSet(this, _manifest, manifest);
|
|
60
|
-
__privateSet(this, _manifestData, {
|
|
34
|
+
this.#manifest = manifest;
|
|
35
|
+
this.#manifestData = {
|
|
61
36
|
routes: manifest.routes.map((route) => route.routeData)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
37
|
+
};
|
|
38
|
+
this.#routeDataToRouteInfo = new Map(manifest.routes.map((route) => [route.routeData, route]));
|
|
39
|
+
this.#env = createEnvironment({
|
|
65
40
|
adapterName: manifest.adapterName,
|
|
66
|
-
logging:
|
|
41
|
+
logging: this.#logging,
|
|
67
42
|
markdown: manifest.markdown,
|
|
68
43
|
mode: "production",
|
|
69
44
|
renderers: manifest.renderers,
|
|
@@ -82,33 +57,33 @@ class App {
|
|
|
82
57
|
}
|
|
83
58
|
}
|
|
84
59
|
},
|
|
85
|
-
routeCache: new RouteCache(
|
|
86
|
-
site:
|
|
60
|
+
routeCache: new RouteCache(this.#logging),
|
|
61
|
+
site: this.#manifest.site,
|
|
87
62
|
ssr: true,
|
|
88
63
|
streaming
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
|
|
64
|
+
});
|
|
65
|
+
this.#base = this.#manifest.base || "/";
|
|
66
|
+
this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#base);
|
|
92
67
|
}
|
|
93
68
|
removeBase(pathname) {
|
|
94
|
-
if (pathname.startsWith(
|
|
95
|
-
return pathname.slice(
|
|
69
|
+
if (pathname.startsWith(this.#base)) {
|
|
70
|
+
return pathname.slice(this.#baseWithoutTrailingSlash.length + 1);
|
|
96
71
|
}
|
|
97
72
|
return pathname;
|
|
98
73
|
}
|
|
99
74
|
match(request, { matchNotFound = false } = {}) {
|
|
100
75
|
const url = new URL(request.url);
|
|
101
|
-
if (
|
|
76
|
+
if (this.#manifest.assets.has(url.pathname)) {
|
|
102
77
|
return void 0;
|
|
103
78
|
}
|
|
104
79
|
let pathname = "/" + this.removeBase(url.pathname);
|
|
105
|
-
let routeData = matchRoute(pathname,
|
|
80
|
+
let routeData = matchRoute(pathname, this.#manifestData);
|
|
106
81
|
if (routeData) {
|
|
107
82
|
if (routeData.prerender)
|
|
108
83
|
return void 0;
|
|
109
84
|
return routeData;
|
|
110
85
|
} else if (matchNotFound) {
|
|
111
|
-
return matchRoute("/404",
|
|
86
|
+
return matchRoute("/404", this.#manifestData);
|
|
112
87
|
} else {
|
|
113
88
|
return void 0;
|
|
114
89
|
}
|
|
@@ -131,15 +106,20 @@ class App {
|
|
|
131
106
|
if (routeData.route === "/404") {
|
|
132
107
|
defaultStatus = 404;
|
|
133
108
|
}
|
|
134
|
-
let mod =
|
|
109
|
+
let mod = this.#manifest.pageMap.get(routeData.component);
|
|
135
110
|
if (routeData.type === "page") {
|
|
136
|
-
let response = await
|
|
111
|
+
let response = await this.#renderPage(request, routeData, mod, defaultStatus);
|
|
137
112
|
if (response.status === 500) {
|
|
138
|
-
const fiveHundredRouteData = matchRoute("/500",
|
|
113
|
+
const fiveHundredRouteData = matchRoute("/500", this.#manifestData);
|
|
139
114
|
if (fiveHundredRouteData) {
|
|
140
|
-
mod =
|
|
115
|
+
mod = this.#manifest.pageMap.get(fiveHundredRouteData.component);
|
|
141
116
|
try {
|
|
142
|
-
let fiveHundredResponse = await
|
|
117
|
+
let fiveHundredResponse = await this.#renderPage(
|
|
118
|
+
request,
|
|
119
|
+
fiveHundredRouteData,
|
|
120
|
+
mod,
|
|
121
|
+
500
|
|
122
|
+
);
|
|
143
123
|
return fiveHundredResponse;
|
|
144
124
|
} catch {
|
|
145
125
|
}
|
|
@@ -147,7 +127,7 @@ class App {
|
|
|
147
127
|
}
|
|
148
128
|
return response;
|
|
149
129
|
} else if (routeData.type === "endpoint") {
|
|
150
|
-
return
|
|
130
|
+
return this.#callEndpoint(request, routeData, mod, defaultStatus);
|
|
151
131
|
} else {
|
|
152
132
|
throw new Error(`Unsupported route type [${routeData.type}].`);
|
|
153
133
|
}
|
|
@@ -155,96 +135,86 @@ class App {
|
|
|
155
135
|
setCookieHeaders(response) {
|
|
156
136
|
return getSetCookiesFromResponse(response);
|
|
157
137
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
for (const script of info.scripts) {
|
|
175
|
-
if ("stage" in script) {
|
|
176
|
-
if (script.stage === "head-inline") {
|
|
177
|
-
scripts.add({
|
|
178
|
-
props: {},
|
|
179
|
-
children: script.children
|
|
180
|
-
});
|
|
138
|
+
async #renderPage(request, routeData, mod, status = 200) {
|
|
139
|
+
const url = new URL(request.url);
|
|
140
|
+
const pathname = "/" + this.removeBase(url.pathname);
|
|
141
|
+
const info = this.#routeDataToRouteInfo.get(routeData);
|
|
142
|
+
const links = createLinkStylesheetElementSet(info.links);
|
|
143
|
+
let scripts = /* @__PURE__ */ new Set();
|
|
144
|
+
for (const script of info.scripts) {
|
|
145
|
+
if ("stage" in script) {
|
|
146
|
+
if (script.stage === "head-inline") {
|
|
147
|
+
scripts.add({
|
|
148
|
+
props: {},
|
|
149
|
+
children: script.children
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
scripts.add(createModuleScriptElement(script));
|
|
181
154
|
}
|
|
182
|
-
}
|
|
183
|
-
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
const ctx = createRenderContext({
|
|
158
|
+
request,
|
|
159
|
+
origin: url.origin,
|
|
160
|
+
pathname,
|
|
161
|
+
propagation: this.#manifest.propagation,
|
|
162
|
+
scripts,
|
|
163
|
+
links,
|
|
164
|
+
route: routeData,
|
|
165
|
+
status
|
|
166
|
+
});
|
|
167
|
+
const response = await renderPage(mod, ctx, this.#env);
|
|
168
|
+
return response;
|
|
169
|
+
} catch (err) {
|
|
170
|
+
error(this.#logging, "ssr", err.stack || err.message || String(err));
|
|
171
|
+
return new Response(null, {
|
|
172
|
+
status: 500,
|
|
173
|
+
statusText: "Internal server error"
|
|
174
|
+
});
|
|
184
175
|
}
|
|
185
176
|
}
|
|
186
|
-
|
|
177
|
+
async #callEndpoint(request, routeData, mod, status = 200) {
|
|
178
|
+
const url = new URL(request.url);
|
|
179
|
+
const pathname = "/" + this.removeBase(url.pathname);
|
|
180
|
+
const handler = mod;
|
|
187
181
|
const ctx = createRenderContext({
|
|
188
182
|
request,
|
|
189
183
|
origin: url.origin,
|
|
190
184
|
pathname,
|
|
191
|
-
propagation: __privateGet(this, _manifest).propagation,
|
|
192
|
-
scripts,
|
|
193
|
-
links,
|
|
194
185
|
route: routeData,
|
|
195
186
|
status
|
|
196
187
|
});
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
_callEndpoint = new WeakSet();
|
|
208
|
-
callEndpoint_fn = async function(request, routeData, mod, status = 200) {
|
|
209
|
-
const url = new URL(request.url);
|
|
210
|
-
const pathname = "/" + this.removeBase(url.pathname);
|
|
211
|
-
const handler = mod;
|
|
212
|
-
const ctx = createRenderContext({
|
|
213
|
-
request,
|
|
214
|
-
origin: url.origin,
|
|
215
|
-
pathname,
|
|
216
|
-
route: routeData,
|
|
217
|
-
status
|
|
218
|
-
});
|
|
219
|
-
const result = await callEndpoint(handler, __privateGet(this, _env), ctx, __privateGet(this, _logging));
|
|
220
|
-
if (result.type === "response") {
|
|
221
|
-
if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
|
|
222
|
-
const fourOhFourRequest = new Request(new URL("/404", request.url));
|
|
223
|
-
const fourOhFourRouteData = this.match(fourOhFourRequest);
|
|
224
|
-
if (fourOhFourRouteData) {
|
|
225
|
-
return this.render(fourOhFourRequest, fourOhFourRouteData);
|
|
188
|
+
const result = await callEndpoint(handler, this.#env, ctx, this.#logging);
|
|
189
|
+
if (result.type === "response") {
|
|
190
|
+
if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
|
|
191
|
+
const fourOhFourRequest = new Request(new URL("/404", request.url));
|
|
192
|
+
const fourOhFourRouteData = this.match(fourOhFourRequest);
|
|
193
|
+
if (fourOhFourRouteData) {
|
|
194
|
+
return this.render(fourOhFourRequest, fourOhFourRouteData);
|
|
195
|
+
}
|
|
226
196
|
}
|
|
227
|
-
|
|
228
|
-
return result.response;
|
|
229
|
-
} else {
|
|
230
|
-
const body = result.body;
|
|
231
|
-
const headers = new Headers();
|
|
232
|
-
const mimeType = mime.getType(url.pathname);
|
|
233
|
-
if (mimeType) {
|
|
234
|
-
headers.set("Content-Type", `${mimeType};charset=utf-8`);
|
|
197
|
+
return result.response;
|
|
235
198
|
} else {
|
|
236
|
-
|
|
199
|
+
const body = result.body;
|
|
200
|
+
const headers = new Headers();
|
|
201
|
+
const mimeType = mime.getType(url.pathname);
|
|
202
|
+
if (mimeType) {
|
|
203
|
+
headers.set("Content-Type", `${mimeType};charset=utf-8`);
|
|
204
|
+
} else {
|
|
205
|
+
headers.set("Content-Type", "text/plain;charset=utf-8");
|
|
206
|
+
}
|
|
207
|
+
const bytes = this.#encoder.encode(body);
|
|
208
|
+
headers.set("Content-Length", bytes.byteLength.toString());
|
|
209
|
+
const response = new Response(bytes, {
|
|
210
|
+
status: 200,
|
|
211
|
+
headers
|
|
212
|
+
});
|
|
213
|
+
attachToResponse(response, result.cookies);
|
|
214
|
+
return response;
|
|
237
215
|
}
|
|
238
|
-
const bytes = __privateGet(this, _encoder).encode(body);
|
|
239
|
-
headers.set("Content-Length", bytes.byteLength.toString());
|
|
240
|
-
const response = new Response(bytes, {
|
|
241
|
-
status: 200,
|
|
242
|
-
headers
|
|
243
|
-
});
|
|
244
|
-
attachToResponse(response, result.cookies);
|
|
245
|
-
return response;
|
|
246
216
|
}
|
|
247
|
-
}
|
|
217
|
+
}
|
|
248
218
|
export {
|
|
249
219
|
App,
|
|
250
220
|
deserializeManifest,
|