astro 2.0.6 → 2.0.8
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} +22 -3
- 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/core/build/{vite-plugin-hoisted-scripts.js → plugins/plugin-hoisted-scripts.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { viteID } from "
|
|
2
|
-
import { getPageDataByViteID } from "
|
|
1
|
+
import { viteID } from "../../util.js";
|
|
2
|
+
import { getPageDataByViteID } from "../internal.js";
|
|
3
3
|
function virtualHoistedEntry(id) {
|
|
4
4
|
return id.startsWith("/astro/hoisted.js?q=");
|
|
5
5
|
}
|
|
@@ -65,6 +65,19 @@ function vitePluginHoistedScripts(settings, internals) {
|
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
+
function pluginHoistedScripts(options, internals) {
|
|
69
|
+
return {
|
|
70
|
+
build: "client",
|
|
71
|
+
hooks: {
|
|
72
|
+
"build:before": () => {
|
|
73
|
+
return {
|
|
74
|
+
vitePlugin: vitePluginHoistedScripts(options.settings, internals)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
68
80
|
export {
|
|
81
|
+
pluginHoistedScripts,
|
|
69
82
|
vitePluginHoistedScripts
|
|
70
83
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Plugin as VitePlugin } from 'vite';
|
|
2
|
+
import type { BuildInternals } from '../internal.js';
|
|
3
|
+
import type { AstroBuildPlugin } from '../plugin';
|
|
4
|
+
export declare function vitePluginInternals(input: Set<string>, internals: BuildInternals): VitePlugin;
|
|
5
|
+
export declare function pluginInternals(internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -29,7 +29,11 @@ function vitePluginInternals(input, internals) {
|
|
|
29
29
|
promises.push(
|
|
30
30
|
this.resolve(specifier).then((result) => {
|
|
31
31
|
if (result) {
|
|
32
|
-
mapping.
|
|
32
|
+
if (mapping.has(result.id)) {
|
|
33
|
+
mapping.get(result.id).add(specifier);
|
|
34
|
+
} else {
|
|
35
|
+
mapping.set(result.id, /* @__PURE__ */ new Set([specifier]));
|
|
36
|
+
}
|
|
33
37
|
}
|
|
34
38
|
})
|
|
35
39
|
);
|
|
@@ -37,8 +41,10 @@ function vitePluginInternals(input, internals) {
|
|
|
37
41
|
await Promise.all(promises);
|
|
38
42
|
for (const [, chunk] of Object.entries(bundle)) {
|
|
39
43
|
if (chunk.type === "chunk" && chunk.facadeModuleId) {
|
|
40
|
-
const
|
|
41
|
-
|
|
44
|
+
const specifiers = mapping.get(chunk.facadeModuleId) || /* @__PURE__ */ new Set([chunk.facadeModuleId]);
|
|
45
|
+
for (const specifier of specifiers) {
|
|
46
|
+
internals.entrySpecifierToBundleMap.set(specifier, chunk.fileName);
|
|
47
|
+
}
|
|
42
48
|
} else if (chunk.type === "chunk") {
|
|
43
49
|
for (const id of Object.keys(chunk.modules)) {
|
|
44
50
|
const pageData = internals.pagesByViteID.get(id);
|
|
@@ -51,6 +57,19 @@ function vitePluginInternals(input, internals) {
|
|
|
51
57
|
}
|
|
52
58
|
};
|
|
53
59
|
}
|
|
60
|
+
function pluginInternals(internals) {
|
|
61
|
+
return {
|
|
62
|
+
build: "both",
|
|
63
|
+
hooks: {
|
|
64
|
+
"build:before": ({ input }) => {
|
|
65
|
+
return {
|
|
66
|
+
vitePlugin: vitePluginInternals(input, internals)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
54
72
|
export {
|
|
73
|
+
pluginInternals,
|
|
55
74
|
vitePluginInternals
|
|
56
75
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plugin as VitePlugin } from 'vite';
|
|
2
|
+
import type { AstroBuildPlugin } from '../plugin';
|
|
3
|
+
import type { StaticBuildOptions } from '../types';
|
|
4
|
+
import { BuildInternals } from '../internal.js';
|
|
5
|
+
export declare function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): VitePlugin;
|
|
6
|
+
export declare function pluginPages(opts: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { pagesVirtualModuleId, resolvedPagesVirtualModuleId } from "
|
|
2
|
-
import { addRollupInput } from "
|
|
3
|
-
import { eachPageData, hasPrerenderedPages } from "
|
|
1
|
+
import { pagesVirtualModuleId, resolvedPagesVirtualModuleId } from "../../app/index.js";
|
|
2
|
+
import { addRollupInput } from "../add-rollup-input.js";
|
|
3
|
+
import { eachPageData, hasPrerenderedPages } from "../internal.js";
|
|
4
4
|
function vitePluginPages(opts, internals) {
|
|
5
5
|
return {
|
|
6
6
|
name: "@astro/plugin-build-pages",
|
|
@@ -42,6 +42,19 @@ export const renderers = [${rendererItems}];`;
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
+
function pluginPages(opts, internals) {
|
|
46
|
+
return {
|
|
47
|
+
build: "ssr",
|
|
48
|
+
hooks: {
|
|
49
|
+
"build:before": () => {
|
|
50
|
+
return {
|
|
51
|
+
vitePlugin: vitePluginPages(opts, internals)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
45
57
|
export {
|
|
58
|
+
pluginPages,
|
|
46
59
|
vitePluginPages
|
|
47
60
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plugin as VitePlugin } from 'vite';
|
|
2
|
+
import type { BuildInternals } from '../internal.js';
|
|
3
|
+
import type { AstroBuildPlugin } from '../plugin.js';
|
|
4
|
+
import type { StaticBuildOptions } from '../types';
|
|
5
|
+
export declare function vitePluginPrerender(opts: StaticBuildOptions, internals: BuildInternals): VitePlugin;
|
|
6
|
+
export declare function pluginPrerender(opts: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { extendManualChunks } from "./util.js";
|
|
2
|
+
function vitePluginPrerender(opts, internals) {
|
|
3
|
+
return {
|
|
4
|
+
name: "astro:rollup-plugin-prerender",
|
|
5
|
+
outputOptions(outputOptions) {
|
|
6
|
+
extendManualChunks(outputOptions, {
|
|
7
|
+
after(id, meta) {
|
|
8
|
+
var _a, _b, _c;
|
|
9
|
+
if (id.includes("astro/dist")) {
|
|
10
|
+
return "astro";
|
|
11
|
+
}
|
|
12
|
+
const pageInfo = internals.pagesByViteID.get(id);
|
|
13
|
+
if (pageInfo) {
|
|
14
|
+
if ((_c = (_b = (_a = meta.getModuleInfo(id)) == null ? void 0 : _a.meta.astro) == null ? void 0 : _b.pageOptions) == null ? void 0 : _c.prerender) {
|
|
15
|
+
return "prerender";
|
|
16
|
+
}
|
|
17
|
+
return `pages/all`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function pluginPrerender(opts, internals) {
|
|
25
|
+
return {
|
|
26
|
+
build: "ssr",
|
|
27
|
+
hooks: {
|
|
28
|
+
"build:before": () => {
|
|
29
|
+
return {
|
|
30
|
+
vitePlugin: vitePluginPrerender(opts, internals)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
pluginPrerender,
|
|
38
|
+
vitePluginPrerender
|
|
39
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin as VitePlugin } from 'vite';
|
|
2
|
+
import type { AstroAdapter } from '../../../@types/astro';
|
|
3
|
+
import type { BuildInternals } from '../internal.js';
|
|
4
|
+
import type { StaticBuildOptions } from '../types';
|
|
5
|
+
import { AstroBuildPlugin } from '../plugin';
|
|
6
|
+
export declare const virtualModuleId = "@astrojs-ssr-virtual-entry";
|
|
7
|
+
export declare function vitePluginSSR(internals: BuildInternals, adapter: AstroAdapter): VitePlugin;
|
|
8
|
+
export declare function injectManifest(buildOpts: StaticBuildOptions, internals: BuildInternals): Promise<string>;
|
|
9
|
+
export declare function pluginSSR(options: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import glob from "fast-glob";
|
|
2
|
-
import * as fs from "fs";
|
|
3
2
|
import { fileURLToPath } from "url";
|
|
4
|
-
import { getContentPaths } from "
|
|
5
|
-
import { runHookBuildSsr } from "
|
|
6
|
-
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "
|
|
7
|
-
import { pagesVirtualModuleId } from "
|
|
8
|
-
import { removeLeadingForwardSlash, removeTrailingForwardSlash } from "
|
|
9
|
-
import { serializeRouteData } from "
|
|
10
|
-
import { addRollupInput } from "
|
|
11
|
-
import { getOutFile, getOutFolder } from "
|
|
12
|
-
import { eachPrerenderedPageData, eachServerPageData, sortedCSS } from "
|
|
3
|
+
import { getContentPaths } from "../../../content/index.js";
|
|
4
|
+
import { runHookBuildSsr } from "../../../integrations/index.js";
|
|
5
|
+
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../../vite-plugin-scripts/index.js";
|
|
6
|
+
import { pagesVirtualModuleId } from "../../app/index.js";
|
|
7
|
+
import { removeLeadingForwardSlash, removeTrailingForwardSlash } from "../../path.js";
|
|
8
|
+
import { serializeRouteData } from "../../routing/index.js";
|
|
9
|
+
import { addRollupInput } from "../add-rollup-input.js";
|
|
10
|
+
import { getOutFile, getOutFolder } from "../common.js";
|
|
11
|
+
import { eachPrerenderedPageData, eachServerPageData, sortedCSS } from "../internal.js";
|
|
13
12
|
const virtualModuleId = "@astrojs-ssr-virtual-entry";
|
|
14
13
|
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
15
14
|
const manifestReplace = "@@ASTRO_MANIFEST_REPLACE@@";
|
|
@@ -21,7 +20,7 @@ function vitePluginSSR(internals, adapter) {
|
|
|
21
20
|
options(opts) {
|
|
22
21
|
return addRollupInput(opts, [virtualModuleId]);
|
|
23
22
|
},
|
|
24
|
-
resolveId(id) {
|
|
23
|
+
resolveId(id, parent) {
|
|
25
24
|
if (id === virtualModuleId) {
|
|
26
25
|
return resolvedVirtualModuleId;
|
|
27
26
|
}
|
|
@@ -93,12 +92,9 @@ async function injectManifest(buildOpts, internals) {
|
|
|
93
92
|
});
|
|
94
93
|
const chunk = internals.ssrEntryChunk;
|
|
95
94
|
const code = chunk.code;
|
|
96
|
-
|
|
95
|
+
return code.replace(replaceExp, () => {
|
|
97
96
|
return JSON.stringify(manifest);
|
|
98
97
|
});
|
|
99
|
-
const serverEntryURL = new URL(buildOpts.buildConfig.serverEntry, buildOpts.buildConfig.server);
|
|
100
|
-
await fs.promises.mkdir(new URL("./", serverEntryURL), { recursive: true });
|
|
101
|
-
await fs.promises.writeFile(serverEntryURL, chunk.code, "utf-8");
|
|
102
98
|
}
|
|
103
99
|
function buildManifest(opts, internals, staticFiles) {
|
|
104
100
|
const { settings } = opts;
|
|
@@ -174,14 +170,42 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
174
170
|
contentDir: getContentPaths(settings.config).contentDir
|
|
175
171
|
},
|
|
176
172
|
pageMap: null,
|
|
173
|
+
propagation: Array.from(internals.propagation),
|
|
177
174
|
renderers: [],
|
|
178
175
|
entryModules,
|
|
179
176
|
assets: staticFiles.map((s) => settings.config.base + s)
|
|
180
177
|
};
|
|
181
178
|
return ssrManifest;
|
|
182
179
|
}
|
|
180
|
+
function pluginSSR(options, internals) {
|
|
181
|
+
const ssr = options.settings.config.output === "server";
|
|
182
|
+
return {
|
|
183
|
+
build: "ssr",
|
|
184
|
+
hooks: {
|
|
185
|
+
"build:before": () => {
|
|
186
|
+
let vitePlugin = ssr ? vitePluginSSR(internals, options.settings.adapter) : void 0;
|
|
187
|
+
return {
|
|
188
|
+
enforce: "after-user-plugins",
|
|
189
|
+
vitePlugin
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
"build:post": async ({ mutate }) => {
|
|
193
|
+
if (!ssr) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (!internals.ssrEntryChunk) {
|
|
197
|
+
throw new Error(`Did not generate an entry chunk for SSR`);
|
|
198
|
+
}
|
|
199
|
+
internals.ssrEntryChunk.fileName = options.settings.config.build.serverEntry;
|
|
200
|
+
const code = await injectManifest(options, internals);
|
|
201
|
+
mutate(internals.ssrEntryChunk, "server", code);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
183
206
|
export {
|
|
184
207
|
injectManifest,
|
|
208
|
+
pluginSSR,
|
|
185
209
|
virtualModuleId,
|
|
186
210
|
vitePluginSSR
|
|
187
211
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin as VitePlugin } from 'vite';
|
|
2
|
+
type OutputOptionsHook = Extract<VitePlugin['outputOptions'], Function>;
|
|
3
|
+
type OutputOptions = Parameters<OutputOptionsHook>[0];
|
|
4
|
+
type ExtendManualChunksHooks = {
|
|
5
|
+
before?: (id: string, meta: any) => string | undefined;
|
|
6
|
+
after?: (id: string, meta: any) => string | undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare function extendManualChunks(outputOptions: OutputOptions, hooks: ExtendManualChunksHooks): void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function extendManualChunks(outputOptions, hooks) {
|
|
2
|
+
const manualChunks = outputOptions.manualChunks;
|
|
3
|
+
outputOptions.manualChunks = function(id, meta) {
|
|
4
|
+
if (hooks.before) {
|
|
5
|
+
let value = hooks.before(id, meta);
|
|
6
|
+
if (value) {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
if (typeof manualChunks == "object") {
|
|
11
|
+
if (id in manualChunks) {
|
|
12
|
+
let value = manualChunks[id];
|
|
13
|
+
return value[0];
|
|
14
|
+
}
|
|
15
|
+
} else if (typeof manualChunks === "function") {
|
|
16
|
+
const outid = manualChunks.call(this, id, meta);
|
|
17
|
+
if (outid) {
|
|
18
|
+
return outid;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (hooks.after) {
|
|
22
|
+
return hooks.after(id, meta) || null;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
extendManualChunks
|
|
29
|
+
};
|
|
@@ -4,7 +4,6 @@ import fs from "fs";
|
|
|
4
4
|
import { bgGreen, bgMagenta, black, dim } from "kleur/colors";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
6
|
import * as vite from "vite";
|
|
7
|
-
import { astroContentProdBundlePlugin } from "../../content/index.js";
|
|
8
7
|
import {
|
|
9
8
|
createBuildInternals,
|
|
10
9
|
eachPrerenderedPageData
|
|
@@ -20,16 +19,11 @@ import { info } from "../logger/core.js";
|
|
|
20
19
|
import { getOutDirWithinCwd } from "./common.js";
|
|
21
20
|
import { generatePages } from "./generate.js";
|
|
22
21
|
import { trackPageData } from "./internal.js";
|
|
22
|
+
import { createPluginContainer } from "./plugin.js";
|
|
23
|
+
import { registerAllPlugins } from "./plugins/index.js";
|
|
23
24
|
import { getTimeStat } from "./util.js";
|
|
24
|
-
import { vitePluginAliasResolve } from "./vite-plugin-alias-resolve.js";
|
|
25
|
-
import { vitePluginAnalyzer } from "./vite-plugin-analyzer.js";
|
|
26
|
-
import { rollupPluginAstroBuildCSS } from "./vite-plugin-css.js";
|
|
27
|
-
import { vitePluginHoistedScripts } from "./vite-plugin-hoisted-scripts.js";
|
|
28
|
-
import { vitePluginInternals } from "./vite-plugin-internals.js";
|
|
29
|
-
import { vitePluginPages } from "./vite-plugin-pages.js";
|
|
30
|
-
import { vitePluginPrerender } from "./vite-plugin-prerender.js";
|
|
31
|
-
import { injectManifest, vitePluginSSR } from "./vite-plugin-ssr.js";
|
|
32
25
|
async function staticBuild(opts) {
|
|
26
|
+
var _a, _b, _c;
|
|
33
27
|
const { allPages, settings } = opts;
|
|
34
28
|
if (isModeServerWithNoAdapter(opts.settings)) {
|
|
35
29
|
throw new AstroError(AstroErrorData.NoAdapterInstalled);
|
|
@@ -46,10 +40,14 @@ async function staticBuild(opts) {
|
|
|
46
40
|
pageInput.add(astroModuleId);
|
|
47
41
|
facadeIdToPageDataMap.set(fileURLToPath(astroModuleURL), pageData);
|
|
48
42
|
}
|
|
49
|
-
|
|
43
|
+
if (((_c = (_b = (_a = settings.config) == null ? void 0 : _a.vite) == null ? void 0 : _b.build) == null ? void 0 : _c.emptyOutDir) !== false) {
|
|
44
|
+
emptyDir(settings.config.outDir, new Set(".git"));
|
|
45
|
+
}
|
|
46
|
+
const container = createPluginContainer(opts, internals);
|
|
47
|
+
registerAllPlugins(container);
|
|
50
48
|
timer.ssr = performance.now();
|
|
51
49
|
info(opts.logging, "build", `Building ${settings.config.output} entrypoints...`);
|
|
52
|
-
await ssrBuild(opts, internals, pageInput);
|
|
50
|
+
const ssrOutput = await ssrBuild(opts, internals, pageInput, container);
|
|
53
51
|
info(opts.logging, "build", dim(`Completed in ${getTimeStat(timer.ssr, performance.now())}.`));
|
|
54
52
|
const rendererClientEntrypoints = settings.renderers.map((r) => r.clientEntrypoint).filter((a) => typeof a === "string");
|
|
55
53
|
const clientInput = /* @__PURE__ */ new Set([
|
|
@@ -62,8 +60,9 @@ async function staticBuild(opts) {
|
|
|
62
60
|
clientInput.add(PAGE_SCRIPT_ID);
|
|
63
61
|
}
|
|
64
62
|
timer.clientBuild = performance.now();
|
|
65
|
-
await clientBuild(opts, internals, clientInput);
|
|
63
|
+
const clientOutput = await clientBuild(opts, internals, clientInput, container);
|
|
66
64
|
timer.generate = performance.now();
|
|
65
|
+
await runPostBuildHooks(container, ssrOutput, clientOutput);
|
|
67
66
|
switch (settings.config.output) {
|
|
68
67
|
case "static": {
|
|
69
68
|
await generatePages(opts, internals);
|
|
@@ -71,7 +70,6 @@ async function staticBuild(opts) {
|
|
|
71
70
|
return;
|
|
72
71
|
}
|
|
73
72
|
case "server": {
|
|
74
|
-
await injectManifest(opts, internals);
|
|
75
73
|
await generatePages(opts, internals);
|
|
76
74
|
await cleanStaticOutput(opts, internals);
|
|
77
75
|
info(opts.logging, null, `
|
|
@@ -82,11 +80,12 @@ ${bgMagenta(black(" finalizing server assets "))}
|
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
82
|
}
|
|
85
|
-
async function ssrBuild(opts, internals, input) {
|
|
83
|
+
async function ssrBuild(opts, internals, input, container) {
|
|
86
84
|
var _a, _b, _c;
|
|
87
85
|
const { settings, viteConfig } = opts;
|
|
88
86
|
const ssr = settings.config.output === "server";
|
|
89
87
|
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(settings.config.outDir);
|
|
88
|
+
const { lastVitePlugins, vitePlugins } = container.runBeforeHook("ssr", input);
|
|
90
89
|
const viteBuildConfig = {
|
|
91
90
|
...viteConfig,
|
|
92
91
|
mode: viteConfig.mode || "production",
|
|
@@ -120,20 +119,7 @@ async function ssrBuild(opts, internals, input) {
|
|
|
120
119
|
modulePreload: { polyfill: false },
|
|
121
120
|
reportCompressedSize: false
|
|
122
121
|
},
|
|
123
|
-
plugins: [
|
|
124
|
-
vitePluginAnalyzer(internals),
|
|
125
|
-
vitePluginInternals(input, internals),
|
|
126
|
-
vitePluginPages(opts, internals),
|
|
127
|
-
rollupPluginAstroBuildCSS({
|
|
128
|
-
buildOptions: opts,
|
|
129
|
-
internals,
|
|
130
|
-
target: "server"
|
|
131
|
-
}),
|
|
132
|
-
vitePluginPrerender(opts, internals),
|
|
133
|
-
...viteConfig.plugins || [],
|
|
134
|
-
astroContentProdBundlePlugin({ internals }),
|
|
135
|
-
ssr && vitePluginSSR(internals, settings.adapter)
|
|
136
|
-
],
|
|
122
|
+
plugins: [...vitePlugins, ...viteConfig.plugins || [], ...lastVitePlugins],
|
|
137
123
|
envPrefix: viteConfig.envPrefix ?? "PUBLIC_",
|
|
138
124
|
base: settings.config.base
|
|
139
125
|
};
|
|
@@ -146,7 +132,7 @@ async function ssrBuild(opts, internals, input) {
|
|
|
146
132
|
});
|
|
147
133
|
return await vite.build(viteBuildConfig);
|
|
148
134
|
}
|
|
149
|
-
async function clientBuild(opts, internals, input) {
|
|
135
|
+
async function clientBuild(opts, internals, input, container) {
|
|
150
136
|
var _a, _b, _c;
|
|
151
137
|
const { settings, viteConfig } = opts;
|
|
152
138
|
const timer = performance.now();
|
|
@@ -158,6 +144,7 @@ async function clientBuild(opts, internals, input) {
|
|
|
158
144
|
}
|
|
159
145
|
return null;
|
|
160
146
|
}
|
|
147
|
+
const { lastVitePlugins, vitePlugins } = container.runBeforeHook("client", input);
|
|
161
148
|
info(opts.logging, null, `
|
|
162
149
|
${bgGreen(black(" building client "))}`);
|
|
163
150
|
const viteBuildConfig = {
|
|
@@ -182,17 +169,7 @@ ${bgGreen(black(" building client "))}`);
|
|
|
182
169
|
preserveEntrySignatures: "exports-only"
|
|
183
170
|
}
|
|
184
171
|
},
|
|
185
|
-
plugins: [
|
|
186
|
-
vitePluginAliasResolve(internals),
|
|
187
|
-
vitePluginInternals(input, internals),
|
|
188
|
-
vitePluginHoistedScripts(settings, internals),
|
|
189
|
-
rollupPluginAstroBuildCSS({
|
|
190
|
-
buildOptions: opts,
|
|
191
|
-
internals,
|
|
192
|
-
target: "client"
|
|
193
|
-
}),
|
|
194
|
-
...viteConfig.plugins || []
|
|
195
|
-
],
|
|
172
|
+
plugins: [...vitePlugins, ...viteConfig.plugins || [], ...lastVitePlugins],
|
|
196
173
|
envPrefix: viteConfig.envPrefix ?? "PUBLIC_",
|
|
197
174
|
base: settings.config.base
|
|
198
175
|
};
|
|
@@ -208,6 +185,17 @@ ${bgGreen(black(" building client "))}`);
|
|
|
208
185
|
`));
|
|
209
186
|
return buildResult;
|
|
210
187
|
}
|
|
188
|
+
async function runPostBuildHooks(container, ssrReturn, clientReturn) {
|
|
189
|
+
const mutations = await container.runPostHook(ssrReturn, clientReturn);
|
|
190
|
+
const config = container.options.settings.config;
|
|
191
|
+
const buildConfig = container.options.settings.config.build;
|
|
192
|
+
for (const [fileName, mutation] of mutations) {
|
|
193
|
+
const root = config.output === "server" ? mutation.build === "server" ? buildConfig.server : buildConfig.client : config.outDir;
|
|
194
|
+
const fileURL = new URL(fileName, root);
|
|
195
|
+
await fs.promises.mkdir(new URL("./", fileURL), { recursive: true });
|
|
196
|
+
await fs.promises.writeFile(fileURL, mutation.code, "utf-8");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
211
199
|
async function cleanStaticOutput(opts, internals) {
|
|
212
200
|
const allStaticFiles = /* @__PURE__ */ new Set();
|
|
213
201
|
for (const pageData of eachPrerenderedPageData(internals)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InlineConfig } from 'vite';
|
|
1
|
+
import type { default as vite, InlineConfig } from 'vite';
|
|
2
2
|
import type { AstroConfig, AstroSettings, BuildConfig, ComponentInstance, ManifestData, RouteData, RuntimeMode, SSRLoadedRenderer } from '../../@types/astro';
|
|
3
3
|
import type { LogOptions } from '../logger/core';
|
|
4
4
|
import type { RouteCache } from '../render/route-cache';
|
|
@@ -13,7 +13,8 @@ export interface PageBuildData {
|
|
|
13
13
|
depth: number;
|
|
14
14
|
order: number;
|
|
15
15
|
}>;
|
|
16
|
-
|
|
16
|
+
propagatedStyles: Map<string, Set<string>>;
|
|
17
|
+
propagatedScripts: Map<string, Set<string>>;
|
|
17
18
|
hoistedScript: {
|
|
18
19
|
type: 'inline' | 'external';
|
|
19
20
|
value: string;
|
|
@@ -37,3 +38,10 @@ export interface SingleFileBuiltModule {
|
|
|
37
38
|
pageMap: Map<ComponentPath, ComponentInstance>;
|
|
38
39
|
renderers: SSRLoadedRenderer[];
|
|
39
40
|
}
|
|
41
|
+
export type ViteBuildReturn = Awaited<ReturnType<typeof vite.build>>;
|
|
42
|
+
export type RollupOutput = Extract<Extract<ViteBuildReturn, Exclude<ViteBuildReturn, Array<any>>>, {
|
|
43
|
+
output: any;
|
|
44
|
+
}>;
|
|
45
|
+
export type OutputChunk = Extract<RollupOutput['output'][number], {
|
|
46
|
+
type: 'chunk';
|
|
47
|
+
}>;
|
package/dist/core/constants.js
CHANGED
package/dist/core/create-vite.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as vite from "vite";
|
|
|
4
4
|
import { crawlFrameworkPkgs } from "vitefu";
|
|
5
5
|
import {
|
|
6
6
|
astroContentAssetPropagationPlugin,
|
|
7
|
-
|
|
7
|
+
astroContentImportPlugin,
|
|
8
8
|
astroContentVirtualModPlugin
|
|
9
9
|
} from "../content/index.js";
|
|
10
10
|
import astroPostprocessVitePlugin from "../vite-plugin-astro-postprocess/index.js";
|
|
@@ -35,8 +35,11 @@ async function createVite(commandConfig, { settings, logging, mode, fs = nodeFs
|
|
|
35
35
|
isBuild: mode === "build",
|
|
36
36
|
viteUserConfig: settings.config.vite,
|
|
37
37
|
isFrameworkPkgByJson(pkgJson) {
|
|
38
|
-
var _a2, _b, _c, _d;
|
|
39
|
-
|
|
38
|
+
var _a2, _b, _c, _d, _e;
|
|
39
|
+
if (((_a2 = pkgJson == null ? void 0 : pkgJson.astro) == null ? void 0 : _a2.external) === true) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return ((_b = pkgJson.peerDependencies) == null ? void 0 : _b.astro) || ((_c = pkgJson.dependencies) == null ? void 0 : _c.astro) || ((_d = pkgJson.keywords) == null ? void 0 : _d.includes("astro")) || ((_e = pkgJson.keywords) == null ? void 0 : _e.includes("astro-component")) || /^(@[^\/]+\/)?astro\-/.test(pkgJson.name);
|
|
40
43
|
},
|
|
41
44
|
isFrameworkPkgByName(pkgName) {
|
|
42
45
|
const isNotAstroPkg = isCommonNotAstro(pkgName);
|
|
@@ -73,7 +76,7 @@ async function createVite(commandConfig, { settings, logging, mode, fs = nodeFs
|
|
|
73
76
|
astroScannerPlugin({ settings }),
|
|
74
77
|
astroInjectEnvTsPlugin({ settings, logging, fs }),
|
|
75
78
|
astroContentVirtualModPlugin({ settings }),
|
|
76
|
-
|
|
79
|
+
astroContentImportPlugin({ fs, settings }),
|
|
77
80
|
astroContentAssetPropagationPlugin({ mode })
|
|
78
81
|
],
|
|
79
82
|
publicDir: fileURLToPath(settings.config.publicDir),
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { performance } from "perf_hooks";
|
|
2
|
+
import { attachContentServerListeners } from "../../content/index.js";
|
|
2
3
|
import { info, warn } from "../logger/core.js";
|
|
3
4
|
import * as msg from "../messages.js";
|
|
4
5
|
import { startContainer } from "./container.js";
|
|
@@ -29,13 +30,14 @@ async function dev(settings, options) {
|
|
|
29
30
|
isRestart: options.isRestart
|
|
30
31
|
})
|
|
31
32
|
);
|
|
32
|
-
const currentVersion = "2.0.
|
|
33
|
+
const currentVersion = "2.0.8";
|
|
33
34
|
if (currentVersion.includes("-")) {
|
|
34
35
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
35
36
|
}
|
|
36
37
|
if (((_b = (_a = restart.container.viteConfig.server) == null ? void 0 : _a.fs) == null ? void 0 : _b.strict) === false) {
|
|
37
38
|
warn(options.logging, null, msg.fsStrictWarning());
|
|
38
39
|
}
|
|
40
|
+
await attachContentServerListeners(restart.container);
|
|
39
41
|
return {
|
|
40
42
|
address: devServerAddressInfo,
|
|
41
43
|
get watcher() {
|
|
@@ -373,6 +373,19 @@ export declare const AstroErrorData: {
|
|
|
373
373
|
readonly message: (name: string) => string;
|
|
374
374
|
readonly hint: "Astro components cannot be rendered directly via function call, such as `Component()` or `{items.map(Component)}`.";
|
|
375
375
|
};
|
|
376
|
+
/**
|
|
377
|
+
* @docs
|
|
378
|
+
* @see
|
|
379
|
+
* - [Pagination](https://docs.astro.build/en/core-concepts/routing/#pagination)
|
|
380
|
+
* @description
|
|
381
|
+
* The page number parameter was not found in your filepath.
|
|
382
|
+
*/
|
|
383
|
+
readonly PageNumberParamNotFound: {
|
|
384
|
+
readonly title: "Page number param not found.";
|
|
385
|
+
readonly code: 3021;
|
|
386
|
+
readonly message: (paramName: string) => string;
|
|
387
|
+
readonly hint: "Rename your file to `[page].astro` or `[...page].astro`.";
|
|
388
|
+
};
|
|
376
389
|
readonly UnknownViteError: {
|
|
377
390
|
readonly title: "Unknown Vite Error.";
|
|
378
391
|
readonly code: 4000;
|
|
@@ -139,6 +139,12 @@ Expected \`true\` value but got \`${suffix}\`.`;
|
|
|
139
139
|
message: (name) => `Invalid arguments passed to${name ? ` <${name}>` : ""} component.`,
|
|
140
140
|
hint: "Astro components cannot be rendered directly via function call, such as `Component()` or `{items.map(Component)}`."
|
|
141
141
|
},
|
|
142
|
+
PageNumberParamNotFound: {
|
|
143
|
+
title: "Page number param not found.",
|
|
144
|
+
code: 3021,
|
|
145
|
+
message: (paramName) => `[paginate()] page number param \`${paramName}\` not found in your filepath.`,
|
|
146
|
+
hint: "Rename your file to `[page].astro` or `[...page].astro`."
|
|
147
|
+
},
|
|
142
148
|
UnknownViteError: {
|
|
143
149
|
title: "Unknown Vite Error.",
|
|
144
150
|
code: 4e3
|
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.0.
|
|
50
|
+
const version = "2.0.8";
|
|
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.0.
|
|
236
|
+
`v${"2.0.8"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import path from "path";
|
|
2
1
|
import { viteID } from "../../util.js";
|
|
3
|
-
import {
|
|
2
|
+
import { isCSSRequest } from "./util.js";
|
|
4
3
|
import { crawlGraph } from "./vite.js";
|
|
5
4
|
async function getStylesForURL(filePath, loader, mode) {
|
|
6
5
|
const importedCssUrls = /* @__PURE__ */ new Set();
|
|
7
6
|
const importedStylesMap = /* @__PURE__ */ new Map();
|
|
8
7
|
for await (const importedModule of crawlGraph(loader, viteID(filePath), true)) {
|
|
9
|
-
|
|
10
|
-
if (STYLE_EXTENSIONS.has(ext)) {
|
|
8
|
+
if (isCSSRequest(importedModule.url)) {
|
|
11
9
|
let ssrModule;
|
|
12
10
|
try {
|
|
13
11
|
ssrModule = importedModule.ssrModule ?? await loader.import(importedModule.url);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { isCSSRequest } from "vite";
|
|
2
|
+
const rawRE = /(?:\?|&)raw(?:&|$)/;
|
|
3
|
+
const inlineRE = /(?:\?|&)inline\b/;
|
|
4
|
+
const isBuildableCSSRequest = (request) => isCSSRequest(request) && !rawRE.test(request) && !inlineRE.test(request);
|
|
5
|
+
export {
|
|
6
|
+
isBuildableCSSRequest,
|
|
7
|
+
isCSSRequest
|
|
8
|
+
};
|