astro 3.4.4 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +86 -0
- package/components/Code.astro +15 -2
- package/components/Picture.astro +2 -1
- package/components/ViewTransitions.astro +39 -38
- package/content-module.template.mjs +4 -14
- package/dist/@types/astro.d.ts +227 -5
- package/dist/assets/build/generate.d.ts +2 -1
- package/dist/assets/build/generate.js +16 -5
- package/dist/assets/consts.d.ts +1 -0
- package/dist/assets/consts.js +2 -0
- package/dist/assets/endpoint/generic.js +6 -2
- package/dist/assets/internal.js +9 -2
- package/dist/assets/services/service.d.ts +8 -3
- package/dist/assets/services/service.js +2 -1
- package/dist/assets/services/vendor/squoosh/image-pool.d.ts +1 -2
- package/dist/assets/types.d.ts +9 -5
- package/dist/assets/utils/emitAsset.js +5 -0
- package/dist/assets/utils/metadata.d.ts +1 -2
- package/dist/assets/utils/proxy.d.ts +1 -0
- package/dist/assets/utils/proxy.js +16 -0
- package/dist/assets/utils/queryParams.d.ts +1 -1
- package/dist/assets/utils/transformToPath.d.ts +1 -1
- package/dist/assets/utils/transformToPath.js +8 -3
- package/dist/assets/vite-plugin-assets.js +33 -12
- package/dist/cli/build/index.js +1 -1
- package/dist/cli/info/index.js +7 -3
- package/dist/content/consts.d.ts +1 -0
- package/dist/content/consts.js +2 -0
- package/dist/content/runtime-assets.d.ts +9 -1
- package/dist/content/runtime-assets.js +1 -1
- package/dist/content/runtime.d.ts +1 -0
- package/dist/content/runtime.js +8 -2
- package/dist/content/utils.d.ts +1 -0
- package/dist/content/utils.js +9 -0
- package/dist/content/vite-plugin-content-assets.js +49 -23
- package/dist/content/vite-plugin-content-imports.js +9 -3
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +17 -12
- package/dist/content/vite-plugin-content-virtual-mod.js +136 -57
- package/dist/core/app/index.js +19 -4
- package/dist/core/app/types.d.ts +7 -1
- package/dist/core/build/buildPipeline.js +17 -4
- package/dist/core/build/common.js +2 -0
- package/dist/core/build/generate.js +64 -34
- package/dist/core/build/index.d.ts +0 -8
- package/dist/core/build/index.js +9 -2
- package/dist/core/build/internal.d.ts +11 -1
- package/dist/core/build/internal.js +23 -1
- package/dist/core/build/page-data.js +46 -18
- package/dist/core/build/plugin.d.ts +12 -10
- package/dist/core/build/plugin.js +14 -22
- package/dist/core/build/plugins/index.js +4 -0
- package/dist/core/build/plugins/plugin-alias-resolve.js +1 -1
- package/dist/core/build/plugins/plugin-analyzer.js +1 -1
- package/dist/core/build/plugins/plugin-chunks.d.ts +4 -0
- package/dist/core/build/plugins/plugin-chunks.js +31 -0
- package/dist/core/build/plugins/plugin-component-entry.js +1 -1
- package/dist/core/build/plugins/plugin-content.d.ts +4 -0
- package/dist/core/build/plugins/plugin-content.js +273 -0
- package/dist/core/build/plugins/plugin-css.js +9 -4
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +1 -1
- package/dist/core/build/plugins/plugin-internals.js +1 -1
- package/dist/core/build/plugins/plugin-manifest.js +14 -5
- package/dist/core/build/plugins/plugin-middleware.d.ts +1 -3
- package/dist/core/build/plugins/plugin-middleware.js +5 -57
- package/dist/core/build/plugins/plugin-pages.js +3 -3
- package/dist/core/build/plugins/plugin-prerender.js +2 -5
- package/dist/core/build/plugins/plugin-renderers.js +1 -1
- package/dist/core/build/plugins/plugin-ssr.js +6 -5
- package/dist/core/build/plugins/util.d.ts +3 -3
- package/dist/core/build/static-build.d.ts +2 -1
- package/dist/core/build/static-build.js +52 -28
- package/dist/core/build/types.d.ts +1 -1
- package/dist/core/build/util.d.ts +7 -0
- package/dist/core/build/util.js +37 -1
- package/dist/core/compile/compile.js +1 -0
- package/dist/core/config/config.js +3 -0
- package/dist/core/config/schema.d.ts +208 -0
- package/dist/core/config/schema.js +55 -2
- package/dist/core/config/settings.js +1 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +9 -3
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/index.d.ts +4 -3
- package/dist/core/endpoint/index.js +29 -3
- package/dist/core/errors/errors-data.d.ts +11 -0
- package/dist/core/errors/errors-data.js +17 -0
- package/dist/core/logger/node.js +1 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/index.d.ts +7 -3
- package/dist/core/middleware/index.js +3 -2
- package/dist/core/middleware/loadMiddleware.d.ts +1 -2
- package/dist/core/middleware/loadMiddleware.js +3 -4
- package/dist/core/middleware/sequence.d.ts +2 -2
- package/dist/core/middleware/sequence.js +3 -2
- package/dist/core/middleware/vite-plugin.d.ts +9 -0
- package/dist/core/middleware/vite-plugin.js +101 -0
- package/dist/core/pipeline.d.ts +1 -1
- package/dist/core/pipeline.js +6 -4
- package/dist/core/redirects/helpers.d.ts +1 -0
- package/dist/core/redirects/helpers.js +4 -0
- package/dist/core/render/context.d.ts +24 -1
- package/dist/core/render/context.js +96 -2
- package/dist/core/render/core.d.ts +2 -14
- package/dist/core/render/core.js +12 -52
- package/dist/core/render/index.d.ts +2 -3
- package/dist/core/render/index.js +3 -4
- package/dist/core/render/params-and-props.d.ts +1 -1
- package/dist/core/render/params-and-props.js +5 -2
- package/dist/core/render/result.d.ts +1 -0
- package/dist/core/render/result.js +23 -0
- package/dist/core/render/route-cache.d.ts +1 -1
- package/dist/core/render/route-cache.js +6 -2
- package/dist/core/routing/manifest/create.js +117 -4
- package/dist/core/sync/index.d.ts +2 -24
- package/dist/i18n/index.d.ts +54 -0
- package/dist/i18n/index.js +91 -0
- package/dist/i18n/middleware.d.ts +2 -0
- package/dist/i18n/middleware.js +62 -0
- package/dist/i18n/vite-plugin-i18n.d.ts +7 -0
- package/dist/i18n/vite-plugin-i18n.js +62 -0
- package/dist/integrations/astroFeaturesValidation.js +4 -1
- package/dist/integrations/index.js +12 -0
- package/dist/prefetch/index.d.ts +31 -0
- package/dist/prefetch/index.js +176 -0
- package/dist/prefetch/vite-plugin-prefetch.d.ts +5 -0
- package/dist/prefetch/vite-plugin-prefetch.js +43 -0
- package/dist/runtime/client/dev-overlay/plugins/audit.js +17 -9
- package/dist/runtime/server/index.d.ts +0 -2
- package/dist/runtime/server/render/component.js +3 -5
- package/dist/transitions/router.d.ts +1 -0
- package/dist/transitions/router.js +9 -4
- package/dist/transitions/vite-plugin-transitions.d.ts +4 -1
- package/dist/transitions/vite-plugin-transitions.js +7 -1
- package/dist/vite-plugin-astro-server/devPipeline.d.ts +1 -0
- package/dist/vite-plugin-astro-server/devPipeline.js +2 -0
- package/dist/vite-plugin-astro-server/plugin.js +11 -1
- package/dist/vite-plugin-astro-server/route.js +113 -51
- package/dist/vite-plugin-head/index.js +1 -1
- package/dist/vite-plugin-markdown/index.js +1 -0
- package/package.json +8 -6
- package/tsconfigs/base.json +1 -1
- package/dist/core/endpoint/dev/index.d.ts +0 -2
- package/dist/core/endpoint/dev/index.js +0 -17
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Rollup } from 'vite';
|
|
2
2
|
import type { RouteData, SSRResult } from '../../@types/astro.js';
|
|
3
3
|
import type { PageOptions } from '../../vite-plugin-astro/types.js';
|
|
4
|
-
import type { PageBuildData, StylesheetAsset, ViteID } from './types.js';
|
|
4
|
+
import type { AllPagesData, PageBuildData, StylesheetAsset, ViteID } from './types.js';
|
|
5
5
|
export interface BuildInternals {
|
|
6
6
|
/**
|
|
7
7
|
* Each CSS module is named with a chunk id derived from the Astro pages they
|
|
@@ -20,8 +20,14 @@ export interface BuildInternals {
|
|
|
20
20
|
pageToBundleMap: Map<string, string>;
|
|
21
21
|
/**
|
|
22
22
|
* A map for page-specific information.
|
|
23
|
+
* // TODO: Remove in Astro 4.0
|
|
24
|
+
* @deprecated
|
|
23
25
|
*/
|
|
24
26
|
pagesByComponent: Map<string, PageBuildData>;
|
|
27
|
+
/**
|
|
28
|
+
* TODO: Use this in Astro 4.0
|
|
29
|
+
*/
|
|
30
|
+
pagesByComponents: Map<string, PageBuildData[]>;
|
|
25
31
|
/**
|
|
26
32
|
* A map for page-specific output.
|
|
27
33
|
*/
|
|
@@ -59,6 +65,9 @@ export interface BuildInternals {
|
|
|
59
65
|
* These will be used as the top-level entrypoints for the client build.
|
|
60
66
|
*/
|
|
61
67
|
discoveredScripts: Set<string>;
|
|
68
|
+
cachedClientEntries: string[];
|
|
69
|
+
propagatedStylesMap: Map<string, Set<StylesheetAsset>>;
|
|
70
|
+
propagatedScriptsMap: Map<string, Set<string>>;
|
|
62
71
|
staticFiles: Set<string>;
|
|
63
72
|
ssrEntryChunk?: Rollup.OutputChunk;
|
|
64
73
|
manifestEntryChunk?: Rollup.OutputChunk;
|
|
@@ -84,6 +93,7 @@ export declare function getPageDataByComponent(internals: BuildInternals, compon
|
|
|
84
93
|
export declare function getPageDataByViteID(internals: BuildInternals, viteid: ViteID): PageBuildData | undefined;
|
|
85
94
|
export declare function hasPageDataByViteID(internals: BuildInternals, viteid: ViteID): boolean;
|
|
86
95
|
export declare function eachPageData(internals: BuildInternals): Generator<PageBuildData, void, undefined>;
|
|
96
|
+
export declare function eachPageFromAllPages(allPages: AllPagesData): Generator<[string, PageBuildData]>;
|
|
87
97
|
export declare function eachPageDataFromEntryPoint(internals: BuildInternals): Generator<[PageBuildData, string]>;
|
|
88
98
|
export declare function hasPrerenderedPages(internals: BuildInternals): boolean;
|
|
89
99
|
interface OrderInfo {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { prependForwardSlash, removeFileExtension } from "../path.js";
|
|
2
|
+
import { routeIsFallback } from "../redirects/helpers.js";
|
|
2
3
|
import { viteID } from "../util.js";
|
|
3
4
|
import {
|
|
4
5
|
ASTRO_PAGE_RESOLVED_MODULE_ID,
|
|
@@ -10,15 +11,19 @@ function createBuildInternals() {
|
|
|
10
11
|
const hoistedScriptIdToHoistedMap = /* @__PURE__ */ new Map();
|
|
11
12
|
const hoistedScriptIdToPagesMap = /* @__PURE__ */ new Map();
|
|
12
13
|
return {
|
|
14
|
+
cachedClientEntries: [],
|
|
13
15
|
cssModuleToChunkIdMap: /* @__PURE__ */ new Map(),
|
|
14
16
|
hoistedScriptIdToHoistedMap,
|
|
15
17
|
hoistedScriptIdToPagesMap,
|
|
16
18
|
entrySpecifierToBundleMap: /* @__PURE__ */ new Map(),
|
|
17
19
|
pageToBundleMap: /* @__PURE__ */ new Map(),
|
|
18
20
|
pagesByComponent: /* @__PURE__ */ new Map(),
|
|
21
|
+
pagesByComponents: /* @__PURE__ */ new Map(),
|
|
19
22
|
pageOptionsByPage: /* @__PURE__ */ new Map(),
|
|
20
23
|
pagesByViteID: /* @__PURE__ */ new Map(),
|
|
21
24
|
pagesByClientOnly: /* @__PURE__ */ new Map(),
|
|
25
|
+
propagatedStylesMap: /* @__PURE__ */ new Map(),
|
|
26
|
+
propagatedScriptsMap: /* @__PURE__ */ new Map(),
|
|
22
27
|
discoveredHydratedComponents: /* @__PURE__ */ new Map(),
|
|
23
28
|
discoveredClientOnlyComponents: /* @__PURE__ */ new Map(),
|
|
24
29
|
discoveredScripts: /* @__PURE__ */ new Set(),
|
|
@@ -30,7 +35,16 @@ function createBuildInternals() {
|
|
|
30
35
|
}
|
|
31
36
|
function trackPageData(internals, component, pageData, componentModuleId, componentURL) {
|
|
32
37
|
pageData.moduleSpecifier = componentModuleId;
|
|
33
|
-
|
|
38
|
+
if (!routeIsFallback(pageData.route)) {
|
|
39
|
+
internals.pagesByComponent.set(component, pageData);
|
|
40
|
+
}
|
|
41
|
+
const list = internals.pagesByComponents.get(component);
|
|
42
|
+
if (list) {
|
|
43
|
+
list.push(pageData);
|
|
44
|
+
internals.pagesByComponents.set(component, list);
|
|
45
|
+
} else {
|
|
46
|
+
internals.pagesByComponents.set(component, [pageData]);
|
|
47
|
+
}
|
|
34
48
|
internals.pagesByViteID.set(viteID(componentURL), pageData);
|
|
35
49
|
}
|
|
36
50
|
function trackClientOnlyPageDatas(internals, pageData, clientOnlys) {
|
|
@@ -90,6 +104,13 @@ function hasPageDataByViteID(internals, viteid) {
|
|
|
90
104
|
function* eachPageData(internals) {
|
|
91
105
|
yield* internals.pagesByComponent.values();
|
|
92
106
|
}
|
|
107
|
+
function* eachPageFromAllPages(allPages) {
|
|
108
|
+
for (const [path, list] of Object.entries(allPages)) {
|
|
109
|
+
for (const pageData of list) {
|
|
110
|
+
yield [path, pageData];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
93
114
|
function* eachPageDataFromEntryPoint(internals) {
|
|
94
115
|
for (const [entryPoint, filePath] of internals.entrySpecifierToBundleMap) {
|
|
95
116
|
if (entryPoint.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) || entryPoint.includes(RESOLVED_SPLIT_MODULE_ID)) {
|
|
@@ -169,6 +190,7 @@ export {
|
|
|
169
190
|
cssOrder,
|
|
170
191
|
eachPageData,
|
|
171
192
|
eachPageDataFromEntryPoint,
|
|
193
|
+
eachPageFromAllPages,
|
|
172
194
|
getEntryFilePathFromComponentPath,
|
|
173
195
|
getPageDataByComponent,
|
|
174
196
|
getPageDataByViteID,
|
|
@@ -21,15 +21,29 @@ async function collectPagesData(opts) {
|
|
|
21
21
|
clearInterval(routeCollectionLogTimeout);
|
|
22
22
|
}, 1e4);
|
|
23
23
|
builtPaths.add(route.pathname);
|
|
24
|
-
allPages[route.component]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
if (allPages[route.component]) {
|
|
25
|
+
allPages[route.component].push({
|
|
26
|
+
component: route.component,
|
|
27
|
+
route,
|
|
28
|
+
moduleSpecifier: "",
|
|
29
|
+
styles: [],
|
|
30
|
+
propagatedStyles: /* @__PURE__ */ new Map(),
|
|
31
|
+
propagatedScripts: /* @__PURE__ */ new Map(),
|
|
32
|
+
hoistedScript: void 0
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
allPages[route.component] = [
|
|
36
|
+
{
|
|
37
|
+
component: route.component,
|
|
38
|
+
route,
|
|
39
|
+
moduleSpecifier: "",
|
|
40
|
+
styles: [],
|
|
41
|
+
propagatedStyles: /* @__PURE__ */ new Map(),
|
|
42
|
+
propagatedScripts: /* @__PURE__ */ new Map(),
|
|
43
|
+
hoistedScript: void 0
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
}
|
|
33
47
|
clearInterval(routeCollectionLogTimeout);
|
|
34
48
|
if (settings.config.output === "static") {
|
|
35
49
|
const html = `${route.pathname}`.replace(/\/?$/, "/index.html");
|
|
@@ -42,15 +56,29 @@ async function collectPagesData(opts) {
|
|
|
42
56
|
}
|
|
43
57
|
continue;
|
|
44
58
|
}
|
|
45
|
-
allPages[route.component]
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
if (allPages[route.component]) {
|
|
60
|
+
allPages[route.component].push({
|
|
61
|
+
component: route.component,
|
|
62
|
+
route,
|
|
63
|
+
moduleSpecifier: "",
|
|
64
|
+
styles: [],
|
|
65
|
+
propagatedStyles: /* @__PURE__ */ new Map(),
|
|
66
|
+
propagatedScripts: /* @__PURE__ */ new Map(),
|
|
67
|
+
hoistedScript: void 0
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
allPages[route.component] = [
|
|
71
|
+
{
|
|
72
|
+
component: route.component,
|
|
73
|
+
route,
|
|
74
|
+
moduleSpecifier: "",
|
|
75
|
+
styles: [],
|
|
76
|
+
propagatedStyles: /* @__PURE__ */ new Map(),
|
|
77
|
+
propagatedScripts: /* @__PURE__ */ new Map(),
|
|
78
|
+
hoistedScript: void 0
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
}
|
|
54
82
|
}
|
|
55
83
|
clearInterval(dataCollectionLogTimeout);
|
|
56
84
|
return { assets, allPages };
|
|
@@ -6,17 +6,19 @@ type OutputChunkorAsset = RollupOutputArray[number]['output'][number];
|
|
|
6
6
|
type OutputChunk = Extract<OutputChunkorAsset, {
|
|
7
7
|
type: 'chunk';
|
|
8
8
|
}>;
|
|
9
|
-
type
|
|
9
|
+
export type BuildTarget = 'server' | 'client';
|
|
10
|
+
type MutateChunk = (chunk: OutputChunk, targets: BuildTarget[], newCode: string) => void;
|
|
11
|
+
export interface BuildBeforeHookResult {
|
|
12
|
+
enforce?: 'after-user-plugins';
|
|
13
|
+
vitePlugin: VitePlugin | VitePlugin[] | undefined;
|
|
14
|
+
}
|
|
10
15
|
export type AstroBuildPlugin = {
|
|
11
|
-
|
|
16
|
+
targets: BuildTarget[];
|
|
12
17
|
hooks?: {
|
|
13
18
|
'build:before'?: (opts: {
|
|
14
|
-
|
|
19
|
+
target: BuildTarget;
|
|
15
20
|
input: Set<string>;
|
|
16
|
-
}) =>
|
|
17
|
-
enforce?: 'after-user-plugins';
|
|
18
|
-
vitePlugin: VitePlugin | VitePlugin[] | undefined;
|
|
19
|
-
};
|
|
21
|
+
}) => BuildBeforeHookResult | Promise<BuildBeforeHookResult>;
|
|
20
22
|
'build:post'?: (opts: {
|
|
21
23
|
ssrOutputs: RollupOutputArray;
|
|
22
24
|
clientOutputs: RollupOutputArray;
|
|
@@ -28,12 +30,12 @@ export declare function createPluginContainer(options: StaticBuildOptions, inter
|
|
|
28
30
|
options: StaticBuildOptions;
|
|
29
31
|
internals: BuildInternals;
|
|
30
32
|
register(plugin: AstroBuildPlugin): void;
|
|
31
|
-
runBeforeHook(
|
|
33
|
+
runBeforeHook(target: BuildTarget, input: Set<string>): Promise<{
|
|
32
34
|
vitePlugins: (VitePlugin | VitePlugin[])[];
|
|
33
35
|
lastVitePlugins: (VitePlugin | VitePlugin[])[];
|
|
34
|
-
}
|
|
36
|
+
}>;
|
|
35
37
|
runPostHook(ssrReturn: ViteBuildReturn, clientReturn: ViteBuildReturn | null): Promise<Map<string, {
|
|
36
|
-
|
|
38
|
+
targets: BuildTarget[];
|
|
37
39
|
code: string;
|
|
38
40
|
}>>;
|
|
39
41
|
};
|
|
@@ -1,36 +1,28 @@
|
|
|
1
1
|
function createPluginContainer(options, internals) {
|
|
2
|
-
const
|
|
3
|
-
const ssrPlugins = [];
|
|
2
|
+
const plugins = /* @__PURE__ */ new Map();
|
|
4
3
|
const allPlugins = /* @__PURE__ */ new Set();
|
|
4
|
+
for (const target of ["client", "server"]) {
|
|
5
|
+
plugins.set(target, []);
|
|
6
|
+
}
|
|
5
7
|
return {
|
|
6
8
|
options,
|
|
7
9
|
internals,
|
|
8
10
|
register(plugin) {
|
|
9
11
|
allPlugins.add(plugin);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
case "ssr": {
|
|
16
|
-
ssrPlugins.push(plugin);
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
case "both": {
|
|
20
|
-
clientPlugins.push(plugin);
|
|
21
|
-
ssrPlugins.push(plugin);
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
12
|
+
for (const target of plugin.targets) {
|
|
13
|
+
const targetPlugins = plugins.get(target) ?? [];
|
|
14
|
+
targetPlugins.push(plugin);
|
|
15
|
+
plugins.set(target, targetPlugins);
|
|
24
16
|
}
|
|
25
17
|
},
|
|
26
18
|
// Hooks
|
|
27
|
-
runBeforeHook(
|
|
28
|
-
let
|
|
19
|
+
async runBeforeHook(target, input) {
|
|
20
|
+
let targetPlugins = plugins.get(target) ?? [];
|
|
29
21
|
let vitePlugins = [];
|
|
30
22
|
let lastVitePlugins = [];
|
|
31
|
-
for (const plugin of
|
|
23
|
+
for (const plugin of targetPlugins) {
|
|
32
24
|
if (plugin.hooks?.["build:before"]) {
|
|
33
|
-
let result = plugin.hooks["build:before"]({
|
|
25
|
+
let result = await plugin.hooks["build:before"]({ target, input });
|
|
34
26
|
if (result.vitePlugin) {
|
|
35
27
|
vitePlugins.push(result.vitePlugin);
|
|
36
28
|
}
|
|
@@ -55,10 +47,10 @@ function createPluginContainer(options, internals) {
|
|
|
55
47
|
} else if (clientReturn && "output" in clientReturn) {
|
|
56
48
|
clientOutputs.push(clientReturn);
|
|
57
49
|
}
|
|
58
|
-
const mutate = (chunk,
|
|
50
|
+
const mutate = (chunk, targets, newCode) => {
|
|
59
51
|
chunk.code = newCode;
|
|
60
52
|
mutations.set(chunk.fileName, {
|
|
61
|
-
|
|
53
|
+
targets,
|
|
62
54
|
code: newCode
|
|
63
55
|
});
|
|
64
56
|
};
|
|
@@ -2,7 +2,9 @@ import { astroConfigBuildPlugin } from "../../../content/vite-plugin-content-ass
|
|
|
2
2
|
import { astroHeadBuildPlugin } from "../../../vite-plugin-head/index.js";
|
|
3
3
|
import { pluginAliasResolve } from "./plugin-alias-resolve.js";
|
|
4
4
|
import { pluginAnalyzer } from "./plugin-analyzer.js";
|
|
5
|
+
import { pluginChunks } from "./plugin-chunks.js";
|
|
5
6
|
import { pluginComponentEntry } from "./plugin-component-entry.js";
|
|
7
|
+
import { pluginContent } from "./plugin-content.js";
|
|
6
8
|
import { pluginCSS } from "./plugin-css.js";
|
|
7
9
|
import { pluginHoistedScripts } from "./plugin-hoisted-scripts.js";
|
|
8
10
|
import { pluginInternals } from "./plugin-internals.js";
|
|
@@ -21,6 +23,7 @@ function registerAllPlugins({ internals, options, register }) {
|
|
|
21
23
|
register(pluginRenderers(options));
|
|
22
24
|
register(pluginMiddleware(options, internals));
|
|
23
25
|
register(pluginPages(options, internals));
|
|
26
|
+
register(pluginContent(options, internals));
|
|
24
27
|
register(pluginCSS(options, internals));
|
|
25
28
|
register(astroHeadBuildPlugin(internals));
|
|
26
29
|
register(pluginPrerender(options, internals));
|
|
@@ -28,6 +31,7 @@ function registerAllPlugins({ internals, options, register }) {
|
|
|
28
31
|
register(pluginHoistedScripts(options, internals));
|
|
29
32
|
register(pluginSSR(options, internals));
|
|
30
33
|
register(pluginSSRSplit(options, internals));
|
|
34
|
+
register(pluginChunks());
|
|
31
35
|
}
|
|
32
36
|
export {
|
|
33
37
|
registerAllPlugins
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { extendManualChunks } from "./util.js";
|
|
2
|
+
function vitePluginChunks() {
|
|
3
|
+
return {
|
|
4
|
+
name: "astro:chunks",
|
|
5
|
+
outputOptions(outputOptions) {
|
|
6
|
+
extendManualChunks(outputOptions, {
|
|
7
|
+
after(id) {
|
|
8
|
+
if (id.includes("astro/dist/runtime/server/")) {
|
|
9
|
+
return "astro/server";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function pluginChunks() {
|
|
17
|
+
return {
|
|
18
|
+
targets: ["server"],
|
|
19
|
+
hooks: {
|
|
20
|
+
"build:before": () => {
|
|
21
|
+
return {
|
|
22
|
+
vitePlugin: vitePluginChunks()
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
pluginChunks,
|
|
30
|
+
vitePluginChunks
|
|
31
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type BuildInternals } from '../internal.js';
|
|
2
|
+
import type { AstroBuildPlugin } from '../plugin.js';
|
|
3
|
+
import type { StaticBuildOptions } from '../types.js';
|
|
4
|
+
export declare function pluginContent(opts: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import fsMod from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import pLimit from "p-limit";
|
|
5
|
+
import { normalizePath } from "vite";
|
|
6
|
+
import { CONTENT_RENDER_FLAG, PROPAGATED_ASSET_FLAG } from "../../../content/consts.js";
|
|
7
|
+
import { hasContentFlag } from "../../../content/utils.js";
|
|
8
|
+
import {
|
|
9
|
+
generateContentEntryFile,
|
|
10
|
+
generateLookupMap
|
|
11
|
+
} from "../../../content/vite-plugin-content-virtual-mod.js";
|
|
12
|
+
import { isServerLikeOutput } from "../../../prerender/utils.js";
|
|
13
|
+
import { joinPaths, removeFileExtension, removeLeadingForwardSlash } from "../../path.js";
|
|
14
|
+
import { addRollupInput } from "../add-rollup-input.js";
|
|
15
|
+
import {} from "../internal.js";
|
|
16
|
+
import { copyFiles } from "../static-build.js";
|
|
17
|
+
import { encodeName } from "../util.js";
|
|
18
|
+
import { extendManualChunks } from "./util.js";
|
|
19
|
+
const CONTENT_CACHE_DIR = "./content/";
|
|
20
|
+
const CONTENT_MANIFEST_FILE = "./manifest.json";
|
|
21
|
+
const CONTENT_MANIFEST_VERSION = 0;
|
|
22
|
+
const virtualEmptyModuleId = `virtual:empty-content`;
|
|
23
|
+
const resolvedVirtualEmptyModuleId = `\0${virtualEmptyModuleId}`;
|
|
24
|
+
function createContentManifest() {
|
|
25
|
+
return { version: -1, entries: [], serverEntries: [], clientEntries: [] };
|
|
26
|
+
}
|
|
27
|
+
function vitePluginContent(opts, lookupMap, internals) {
|
|
28
|
+
const { config } = opts.settings;
|
|
29
|
+
const { cacheDir } = config;
|
|
30
|
+
const distRoot = config.outDir;
|
|
31
|
+
const distContentRoot = new URL("./content/", distRoot);
|
|
32
|
+
const cachedChunks = new URL("./chunks/", opts.settings.config.cacheDir);
|
|
33
|
+
const distChunks = new URL("./chunks/", opts.settings.config.outDir);
|
|
34
|
+
const contentCacheDir = new URL(CONTENT_CACHE_DIR, cacheDir);
|
|
35
|
+
const contentManifestFile = new URL(CONTENT_MANIFEST_FILE, contentCacheDir);
|
|
36
|
+
const cache = contentCacheDir;
|
|
37
|
+
const cacheTmp = new URL("./.tmp/", cache);
|
|
38
|
+
let oldManifest = createContentManifest();
|
|
39
|
+
let newManifest = createContentManifest();
|
|
40
|
+
let entries;
|
|
41
|
+
let injectedEmptyFile = false;
|
|
42
|
+
if (fsMod.existsSync(contentManifestFile)) {
|
|
43
|
+
try {
|
|
44
|
+
const data = fsMod.readFileSync(contentManifestFile, { encoding: "utf8" });
|
|
45
|
+
oldManifest = JSON.parse(data);
|
|
46
|
+
internals.cachedClientEntries = oldManifest.clientEntries;
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
name: "@astro/plugin-build-content",
|
|
52
|
+
async options(options) {
|
|
53
|
+
let newOptions = Object.assign({}, options);
|
|
54
|
+
newManifest = await generateContentManifest(opts, lookupMap);
|
|
55
|
+
entries = getEntriesFromManifests(oldManifest, newManifest);
|
|
56
|
+
for (const { type, entry } of entries.buildFromSource) {
|
|
57
|
+
const fileURL = encodeURI(joinPaths(opts.settings.config.root.toString(), entry));
|
|
58
|
+
const input = fileURLToPath(fileURL);
|
|
59
|
+
const inputs = [`${input}?${collectionTypeToFlag(type)}`];
|
|
60
|
+
if (type === "content") {
|
|
61
|
+
inputs.push(`${input}?${CONTENT_RENDER_FLAG}`);
|
|
62
|
+
}
|
|
63
|
+
newOptions = addRollupInput(newOptions, inputs);
|
|
64
|
+
}
|
|
65
|
+
if (fsMod.existsSync(cachedChunks)) {
|
|
66
|
+
await copyFiles(cachedChunks, distChunks, true);
|
|
67
|
+
}
|
|
68
|
+
if (entries.buildFromSource.length === 0) {
|
|
69
|
+
newOptions = addRollupInput(newOptions, [virtualEmptyModuleId]);
|
|
70
|
+
injectedEmptyFile = true;
|
|
71
|
+
}
|
|
72
|
+
return newOptions;
|
|
73
|
+
},
|
|
74
|
+
outputOptions(outputOptions) {
|
|
75
|
+
const rootPath = normalizePath(fileURLToPath(opts.settings.config.root));
|
|
76
|
+
const srcPath = normalizePath(fileURLToPath(opts.settings.config.srcDir));
|
|
77
|
+
extendManualChunks(outputOptions, {
|
|
78
|
+
before(id, meta) {
|
|
79
|
+
if (id.startsWith(srcPath) && id.slice(srcPath.length).startsWith("content")) {
|
|
80
|
+
const info = meta.getModuleInfo(id);
|
|
81
|
+
if (info?.dynamicImporters.length === 1 && hasContentFlag(info.dynamicImporters[0], PROPAGATED_ASSET_FLAG)) {
|
|
82
|
+
const [srcRelativePath2] = id.replace(rootPath, "/").split("?");
|
|
83
|
+
const resultId = encodeName(
|
|
84
|
+
`${removeLeadingForwardSlash(removeFileExtension(srcRelativePath2))}.render.mjs`
|
|
85
|
+
);
|
|
86
|
+
return resultId;
|
|
87
|
+
}
|
|
88
|
+
const [srcRelativePath, flag] = id.replace(rootPath, "/").split("?");
|
|
89
|
+
const collectionEntry = findEntryFromSrcRelativePath(lookupMap, srcRelativePath);
|
|
90
|
+
if (collectionEntry) {
|
|
91
|
+
let suffix = ".mjs";
|
|
92
|
+
if (flag === PROPAGATED_ASSET_FLAG) {
|
|
93
|
+
suffix = ".entry.mjs";
|
|
94
|
+
}
|
|
95
|
+
id = removeLeadingForwardSlash(
|
|
96
|
+
removeFileExtension(encodeName(id.replace(srcPath, "/")))
|
|
97
|
+
) + suffix;
|
|
98
|
+
return id;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
resolveId(id) {
|
|
105
|
+
if (id === virtualEmptyModuleId) {
|
|
106
|
+
return resolvedVirtualEmptyModuleId;
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
async load(id) {
|
|
110
|
+
if (id === resolvedVirtualEmptyModuleId) {
|
|
111
|
+
return {
|
|
112
|
+
code: `// intentionally left empty!
|
|
113
|
+
export default {}`
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
async generateBundle(_options, bundle) {
|
|
118
|
+
const code = await generateContentEntryFile({
|
|
119
|
+
settings: opts.settings,
|
|
120
|
+
fs: fsMod,
|
|
121
|
+
lookupMap,
|
|
122
|
+
IS_DEV: false,
|
|
123
|
+
IS_SERVER: false
|
|
124
|
+
});
|
|
125
|
+
this.emitFile({
|
|
126
|
+
type: "prebuilt-chunk",
|
|
127
|
+
code,
|
|
128
|
+
fileName: "content/entry.mjs"
|
|
129
|
+
});
|
|
130
|
+
if (!injectedEmptyFile)
|
|
131
|
+
return;
|
|
132
|
+
Object.keys(bundle).forEach((key) => {
|
|
133
|
+
const mod = bundle[key];
|
|
134
|
+
if (mod.type === "asset")
|
|
135
|
+
return;
|
|
136
|
+
if (mod.facadeModuleId === resolvedVirtualEmptyModuleId) {
|
|
137
|
+
delete bundle[key];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
async writeBundle() {
|
|
142
|
+
const clientComponents = /* @__PURE__ */ new Set([
|
|
143
|
+
...oldManifest.clientEntries,
|
|
144
|
+
...internals.discoveredHydratedComponents.keys(),
|
|
145
|
+
...internals.discoveredClientOnlyComponents.keys(),
|
|
146
|
+
...internals.discoveredScripts
|
|
147
|
+
]);
|
|
148
|
+
const serverComponents = /* @__PURE__ */ new Set([
|
|
149
|
+
...oldManifest.serverEntries,
|
|
150
|
+
...internals.discoveredHydratedComponents.keys()
|
|
151
|
+
]);
|
|
152
|
+
newManifest.serverEntries = Array.from(serverComponents);
|
|
153
|
+
newManifest.clientEntries = Array.from(clientComponents);
|
|
154
|
+
await fsMod.promises.mkdir(contentCacheDir, { recursive: true });
|
|
155
|
+
await fsMod.promises.writeFile(contentManifestFile, JSON.stringify(newManifest), {
|
|
156
|
+
encoding: "utf8"
|
|
157
|
+
});
|
|
158
|
+
const cacheExists = fsMod.existsSync(cache);
|
|
159
|
+
fsMod.mkdirSync(cache, { recursive: true });
|
|
160
|
+
await fsMod.promises.mkdir(cacheTmp, { recursive: true });
|
|
161
|
+
await copyFiles(distContentRoot, cacheTmp, true);
|
|
162
|
+
if (cacheExists) {
|
|
163
|
+
await copyFiles(contentCacheDir, distContentRoot, false);
|
|
164
|
+
}
|
|
165
|
+
await copyFiles(cacheTmp, contentCacheDir);
|
|
166
|
+
await fsMod.promises.rm(cacheTmp, { recursive: true, force: true });
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const entryCache = /* @__PURE__ */ new Map();
|
|
171
|
+
function findEntryFromSrcRelativePath(lookupMap, srcRelativePath) {
|
|
172
|
+
let value = entryCache.get(srcRelativePath);
|
|
173
|
+
if (value)
|
|
174
|
+
return value;
|
|
175
|
+
for (const collection of Object.values(lookupMap)) {
|
|
176
|
+
for (const entry of Object.values(collection)) {
|
|
177
|
+
for (const entryFile of Object.values(entry)) {
|
|
178
|
+
if (entryFile === srcRelativePath) {
|
|
179
|
+
value = entryFile;
|
|
180
|
+
entryCache.set(srcRelativePath, entryFile);
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function getEntriesFromManifests(oldManifest, newManifest) {
|
|
188
|
+
const { version: oldVersion, entries: oldEntries } = oldManifest;
|
|
189
|
+
const { version: newVersion, entries: newEntries } = newManifest;
|
|
190
|
+
let entries = { restoreFromCache: [], buildFromSource: [] };
|
|
191
|
+
const newEntryMap = new Map(newEntries);
|
|
192
|
+
if (oldVersion !== newVersion || oldEntries.length === 0) {
|
|
193
|
+
entries.buildFromSource = Array.from(newEntryMap.keys());
|
|
194
|
+
return entries;
|
|
195
|
+
}
|
|
196
|
+
const oldEntryHashMap = new Map(
|
|
197
|
+
oldEntries.map(([key, hash]) => [hash, key])
|
|
198
|
+
);
|
|
199
|
+
for (const [entry, hash] of newEntryMap) {
|
|
200
|
+
if (oldEntryHashMap.has(hash)) {
|
|
201
|
+
entries.restoreFromCache.push(entry);
|
|
202
|
+
} else {
|
|
203
|
+
entries.buildFromSource.push(entry);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return entries;
|
|
207
|
+
}
|
|
208
|
+
async function generateContentManifest(opts, lookupMap) {
|
|
209
|
+
let manifest = {
|
|
210
|
+
version: CONTENT_MANIFEST_VERSION,
|
|
211
|
+
entries: [],
|
|
212
|
+
serverEntries: [],
|
|
213
|
+
clientEntries: []
|
|
214
|
+
};
|
|
215
|
+
const limit = pLimit(10);
|
|
216
|
+
const promises = [];
|
|
217
|
+
for (const [collection, { type, entries }] of Object.entries(lookupMap)) {
|
|
218
|
+
for (const entry of Object.values(entries)) {
|
|
219
|
+
const key = { collection, type, entry };
|
|
220
|
+
const fileURL = new URL(encodeURI(joinPaths(opts.settings.config.root.toString(), entry)));
|
|
221
|
+
promises.push(
|
|
222
|
+
limit(async () => {
|
|
223
|
+
const data = await fsMod.promises.readFile(fileURL, { encoding: "utf8" });
|
|
224
|
+
manifest.entries.push([key, checksum(data)]);
|
|
225
|
+
})
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
await Promise.all(promises);
|
|
230
|
+
return manifest;
|
|
231
|
+
}
|
|
232
|
+
function checksum(data) {
|
|
233
|
+
return createHash("sha1").update(data).digest("base64");
|
|
234
|
+
}
|
|
235
|
+
function collectionTypeToFlag(type) {
|
|
236
|
+
const name = type[0].toUpperCase() + type.slice(1);
|
|
237
|
+
return `astro${name}CollectionEntry`;
|
|
238
|
+
}
|
|
239
|
+
function pluginContent(opts, internals) {
|
|
240
|
+
const cachedChunks = new URL("./chunks/", opts.settings.config.cacheDir);
|
|
241
|
+
const distChunks = new URL("./chunks/", opts.settings.config.outDir);
|
|
242
|
+
return {
|
|
243
|
+
targets: ["server"],
|
|
244
|
+
hooks: {
|
|
245
|
+
async "build:before"() {
|
|
246
|
+
if (!opts.settings.config.experimental.contentCollectionCache) {
|
|
247
|
+
return { vitePlugin: void 0 };
|
|
248
|
+
}
|
|
249
|
+
if (isServerLikeOutput(opts.settings.config)) {
|
|
250
|
+
return { vitePlugin: void 0 };
|
|
251
|
+
}
|
|
252
|
+
const lookupMap = await generateLookupMap({ settings: opts.settings, fs: fsMod });
|
|
253
|
+
return {
|
|
254
|
+
vitePlugin: vitePluginContent(opts, lookupMap, internals)
|
|
255
|
+
};
|
|
256
|
+
},
|
|
257
|
+
async "build:post"() {
|
|
258
|
+
if (!opts.settings.config.experimental.contentCollectionCache) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (isServerLikeOutput(opts.settings.config)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (fsMod.existsSync(distChunks)) {
|
|
265
|
+
await copyFiles(distChunks, cachedChunks, true);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
export {
|
|
272
|
+
pluginContent
|
|
273
|
+
};
|