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
|
@@ -13,13 +13,13 @@ import {
|
|
|
13
13
|
import { extendManualChunks } from "./util.js";
|
|
14
14
|
function pluginCSS(options, internals) {
|
|
15
15
|
return {
|
|
16
|
-
|
|
16
|
+
targets: ["client", "server"],
|
|
17
17
|
hooks: {
|
|
18
|
-
"build:before": ({
|
|
18
|
+
"build:before": ({ target }) => {
|
|
19
19
|
let plugins = rollupPluginAstroBuildCSS({
|
|
20
20
|
buildOptions: options,
|
|
21
21
|
internals,
|
|
22
|
-
target
|
|
22
|
+
target
|
|
23
23
|
});
|
|
24
24
|
return {
|
|
25
25
|
vitePlugin: plugins
|
|
@@ -52,6 +52,11 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
52
52
|
if (new URL(pageInfo.id, "file://").searchParams.has(PROPAGATED_ASSET_FLAG)) {
|
|
53
53
|
const chunkId2 = assetName.createNameHash(id, [id]);
|
|
54
54
|
internals.cssModuleToChunkIdMap.set(id, chunkId2);
|
|
55
|
+
if (options.buildOptions.settings.config.output === "static" && options.buildOptions.settings.config.experimental.contentCollectionCache) {
|
|
56
|
+
const propagatedStyles = internals.propagatedStylesMap.get(pageInfo.id) ?? /* @__PURE__ */ new Set();
|
|
57
|
+
propagatedStyles.add({ type: "external", src: chunkId2 });
|
|
58
|
+
internals.propagatedStylesMap.set(pageInfo.id, propagatedStyles);
|
|
59
|
+
}
|
|
55
60
|
return chunkId2;
|
|
56
61
|
}
|
|
57
62
|
}
|
|
@@ -169,7 +174,7 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
169
174
|
return;
|
|
170
175
|
if (pageData.styles.some((s) => s.sheet === sheet))
|
|
171
176
|
return;
|
|
172
|
-
const propagatedStyles =
|
|
177
|
+
const propagatedStyles = internals.propagatedStylesMap.get(pageInfoId) ?? internals.propagatedStylesMap.set(pageInfoId, /* @__PURE__ */ new Set()).get(pageInfoId);
|
|
173
178
|
propagatedStyles.add(sheet);
|
|
174
179
|
sheetAddedToPage = true;
|
|
175
180
|
});
|
|
@@ -64,7 +64,7 @@ _privateSetManifestDontUseThis(manifest);
|
|
|
64
64
|
}
|
|
65
65
|
function pluginManifest(options, internals) {
|
|
66
66
|
return {
|
|
67
|
-
|
|
67
|
+
targets: ["server"],
|
|
68
68
|
hooks: {
|
|
69
69
|
"build:before": () => {
|
|
70
70
|
return {
|
|
@@ -88,7 +88,7 @@ function pluginManifest(options, internals) {
|
|
|
88
88
|
middlewareEntryPoint: shouldPassMiddlewareEntryPoint ? internals.middlewareEntryPoint : void 0
|
|
89
89
|
});
|
|
90
90
|
const code = injectManifest(manifest, internals.manifestEntryChunk);
|
|
91
|
-
mutate(internals.manifestEntryChunk, "server", code);
|
|
91
|
+
mutate(internals.manifestEntryChunk, ["server"], code);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
};
|
|
@@ -182,7 +182,16 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
182
182
|
if (!(BEFORE_HYDRATION_SCRIPT_ID in entryModules)) {
|
|
183
183
|
entryModules[BEFORE_HYDRATION_SCRIPT_ID] = "";
|
|
184
184
|
}
|
|
185
|
-
|
|
185
|
+
let i18nManifest = void 0;
|
|
186
|
+
if (settings.config.experimental.i18n) {
|
|
187
|
+
i18nManifest = {
|
|
188
|
+
fallback: settings.config.experimental.i18n.fallback,
|
|
189
|
+
routingStrategy: settings.config.experimental.i18n.routingStrategy,
|
|
190
|
+
locales: settings.config.experimental.i18n.locales,
|
|
191
|
+
defaultLocale: settings.config.experimental.i18n.defaultLocale
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
186
195
|
adapterName: opts.settings.adapter?.name ?? "",
|
|
187
196
|
routes,
|
|
188
197
|
site: settings.config.site,
|
|
@@ -193,9 +202,9 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
193
202
|
renderers: [],
|
|
194
203
|
clientDirectives: Array.from(settings.clientDirectives),
|
|
195
204
|
entryModules,
|
|
196
|
-
assets: staticFiles.map(prefixAssetPath)
|
|
205
|
+
assets: staticFiles.map(prefixAssetPath),
|
|
206
|
+
i18n: i18nManifest
|
|
197
207
|
};
|
|
198
|
-
return ssrManifest;
|
|
199
208
|
}
|
|
200
209
|
export {
|
|
201
210
|
RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID,
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { Plugin as VitePlugin } from 'vite';
|
|
2
1
|
import type { BuildInternals } from '../internal.js';
|
|
3
2
|
import type { AstroBuildPlugin } from '../plugin.js';
|
|
4
3
|
import type { StaticBuildOptions } from '../types.js';
|
|
5
|
-
export
|
|
6
|
-
export declare function vitePluginMiddleware(opts: StaticBuildOptions, internals: BuildInternals): VitePlugin;
|
|
4
|
+
export { MIDDLEWARE_MODULE_ID } from '../../middleware/vite-plugin.js';
|
|
7
5
|
export declare function pluginMiddleware(opts: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -1,63 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { addRollupInput } from "../add-rollup-input.js";
|
|
4
|
-
const MIDDLEWARE_MODULE_ID = "@astro-middleware";
|
|
5
|
-
const EMPTY_MIDDLEWARE = "\0empty-middleware";
|
|
6
|
-
function vitePluginMiddleware(opts, internals) {
|
|
7
|
-
let resolvedMiddlewareId;
|
|
8
|
-
return {
|
|
9
|
-
name: "@astro/plugin-middleware",
|
|
10
|
-
options(options) {
|
|
11
|
-
return addRollupInput(options, [MIDDLEWARE_MODULE_ID]);
|
|
12
|
-
},
|
|
13
|
-
async resolveId(id) {
|
|
14
|
-
if (id === MIDDLEWARE_MODULE_ID) {
|
|
15
|
-
const middlewareId = await this.resolve(
|
|
16
|
-
`${decodeURI(opts.settings.config.srcDir.pathname)}${MIDDLEWARE_PATH_SEGMENT_NAME}`
|
|
17
|
-
);
|
|
18
|
-
if (middlewareId) {
|
|
19
|
-
resolvedMiddlewareId = middlewareId.id;
|
|
20
|
-
return middlewareId.id;
|
|
21
|
-
} else {
|
|
22
|
-
return EMPTY_MIDDLEWARE;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (id === EMPTY_MIDDLEWARE) {
|
|
26
|
-
return EMPTY_MIDDLEWARE;
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
load(id) {
|
|
30
|
-
if (id === EMPTY_MIDDLEWARE) {
|
|
31
|
-
return "export const onRequest = undefined";
|
|
32
|
-
} else if (id === resolvedMiddlewareId) {
|
|
33
|
-
this.emitFile({
|
|
34
|
-
type: "chunk",
|
|
35
|
-
preserveSignature: "strict",
|
|
36
|
-
fileName: "middleware.mjs",
|
|
37
|
-
id
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
writeBundle(_, bundle) {
|
|
42
|
-
for (const [chunkName, chunk] of Object.entries(bundle)) {
|
|
43
|
-
if (chunk.type === "asset") {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (chunk.fileName === "middleware.mjs") {
|
|
47
|
-
const outputDirectory = getOutputDirectory(opts.settings.config);
|
|
48
|
-
internals.middlewareEntryPoint = new URL(chunkName, outputDirectory);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
1
|
+
import { vitePluginMiddlewareBuild } from "../../middleware/vite-plugin.js";
|
|
2
|
+
import { MIDDLEWARE_MODULE_ID } from "../../middleware/vite-plugin.js";
|
|
54
3
|
function pluginMiddleware(opts, internals) {
|
|
55
4
|
return {
|
|
56
|
-
|
|
5
|
+
targets: ["server"],
|
|
57
6
|
hooks: {
|
|
58
7
|
"build:before": () => {
|
|
59
8
|
return {
|
|
60
|
-
vitePlugin:
|
|
9
|
+
vitePlugin: vitePluginMiddlewareBuild(opts, internals)
|
|
61
10
|
};
|
|
62
11
|
}
|
|
63
12
|
}
|
|
@@ -65,6 +14,5 @@ function pluginMiddleware(opts, internals) {
|
|
|
65
14
|
}
|
|
66
15
|
export {
|
|
67
16
|
MIDDLEWARE_MODULE_ID,
|
|
68
|
-
pluginMiddleware
|
|
69
|
-
vitePluginMiddleware
|
|
17
|
+
pluginMiddleware
|
|
70
18
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { extname } from "node:path";
|
|
2
2
|
import { routeIsRedirect } from "../../redirects/index.js";
|
|
3
3
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
4
|
-
import {} from "../internal.js";
|
|
4
|
+
import { eachPageFromAllPages } from "../internal.js";
|
|
5
5
|
import { MIDDLEWARE_MODULE_ID } from "./plugin-middleware.js";
|
|
6
6
|
import { RENDERERS_MODULE_ID } from "./plugin-renderers.js";
|
|
7
7
|
import { ASTRO_PAGE_EXTENSION_POST_PATTERN, getPathFromVirtualModulePageName } from "./util.js";
|
|
@@ -24,7 +24,7 @@ function vitePluginPages(opts, internals) {
|
|
|
24
24
|
options(options) {
|
|
25
25
|
if (opts.settings.config.output === "static") {
|
|
26
26
|
const inputs = /* @__PURE__ */ new Set();
|
|
27
|
-
for (const [path, pageData] of
|
|
27
|
+
for (const [path, pageData] of eachPageFromAllPages(opts.allPages)) {
|
|
28
28
|
if (routeIsRedirect(pageData.route)) {
|
|
29
29
|
continue;
|
|
30
30
|
}
|
|
@@ -76,7 +76,7 @@ function shouldBundleMiddleware(settings) {
|
|
|
76
76
|
}
|
|
77
77
|
function pluginPages(opts, internals) {
|
|
78
78
|
return {
|
|
79
|
-
|
|
79
|
+
targets: ["server"],
|
|
80
80
|
hooks: {
|
|
81
81
|
"build:before": () => {
|
|
82
82
|
return {
|
|
@@ -6,10 +6,7 @@ function vitePluginPrerender(opts, internals) {
|
|
|
6
6
|
name: "astro:rollup-plugin-prerender",
|
|
7
7
|
outputOptions(outputOptions) {
|
|
8
8
|
extendManualChunks(outputOptions, {
|
|
9
|
-
|
|
10
|
-
if (id.includes("astro/dist/runtime")) {
|
|
11
|
-
return "astro";
|
|
12
|
-
}
|
|
9
|
+
before(id, meta) {
|
|
13
10
|
const pageInfo = internals.pagesByViteID.get(id);
|
|
14
11
|
if (pageInfo) {
|
|
15
12
|
if (getPrerenderMetadata(meta.getModuleInfo(id))) {
|
|
@@ -26,7 +23,7 @@ function vitePluginPrerender(opts, internals) {
|
|
|
26
23
|
}
|
|
27
24
|
function pluginPrerender(opts, internals) {
|
|
28
25
|
return {
|
|
29
|
-
|
|
26
|
+
targets: ["server"],
|
|
30
27
|
hooks: {
|
|
31
28
|
"build:before": () => {
|
|
32
29
|
return {
|
|
@@ -4,6 +4,7 @@ import { isFunctionPerRouteEnabled } from "../../../integrations/index.js";
|
|
|
4
4
|
import { isServerLikeOutput } from "../../../prerender/utils.js";
|
|
5
5
|
import { routeIsRedirect } from "../../redirects/index.js";
|
|
6
6
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
7
|
+
import { eachPageFromAllPages } from "../internal.js";
|
|
7
8
|
import { SSR_MANIFEST_VIRTUAL_MODULE_ID } from "./plugin-manifest.js";
|
|
8
9
|
import { ASTRO_PAGE_MODULE_ID } from "./plugin-pages.js";
|
|
9
10
|
import { RENDERERS_MODULE_ID } from "./plugin-renderers.js";
|
|
@@ -30,7 +31,7 @@ function vitePluginSSR(internals, adapter, options) {
|
|
|
30
31
|
const exports = [];
|
|
31
32
|
let i = 0;
|
|
32
33
|
const pageMap = [];
|
|
33
|
-
for (const [path, pageData] of
|
|
34
|
+
for (const [path, pageData] of eachPageFromAllPages(allPages)) {
|
|
34
35
|
if (routeIsRedirect(pageData.route)) {
|
|
35
36
|
continue;
|
|
36
37
|
}
|
|
@@ -76,7 +77,7 @@ function pluginSSR(options, internals) {
|
|
|
76
77
|
const ssr = isServerLikeOutput(options.settings.config);
|
|
77
78
|
const functionPerRouteEnabled = isFunctionPerRouteEnabled(options.settings.adapter);
|
|
78
79
|
return {
|
|
79
|
-
|
|
80
|
+
targets: ["server"],
|
|
80
81
|
hooks: {
|
|
81
82
|
"build:before": () => {
|
|
82
83
|
let vitePlugin = ssr && // TODO: Remove in Astro 4.0
|
|
@@ -111,7 +112,7 @@ function vitePluginSSRSplit(internals, adapter, options) {
|
|
|
111
112
|
options(opts) {
|
|
112
113
|
if (options.settings.config.build.split || functionPerRouteEnabled) {
|
|
113
114
|
const inputs = /* @__PURE__ */ new Set();
|
|
114
|
-
for (const [path, pageData] of
|
|
115
|
+
for (const [path, pageData] of eachPageFromAllPages(options.allPages)) {
|
|
115
116
|
if (routeIsRedirect(pageData.route)) {
|
|
116
117
|
continue;
|
|
117
118
|
}
|
|
@@ -168,7 +169,7 @@ function pluginSSRSplit(options, internals) {
|
|
|
168
169
|
const ssr = isServerLikeOutput(options.settings.config);
|
|
169
170
|
const functionPerRouteEnabled = isFunctionPerRouteEnabled(options.settings.adapter);
|
|
170
171
|
return {
|
|
171
|
-
|
|
172
|
+
targets: ["server"],
|
|
172
173
|
hooks: {
|
|
173
174
|
"build:before": () => {
|
|
174
175
|
let vitePlugin = ssr && (options.settings.config.build.split || functionPerRouteEnabled) ? vitePluginSSRSplit(internals, options.settings.adapter, options) : void 0;
|
|
@@ -219,7 +220,7 @@ if(_start in adapter) {
|
|
|
219
220
|
}
|
|
220
221
|
function storeEntryPoint(moduleKey, options, internals, fileName) {
|
|
221
222
|
const componentPath = getPathFromVirtualModulePageName(RESOLVED_SPLIT_MODULE_ID, moduleKey);
|
|
222
|
-
for (const [page, pageData] of
|
|
223
|
+
for (const [page, pageData] of eachPageFromAllPages(options.allPages)) {
|
|
223
224
|
if (componentPath == page) {
|
|
224
225
|
const publicPath = fileURLToPath(options.settings.config.build.server);
|
|
225
226
|
internals.entryPoints.set(pageData.route, pathToFileURL(join(publicPath, fileName)));
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Plugin as VitePlugin } from 'vite';
|
|
1
|
+
import type { Rollup, Plugin as VitePlugin } from 'vite';
|
|
2
2
|
type OutputOptionsHook = Extract<VitePlugin['outputOptions'], Function>;
|
|
3
3
|
type OutputOptions = Parameters<OutputOptionsHook>[0];
|
|
4
4
|
type ExtendManualChunksHooks = {
|
|
5
|
-
before?:
|
|
6
|
-
after?:
|
|
5
|
+
before?: Rollup.GetManualChunk;
|
|
6
|
+
after?: Rollup.GetManualChunk;
|
|
7
7
|
};
|
|
8
8
|
export declare function extendManualChunks(outputOptions: OutputOptions, hooks: ExtendManualChunksHooks): void;
|
|
9
9
|
export declare const ASTRO_PAGE_EXTENSION_POST_PATTERN = "@_@";
|
|
@@ -5,6 +5,7 @@ export declare function viteBuild(opts: StaticBuildOptions): Promise<{
|
|
|
5
5
|
internals: BuildInternals;
|
|
6
6
|
}>;
|
|
7
7
|
export declare function staticBuild(opts: StaticBuildOptions, internals: BuildInternals): Promise<void>;
|
|
8
|
+
export declare function copyFiles(fromFolder: URL, toFolder: URL, includeDotfiles?: boolean): Promise<void>;
|
|
8
9
|
/**
|
|
9
10
|
* This function takes the virtual module name of any page entrypoint and
|
|
10
11
|
* transforms it to generate a final `.mjs` output file.
|
|
@@ -31,7 +32,7 @@ export declare function makeAstroPageEntryPointFileName(prefix: string, facadeMo
|
|
|
31
32
|
* 2. We split the file path using the file system separator and attempt to retrieve the last entry
|
|
32
33
|
* 3. The last entry should be the file
|
|
33
34
|
* 4. We prepend the file name with `entry.`
|
|
34
|
-
* 5. We built the file path again, using the new
|
|
35
|
+
* 5. We built the file path again, using the new en3built in the previous step
|
|
35
36
|
*
|
|
36
37
|
* @param facadeModuleId
|
|
37
38
|
* @param opts
|
|
@@ -6,12 +6,14 @@ import fs from "node:fs";
|
|
|
6
6
|
import path, { extname } from "node:path";
|
|
7
7
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
8
|
import * as vite from "vite";
|
|
9
|
+
import { PROPAGATED_ASSET_FLAG } from "../../content/consts.js";
|
|
10
|
+
import { hasAnyContentFlag } from "../../content/utils.js";
|
|
9
11
|
import {
|
|
10
12
|
createBuildInternals,
|
|
11
13
|
eachPageData
|
|
12
14
|
} from "../../core/build/internal.js";
|
|
13
15
|
import { emptyDir, removeEmptyDirs } from "../../core/fs/index.js";
|
|
14
|
-
import { appendForwardSlash, prependForwardSlash } from "../../core/path.js";
|
|
16
|
+
import { appendForwardSlash, prependForwardSlash, removeFileExtension } from "../../core/path.js";
|
|
15
17
|
import { isModeServerWithNoAdapter } from "../../core/util.js";
|
|
16
18
|
import { runHookBuildSetup } from "../../integrations/index.js";
|
|
17
19
|
import { getOutputDirectory, isServerLikeOutput } from "../../prerender/utils.js";
|
|
@@ -28,7 +30,7 @@ import { ASTRO_PAGE_RESOLVED_MODULE_ID } from "./plugins/plugin-pages.js";
|
|
|
28
30
|
import { RESOLVED_RENDERERS_MODULE_ID } from "./plugins/plugin-renderers.js";
|
|
29
31
|
import { RESOLVED_SPLIT_MODULE_ID, RESOLVED_SSR_VIRTUAL_MODULE_ID } from "./plugins/plugin-ssr.js";
|
|
30
32
|
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from "./plugins/util.js";
|
|
31
|
-
import { getTimeStat } from "./util.js";
|
|
33
|
+
import { encodeName, getTimeStat } from "./util.js";
|
|
32
34
|
async function viteBuild(opts) {
|
|
33
35
|
const { allPages, settings } = opts;
|
|
34
36
|
if (isModeServerWithNoAdapter(opts.settings)) {
|
|
@@ -36,15 +38,15 @@ async function viteBuild(opts) {
|
|
|
36
38
|
}
|
|
37
39
|
settings.timer.start("SSR build");
|
|
38
40
|
const pageInput = /* @__PURE__ */ new Set();
|
|
39
|
-
const facadeIdToPageDataMap = /* @__PURE__ */ new Map();
|
|
40
41
|
const internals = createBuildInternals();
|
|
41
|
-
for (const [component,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
for (const [component, pageDataList] of Object.entries(allPages)) {
|
|
43
|
+
for (const pageData of pageDataList) {
|
|
44
|
+
const astroModuleURL = new URL("./" + component, settings.config.root);
|
|
45
|
+
const astroModuleId = prependForwardSlash(component);
|
|
46
|
+
trackPageData(internals, component, pageData, astroModuleId, astroModuleURL);
|
|
47
|
+
if (!routeIsRedirect(pageData.route)) {
|
|
48
|
+
pageInput.add(astroModuleId);
|
|
49
|
+
}
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
if (settings.config?.vite?.build?.emptyOutDir !== false) {
|
|
@@ -60,6 +62,7 @@ async function viteBuild(opts) {
|
|
|
60
62
|
settings.timer.start("Client build");
|
|
61
63
|
const rendererClientEntrypoints = settings.renderers.map((r) => r.clientEntrypoint).filter((a) => typeof a === "string");
|
|
62
64
|
const clientInput = /* @__PURE__ */ new Set([
|
|
65
|
+
...internals.cachedClientEntries,
|
|
63
66
|
...internals.discoveredHydratedComponents.keys(),
|
|
64
67
|
...internals.discoveredClientOnlyComponents.keys(),
|
|
65
68
|
...rendererClientEntrypoints,
|
|
@@ -101,11 +104,13 @@ ${bgMagenta(black(" finalizing server assets "))}
|
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
async function ssrBuild(opts, internals, input, container) {
|
|
107
|
+
const buildID = Date.now().toString();
|
|
104
108
|
const { allPages, settings, viteConfig } = opts;
|
|
105
109
|
const ssr = isServerLikeOutput(settings.config);
|
|
106
110
|
const out = getOutputDirectory(settings.config);
|
|
107
|
-
const routes = Object.values(allPages).map((
|
|
108
|
-
const
|
|
111
|
+
const routes = Object.values(allPages).flat().map((pageData) => pageData.route);
|
|
112
|
+
const isContentCache = !ssr && settings.config.experimental.contentCollectionCache;
|
|
113
|
+
const { lastVitePlugins, vitePlugins } = await container.runBeforeHook("server", input);
|
|
109
114
|
const viteBuildConfig = {
|
|
110
115
|
...viteConfig,
|
|
111
116
|
mode: viteConfig.mode || "production",
|
|
@@ -125,28 +130,35 @@ async function ssrBuild(opts, internals, input, container) {
|
|
|
125
130
|
...viteConfig.build?.rollupOptions,
|
|
126
131
|
input: [],
|
|
127
132
|
output: {
|
|
133
|
+
hoistTransitiveImports: isContentCache,
|
|
128
134
|
format: "esm",
|
|
135
|
+
minifyInternalExports: !isContentCache,
|
|
129
136
|
// Server chunks can't go in the assets (_astro) folder
|
|
130
137
|
// We need to keep these separate
|
|
131
138
|
chunkFileNames(chunkInfo) {
|
|
132
139
|
const { name } = chunkInfo;
|
|
140
|
+
let prefix = "chunks/";
|
|
141
|
+
let suffix = "_[hash].mjs";
|
|
142
|
+
if (isContentCache) {
|
|
143
|
+
prefix += `${buildID}/`;
|
|
144
|
+
suffix = ".mjs";
|
|
145
|
+
}
|
|
146
|
+
if (isContentCache && name.includes("/content/")) {
|
|
147
|
+
const parts = name.split("/");
|
|
148
|
+
if (parts.at(1) === "content") {
|
|
149
|
+
return encodeName(parts.slice(1).join("/"));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
133
152
|
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
|
|
134
153
|
const [sanitizedName] = name.split(ASTRO_PAGE_EXTENSION_POST_PATTERN);
|
|
135
|
-
return
|
|
154
|
+
return [prefix, sanitizedName, suffix].join("");
|
|
136
155
|
}
|
|
137
156
|
if (name.startsWith("pages/")) {
|
|
138
157
|
const sanitizedName = name.split(".")[0];
|
|
139
|
-
return
|
|
158
|
+
return [prefix, sanitizedName, suffix].join("");
|
|
140
159
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const third = name.codePointAt(i + 2) | 32;
|
|
144
|
-
if (name[i + 1] !== "2" || third !== 102) {
|
|
145
|
-
return `chunks/${name.replace(/%/g, "_percent_")}_[hash].mjs`;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return `chunks/[name]_[hash].mjs`;
|
|
160
|
+
const encoded = encodeName(name);
|
|
161
|
+
return [prefix, encoded, suffix].join("");
|
|
150
162
|
},
|
|
151
163
|
assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`,
|
|
152
164
|
...viteConfig.build?.rollupOptions?.output,
|
|
@@ -165,6 +177,12 @@ async function ssrBuild(opts, internals, input, container) {
|
|
|
165
177
|
return "renderers.mjs";
|
|
166
178
|
} else if (chunkInfo.facadeModuleId === RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID) {
|
|
167
179
|
return "manifest_[hash].mjs";
|
|
180
|
+
} else if (settings.config.experimental.contentCollectionCache && chunkInfo.facadeModuleId && hasAnyContentFlag(chunkInfo.facadeModuleId)) {
|
|
181
|
+
const [srcRelative, flag] = chunkInfo.facadeModuleId.split("/src/")[1].split("?");
|
|
182
|
+
if (flag === PROPAGATED_ASSET_FLAG) {
|
|
183
|
+
return encodeName(`${removeFileExtension(srcRelative)}.entry.mjs`);
|
|
184
|
+
}
|
|
185
|
+
return encodeName(`${removeFileExtension(srcRelative)}.mjs`);
|
|
168
186
|
} else {
|
|
169
187
|
return "[name].mjs";
|
|
170
188
|
}
|
|
@@ -202,7 +220,7 @@ async function clientBuild(opts, internals, input, container) {
|
|
|
202
220
|
}
|
|
203
221
|
return null;
|
|
204
222
|
}
|
|
205
|
-
const { lastVitePlugins, vitePlugins } = container.runBeforeHook("client", input);
|
|
223
|
+
const { lastVitePlugins, vitePlugins } = await container.runBeforeHook("client", input);
|
|
206
224
|
opts.logger.info(null, `
|
|
207
225
|
${bgGreen(black(" building client "))}`);
|
|
208
226
|
const viteBuildConfig = {
|
|
@@ -249,7 +267,7 @@ async function runPostBuildHooks(container, ssrReturn, clientReturn) {
|
|
|
249
267
|
const config = container.options.settings.config;
|
|
250
268
|
const build = container.options.settings.config.build;
|
|
251
269
|
for (const [fileName, mutation] of mutations) {
|
|
252
|
-
const root = isServerLikeOutput(config) ? mutation.
|
|
270
|
+
const root = isServerLikeOutput(config) ? mutation.targets.includes("server") ? build.server : build.client : config.outDir;
|
|
253
271
|
const fullPath = path.join(fileURLToPath(root), fileName);
|
|
254
272
|
const fileURL = pathToFileURL(fullPath);
|
|
255
273
|
await fs.promises.mkdir(new URL("./", fileURL), { recursive: true });
|
|
@@ -323,12 +341,17 @@ async function copyFiles(fromFolder, toFolder, includeDotfiles = false) {
|
|
|
323
341
|
cwd: fileURLToPath(fromFolder),
|
|
324
342
|
dot: includeDotfiles
|
|
325
343
|
});
|
|
344
|
+
if (files.length === 0)
|
|
345
|
+
return;
|
|
326
346
|
await Promise.all(
|
|
327
|
-
files.map(async (filename)
|
|
347
|
+
files.map(async function copyFile(filename) {
|
|
328
348
|
const from = new URL(filename, fromFolder);
|
|
329
349
|
const to = new URL(filename, toFolder);
|
|
330
350
|
const lastFolder = new URL("./", to);
|
|
331
|
-
return fs.promises.mkdir(lastFolder, { recursive: true }).then(
|
|
351
|
+
return fs.promises.mkdir(lastFolder, { recursive: true }).then(async function fsCopyFile() {
|
|
352
|
+
const p = await fs.promises.copyFile(from, to, fs.constants.COPYFILE_FICLONE);
|
|
353
|
+
return p;
|
|
354
|
+
});
|
|
332
355
|
})
|
|
333
356
|
);
|
|
334
357
|
}
|
|
@@ -344,7 +367,7 @@ async function ssrMoveAssets(opts) {
|
|
|
344
367
|
});
|
|
345
368
|
if (files.length > 0) {
|
|
346
369
|
await Promise.all(
|
|
347
|
-
files.map(async (filename)
|
|
370
|
+
files.map(async function moveAsset(filename) {
|
|
348
371
|
const currentUrl = new URL(filename, appendForwardSlash(serverAssets.toString()));
|
|
349
372
|
const clientUrl = new URL(filename, appendForwardSlash(clientAssets.toString()));
|
|
350
373
|
const dir = new URL(path.parse(clientUrl.href).dir);
|
|
@@ -380,6 +403,7 @@ function makeSplitEntryPointFileName(facadeModuleId, routes) {
|
|
|
380
403
|
return filePath;
|
|
381
404
|
}
|
|
382
405
|
export {
|
|
406
|
+
copyFiles,
|
|
383
407
|
makeAstroPageEntryPointFileName,
|
|
384
408
|
makeSplitEntryPointFileName,
|
|
385
409
|
staticBuild,
|
|
@@ -29,7 +29,7 @@ export interface PageBuildData {
|
|
|
29
29
|
sheet: StylesheetAsset;
|
|
30
30
|
}>;
|
|
31
31
|
}
|
|
32
|
-
export type AllPagesData = Record<ComponentPath, PageBuildData>;
|
|
32
|
+
export type AllPagesData = Record<ComponentPath, PageBuildData[]>;
|
|
33
33
|
/** Options for the static build */
|
|
34
34
|
export interface StaticBuildOptions {
|
|
35
35
|
allPages: AllPagesData;
|
|
@@ -1 +1,8 @@
|
|
|
1
|
+
import type { AstroConfig } from '../../@types/astro.js';
|
|
1
2
|
export declare function getTimeStat(timeStart: number, timeEnd: number): string;
|
|
3
|
+
/**
|
|
4
|
+
* Given the Astro configuration, it tells if a slash should be appended or not
|
|
5
|
+
*/
|
|
6
|
+
export declare function shouldAppendForwardSlash(trailingSlash: AstroConfig['trailingSlash'], buildFormat: AstroConfig['build']['format']): boolean;
|
|
7
|
+
export declare function i18nHasFallback(config: AstroConfig): boolean;
|
|
8
|
+
export declare function encodeName(name: string): string;
|
package/dist/core/build/util.js
CHANGED
|
@@ -2,6 +2,42 @@ function getTimeStat(timeStart, timeEnd) {
|
|
|
2
2
|
const buildTime = timeEnd - timeStart;
|
|
3
3
|
return buildTime < 750 ? `${Math.round(buildTime)}ms` : `${(buildTime / 1e3).toFixed(2)}s`;
|
|
4
4
|
}
|
|
5
|
+
function shouldAppendForwardSlash(trailingSlash, buildFormat) {
|
|
6
|
+
switch (trailingSlash) {
|
|
7
|
+
case "always":
|
|
8
|
+
return true;
|
|
9
|
+
case "never":
|
|
10
|
+
return false;
|
|
11
|
+
case "ignore": {
|
|
12
|
+
switch (buildFormat) {
|
|
13
|
+
case "directory":
|
|
14
|
+
return true;
|
|
15
|
+
case "file":
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function i18nHasFallback(config) {
|
|
22
|
+
if (config.experimental.i18n && config.experimental.i18n.fallback) {
|
|
23
|
+
return Object.keys(config.experimental.i18n.fallback).length > 0;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
function encodeName(name) {
|
|
28
|
+
for (let i = 0; i < name.length; i++) {
|
|
29
|
+
if (name[i] === "%") {
|
|
30
|
+
const third = name.codePointAt(i + 2) | 32;
|
|
31
|
+
if (name[i + 1] !== "2" || third !== 102) {
|
|
32
|
+
return `${name.replace(/%/g, "_percent_")}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return name;
|
|
37
|
+
}
|
|
5
38
|
export {
|
|
6
|
-
|
|
39
|
+
encodeName,
|
|
40
|
+
getTimeStat,
|
|
41
|
+
i18nHasFallback,
|
|
42
|
+
shouldAppendForwardSlash
|
|
7
43
|
};
|
|
@@ -25,6 +25,7 @@ async function compile({
|
|
|
25
25
|
scopedStyleStrategy: astroConfig.scopedStyleStrategy,
|
|
26
26
|
resultScopedSlot: true,
|
|
27
27
|
transitionsAnimationURL: "astro/components/viewtransitions.css",
|
|
28
|
+
annotateSourceFile: !viteConfig.isProduction && astroConfig.experimental.devOverlay,
|
|
28
29
|
preprocessStyle: createStylePreprocessor({
|
|
29
30
|
filename,
|
|
30
31
|
viteConfig,
|
|
@@ -23,6 +23,9 @@ async function validateConfig(userConfig, root, cmd) {
|
|
|
23
23
|
}
|
|
24
24
|
throw e;
|
|
25
25
|
}
|
|
26
|
+
if (result.build.inlineStylesheets !== "auto" && result.experimental.contentCollectionCache) {
|
|
27
|
+
result.experimental.contentCollectionCache = false;
|
|
28
|
+
}
|
|
26
29
|
return result;
|
|
27
30
|
}
|
|
28
31
|
function resolveFlags(flags) {
|