astro 4.7.1 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +1 -0
- package/content-module.template.mjs +2 -0
- package/dist/@types/astro.d.ts +219 -3
- package/dist/actions/consts.d.ts +3 -0
- package/dist/actions/consts.js +8 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +72 -0
- package/dist/actions/runtime/middleware.d.ts +7 -0
- package/dist/actions/runtime/middleware.js +38 -0
- package/dist/actions/runtime/route.d.ts +2 -0
- package/dist/actions/runtime/route.js +37 -0
- package/dist/actions/runtime/store.d.ts +6 -0
- package/dist/actions/runtime/store.js +18 -0
- package/dist/actions/runtime/utils.d.ts +4 -0
- package/dist/actions/runtime/utils.js +23 -0
- package/dist/actions/runtime/virtual/client.d.ts +4 -0
- package/dist/actions/runtime/virtual/client.js +20 -0
- package/dist/actions/runtime/virtual/server.d.ts +21 -0
- package/dist/actions/runtime/virtual/server.js +98 -0
- package/dist/actions/runtime/virtual/shared.d.ts +37 -0
- package/dist/actions/runtime/virtual/shared.js +104 -0
- package/dist/actions/utils.d.ts +2 -0
- package/dist/actions/utils.js +18 -0
- package/dist/assets/build/generate.js +1 -1
- package/dist/assets/internal.js +1 -2
- package/dist/assets/services/service.js +2 -4
- package/dist/assets/services/sharp.js +2 -4
- package/dist/assets/services/squoosh.js +2 -4
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +34 -68
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +39 -78
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +32 -64
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +32 -64
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +2 -4
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +29 -58
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +29 -58
- package/dist/assets/utils/getAssetsPrefix.js +2 -4
- package/dist/assets/utils/remotePattern.js +1 -2
- package/dist/assets/utils/remoteProbe.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/cur.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/icns.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/ico.js +2 -4
- package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -4
- package/dist/assets/utils/vendor/image-size/types/utils.js +4 -8
- package/dist/assets/vite-plugin-assets.js +1 -1
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/imports.js +4 -8
- package/dist/cli/add/index.js +23 -46
- package/dist/cli/add/wrapper.js +1 -2
- package/dist/cli/index.js +1 -2
- package/dist/cli/info/index.js +1 -2
- package/dist/cli/install-package.js +3 -6
- package/dist/cli/throw-and-exit.js +1 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +2 -2
- package/dist/content/index.d.ts +1 -1
- package/dist/content/index.js +1 -7
- package/dist/content/runtime.d.ts +2 -1
- package/dist/content/runtime.js +11 -20
- package/dist/content/server-listeners.js +5 -10
- package/dist/content/types-generator.js +5 -10
- package/dist/content/utils.d.ts +0 -4
- package/dist/content/utils.js +4 -15
- package/dist/content/vite-plugin-content-assets.d.ts +1 -1
- package/dist/content/vite-plugin-content-assets.js +14 -47
- package/dist/content/vite-plugin-content-imports.js +6 -11
- package/dist/content/vite-plugin-content-virtual-mod.js +7 -14
- package/dist/core/app/index.js +11 -46
- package/dist/core/app/node.js +4 -3
- package/dist/core/app/pipeline.d.ts +7 -2
- package/dist/core/app/pipeline.js +70 -2
- package/dist/core/app/types.d.ts +1 -0
- package/dist/core/base-pipeline.d.ts +16 -1
- package/dist/core/build/generate.js +15 -61
- package/dist/core/build/index.js +2 -4
- package/dist/core/build/internal.d.ts +39 -9
- package/dist/core/build/internal.js +43 -54
- package/dist/core/build/page-data.js +6 -6
- package/dist/core/build/pipeline.d.ts +7 -3
- package/dist/core/build/pipeline.js +134 -23
- package/dist/core/build/plugins/plugin-analyzer.js +11 -32
- package/dist/core/build/plugins/plugin-content.d.ts +1 -0
- package/dist/core/build/plugins/plugin-content.js +34 -32
- package/dist/core/build/plugins/plugin-css.js +23 -51
- package/dist/core/build/plugins/plugin-manifest.js +7 -8
- package/dist/core/build/plugins/plugin-pages.d.ts +0 -1
- package/dist/core/build/plugins/plugin-pages.js +10 -12
- package/dist/core/build/plugins/plugin-ssr.js +15 -13
- package/dist/core/build/plugins/util.d.ts +26 -11
- package/dist/core/build/plugins/util.js +22 -6
- package/dist/core/build/static-build.js +30 -25
- package/dist/core/build/types.d.ts +6 -6
- package/dist/core/client-directive/build.js +1 -2
- package/dist/core/config/config.js +2 -7
- package/dist/core/config/logging.js +1 -2
- package/dist/core/config/schema.d.ts +92 -60
- package/dist/core/config/schema.js +6 -2
- package/dist/core/config/settings.js +1 -2
- package/dist/core/config/timer.js +4 -8
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.js +3 -6
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +1 -2
- package/dist/core/errors/errors-data.d.ts +24 -0
- package/dist/core/errors/errors-data.js +13 -2
- package/dist/core/errors/errors.js +1 -2
- package/dist/core/errors/overlay.js +1 -2
- package/dist/core/errors/printer.js +2 -4
- package/dist/core/errors/zod-error-map.js +2 -4
- package/dist/core/fs/index.js +2 -4
- package/dist/core/logger/vite.js +9 -18
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +3 -2
- package/dist/core/middleware/callMiddleware.js +13 -3
- package/dist/core/middleware/index.js +12 -8
- package/dist/core/middleware/sequence.js +22 -4
- package/dist/core/module-loader/vite.js +1 -2
- package/dist/core/render/params-and-props.js +2 -4
- package/dist/core/render/slots.js +4 -8
- package/dist/core/render-context.d.ts +15 -5
- package/dist/core/render-context.js +134 -28
- package/dist/core/request.js +1 -2
- package/dist/core/routing/manifest/create.js +3 -6
- package/dist/core/sync/index.js +10 -3
- package/dist/core/util.d.ts +2 -0
- package/dist/core/util.js +18 -19
- package/dist/i18n/index.js +2 -4
- package/dist/i18n/middleware.js +1 -2
- package/dist/i18n/utils.js +1 -2
- package/dist/i18n/vite-plugin-i18n.js +1 -2
- package/dist/integrations/hooks.js +5 -1
- package/dist/jsx/babel.d.ts +3 -0
- package/dist/jsx/babel.js +9 -18
- package/dist/jsx/rehype.d.ts +11 -0
- package/dist/jsx/rehype.js +197 -0
- package/dist/jsx/server.js +20 -14
- package/dist/jsx/transform-options.d.ts +3 -0
- package/dist/jsx-runtime/index.js +8 -16
- package/dist/preferences/index.js +3 -6
- package/dist/preferences/store.js +3 -6
- package/dist/prefetch/index.js +8 -16
- package/dist/prefetch/vite-plugin-prefetch.js +2 -4
- package/dist/prerender/metadata.js +1 -2
- package/dist/prerender/routing.js +1 -1
- package/dist/prerender/utils.d.ts +0 -1
- package/dist/prerender/utils.js +2 -5
- package/dist/runtime/client/dev-toolbar/apps/astro.js +5 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/index.js +5 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +45 -90
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/index.js +1 -2
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/perf.js +16 -32
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-window.js +2 -4
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +3 -6
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +1 -2
- package/dist/runtime/client/dev-toolbar/apps/utils/window.js +4 -8
- package/dist/runtime/client/dev-toolbar/entrypoint.js +8 -11
- package/dist/runtime/client/dev-toolbar/helpers.js +2 -4
- package/dist/runtime/client/dev-toolbar/toolbar.js +11 -22
- package/dist/runtime/client/dev-toolbar/ui-library/badge.js +1 -2
- package/dist/runtime/client/dev-toolbar/ui-library/button.d.ts +5 -0
- package/dist/runtime/client/dev-toolbar/ui-library/button.js +26 -5
- package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +1 -0
- package/dist/runtime/client/dev-toolbar/ui-library/index.js +2 -0
- package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.d.ts +13 -0
- package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.js +109 -0
- package/dist/runtime/client/visible.js +1 -2
- package/dist/runtime/server/astro-component.js +2 -4
- package/dist/runtime/server/astro-island.js +7 -14
- package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/index.js +3 -6
- package/dist/runtime/server/jsx.js +1 -2
- package/dist/runtime/server/render/any.js +1 -2
- package/dist/runtime/server/render/astro/instance.js +1 -2
- package/dist/runtime/server/render/astro/render.js +5 -10
- package/dist/runtime/server/render/component.js +6 -11
- package/dist/runtime/server/render/dom.js +1 -2
- package/dist/runtime/server/render/page.js +1 -2
- package/dist/runtime/server/render/script.js +1 -2
- package/dist/runtime/server/render/slot.js +1 -2
- package/dist/runtime/server/render/tags.js +2 -4
- package/dist/runtime/server/render/util.js +2 -4
- package/dist/runtime/server/shorthash.js +1 -2
- package/dist/runtime/server/transition.js +4 -8
- package/dist/runtime/server/util.js +1 -2
- package/dist/transitions/events.d.ts +3 -3
- package/dist/transitions/events.js +5 -4
- package/dist/transitions/router.js +22 -113
- package/dist/transitions/swap-functions.d.ts +12 -0
- package/dist/transitions/swap-functions.js +105 -0
- package/dist/vite-plugin-astro/compile.js +1 -2
- package/dist/vite-plugin-astro/hmr.js +5 -10
- package/dist/vite-plugin-astro/index.js +2 -4
- package/dist/vite-plugin-astro-server/pipeline.d.ts +8 -3
- package/dist/vite-plugin-astro-server/pipeline.js +59 -11
- package/dist/vite-plugin-astro-server/plugin.js +6 -6
- package/dist/vite-plugin-astro-server/response.js +1 -2
- package/dist/vite-plugin-astro-server/route.js +36 -42
- package/dist/vite-plugin-astro-server/vite.js +1 -2
- package/dist/vite-plugin-config-alias/index.js +7 -14
- package/dist/vite-plugin-head/index.js +3 -6
- package/dist/vite-plugin-html/index.js +1 -2
- package/dist/vite-plugin-html/transform/escape.js +2 -4
- package/dist/vite-plugin-html/transform/slots.js +1 -2
- package/dist/vite-plugin-html/transform/utils.js +1 -2
- package/dist/vite-plugin-inject-env-ts/index.js +37 -11
- package/dist/vite-plugin-integrations-container/index.js +3 -6
- package/dist/vite-plugin-load-fallback/index.js +1 -2
- package/dist/vite-plugin-markdown/index.js +1 -2
- package/dist/vite-plugin-mdx/index.d.ts +3 -0
- package/dist/vite-plugin-mdx/tag.d.ts +2 -0
- package/dist/vite-plugin-mdx/tag.js +3 -6
- package/dist/vite-plugin-mdx/transform-jsx.d.ts +3 -0
- package/dist/vite-plugin-mdx/transform-jsx.js +1 -2
- package/dist/vite-plugin-scanner/index.js +4 -6
- package/dist/vite-plugin-scanner/scan.js +2 -4
- package/dist/vite-plugin-scripts/page-ssr.js +3 -6
- package/package.json +18 -14
- package/templates/actions.mjs +61 -0
- package/types/actions.d.ts +3 -0
- package/types/content.d.ts +2 -2
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import { routeIsRedirect } from "../../redirects/index.js";
|
|
2
2
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
3
|
-
import {
|
|
3
|
+
import {} from "../internal.js";
|
|
4
4
|
import { RENDERERS_MODULE_ID } from "./plugin-renderers.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getPagesFromVirtualModulePageName, getVirtualModulePageName } from "./util.js";
|
|
6
6
|
const ASTRO_PAGE_MODULE_ID = "@astro-page:";
|
|
7
7
|
const ASTRO_PAGE_RESOLVED_MODULE_ID = "\0" + ASTRO_PAGE_MODULE_ID;
|
|
8
|
-
function getVirtualModulePageIdFromPath(path) {
|
|
9
|
-
const name = getVirtualModulePageNameFromPath(ASTRO_PAGE_MODULE_ID, path);
|
|
10
|
-
return "\0" + name;
|
|
11
|
-
}
|
|
12
8
|
function vitePluginPages(opts, internals) {
|
|
13
9
|
return {
|
|
14
10
|
name: "@astro/plugin-build-pages",
|
|
15
11
|
options(options) {
|
|
16
12
|
if (opts.settings.config.output === "static") {
|
|
17
13
|
const inputs = /* @__PURE__ */ new Set();
|
|
18
|
-
for (const
|
|
14
|
+
for (const pageData of Object.values(opts.allPages)) {
|
|
19
15
|
if (routeIsRedirect(pageData.route)) {
|
|
20
16
|
continue;
|
|
21
17
|
}
|
|
22
|
-
inputs.add(
|
|
18
|
+
inputs.add(getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, pageData.component));
|
|
23
19
|
}
|
|
24
20
|
return addRollupInput(options, Array.from(inputs));
|
|
25
21
|
}
|
|
@@ -33,9 +29,12 @@ function vitePluginPages(opts, internals) {
|
|
|
33
29
|
if (id.startsWith(ASTRO_PAGE_RESOLVED_MODULE_ID)) {
|
|
34
30
|
const imports = [];
|
|
35
31
|
const exports = [];
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const pageDatas = getPagesFromVirtualModulePageName(
|
|
33
|
+
internals,
|
|
34
|
+
ASTRO_PAGE_RESOLVED_MODULE_ID,
|
|
35
|
+
id
|
|
36
|
+
);
|
|
37
|
+
for (const pageData of pageDatas) {
|
|
39
38
|
const resolvedPage = await this.resolve(pageData.moduleSpecifier);
|
|
40
39
|
if (resolvedPage) {
|
|
41
40
|
imports.push(`const page = () => import(${JSON.stringify(pageData.moduleSpecifier)});`);
|
|
@@ -64,6 +63,5 @@ function pluginPages(opts, internals) {
|
|
|
64
63
|
export {
|
|
65
64
|
ASTRO_PAGE_MODULE_ID,
|
|
66
65
|
ASTRO_PAGE_RESOLVED_MODULE_ID,
|
|
67
|
-
getVirtualModulePageIdFromPath,
|
|
68
66
|
pluginPages
|
|
69
67
|
};
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
3
|
import { isFunctionPerRouteEnabled } from "../../../integrations/hooks.js";
|
|
4
|
-
import { isServerLikeOutput } from "../../../prerender/utils.js";
|
|
5
4
|
import { routeIsRedirect } from "../../redirects/index.js";
|
|
5
|
+
import { isServerLikeOutput } from "../../util.js";
|
|
6
6
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
7
|
-
import { eachPageFromAllPages } from "../internal.js";
|
|
8
7
|
import { SSR_MANIFEST_VIRTUAL_MODULE_ID } from "./plugin-manifest.js";
|
|
9
8
|
import { MIDDLEWARE_MODULE_ID } from "./plugin-middleware.js";
|
|
10
9
|
import { ASTRO_PAGE_MODULE_ID } from "./plugin-pages.js";
|
|
11
10
|
import { RENDERERS_MODULE_ID } from "./plugin-renderers.js";
|
|
12
|
-
import {
|
|
11
|
+
import { getComponentFromVirtualModulePageName, getVirtualModulePageName } from "./util.js";
|
|
13
12
|
const SSR_VIRTUAL_MODULE_ID = "@astrojs-ssr-virtual-entry";
|
|
14
13
|
const RESOLVED_SSR_VIRTUAL_MODULE_ID = "\0" + SSR_VIRTUAL_MODULE_ID;
|
|
15
14
|
function vitePluginSSR(internals, adapter, options) {
|
|
@@ -32,16 +31,19 @@ function vitePluginSSR(internals, adapter, options) {
|
|
|
32
31
|
const exports = [];
|
|
33
32
|
let i = 0;
|
|
34
33
|
const pageMap = [];
|
|
35
|
-
for (const
|
|
34
|
+
for (const pageData of Object.values(allPages)) {
|
|
36
35
|
if (routeIsRedirect(pageData.route)) {
|
|
37
36
|
continue;
|
|
38
37
|
}
|
|
39
|
-
const virtualModuleName =
|
|
38
|
+
const virtualModuleName = getVirtualModulePageName(
|
|
39
|
+
ASTRO_PAGE_MODULE_ID,
|
|
40
|
+
pageData.component
|
|
41
|
+
);
|
|
40
42
|
let module = await this.resolve(virtualModuleName);
|
|
41
43
|
if (module) {
|
|
42
44
|
const variable = `_page${i}`;
|
|
43
45
|
imports.push(`const ${variable} = () => import("${virtualModuleName}");`);
|
|
44
|
-
const pageData2 = internals.
|
|
46
|
+
const pageData2 = internals.pagesByKeys.get(pageData.key);
|
|
45
47
|
if (pageData2) {
|
|
46
48
|
pageMap.push(`[${JSON.stringify(pageData2.component)}, ${variable}]`);
|
|
47
49
|
}
|
|
@@ -115,11 +117,11 @@ function vitePluginSSRSplit(internals, adapter, options) {
|
|
|
115
117
|
options(opts) {
|
|
116
118
|
if (functionPerRouteEnabled) {
|
|
117
119
|
const inputs = /* @__PURE__ */ new Set();
|
|
118
|
-
for (const
|
|
120
|
+
for (const pageData of Object.values(options.allPages)) {
|
|
119
121
|
if (routeIsRedirect(pageData.route)) {
|
|
120
122
|
continue;
|
|
121
123
|
}
|
|
122
|
-
inputs.add(
|
|
124
|
+
inputs.add(getVirtualModulePageName(SPLIT_MODULE_ID, pageData.component));
|
|
123
125
|
}
|
|
124
126
|
return addRollupInput(opts, Array.from(inputs));
|
|
125
127
|
}
|
|
@@ -134,8 +136,8 @@ function vitePluginSSRSplit(internals, adapter, options) {
|
|
|
134
136
|
const imports = [];
|
|
135
137
|
const contents = [];
|
|
136
138
|
const exports = [];
|
|
137
|
-
const
|
|
138
|
-
const virtualModuleName =
|
|
139
|
+
const componentPath = getComponentFromVirtualModulePageName(RESOLVED_SPLIT_MODULE_ID, id);
|
|
140
|
+
const virtualModuleName = getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, componentPath);
|
|
139
141
|
let module = await this.resolve(virtualModuleName);
|
|
140
142
|
if (module) {
|
|
141
143
|
imports.push(`import * as pageModule from "${virtualModuleName}";`);
|
|
@@ -225,9 +227,9 @@ if (_start in serverEntrypointModule) {
|
|
|
225
227
|
};
|
|
226
228
|
}
|
|
227
229
|
function storeEntryPoint(moduleKey, options, internals, fileName) {
|
|
228
|
-
const componentPath =
|
|
229
|
-
for (const
|
|
230
|
-
if (componentPath ==
|
|
230
|
+
const componentPath = getComponentFromVirtualModulePageName(RESOLVED_SPLIT_MODULE_ID, moduleKey);
|
|
231
|
+
for (const pageData of Object.values(options.allPages)) {
|
|
232
|
+
if (componentPath == pageData.component) {
|
|
231
233
|
const publicPath = fileURLToPath(options.settings.config.build.server);
|
|
232
234
|
internals.entryPoints.set(pageData.route, pathToFileURL(join(publicPath, fileName)));
|
|
233
235
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { BuildOptions, Rollup, Plugin as VitePlugin } from 'vite';
|
|
2
|
+
import type { BuildInternals } from '../internal.js';
|
|
3
|
+
import type { PageBuildData } from '../types.js';
|
|
2
4
|
type OutputOptionsHook = Extract<VitePlugin['outputOptions'], Function>;
|
|
3
5
|
type OutputOptions = Parameters<OutputOptionsHook>[0];
|
|
4
6
|
type ExtendManualChunksHooks = {
|
|
@@ -7,21 +9,34 @@ type ExtendManualChunksHooks = {
|
|
|
7
9
|
};
|
|
8
10
|
export declare function extendManualChunks(outputOptions: OutputOptions, hooks: ExtendManualChunksHooks): void;
|
|
9
11
|
export declare const ASTRO_PAGE_EXTENSION_POST_PATTERN = "@_@";
|
|
12
|
+
export declare const ASTRO_PAGE_KEY_SEPARATOR = "&";
|
|
13
|
+
/**
|
|
14
|
+
* Generate a unique key to identify each page in the build process.
|
|
15
|
+
* @param route Usually pageData.route.route
|
|
16
|
+
* @param componentPath Usually pageData.component
|
|
17
|
+
*/
|
|
18
|
+
export declare function makePageDataKey(route: string, componentPath: string): string;
|
|
10
19
|
/**
|
|
11
20
|
* Prevents Rollup from triggering other plugins in the process by masking the extension (hence the virtual file).
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
* Inverse function of getComponentFromVirtualModulePageName() below.
|
|
22
|
+
* @param virtualModulePrefix The prefix used to create the virtual module
|
|
23
|
+
* @param path Page component path
|
|
24
|
+
*/
|
|
25
|
+
export declare function getVirtualModulePageName(virtualModulePrefix: string, path: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* From the VirtualModulePageName, and the internals, get all pageDatas that use this
|
|
28
|
+
* component as their entry point.
|
|
29
|
+
* @param virtualModulePrefix The prefix used to create the virtual module
|
|
30
|
+
* @param id Virtual module name
|
|
18
31
|
*/
|
|
19
|
-
export declare function
|
|
32
|
+
export declare function getPagesFromVirtualModulePageName(internals: BuildInternals, virtualModulePrefix: string, id: string): PageBuildData[];
|
|
20
33
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
34
|
+
* From the VirtualModulePageName, get the component path.
|
|
35
|
+
* Remember that the component can be use by multiple routes.
|
|
36
|
+
* Inverse function of getVirtualModulePageName() above.
|
|
37
|
+
* @param virtualModulePrefix The prefix at the beginning of the virtual module
|
|
38
|
+
* @param id Virtual module name
|
|
24
39
|
*/
|
|
25
|
-
export declare function
|
|
40
|
+
export declare function getComponentFromVirtualModulePageName(virtualModulePrefix: string, id: string): string;
|
|
26
41
|
export declare function shouldInlineAsset(assetContent: string, assetPath: string, assetsInlineLimit: NonNullable<BuildOptions['assetsInlineLimit']>): boolean;
|
|
27
42
|
export {};
|
|
@@ -26,13 +26,26 @@ function extendManualChunks(outputOptions, hooks) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
const ASTRO_PAGE_EXTENSION_POST_PATTERN = "@_@";
|
|
29
|
-
|
|
29
|
+
const ASTRO_PAGE_KEY_SEPARATOR = "&";
|
|
30
|
+
function makePageDataKey(route, componentPath) {
|
|
31
|
+
return route + ASTRO_PAGE_KEY_SEPARATOR + componentPath;
|
|
32
|
+
}
|
|
33
|
+
function getVirtualModulePageName(virtualModulePrefix, path) {
|
|
30
34
|
const extension = extname(path);
|
|
31
35
|
return virtualModulePrefix + (extension.startsWith(".") ? path.slice(0, -extension.length) + extension.replace(".", ASTRO_PAGE_EXTENSION_POST_PATTERN) : path);
|
|
32
36
|
}
|
|
33
|
-
function
|
|
34
|
-
const
|
|
35
|
-
|
|
37
|
+
function getPagesFromVirtualModulePageName(internals, virtualModulePrefix, id) {
|
|
38
|
+
const path = getComponentFromVirtualModulePageName(virtualModulePrefix, id);
|
|
39
|
+
const pages = [];
|
|
40
|
+
internals.pagesByKeys.forEach((pageData) => {
|
|
41
|
+
if (pageData.component === path) {
|
|
42
|
+
pages.push(pageData);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return pages;
|
|
46
|
+
}
|
|
47
|
+
function getComponentFromVirtualModulePageName(virtualModulePrefix, id) {
|
|
48
|
+
return id.slice(virtualModulePrefix.length).replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, ".");
|
|
36
49
|
}
|
|
37
50
|
function shouldInlineAsset(assetContent, assetPath, assetsInlineLimit) {
|
|
38
51
|
if (typeof assetsInlineLimit === "function") {
|
|
@@ -47,8 +60,11 @@ function shouldInlineAsset(assetContent, assetPath, assetsInlineLimit) {
|
|
|
47
60
|
}
|
|
48
61
|
export {
|
|
49
62
|
ASTRO_PAGE_EXTENSION_POST_PATTERN,
|
|
63
|
+
ASTRO_PAGE_KEY_SEPARATOR,
|
|
50
64
|
extendManualChunks,
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
getComponentFromVirtualModulePageName,
|
|
66
|
+
getPagesFromVirtualModulePageName,
|
|
67
|
+
getVirtualModulePageName,
|
|
68
|
+
makePageDataKey,
|
|
53
69
|
shouldInlineAsset
|
|
54
70
|
};
|
|
@@ -10,13 +10,13 @@ import { PROPAGATED_ASSET_FLAG } from "../../content/consts.js";
|
|
|
10
10
|
import { hasAnyContentFlag } from "../../content/utils.js";
|
|
11
11
|
import {
|
|
12
12
|
createBuildInternals,
|
|
13
|
-
|
|
13
|
+
getPageDatasWithPublicKey
|
|
14
14
|
} from "../../core/build/internal.js";
|
|
15
15
|
import { emptyDir, removeEmptyDirs } from "../../core/fs/index.js";
|
|
16
16
|
import { appendForwardSlash, prependForwardSlash, removeFileExtension } from "../../core/path.js";
|
|
17
|
-
import { isModeServerWithNoAdapter } from "../../core/util.js";
|
|
17
|
+
import { isModeServerWithNoAdapter, isServerLikeOutput } from "../../core/util.js";
|
|
18
18
|
import { runHookBuildSetup } from "../../integrations/hooks.js";
|
|
19
|
-
import { getOutputDirectory
|
|
19
|
+
import { getOutputDirectory } from "../../prerender/utils.js";
|
|
20
20
|
import { PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
21
21
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
22
22
|
import { routeIsRedirect } from "../redirects/index.js";
|
|
@@ -26,6 +26,7 @@ import { generatePages } from "./generate.js";
|
|
|
26
26
|
import { trackPageData } from "./internal.js";
|
|
27
27
|
import { createPluginContainer } from "./plugin.js";
|
|
28
28
|
import { registerAllPlugins } from "./plugins/index.js";
|
|
29
|
+
import { copyContentToCache } from "./plugins/plugin-content.js";
|
|
29
30
|
import { RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID } from "./plugins/plugin-manifest.js";
|
|
30
31
|
import { ASTRO_PAGE_RESOLVED_MODULE_ID } from "./plugins/plugin-pages.js";
|
|
31
32
|
import { RESOLVED_RENDERERS_MODULE_ID } from "./plugins/plugin-renderers.js";
|
|
@@ -40,10 +41,10 @@ async function viteBuild(opts) {
|
|
|
40
41
|
settings.timer.start("SSR build");
|
|
41
42
|
const pageInput = /* @__PURE__ */ new Set();
|
|
42
43
|
const internals = createBuildInternals();
|
|
43
|
-
for (const
|
|
44
|
-
const astroModuleURL = new URL("./" + component, settings.config.root);
|
|
45
|
-
const astroModuleId = prependForwardSlash(component);
|
|
46
|
-
trackPageData(internals, component, pageData, astroModuleId, astroModuleURL);
|
|
44
|
+
for (const pageData of Object.values(allPages)) {
|
|
45
|
+
const astroModuleURL = new URL("./" + pageData.component, settings.config.root);
|
|
46
|
+
const astroModuleId = prependForwardSlash(pageData.component);
|
|
47
|
+
trackPageData(internals, pageData.component, pageData, astroModuleId, astroModuleURL);
|
|
47
48
|
if (!routeIsRedirect(pageData.route)) {
|
|
48
49
|
pageInput.add(astroModuleId);
|
|
49
50
|
}
|
|
@@ -74,6 +75,9 @@ async function viteBuild(opts) {
|
|
|
74
75
|
const ssrOutputs = viteBuildReturnToRollupOutputs(ssrOutput);
|
|
75
76
|
const clientOutputs = viteBuildReturnToRollupOutputs(clientOutput ?? []);
|
|
76
77
|
await runPostBuildHooks(container, ssrOutputs, clientOutputs);
|
|
78
|
+
if (opts.settings.config.experimental.contentCollectionCache) {
|
|
79
|
+
await copyContentToCache(opts);
|
|
80
|
+
}
|
|
77
81
|
settings.timer.end("Client build");
|
|
78
82
|
internals.ssrEntryChunk = void 0;
|
|
79
83
|
if (opts.teardownCompiler) {
|
|
@@ -212,7 +216,7 @@ async function ssrBuild(opts, internals, input, container) {
|
|
|
212
216
|
};
|
|
213
217
|
const updatedViteBuildConfig = await runHookBuildSetup({
|
|
214
218
|
config: settings.config,
|
|
215
|
-
pages: internals.
|
|
219
|
+
pages: getPageDatasWithPublicKey(internals.pagesByKeys),
|
|
216
220
|
vite: viteBuildConfig,
|
|
217
221
|
target: "server",
|
|
218
222
|
logger: opts.logger
|
|
@@ -260,7 +264,7 @@ ${bgGreen(black(" building client (vite) "))}`);
|
|
|
260
264
|
};
|
|
261
265
|
await runHookBuildSetup({
|
|
262
266
|
config: settings.config,
|
|
263
|
-
pages: internals.
|
|
267
|
+
pages: getPageDatasWithPublicKey(internals.pagesByKeys),
|
|
264
268
|
vite: viteBuildConfig,
|
|
265
269
|
target: "client",
|
|
266
270
|
logger: opts.logger
|
|
@@ -281,13 +285,18 @@ async function runPostBuildHooks(container, ssrOutputs, clientOutputs) {
|
|
|
281
285
|
}
|
|
282
286
|
}
|
|
283
287
|
async function cleanStaticOutput(opts, internals, ssrOutputChunkNames) {
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
288
|
+
const prerenderedFiles = /* @__PURE__ */ new Set();
|
|
289
|
+
const onDemandsFiles = /* @__PURE__ */ new Set();
|
|
290
|
+
for (const pageData of internals.pagesByKeys.values()) {
|
|
291
|
+
const { moduleSpecifier } = pageData;
|
|
292
|
+
const bundleId = internals.pageToBundleMap.get(moduleSpecifier) ?? internals.entrySpecifierToBundleMap.get(moduleSpecifier);
|
|
293
|
+
if (pageData.route.prerender && !pageData.hasSharedModules && !onDemandsFiles.has(bundleId)) {
|
|
294
|
+
prerenderedFiles.add(bundleId);
|
|
295
|
+
} else {
|
|
296
|
+
onDemandsFiles.add(bundleId);
|
|
297
|
+
if (prerenderedFiles.has(bundleId)) {
|
|
298
|
+
prerenderedFiles.delete(bundleId);
|
|
299
|
+
}
|
|
291
300
|
}
|
|
292
301
|
}
|
|
293
302
|
const ssr = isServerLikeOutput(opts.settings.config);
|
|
@@ -297,7 +306,7 @@ async function cleanStaticOutput(opts, internals, ssrOutputChunkNames) {
|
|
|
297
306
|
await eslexer.init;
|
|
298
307
|
await Promise.all(
|
|
299
308
|
files.map(async (filename) => {
|
|
300
|
-
if (!
|
|
309
|
+
if (!prerenderedFiles.has(filename)) {
|
|
301
310
|
return;
|
|
302
311
|
}
|
|
303
312
|
const url = new URL(filename, out);
|
|
@@ -305,11 +314,9 @@ async function cleanStaticOutput(opts, internals, ssrOutputChunkNames) {
|
|
|
305
314
|
const [, exports] = eslexer.parse(text);
|
|
306
315
|
let value = "const noop = () => {};";
|
|
307
316
|
for (const e of exports) {
|
|
308
|
-
if (e.n === "default")
|
|
309
|
-
value += `
|
|
317
|
+
if (e.n === "default") value += `
|
|
310
318
|
export default noop;`;
|
|
311
|
-
else
|
|
312
|
-
value += `
|
|
319
|
+
else value += `
|
|
313
320
|
export const ${e.n} = noop;`;
|
|
314
321
|
}
|
|
315
322
|
await fs.promises.writeFile(url, value, { encoding: "utf8" });
|
|
@@ -348,8 +355,7 @@ async function copyFiles(fromFolder, toFolder, includeDotfiles = false) {
|
|
|
348
355
|
cwd: fileURLToPath(fromFolder),
|
|
349
356
|
dot: includeDotfiles
|
|
350
357
|
});
|
|
351
|
-
if (files.length === 0)
|
|
352
|
-
return;
|
|
358
|
+
if (files.length === 0) return;
|
|
353
359
|
return await Promise.all(
|
|
354
360
|
files.map(async function copyFile(filename) {
|
|
355
361
|
const from = new URL(filename, fromFolder);
|
|
@@ -378,8 +384,7 @@ async function ssrMoveAssets(opts) {
|
|
|
378
384
|
const currentUrl = new URL(filename, appendForwardSlash(serverAssets.toString()));
|
|
379
385
|
const clientUrl = new URL(filename, appendForwardSlash(clientAssets.toString()));
|
|
380
386
|
const dir = new URL(path.parse(clientUrl.href).dir);
|
|
381
|
-
if (!fs.existsSync(dir))
|
|
382
|
-
await fs.promises.mkdir(dir, { recursive: true });
|
|
387
|
+
if (!fs.existsSync(dir)) await fs.promises.mkdir(dir, { recursive: true });
|
|
383
388
|
return fs.promises.rename(currentUrl, clientUrl);
|
|
384
389
|
})
|
|
385
390
|
);
|
|
@@ -12,16 +12,16 @@ export type StylesheetAsset = {
|
|
|
12
12
|
type: 'external';
|
|
13
13
|
src: string;
|
|
14
14
|
};
|
|
15
|
+
export type HoistedScriptAsset = {
|
|
16
|
+
type: 'inline' | 'external';
|
|
17
|
+
value: string;
|
|
18
|
+
};
|
|
15
19
|
export interface PageBuildData {
|
|
20
|
+
key: string;
|
|
16
21
|
component: ComponentPath;
|
|
17
22
|
route: RouteData;
|
|
18
23
|
moduleSpecifier: string;
|
|
19
|
-
|
|
20
|
-
propagatedScripts: Map<string, Set<string>>;
|
|
21
|
-
hoistedScript: {
|
|
22
|
-
type: 'inline' | 'external';
|
|
23
|
-
value: string;
|
|
24
|
-
} | undefined;
|
|
24
|
+
hoistedScript: HoistedScriptAsset | undefined;
|
|
25
25
|
styles: Array<{
|
|
26
26
|
depth: number;
|
|
27
27
|
order: number;
|
|
@@ -23,9 +23,6 @@ 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
|
-
}
|
|
29
26
|
return result;
|
|
30
27
|
}
|
|
31
28
|
function resolveFlags(flags) {
|
|
@@ -77,15 +74,13 @@ async function resolveConfigPath(options) {
|
|
|
77
74
|
return userConfigPath;
|
|
78
75
|
}
|
|
79
76
|
async function loadConfig(root, configFile, fsMod = fs) {
|
|
80
|
-
if (configFile === false)
|
|
81
|
-
return {};
|
|
77
|
+
if (configFile === false) return {};
|
|
82
78
|
const configPath = await resolveConfigPath({
|
|
83
79
|
root,
|
|
84
80
|
configFile,
|
|
85
81
|
fs: fsMod
|
|
86
82
|
});
|
|
87
|
-
if (!configPath)
|
|
88
|
-
return {};
|
|
83
|
+
if (!configPath) return {};
|
|
89
84
|
try {
|
|
90
85
|
return await loadConfigWithVite({
|
|
91
86
|
root,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Logger } from "../logger/core.js";
|
|
2
2
|
import { nodeLogDestination } from "../logger/node.js";
|
|
3
3
|
function createNodeLogger(inlineConfig) {
|
|
4
|
-
if (inlineConfig.logger)
|
|
5
|
-
return inlineConfig.logger;
|
|
4
|
+
if (inlineConfig.logger) return inlineConfig.logger;
|
|
6
5
|
return new Logger({
|
|
7
6
|
dest: nodeLogDestination,
|
|
8
7
|
level: inlineConfig.logLevel ?? "info"
|