astro 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/sync/index.js +19 -3
- package/dist/content/index.d.ts +3 -2
- package/dist/content/index.js +5 -7
- package/dist/content/internal.js +8 -1
- package/dist/content/server-listeners.d.ts +13 -0
- package/dist/content/server-listeners.js +65 -0
- package/dist/content/types-generator.d.ts +5 -3
- package/dist/content/types-generator.js +16 -29
- package/dist/content/utils.d.ts +12 -1
- package/dist/content/utils.js +36 -17
- package/dist/content/vite-plugin-content-assets.d.ts +3 -3
- package/dist/content/vite-plugin-content-assets.js +81 -22
- package/dist/content/vite-plugin-content-imports.d.ts +8 -0
- package/dist/content/vite-plugin-content-imports.js +105 -0
- package/dist/core/app/common.js +2 -0
- package/dist/core/app/index.js +1 -0
- package/dist/core/app/types.d.ts +4 -2
- package/dist/core/build/generate.js +1 -0
- package/dist/core/build/index.js +5 -0
- package/dist/core/build/internal.d.ts +2 -0
- package/dist/core/build/internal.js +2 -1
- package/dist/core/build/page-data.js +4 -2
- package/dist/core/build/plugin.d.ts +41 -0
- package/dist/core/build/plugin.js +82 -0
- package/dist/core/build/plugins/index.d.ts +2 -0
- package/dist/core/build/plugins/index.js +25 -0
- package/dist/core/build/{vite-plugin-alias-resolve.d.ts → plugins/plugin-alias-resolve.d.ts} +3 -1
- package/dist/core/build/{vite-plugin-alias-resolve.js → plugins/plugin-alias-resolve.js} +13 -0
- package/dist/core/build/plugins/plugin-analyzer.d.ts +5 -0
- package/dist/core/build/{vite-plugin-analyzer.js → plugins/plugin-analyzer.js} +63 -13
- package/dist/core/build/{vite-plugin-css.d.ts → plugins/plugin-css.d.ts} +4 -2
- package/dist/core/build/{vite-plugin-css.js → plugins/plugin-css.js} +37 -27
- package/dist/core/build/plugins/plugin-hoisted-scripts.d.ts +7 -0
- package/dist/core/build/{vite-plugin-hoisted-scripts.js → plugins/plugin-hoisted-scripts.js} +15 -2
- package/dist/core/build/plugins/plugin-internals.d.ts +5 -0
- package/dist/core/build/{vite-plugin-internals.js → plugins/plugin-internals.js} +13 -0
- package/dist/core/build/plugins/plugin-pages.d.ts +6 -0
- package/dist/core/build/{vite-plugin-pages.js → plugins/plugin-pages.js} +16 -3
- package/dist/core/build/plugins/plugin-prerender.d.ts +6 -0
- package/dist/core/build/plugins/plugin-prerender.js +39 -0
- package/dist/core/build/plugins/plugin-ssr.d.ts +9 -0
- package/dist/core/build/{vite-plugin-ssr.js → plugins/plugin-ssr.js} +39 -15
- package/dist/core/build/plugins/util.d.ts +9 -0
- package/dist/core/build/plugins/util.js +29 -0
- package/dist/core/build/static-build.js +28 -40
- package/dist/core/build/types.d.ts +10 -2
- package/dist/core/compile/compile.js +1 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +7 -4
- package/dist/core/dev/dev.js +3 -1
- package/dist/core/errors/errors-data.d.ts +13 -0
- package/dist/core/errors/errors-data.js +6 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/render/dev/css.js +2 -4
- package/dist/core/render/dev/util.d.ts +3 -0
- package/dist/core/render/dev/util.js +8 -0
- package/dist/core/render/dev/vite.js +3 -3
- package/dist/core/render/paginate.js +5 -4
- package/dist/core/render/result.js +13 -9
- package/dist/runtime/server/index.d.ts +2 -2
- package/dist/runtime/server/index.js +8 -0
- package/dist/runtime/server/jsx.js +4 -3
- package/dist/runtime/server/render/astro/factory.js +3 -3
- package/dist/runtime/server/render/astro/index.d.ts +1 -1
- package/dist/runtime/server/render/astro/instance.d.ts +2 -5
- package/dist/runtime/server/render/astro/instance.js +7 -4
- package/dist/runtime/server/render/common.js +20 -0
- package/dist/runtime/server/render/component.js +2 -1
- package/dist/runtime/server/render/head.d.ts +2 -1
- package/dist/runtime/server/render/head.js +2 -7
- package/dist/runtime/server/render/index.d.ts +3 -2
- package/dist/runtime/server/render/index.js +5 -0
- package/dist/runtime/server/render/page.js +3 -1
- package/dist/runtime/server/render/scope.d.ts +13 -0
- package/dist/runtime/server/render/scope.js +31 -0
- package/dist/runtime/server/render/slot.d.ts +6 -2
- package/dist/runtime/server/render/slot.js +7 -5
- package/dist/runtime/server/render/types.d.ts +6 -1
- package/dist/runtime/server/render/util.d.ts +0 -5
- package/dist/runtime/server/render/util.js +0 -6
- package/dist/vite-plugin-astro-server/route.js +1 -1
- package/dist/vite-plugin-head-propagation/index.d.ts +4 -0
- package/dist/vite-plugin-head-propagation/index.js +42 -0
- package/dist/vite-plugin-scanner/index.js +1 -0
- package/package.json +2 -2
- package/dist/content/vite-plugin-content-server.d.ts +0 -13
- package/dist/content/vite-plugin-content-server.js +0 -169
- package/dist/core/build/vite-plugin-analyzer.d.ts +0 -3
- package/dist/core/build/vite-plugin-hoisted-scripts.d.ts +0 -4
- package/dist/core/build/vite-plugin-internals.d.ts +0 -3
- package/dist/core/build/vite-plugin-pages.d.ts +0 -4
- package/dist/core/build/vite-plugin-prerender.d.ts +0 -4
- package/dist/core/build/vite-plugin-prerender.js +0 -34
- package/dist/core/build/vite-plugin-ssr.d.ts +0 -7
- package/dist/core/render/util.d.ts +0 -2
- package/dist/core/render/util.js +0 -18
package/dist/cli/sync/index.js
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
1
|
import { dim } from "kleur/colors";
|
|
2
2
|
import { performance } from "node:perf_hooks";
|
|
3
|
-
import {
|
|
3
|
+
import { createServer } from "vite";
|
|
4
|
+
import { createContentTypesGenerator } from "../../content/index.js";
|
|
5
|
+
import { globalContentConfigObserver } from "../../content/utils.js";
|
|
4
6
|
import { getTimeStat } from "../../core/build/util.js";
|
|
7
|
+
import { createVite } from "../../core/create-vite.js";
|
|
5
8
|
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
|
6
9
|
import { info } from "../../core/logger/core.js";
|
|
7
10
|
import { setUpEnvTs } from "../../vite-plugin-inject-env-ts/index.js";
|
|
8
11
|
async function sync(settings, { logging, fs }) {
|
|
9
12
|
const timerStart = performance.now();
|
|
13
|
+
const tempViteServer = await createServer(
|
|
14
|
+
await createVite(
|
|
15
|
+
{
|
|
16
|
+
server: { middlewareMode: true, hmr: false },
|
|
17
|
+
optimizeDeps: { entries: [] },
|
|
18
|
+
logLevel: "silent"
|
|
19
|
+
},
|
|
20
|
+
{ settings, logging, mode: "build", fs }
|
|
21
|
+
)
|
|
22
|
+
);
|
|
10
23
|
try {
|
|
11
24
|
const contentTypesGenerator = await createContentTypesGenerator({
|
|
12
|
-
contentConfigObserver:
|
|
25
|
+
contentConfigObserver: globalContentConfigObserver,
|
|
13
26
|
logging,
|
|
14
27
|
fs,
|
|
15
|
-
settings
|
|
28
|
+
settings,
|
|
29
|
+
viteServer: tempViteServer
|
|
16
30
|
});
|
|
17
31
|
const typesResult = await contentTypesGenerator.init();
|
|
18
32
|
if (typesResult.typesGenerated === false) {
|
|
@@ -25,6 +39,8 @@ async function sync(settings, { logging, fs }) {
|
|
|
25
39
|
}
|
|
26
40
|
} catch (e) {
|
|
27
41
|
throw new AstroError(AstroErrorData.GenerateContentTypesError);
|
|
42
|
+
} finally {
|
|
43
|
+
await tempViteServer.close();
|
|
28
44
|
}
|
|
29
45
|
info(logging, "content", `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`);
|
|
30
46
|
await setUpEnvTs({ settings, logging, fs });
|
package/dist/content/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export { attachContentServerListeners } from './server-listeners.js';
|
|
1
2
|
export { createContentTypesGenerator } from './types-generator.js';
|
|
2
3
|
export { contentObservable, getContentPaths, getDotAstroTypeReference } from './utils.js';
|
|
3
|
-
export { astroContentAssetPropagationPlugin
|
|
4
|
-
export {
|
|
4
|
+
export { astroContentAssetPropagationPlugin } from './vite-plugin-content-assets.js';
|
|
5
|
+
export { astroContentImportPlugin } from './vite-plugin-content-imports.js';
|
|
5
6
|
export { astroContentVirtualModPlugin } from './vite-plugin-content-virtual-mod.js';
|
package/dist/content/index.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
+
import { attachContentServerListeners } from "./server-listeners.js";
|
|
1
2
|
import { createContentTypesGenerator } from "./types-generator.js";
|
|
2
3
|
import { contentObservable, getContentPaths, getDotAstroTypeReference } from "./utils.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
astroContentProdBundlePlugin
|
|
6
|
-
} from "./vite-plugin-content-assets.js";
|
|
7
|
-
import { astroContentServerPlugin } from "./vite-plugin-content-server.js";
|
|
4
|
+
import { astroContentAssetPropagationPlugin } from "./vite-plugin-content-assets.js";
|
|
5
|
+
import { astroContentImportPlugin } from "./vite-plugin-content-imports.js";
|
|
8
6
|
import { astroContentVirtualModPlugin } from "./vite-plugin-content-virtual-mod.js";
|
|
9
7
|
export {
|
|
10
8
|
astroContentAssetPropagationPlugin,
|
|
11
|
-
|
|
12
|
-
astroContentServerPlugin,
|
|
9
|
+
astroContentImportPlugin,
|
|
13
10
|
astroContentVirtualModPlugin,
|
|
11
|
+
attachContentServerListeners,
|
|
14
12
|
contentObservable,
|
|
15
13
|
createContentTypesGenerator,
|
|
16
14
|
getContentPaths,
|
package/dist/content/internal.js
CHANGED
|
@@ -3,6 +3,7 @@ import { prependForwardSlash } from "../core/path.js";
|
|
|
3
3
|
import {
|
|
4
4
|
createComponent,
|
|
5
5
|
createHeadAndContent,
|
|
6
|
+
createScopedResult,
|
|
6
7
|
renderComponent,
|
|
7
8
|
renderScriptElement,
|
|
8
9
|
renderStyleElement,
|
|
@@ -139,7 +140,13 @@ async function render({
|
|
|
139
140
|
}
|
|
140
141
|
return createHeadAndContent(
|
|
141
142
|
unescapeHTML(styles + links + scripts),
|
|
142
|
-
renderTemplate`${renderComponent(
|
|
143
|
+
renderTemplate`${renderComponent(
|
|
144
|
+
createScopedResult(result),
|
|
145
|
+
"Content",
|
|
146
|
+
mod.Content,
|
|
147
|
+
props,
|
|
148
|
+
slots
|
|
149
|
+
)}`
|
|
143
150
|
);
|
|
144
151
|
},
|
|
145
152
|
propagation: "self"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type fsMod from 'node:fs';
|
|
3
|
+
import type { ViteDevServer } from 'vite';
|
|
4
|
+
import type { AstroSettings } from '../@types/astro.js';
|
|
5
|
+
import { LogOptions } from '../core/logger/core.js';
|
|
6
|
+
interface ContentServerListenerParams {
|
|
7
|
+
fs: typeof fsMod;
|
|
8
|
+
logging: LogOptions;
|
|
9
|
+
settings: AstroSettings;
|
|
10
|
+
viteServer: ViteDevServer;
|
|
11
|
+
}
|
|
12
|
+
export declare function attachContentServerListeners({ viteServer, fs, logging, settings, }: ContentServerListenerParams): Promise<void>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { cyan } from "kleur/colors";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { info } from "../core/logger/core.js";
|
|
4
|
+
import { appendForwardSlash } from "../core/path.js";
|
|
5
|
+
import { createContentTypesGenerator } from "./types-generator.js";
|
|
6
|
+
import { getContentPaths, globalContentConfigObserver } from "./utils.js";
|
|
7
|
+
async function attachContentServerListeners({
|
|
8
|
+
viteServer,
|
|
9
|
+
fs,
|
|
10
|
+
logging,
|
|
11
|
+
settings
|
|
12
|
+
}) {
|
|
13
|
+
const contentPaths = getContentPaths(settings.config);
|
|
14
|
+
if (fs.existsSync(contentPaths.contentDir)) {
|
|
15
|
+
info(
|
|
16
|
+
logging,
|
|
17
|
+
"content",
|
|
18
|
+
`Watching ${cyan(
|
|
19
|
+
contentPaths.contentDir.href.replace(settings.config.root.href, "")
|
|
20
|
+
)} for changes`
|
|
21
|
+
);
|
|
22
|
+
await attachListeners();
|
|
23
|
+
} else {
|
|
24
|
+
viteServer.watcher.on("addDir", contentDirListener);
|
|
25
|
+
async function contentDirListener(dir) {
|
|
26
|
+
if (appendForwardSlash(pathToFileURL(dir).href) === contentPaths.contentDir.href) {
|
|
27
|
+
info(logging, "content", `Content dir found. Watching for changes`);
|
|
28
|
+
await attachListeners();
|
|
29
|
+
viteServer.watcher.removeListener("addDir", contentDirListener);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function attachListeners() {
|
|
34
|
+
const contentGenerator = await createContentTypesGenerator({
|
|
35
|
+
fs,
|
|
36
|
+
settings,
|
|
37
|
+
logging,
|
|
38
|
+
viteServer,
|
|
39
|
+
contentConfigObserver: globalContentConfigObserver
|
|
40
|
+
});
|
|
41
|
+
await contentGenerator.init();
|
|
42
|
+
info(logging, "content", "Types generated");
|
|
43
|
+
viteServer.watcher.on("add", (entry) => {
|
|
44
|
+
contentGenerator.queueEvent({ name: "add", entry });
|
|
45
|
+
});
|
|
46
|
+
viteServer.watcher.on(
|
|
47
|
+
"addDir",
|
|
48
|
+
(entry) => contentGenerator.queueEvent({ name: "addDir", entry })
|
|
49
|
+
);
|
|
50
|
+
viteServer.watcher.on(
|
|
51
|
+
"change",
|
|
52
|
+
(entry) => contentGenerator.queueEvent({ name: "change", entry })
|
|
53
|
+
);
|
|
54
|
+
viteServer.watcher.on("unlink", (entry) => {
|
|
55
|
+
contentGenerator.queueEvent({ name: "unlink", entry });
|
|
56
|
+
});
|
|
57
|
+
viteServer.watcher.on(
|
|
58
|
+
"unlinkDir",
|
|
59
|
+
(entry) => contentGenerator.queueEvent({ name: "unlinkDir", entry })
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
attachContentServerListeners
|
|
65
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type fsMod from 'node:fs';
|
|
3
|
+
import { ViteDevServer } from 'vite';
|
|
3
4
|
import type { AstroSettings } from '../@types/astro.js';
|
|
4
5
|
import { LogOptions } from '../core/logger/core.js';
|
|
5
|
-
import { ContentObservable
|
|
6
|
+
import { ContentObservable } from './utils.js';
|
|
6
7
|
type ChokidarEvent = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir';
|
|
7
8
|
type RawContentEvent = {
|
|
8
9
|
name: ChokidarEvent;
|
|
@@ -12,12 +13,14 @@ type CreateContentGeneratorParams = {
|
|
|
12
13
|
contentConfigObserver: ContentObservable;
|
|
13
14
|
logging: LogOptions;
|
|
14
15
|
settings: AstroSettings;
|
|
16
|
+
/** This is required for loading the content config */
|
|
17
|
+
viteServer: ViteDevServer;
|
|
15
18
|
fs: typeof fsMod;
|
|
16
19
|
};
|
|
17
20
|
type EventOpts = {
|
|
18
21
|
logLevel: 'info' | 'warn';
|
|
19
22
|
};
|
|
20
|
-
export declare function createContentTypesGenerator({ contentConfigObserver, fs, logging, settings, }: CreateContentGeneratorParams): Promise<{
|
|
23
|
+
export declare function createContentTypesGenerator({ contentConfigObserver, fs, logging, settings, viteServer, }: CreateContentGeneratorParams): Promise<{
|
|
21
24
|
init: () => Promise<{
|
|
22
25
|
typesGenerated: true;
|
|
23
26
|
} | {
|
|
@@ -26,5 +29,4 @@ export declare function createContentTypesGenerator({ contentConfigObserver, fs,
|
|
|
26
29
|
}>;
|
|
27
30
|
queueEvent: (rawEvent: RawContentEvent, opts?: EventOpts) => void;
|
|
28
31
|
}>;
|
|
29
|
-
export declare function getEntryType(entryPath: string, paths: ContentPaths): 'content' | 'config' | 'unknown' | 'generated-types';
|
|
30
32
|
export {};
|
|
@@ -4,12 +4,13 @@ import * as path from "node:path";
|
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
import { normalizePath } from "vite";
|
|
6
6
|
import { info, warn } from "../core/logger/core.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { isRelativePath } from "../core/path.js";
|
|
8
|
+
import { CONTENT_TYPES_FILE } from "./consts.js";
|
|
9
9
|
import {
|
|
10
10
|
getContentPaths,
|
|
11
11
|
getEntryInfo,
|
|
12
12
|
getEntrySlug,
|
|
13
|
+
getEntryType,
|
|
13
14
|
loadContentConfig,
|
|
14
15
|
NoCollectionError,
|
|
15
16
|
parseFrontmatter
|
|
@@ -20,7 +21,8 @@ async function createContentTypesGenerator({
|
|
|
20
21
|
contentConfigObserver,
|
|
21
22
|
fs,
|
|
22
23
|
logging,
|
|
23
|
-
settings
|
|
24
|
+
settings,
|
|
25
|
+
viteServer
|
|
24
26
|
}) {
|
|
25
27
|
const contentTypes = {};
|
|
26
28
|
const contentPaths = getContentPaths(settings.config);
|
|
@@ -72,12 +74,12 @@ async function createContentTypesGenerator({
|
|
|
72
74
|
return { shouldGenerateTypes: true };
|
|
73
75
|
}
|
|
74
76
|
const fileType = getEntryType(fileURLToPath(event.entry), contentPaths);
|
|
75
|
-
if (fileType === "
|
|
77
|
+
if (fileType === "ignored") {
|
|
76
78
|
return { shouldGenerateTypes: false };
|
|
77
79
|
}
|
|
78
80
|
if (fileType === "config") {
|
|
79
81
|
contentConfigObserver.set({ status: "loading" });
|
|
80
|
-
const config = await loadContentConfig({ fs, settings });
|
|
82
|
+
const config = await loadContentConfig({ fs, settings, viteServer });
|
|
81
83
|
if (config) {
|
|
82
84
|
contentConfigObserver.set({ status: "loaded", config });
|
|
83
85
|
} else {
|
|
@@ -85,20 +87,19 @@ async function createContentTypesGenerator({
|
|
|
85
87
|
}
|
|
86
88
|
return { shouldGenerateTypes: true };
|
|
87
89
|
}
|
|
88
|
-
if (fileType === "
|
|
90
|
+
if (fileType === "unsupported") {
|
|
91
|
+
if (event.name === "unlink") {
|
|
92
|
+
return { shouldGenerateTypes: false };
|
|
93
|
+
}
|
|
89
94
|
const entryInfo2 = getEntryInfo({
|
|
90
95
|
entry: event.entry,
|
|
91
96
|
contentDir: contentPaths.contentDir,
|
|
92
97
|
allowFilesOutsideCollection: true
|
|
93
98
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
shouldGenerateTypes: false,
|
|
99
|
-
error: new UnsupportedFileTypeError(entryInfo2.id)
|
|
100
|
-
};
|
|
101
|
-
}
|
|
99
|
+
return {
|
|
100
|
+
shouldGenerateTypes: false,
|
|
101
|
+
error: new UnsupportedFileTypeError(entryInfo2.id)
|
|
102
|
+
};
|
|
102
103
|
}
|
|
103
104
|
const entryInfo = getEntryInfo({
|
|
104
105
|
entry: event.entry,
|
|
@@ -220,19 +221,6 @@ function setEntry(contentTypes, collectionKey, entryKey, slug) {
|
|
|
220
221
|
function removeEntry(contentTypes, collectionKey, entryKey) {
|
|
221
222
|
delete contentTypes[collectionKey][entryKey];
|
|
222
223
|
}
|
|
223
|
-
function getEntryType(entryPath, paths) {
|
|
224
|
-
const { dir: rawDir, ext, base } = path.parse(entryPath);
|
|
225
|
-
const dir = appendForwardSlash(pathToFileURL(rawDir).href);
|
|
226
|
-
if (contentFileExts.includes(ext)) {
|
|
227
|
-
return "content";
|
|
228
|
-
} else if (new URL(base, dir).href === paths.config.href) {
|
|
229
|
-
return "config";
|
|
230
|
-
} else if (new URL(base, dir).href === new URL(CONTENT_TYPES_FILE, paths.cacheDir).href) {
|
|
231
|
-
return "generated-types";
|
|
232
|
-
} else {
|
|
233
|
-
return "unknown";
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
224
|
async function writeContentFiles({
|
|
237
225
|
fs,
|
|
238
226
|
contentPaths,
|
|
@@ -299,6 +287,5 @@ function warnNonexistentCollections({
|
|
|
299
287
|
}
|
|
300
288
|
}
|
|
301
289
|
export {
|
|
302
|
-
createContentTypesGenerator
|
|
303
|
-
getEntryType
|
|
290
|
+
createContentTypesGenerator
|
|
304
291
|
};
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import matter from 'gray-matter';
|
|
3
3
|
import type fsMod from 'node:fs';
|
|
4
|
+
import { ViteDevServer } from 'vite';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
import { AstroConfig, AstroSettings } from '../@types/astro.js';
|
|
6
7
|
export declare const collectionConfigParser: z.ZodObject<{
|
|
@@ -60,16 +61,26 @@ export declare function getEntryInfo(params: Pick<ContentPaths, 'contentDir'> &
|
|
|
60
61
|
entry: URL;
|
|
61
62
|
allowFilesOutsideCollection?: true;
|
|
62
63
|
}): EntryInfo;
|
|
64
|
+
export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config'>): 'content' | 'config' | 'ignored' | 'unsupported';
|
|
63
65
|
/**
|
|
64
66
|
* Match YAML exception handling from Astro core errors
|
|
65
67
|
* @see 'astro/src/core/errors.ts'
|
|
66
68
|
*/
|
|
67
69
|
export declare function parseFrontmatter(fileContents: string, filePath: string): matter.GrayMatterFile<string>;
|
|
68
|
-
|
|
70
|
+
/**
|
|
71
|
+
* The content config is loaded separately from other `src/` files.
|
|
72
|
+
* This global observable lets dependent plugins (like the content flag plugin)
|
|
73
|
+
* subscribe to changes during dev server updates.
|
|
74
|
+
*/
|
|
75
|
+
export declare const globalContentConfigObserver: ContentObservable;
|
|
76
|
+
export declare function loadContentConfig({ fs, settings, viteServer, }: {
|
|
69
77
|
fs: typeof fsMod;
|
|
70
78
|
settings: AstroSettings;
|
|
79
|
+
viteServer: ViteDevServer;
|
|
71
80
|
}): Promise<ContentConfig | undefined>;
|
|
72
81
|
type ContentCtx = {
|
|
82
|
+
status: 'init';
|
|
83
|
+
} | {
|
|
73
84
|
status: 'loading';
|
|
74
85
|
} | {
|
|
75
86
|
status: 'error';
|
package/dist/content/utils.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { slug as githubSlug } from "github-slugger";
|
|
2
2
|
import matter from "gray-matter";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import {
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
+
import { normalizePath } from "vite";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { appendForwardSlash } from "../core/path.js";
|
|
9
|
+
import { contentFileExts, CONTENT_TYPES_FILE } from "./consts.js";
|
|
10
10
|
const collectionConfigParser = z.object({
|
|
11
11
|
schema: z.any().optional()
|
|
12
12
|
});
|
|
@@ -103,6 +103,32 @@ function getEntryInfo({
|
|
|
103
103
|
};
|
|
104
104
|
return res;
|
|
105
105
|
}
|
|
106
|
+
function getEntryType(entryPath, paths) {
|
|
107
|
+
const { dir: rawDir, ext, base } = path.parse(entryPath);
|
|
108
|
+
const dir = appendForwardSlash(pathToFileURL(rawDir).href);
|
|
109
|
+
const fileUrl = new URL(base, dir);
|
|
110
|
+
if (hasUnderscoreInPath(fileUrl) || isOnIgnoreList(fileUrl)) {
|
|
111
|
+
return "ignored";
|
|
112
|
+
} else if (contentFileExts.includes(ext)) {
|
|
113
|
+
return "content";
|
|
114
|
+
} else if (fileUrl.href === paths.config.href) {
|
|
115
|
+
return "config";
|
|
116
|
+
} else {
|
|
117
|
+
return "unsupported";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function isOnIgnoreList(fileUrl) {
|
|
121
|
+
const { base } = path.parse(fileURLToPath(fileUrl));
|
|
122
|
+
return [".DS_Store"].includes(base);
|
|
123
|
+
}
|
|
124
|
+
function hasUnderscoreInPath(fileUrl) {
|
|
125
|
+
const parts = fileUrl.pathname.split("/");
|
|
126
|
+
for (const part of parts) {
|
|
127
|
+
if (part.startsWith("_"))
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
106
132
|
const flattenErrorPath = (errorPath) => errorPath.join(".");
|
|
107
133
|
const errorMap = (error, ctx) => {
|
|
108
134
|
if (error.code === "invalid_type") {
|
|
@@ -140,31 +166,22 @@ function parseFrontmatter(fileContents, filePath) {
|
|
|
140
166
|
}
|
|
141
167
|
}
|
|
142
168
|
}
|
|
169
|
+
const globalContentConfigObserver = contentObservable({ status: "init" });
|
|
143
170
|
async function loadContentConfig({
|
|
144
171
|
fs,
|
|
145
|
-
settings
|
|
172
|
+
settings,
|
|
173
|
+
viteServer
|
|
146
174
|
}) {
|
|
147
175
|
const contentPaths = getContentPaths(settings.config);
|
|
148
|
-
const tempConfigServer = await createServer({
|
|
149
|
-
root: fileURLToPath(settings.config.root),
|
|
150
|
-
server: { middlewareMode: true, hmr: false },
|
|
151
|
-
optimizeDeps: { entries: [] },
|
|
152
|
-
clearScreen: false,
|
|
153
|
-
appType: "custom",
|
|
154
|
-
logLevel: "silent",
|
|
155
|
-
plugins: [astroContentVirtualModPlugin({ settings })]
|
|
156
|
-
});
|
|
157
176
|
let unparsedConfig;
|
|
158
177
|
if (!fs.existsSync(contentPaths.config)) {
|
|
159
178
|
return void 0;
|
|
160
179
|
}
|
|
161
180
|
try {
|
|
162
181
|
const configPathname = fileURLToPath(contentPaths.config);
|
|
163
|
-
unparsedConfig = await
|
|
182
|
+
unparsedConfig = await viteServer.ssrLoadModule(configPathname);
|
|
164
183
|
} catch (e) {
|
|
165
184
|
throw e;
|
|
166
|
-
} finally {
|
|
167
|
-
await tempConfigServer.close();
|
|
168
185
|
}
|
|
169
186
|
const config = contentConfigParser.safeParse(unparsedConfig);
|
|
170
187
|
if (config.success) {
|
|
@@ -218,6 +235,8 @@ export {
|
|
|
218
235
|
getEntryData,
|
|
219
236
|
getEntryInfo,
|
|
220
237
|
getEntrySlug,
|
|
238
|
+
getEntryType,
|
|
239
|
+
globalContentConfigObserver,
|
|
221
240
|
loadContentConfig,
|
|
222
241
|
msg,
|
|
223
242
|
parseFrontmatter
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
2
|
import { BuildInternals } from '../core/build/internal.js';
|
|
3
|
+
import { AstroBuildPlugin } from '../core/build/plugin.js';
|
|
4
|
+
import type { StaticBuildOptions } from '../core/build/types';
|
|
3
5
|
export declare function astroContentAssetPropagationPlugin({ mode }: {
|
|
4
6
|
mode: string;
|
|
5
7
|
}): Plugin;
|
|
6
|
-
export declare function
|
|
7
|
-
internals: BuildInternals;
|
|
8
|
-
}): Plugin;
|
|
8
|
+
export declare function astroConfigBuildPlugin(options: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import npath from "node:path";
|
|
1
2
|
import { pathToFileURL } from "url";
|
|
2
3
|
import { moduleIsTopLevelPage, walkParentInfos } from "../core/build/graph.js";
|
|
3
4
|
import { getPageDataByViteID } from "../core/build/internal.js";
|
|
4
5
|
import { createViteLoader } from "../core/module-loader/vite.js";
|
|
6
|
+
import { prependForwardSlash } from "../core/path.js";
|
|
5
7
|
import { getStylesForURL } from "../core/render/dev/css.js";
|
|
6
8
|
import { getScriptsForURL } from "../core/render/dev/scripts.js";
|
|
7
9
|
import {
|
|
@@ -61,29 +63,86 @@ function astroContentAssetPropagationPlugin({ mode }) {
|
|
|
61
63
|
}
|
|
62
64
|
};
|
|
63
65
|
}
|
|
64
|
-
function
|
|
66
|
+
function astroConfigBuildPlugin(options, internals) {
|
|
67
|
+
let ssrPluginContext = void 0;
|
|
65
68
|
return {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
build: "ssr",
|
|
70
|
+
hooks: {
|
|
71
|
+
"build:before": ({ build }) => {
|
|
72
|
+
return {
|
|
73
|
+
vitePlugin: {
|
|
74
|
+
name: "astro:content-build-plugin",
|
|
75
|
+
generateBundle() {
|
|
76
|
+
if (build === "ssr") {
|
|
77
|
+
ssrPluginContext = this;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
"build:post": ({ ssrOutputs, clientOutputs, mutate }) => {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
const outputs = ssrOutputs.flatMap((o) => o.output);
|
|
86
|
+
for (const chunk of outputs) {
|
|
87
|
+
if (chunk.type === "chunk" && (chunk.code.includes(LINKS_PLACEHOLDER) || chunk.code.includes(SCRIPTS_PLACEHOLDER))) {
|
|
88
|
+
let entryCSS = /* @__PURE__ */ new Set();
|
|
89
|
+
let entryScripts = /* @__PURE__ */ new Set();
|
|
90
|
+
for (const id of Object.keys(chunk.modules)) {
|
|
91
|
+
for (const [pageInfo] of walkParentInfos(id, ssrPluginContext)) {
|
|
92
|
+
if (moduleIsTopLevelPage(pageInfo)) {
|
|
93
|
+
const pageViteID = pageInfo.id;
|
|
94
|
+
const pageData = getPageDataByViteID(internals, pageViteID);
|
|
95
|
+
if (!pageData)
|
|
96
|
+
continue;
|
|
97
|
+
const _entryCss = (_a = pageData.propagatedStyles) == null ? void 0 : _a.get(id);
|
|
98
|
+
const _entryScripts = (_b = pageData.propagatedScripts) == null ? void 0 : _b.get(id);
|
|
99
|
+
if (_entryCss) {
|
|
100
|
+
for (const value of _entryCss) {
|
|
101
|
+
entryCSS.add(value);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (_entryScripts) {
|
|
105
|
+
for (const value of _entryScripts) {
|
|
106
|
+
entryScripts.add(value);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
let newCode = chunk.code;
|
|
113
|
+
if (entryCSS.size) {
|
|
114
|
+
newCode = newCode.replace(
|
|
115
|
+
JSON.stringify(LINKS_PLACEHOLDER),
|
|
116
|
+
JSON.stringify([...entryCSS])
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
if (entryScripts.size) {
|
|
120
|
+
const entryFileNames = /* @__PURE__ */ new Set();
|
|
121
|
+
for (const output of clientOutputs) {
|
|
122
|
+
for (const clientChunk of output.output) {
|
|
123
|
+
if (clientChunk.type !== "chunk")
|
|
124
|
+
continue;
|
|
125
|
+
for (const [id] of Object.entries(clientChunk.modules)) {
|
|
126
|
+
if (entryScripts.has(id)) {
|
|
127
|
+
entryFileNames.add(clientChunk.fileName);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
85
131
|
}
|
|
132
|
+
newCode = newCode.replace(
|
|
133
|
+
JSON.stringify(SCRIPTS_PLACEHOLDER),
|
|
134
|
+
JSON.stringify(
|
|
135
|
+
[...entryFileNames].map((src) => ({
|
|
136
|
+
props: {
|
|
137
|
+
src: prependForwardSlash(npath.posix.join(options.settings.config.base, src)),
|
|
138
|
+
type: "module"
|
|
139
|
+
},
|
|
140
|
+
children: ""
|
|
141
|
+
}))
|
|
142
|
+
)
|
|
143
|
+
);
|
|
86
144
|
}
|
|
145
|
+
mutate(chunk, "server", newCode);
|
|
87
146
|
}
|
|
88
147
|
}
|
|
89
148
|
}
|
|
@@ -91,6 +150,6 @@ function astroContentProdBundlePlugin({ internals }) {
|
|
|
91
150
|
};
|
|
92
151
|
}
|
|
93
152
|
export {
|
|
94
|
-
|
|
95
|
-
|
|
153
|
+
astroConfigBuildPlugin,
|
|
154
|
+
astroContentAssetPropagationPlugin
|
|
96
155
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type fsMod from 'node:fs';
|
|
3
|
+
import type { Plugin } from 'vite';
|
|
4
|
+
import { AstroSettings } from '../@types/astro.js';
|
|
5
|
+
export declare function astroContentImportPlugin({ fs, settings, }: {
|
|
6
|
+
fs: typeof fsMod;
|
|
7
|
+
settings: AstroSettings;
|
|
8
|
+
}): Plugin;
|