astro 5.0.0-alpha.4 → 5.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/integration.js +2 -2
- package/dist/actions/runtime/middleware.js +1 -1
- package/dist/assets/build/generate.js +4 -4
- package/dist/assets/endpoint/config.d.ts +3 -2
- package/dist/assets/endpoint/config.js +24 -7
- package/dist/assets/vite-plugin-assets.js +2 -3
- package/dist/config/index.js +3 -1
- package/dist/content/loaders/glob.d.ts +1 -1
- package/dist/content/loaders/glob.js +12 -6
- package/dist/content/utils.d.ts +16 -0
- package/dist/content/utils.js +2 -1
- package/dist/content/vite-plugin-content-imports.js +2 -3
- package/dist/content/vite-plugin-content-virtual-mod.js +1 -2
- package/dist/core/build/common.d.ts +2 -1
- package/dist/core/build/common.js +7 -7
- package/dist/core/build/generate.js +6 -7
- package/dist/core/build/index.js +16 -9
- package/dist/core/build/page-data.js +1 -1
- package/dist/core/build/pipeline.js +3 -6
- package/dist/core/build/plugins/plugin-content.js +2 -2
- package/dist/core/build/plugins/plugin-manifest.js +1 -1
- package/dist/core/build/plugins/plugin-pages.js +1 -1
- package/dist/core/build/plugins/plugin-prerender.js +1 -1
- package/dist/core/build/plugins/plugin-ssr.js +1 -2
- package/dist/core/build/static-build.js +10 -18
- package/dist/core/config/schema.d.ts +12 -12
- package/dist/core/config/schema.js +26 -11
- package/dist/core/config/settings.js +2 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.d.ts +5 -2
- package/dist/core/create-vite.js +5 -4
- package/dist/core/dev/adapter-validation.d.ts +5 -0
- package/dist/core/dev/adapter-validation.js +39 -0
- package/dist/core/dev/container.js +21 -5
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +23 -8
- package/dist/core/errors/errors-data.js +10 -5
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/index.js +1 -0
- package/dist/core/middleware/vite-plugin.js +1 -1
- package/dist/core/preview/index.js +4 -2
- package/dist/core/render-context.d.ts +1 -1
- package/dist/core/render-context.js +19 -20
- package/dist/core/request.d.ts +2 -2
- package/dist/core/request.js +6 -9
- package/dist/core/routing/dev-default.d.ts +3 -0
- package/dist/core/routing/dev-default.js +10 -0
- package/dist/core/routing/manifest/create.d.ts +5 -1
- package/dist/core/routing/manifest/create.js +34 -8
- package/dist/core/routing/manifest/prerender.d.ts +4 -0
- package/dist/core/routing/manifest/prerender.js +17 -0
- package/dist/core/sync/index.d.ts +3 -2
- package/dist/core/sync/index.js +9 -6
- package/dist/core/util.d.ts +1 -3
- package/dist/core/util.js +3 -11
- package/dist/integrations/features-validation.d.ts +3 -2
- package/dist/integrations/features-validation.js +14 -8
- package/dist/integrations/hooks.d.ts +6 -5
- package/dist/integrations/hooks.js +18 -15
- package/dist/prerender/utils.d.ts +2 -1
- package/dist/prerender/utils.js +4 -6
- package/dist/runtime/server/endpoint.d.ts +1 -1
- package/dist/runtime/server/endpoint.js +3 -3
- package/dist/types/astro.d.ts +5 -0
- package/dist/types/public/config.d.ts +50 -11
- package/dist/types/public/context.d.ts +4 -0
- package/dist/types/public/integrations.d.ts +6 -1
- package/dist/vite-plugin-astro-server/pipeline.js +3 -3
- package/dist/vite-plugin-astro-server/plugin.d.ts +4 -2
- package/dist/vite-plugin-astro-server/plugin.js +21 -12
- package/dist/vite-plugin-astro-server/route.js +1 -1
- package/dist/vite-plugin-env/index.d.ts +1 -3
- package/dist/vite-plugin-env/index.js +1 -19
- package/dist/vite-plugin-scanner/index.d.ts +3 -2
- package/dist/vite-plugin-scanner/index.js +39 -21
- package/package.json +5 -4
- package/dist/vite-plugin-scanner/scan.d.ts +0 -3
- package/dist/vite-plugin-scanner/scan.js +0 -58
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionsWithoutServerOutputError } from "../core/errors/errors-data.js";
|
|
2
2
|
import { AstroError } from "../core/errors/errors.js";
|
|
3
|
-
import {
|
|
3
|
+
import { viteID } from "../core/util.js";
|
|
4
4
|
import { ACTIONS_TYPES_FILE, VIRTUAL_MODULE_ID } from "./consts.js";
|
|
5
5
|
function astroIntegrationActionsRouteHandler({
|
|
6
6
|
settings
|
|
@@ -20,7 +20,7 @@ function astroIntegrationActionsRouteHandler({
|
|
|
20
20
|
});
|
|
21
21
|
},
|
|
22
22
|
"astro:config:done": async (params) => {
|
|
23
|
-
if (
|
|
23
|
+
if (params.buildOutput === "static") {
|
|
24
24
|
const error = new AstroError(ActionsWithoutServerOutputError);
|
|
25
25
|
error.stack = void 0;
|
|
26
26
|
throw error;
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
serializeActionResult
|
|
8
8
|
} from "./virtual/shared.js";
|
|
9
9
|
const onRequest = defineMiddleware(async (context, next) => {
|
|
10
|
-
if (context.
|
|
10
|
+
if (context.isPrerendered) {
|
|
11
11
|
if (context.request.method === "POST") {
|
|
12
12
|
console.warn(
|
|
13
13
|
yellow("[astro:actions]"),
|
|
@@ -6,12 +6,11 @@ import { getTimeStat } from "../../core/build/util.js";
|
|
|
6
6
|
import { AstroError } from "../../core/errors/errors.js";
|
|
7
7
|
import { AstroErrorData } from "../../core/errors/index.js";
|
|
8
8
|
import { isRemotePath, removeLeadingForwardSlash } from "../../core/path.js";
|
|
9
|
-
import { isServerLikeOutput } from "../../core/util.js";
|
|
10
9
|
import { getConfiguredImageService } from "../internal.js";
|
|
11
10
|
import { isESMImportedImage } from "../utils/imageKind.js";
|
|
12
11
|
import { loadRemoteImage } from "./remote.js";
|
|
13
12
|
async function prepareAssetsGenerationEnv(pipeline, totalCount) {
|
|
14
|
-
const { config, logger } = pipeline;
|
|
13
|
+
const { config, logger, settings } = pipeline;
|
|
15
14
|
let useCache = true;
|
|
16
15
|
const assetsCacheDir = new URL("assets/", config.cacheDir);
|
|
17
16
|
const count = { total: totalCount, current: 1 };
|
|
@@ -24,8 +23,9 @@ async function prepareAssetsGenerationEnv(pipeline, totalCount) {
|
|
|
24
23
|
);
|
|
25
24
|
useCache = false;
|
|
26
25
|
}
|
|
26
|
+
const isServerOutput = settings.buildOutput === "server";
|
|
27
27
|
let serverRoot, clientRoot;
|
|
28
|
-
if (
|
|
28
|
+
if (isServerOutput) {
|
|
29
29
|
serverRoot = config.build.server;
|
|
30
30
|
clientRoot = config.build.client;
|
|
31
31
|
} else {
|
|
@@ -34,7 +34,7 @@ async function prepareAssetsGenerationEnv(pipeline, totalCount) {
|
|
|
34
34
|
}
|
|
35
35
|
return {
|
|
36
36
|
logger,
|
|
37
|
-
isSSR:
|
|
37
|
+
isSSR: isServerOutput,
|
|
38
38
|
count,
|
|
39
39
|
useCache,
|
|
40
40
|
assetsCacheDir,
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { AstroSettings } from '../../types/astro.js';
|
|
2
|
-
export declare function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'build'):
|
|
1
|
+
import type { AstroSettings, ManifestData } from '../../types/astro.js';
|
|
2
|
+
export declare function injectImageEndpoint(settings: AstroSettings, manifest: ManifestData, mode: 'dev' | 'build', cwd?: string): void;
|
|
3
|
+
export declare function ensureImageEndpointRoute(settings: AstroSettings, manifest: ManifestData, mode: 'dev' | 'build', cwd?: string): void;
|
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolveInjectedRoute } from "../../core/routing/manifest/create.js";
|
|
2
|
+
function injectImageEndpoint(settings, manifest, mode, cwd) {
|
|
3
|
+
manifest.routes.push(getImageEndpointData(settings, mode, cwd));
|
|
4
|
+
}
|
|
5
|
+
function ensureImageEndpointRoute(settings, manifest, mode, cwd) {
|
|
6
|
+
if (!manifest.routes.some((route) => route.route === "/_image")) {
|
|
7
|
+
manifest.routes.push(getImageEndpointData(settings, mode, cwd));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function getImageEndpointData(settings, mode, cwd) {
|
|
2
11
|
const endpointEntrypoint = settings.config.image.endpoint ?? (mode === "dev" ? "astro/assets/endpoint/node" : "astro/assets/endpoint/generic");
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
return {
|
|
13
|
+
type: "endpoint",
|
|
14
|
+
isIndex: false,
|
|
15
|
+
route: "/_image",
|
|
16
|
+
pattern: /^\/_image$/,
|
|
17
|
+
segments: [[{ content: "_image", dynamic: false, spread: false }]],
|
|
18
|
+
params: [],
|
|
19
|
+
component: resolveInjectedRoute(endpointEntrypoint, settings.config.root, cwd).component,
|
|
20
|
+
generate: () => "",
|
|
21
|
+
pathname: "/_image",
|
|
22
|
+
prerender: false,
|
|
23
|
+
fallbackRoutes: []
|
|
24
|
+
};
|
|
9
25
|
}
|
|
10
26
|
export {
|
|
27
|
+
ensureImageEndpointRoute,
|
|
11
28
|
injectImageEndpoint
|
|
12
29
|
};
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
removeBase,
|
|
10
10
|
removeQueryString
|
|
11
11
|
} from "../core/path.js";
|
|
12
|
-
import { isServerLikeOutput } from "../core/util.js";
|
|
13
12
|
import { VALID_INPUT_FORMATS, VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from "./consts.js";
|
|
14
13
|
import { getAssetsPrefix } from "./utils/getAssetsPrefix.js";
|
|
15
14
|
import { isESMImportedImage } from "./utils/imageKind.js";
|
|
@@ -102,7 +101,7 @@ function assets({
|
|
|
102
101
|
// so that it's tree-shaken away for all platforms that don't need it.
|
|
103
102
|
export const outDir = /* #__PURE__ */ new URL(${JSON.stringify(
|
|
104
103
|
new URL(
|
|
105
|
-
|
|
104
|
+
settings.buildOutput === "server" ? settings.config.build.client : settings.config.outDir
|
|
106
105
|
)
|
|
107
106
|
)});
|
|
108
107
|
export const assetsDir = /* #__PURE__ */ new URL(${JSON.stringify(
|
|
@@ -175,7 +174,7 @@ function assets({
|
|
|
175
174
|
if (options?.ssr) {
|
|
176
175
|
return `export default ${getProxyCode(
|
|
177
176
|
imageMetadata,
|
|
178
|
-
|
|
177
|
+
settings.buildOutput === "server"
|
|
179
178
|
)}`;
|
|
180
179
|
} else {
|
|
181
180
|
globalThis.astroAsset.referencedImages.add(imageMetadata.fsPath);
|
package/dist/config/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Logger } from "../core/logger/core.js";
|
|
2
|
+
import { createRouteManifest } from "../core/routing/index.js";
|
|
2
3
|
function defineConfig(config) {
|
|
3
4
|
return config;
|
|
4
5
|
}
|
|
@@ -29,6 +30,7 @@ function getViteConfig(userViteConfig, inlineAstroConfig = {}) {
|
|
|
29
30
|
const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
|
|
30
31
|
let settings = await createSettings(config, userViteConfig.root);
|
|
31
32
|
settings = await runHookConfigSetup({ settings, command: cmd, logger });
|
|
33
|
+
const manifest = await createRouteManifest({ settings }, logger);
|
|
32
34
|
const viteConfig = await createVite(
|
|
33
35
|
{
|
|
34
36
|
mode,
|
|
@@ -37,7 +39,7 @@ function getViteConfig(userViteConfig, inlineAstroConfig = {}) {
|
|
|
37
39
|
astroContentListenPlugin({ settings, logger, fs })
|
|
38
40
|
]
|
|
39
41
|
},
|
|
40
|
-
{ settings, logger, mode, sync: false }
|
|
42
|
+
{ settings, logger, mode, sync: false, manifest }
|
|
41
43
|
);
|
|
42
44
|
await runHookConfigDone({ settings, logger });
|
|
43
45
|
return mergeConfig(viteConfig, userViteConfig);
|
|
@@ -9,7 +9,7 @@ export interface GenerateIdOptions {
|
|
|
9
9
|
}
|
|
10
10
|
export interface GlobOptions {
|
|
11
11
|
/** The glob pattern to match files, relative to the base directory */
|
|
12
|
-
pattern: string
|
|
12
|
+
pattern: string | Array<string>;
|
|
13
13
|
/** The base directory to resolve the glob pattern from. Relative to the root directory, or an absolute file URL. Defaults to `.` */
|
|
14
14
|
base?: string | URL;
|
|
15
15
|
/**
|
|
@@ -17,13 +17,19 @@ function generateIdDefault({ entry, base, data }) {
|
|
|
17
17
|
});
|
|
18
18
|
return slug;
|
|
19
19
|
}
|
|
20
|
+
function checkPrefix(pattern, prefix) {
|
|
21
|
+
if (Array.isArray(pattern)) {
|
|
22
|
+
return pattern.some((p) => p.startsWith(prefix));
|
|
23
|
+
}
|
|
24
|
+
return pattern.startsWith(prefix);
|
|
25
|
+
}
|
|
20
26
|
function glob(globOptions) {
|
|
21
|
-
if (globOptions.pattern
|
|
27
|
+
if (checkPrefix(globOptions.pattern, "../")) {
|
|
22
28
|
throw new Error(
|
|
23
29
|
"Glob patterns cannot start with `../`. Set the `base` option to a parent directory instead."
|
|
24
30
|
);
|
|
25
31
|
}
|
|
26
|
-
if (globOptions.pattern
|
|
32
|
+
if (checkPrefix(globOptions.pattern, "/")) {
|
|
27
33
|
throw new Error(
|
|
28
34
|
"Glob patterns cannot start with `/`. Set the `base` option to a parent directory or use a relative path instead."
|
|
29
35
|
);
|
|
@@ -160,13 +166,14 @@ function glob(globOptions) {
|
|
|
160
166
|
);
|
|
161
167
|
const skipCount = skippedFiles.length;
|
|
162
168
|
if (skipCount > 0) {
|
|
169
|
+
const patternList = Array.isArray(globOptions.pattern) ? globOptions.pattern.join(", ") : globOptions.pattern;
|
|
163
170
|
logger.warn(`The glob() loader cannot be used for files in ${bold("src/content")}.`);
|
|
164
171
|
if (skipCount > 10) {
|
|
165
172
|
logger.warn(
|
|
166
|
-
`Skipped ${green(skippedFiles.length)} files that matched ${green(
|
|
173
|
+
`Skipped ${green(skippedFiles.length)} files that matched ${green(patternList)}.`
|
|
167
174
|
);
|
|
168
175
|
} else {
|
|
169
|
-
logger.warn(`Skipped the following files that matched ${green(
|
|
176
|
+
logger.warn(`Skipped the following files that matched ${green(patternList)}:`);
|
|
170
177
|
skippedFiles.forEach((file) => logger.warn(`\u2022 ${green(file)}`));
|
|
171
178
|
}
|
|
172
179
|
}
|
|
@@ -174,8 +181,7 @@ function glob(globOptions) {
|
|
|
174
181
|
if (!watcher) {
|
|
175
182
|
return;
|
|
176
183
|
}
|
|
177
|
-
const
|
|
178
|
-
const matchesGlob = (entry) => !entry.startsWith("../") && matcher.test(entry);
|
|
184
|
+
const matchesGlob = (entry) => !entry.startsWith("../") && micromatch.isMatch(entry, globOptions.pattern);
|
|
179
185
|
const basePath = fileURLToPath(baseDir);
|
|
180
186
|
async function onChange(changedPath) {
|
|
181
187
|
const entry = posixRelative(basePath, changedPath);
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -66,6 +66,7 @@ declare const collectionConfigParser: z.ZodUnion<[z.ZodObject<{
|
|
|
66
66
|
parseData: z.ZodAny;
|
|
67
67
|
generateDigest: z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>;
|
|
68
68
|
watcher: z.ZodOptional<z.ZodAny>;
|
|
69
|
+
refreshContextData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
69
70
|
}, "strip", z.ZodTypeAny, {
|
|
70
71
|
collection: string;
|
|
71
72
|
generateDigest: (args_0: any) => unknown;
|
|
@@ -76,6 +77,7 @@ declare const collectionConfigParser: z.ZodUnion<[z.ZodObject<{
|
|
|
76
77
|
entryTypes?: any;
|
|
77
78
|
parseData?: any;
|
|
78
79
|
watcher?: any;
|
|
80
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
79
81
|
}, {
|
|
80
82
|
collection: string;
|
|
81
83
|
generateDigest: (args_0: any) => unknown;
|
|
@@ -86,6 +88,7 @@ declare const collectionConfigParser: z.ZodUnion<[z.ZodObject<{
|
|
|
86
88
|
entryTypes?: any;
|
|
87
89
|
parseData?: any;
|
|
88
90
|
watcher?: any;
|
|
91
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
89
92
|
}>], null>, z.ZodUnknown>;
|
|
90
93
|
schema: z.ZodOptional<z.ZodAny>;
|
|
91
94
|
render: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>>;
|
|
@@ -100,6 +103,7 @@ declare const collectionConfigParser: z.ZodUnion<[z.ZodObject<{
|
|
|
100
103
|
entryTypes?: any;
|
|
101
104
|
parseData?: any;
|
|
102
105
|
watcher?: any;
|
|
106
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
103
107
|
}) => unknown;
|
|
104
108
|
name: string;
|
|
105
109
|
render?: ((args_0: any) => unknown) | undefined;
|
|
@@ -115,6 +119,7 @@ declare const collectionConfigParser: z.ZodUnion<[z.ZodObject<{
|
|
|
115
119
|
entryTypes?: any;
|
|
116
120
|
parseData?: any;
|
|
117
121
|
watcher?: any;
|
|
122
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
118
123
|
}) => unknown;
|
|
119
124
|
name: string;
|
|
120
125
|
render?: ((args_0: any) => unknown) | undefined;
|
|
@@ -137,6 +142,7 @@ declare const collectionConfigParser: z.ZodUnion<[z.ZodObject<{
|
|
|
137
142
|
entryTypes?: any;
|
|
138
143
|
parseData?: any;
|
|
139
144
|
watcher?: any;
|
|
145
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
140
146
|
}) => unknown;
|
|
141
147
|
name: string;
|
|
142
148
|
render?: ((args_0: any) => unknown) | undefined;
|
|
@@ -160,6 +166,7 @@ declare const collectionConfigParser: z.ZodUnion<[z.ZodObject<{
|
|
|
160
166
|
entryTypes?: any;
|
|
161
167
|
parseData?: any;
|
|
162
168
|
watcher?: any;
|
|
169
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
163
170
|
}) => unknown;
|
|
164
171
|
name: string;
|
|
165
172
|
render?: ((args_0: any) => unknown) | undefined;
|
|
@@ -213,6 +220,7 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
213
220
|
parseData: z.ZodAny;
|
|
214
221
|
generateDigest: z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>;
|
|
215
222
|
watcher: z.ZodOptional<z.ZodAny>;
|
|
223
|
+
refreshContextData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
216
224
|
}, "strip", z.ZodTypeAny, {
|
|
217
225
|
collection: string;
|
|
218
226
|
generateDigest: (args_0: any) => unknown;
|
|
@@ -223,6 +231,7 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
223
231
|
entryTypes?: any;
|
|
224
232
|
parseData?: any;
|
|
225
233
|
watcher?: any;
|
|
234
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
226
235
|
}, {
|
|
227
236
|
collection: string;
|
|
228
237
|
generateDigest: (args_0: any) => unknown;
|
|
@@ -233,6 +242,7 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
233
242
|
entryTypes?: any;
|
|
234
243
|
parseData?: any;
|
|
235
244
|
watcher?: any;
|
|
245
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
236
246
|
}>], null>, z.ZodUnknown>;
|
|
237
247
|
schema: z.ZodOptional<z.ZodAny>;
|
|
238
248
|
render: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>>;
|
|
@@ -247,6 +257,7 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
247
257
|
entryTypes?: any;
|
|
248
258
|
parseData?: any;
|
|
249
259
|
watcher?: any;
|
|
260
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
250
261
|
}) => unknown;
|
|
251
262
|
name: string;
|
|
252
263
|
render?: ((args_0: any) => unknown) | undefined;
|
|
@@ -262,6 +273,7 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
262
273
|
entryTypes?: any;
|
|
263
274
|
parseData?: any;
|
|
264
275
|
watcher?: any;
|
|
276
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
265
277
|
}) => unknown;
|
|
266
278
|
name: string;
|
|
267
279
|
render?: ((args_0: any) => unknown) | undefined;
|
|
@@ -284,6 +296,7 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
284
296
|
entryTypes?: any;
|
|
285
297
|
parseData?: any;
|
|
286
298
|
watcher?: any;
|
|
299
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
287
300
|
}) => unknown;
|
|
288
301
|
name: string;
|
|
289
302
|
render?: ((args_0: any) => unknown) | undefined;
|
|
@@ -307,6 +320,7 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
307
320
|
entryTypes?: any;
|
|
308
321
|
parseData?: any;
|
|
309
322
|
watcher?: any;
|
|
323
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
310
324
|
}) => unknown;
|
|
311
325
|
name: string;
|
|
312
326
|
render?: ((args_0: any) => unknown) | undefined;
|
|
@@ -338,6 +352,7 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
338
352
|
entryTypes?: any;
|
|
339
353
|
parseData?: any;
|
|
340
354
|
watcher?: any;
|
|
355
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
341
356
|
}) => unknown;
|
|
342
357
|
name: string;
|
|
343
358
|
render?: ((args_0: any) => unknown) | undefined;
|
|
@@ -369,6 +384,7 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
369
384
|
entryTypes?: any;
|
|
370
385
|
parseData?: any;
|
|
371
386
|
watcher?: any;
|
|
387
|
+
refreshContextData?: Record<string, unknown> | undefined;
|
|
372
388
|
}) => unknown;
|
|
373
389
|
name: string;
|
|
374
390
|
render?: ((args_0: any) => unknown) | undefined;
|
package/dist/content/utils.js
CHANGED
|
@@ -60,7 +60,8 @@ const collectionConfigParser = z.union([
|
|
|
60
60
|
entryTypes: z.any(),
|
|
61
61
|
parseData: z.any(),
|
|
62
62
|
generateDigest: z.function(z.tuple([z.any()], z.string())),
|
|
63
|
-
watcher: z.any().optional()
|
|
63
|
+
watcher: z.any().optional(),
|
|
64
|
+
refreshContextData: z.record(z.unknown()).optional()
|
|
64
65
|
})
|
|
65
66
|
],
|
|
66
67
|
z.unknown()
|
|
@@ -4,7 +4,6 @@ import * as devalue from "devalue";
|
|
|
4
4
|
import { getProxyCode } from "../assets/utils/proxy.js";
|
|
5
5
|
import { AstroError } from "../core/errors/errors.js";
|
|
6
6
|
import { AstroErrorData } from "../core/errors/index.js";
|
|
7
|
-
import { isServerLikeOutput } from "../core/util.js";
|
|
8
7
|
import { CONTENT_FLAG, DATA_FLAG } from "./consts.js";
|
|
9
8
|
import {
|
|
10
9
|
getContentEntryExts,
|
|
@@ -76,7 +75,7 @@ function astroContentImportPlugin({
|
|
|
76
75
|
const code = `
|
|
77
76
|
export const id = ${JSON.stringify(id)};
|
|
78
77
|
export const collection = ${JSON.stringify(collection)};
|
|
79
|
-
export const data = ${stringifyEntryData(data,
|
|
78
|
+
export const data = ${stringifyEntryData(data, settings.buildOutput === "server")};
|
|
80
79
|
export const _internal = {
|
|
81
80
|
type: 'data',
|
|
82
81
|
filePath: ${JSON.stringify(_internal.filePath)},
|
|
@@ -100,7 +99,7 @@ export const _internal = {
|
|
|
100
99
|
export const collection = ${JSON.stringify(collection)};
|
|
101
100
|
export const slug = ${JSON.stringify(slug)};
|
|
102
101
|
export const body = ${JSON.stringify(body)};
|
|
103
|
-
export const data = ${stringifyEntryData(data,
|
|
102
|
+
export const data = ${stringifyEntryData(data, settings.buildOutput === "server")};
|
|
104
103
|
export const _internal = {
|
|
105
104
|
type: 'content',
|
|
106
105
|
filePath: ${JSON.stringify(_internal.filePath)},
|
|
@@ -7,7 +7,6 @@ import pLimit from "p-limit";
|
|
|
7
7
|
import { encodeName } from "../core/build/util.js";
|
|
8
8
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
9
9
|
import { appendForwardSlash, removeFileExtension } from "../core/path.js";
|
|
10
|
-
import { isServerLikeOutput } from "../core/util.js";
|
|
11
10
|
import { rootRelativePath } from "../core/viteUtils.js";
|
|
12
11
|
import { createDefaultAstroMetadata } from "../vite-plugin-astro/metadata.js";
|
|
13
12
|
import {
|
|
@@ -43,7 +42,7 @@ function astroContentVirtualModPlugin({
|
|
|
43
42
|
fs
|
|
44
43
|
}) {
|
|
45
44
|
let IS_DEV = false;
|
|
46
|
-
const IS_SERVER =
|
|
45
|
+
const IS_SERVER = settings.buildOutput === "server";
|
|
47
46
|
let dataStoreFile;
|
|
48
47
|
return {
|
|
49
48
|
name: "astro-content-virtual-mod-plugin",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { AstroSettings } from '../../types/astro.js';
|
|
1
2
|
import type { AstroConfig } from '../../types/public/config.js';
|
|
2
3
|
import type { RouteData } from '../../types/public/internal.js';
|
|
3
|
-
export declare function getOutFolder(
|
|
4
|
+
export declare function getOutFolder(astroSettings: AstroSettings, pathname: string, routeData: RouteData): URL;
|
|
4
5
|
export declare function getOutFile(astroConfig: AstroConfig, outFolder: URL, pathname: string, routeData: RouteData): URL;
|
|
5
6
|
/**
|
|
6
7
|
* Ensures the `outDir` is within `process.cwd()`. If not it will fallback to `<cwd>/.astro`.
|
|
@@ -3,15 +3,15 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
3
3
|
import { appendForwardSlash } from "../../core/path.js";
|
|
4
4
|
const STATUS_CODE_PAGES = /* @__PURE__ */ new Set(["/404", "/500"]);
|
|
5
5
|
const FALLBACK_OUT_DIR_NAME = "./.astro/";
|
|
6
|
-
function getOutRoot(
|
|
7
|
-
if (
|
|
8
|
-
return new URL("./",
|
|
6
|
+
function getOutRoot(astroSettings) {
|
|
7
|
+
if (astroSettings.buildOutput === "static") {
|
|
8
|
+
return new URL("./", astroSettings.config.outDir);
|
|
9
9
|
} else {
|
|
10
|
-
return new URL("./",
|
|
10
|
+
return new URL("./", astroSettings.config.build.client);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
function getOutFolder(
|
|
14
|
-
const outRoot = getOutRoot(
|
|
13
|
+
function getOutFolder(astroSettings, pathname, routeData) {
|
|
14
|
+
const outRoot = getOutRoot(astroSettings);
|
|
15
15
|
const routeType = routeData.type;
|
|
16
16
|
switch (routeType) {
|
|
17
17
|
case "endpoint":
|
|
@@ -19,7 +19,7 @@ function getOutFolder(astroConfig, pathname, routeData) {
|
|
|
19
19
|
case "fallback":
|
|
20
20
|
case "page":
|
|
21
21
|
case "redirect":
|
|
22
|
-
switch (
|
|
22
|
+
switch (astroSettings.config.build.format) {
|
|
23
23
|
case "directory": {
|
|
24
24
|
if (STATUS_CODE_PAGES.has(pathname)) {
|
|
25
25
|
return new URL("." + appendForwardSlash(npath.dirname(pathname)), outRoot);
|
|
@@ -25,19 +25,19 @@ import { callGetStaticPaths } from "../render/route-cache.js";
|
|
|
25
25
|
import { createRequest } from "../request.js";
|
|
26
26
|
import { matchRoute } from "../routing/match.js";
|
|
27
27
|
import { stringifyParams } from "../routing/params.js";
|
|
28
|
-
import { getOutputFilename
|
|
28
|
+
import { getOutputFilename } from "../util.js";
|
|
29
29
|
import { getOutFile, getOutFolder } from "./common.js";
|
|
30
30
|
import { cssOrder, mergeInlineCss } from "./internal.js";
|
|
31
31
|
import { BuildPipeline } from "./pipeline.js";
|
|
32
32
|
import { getTimeStat, shouldAppendForwardSlash } from "./util.js";
|
|
33
33
|
async function generatePages(options, internals) {
|
|
34
34
|
const generatePagesTimer = performance.now();
|
|
35
|
-
const ssr =
|
|
35
|
+
const ssr = options.settings.buildOutput === "server";
|
|
36
36
|
let manifest;
|
|
37
37
|
if (ssr) {
|
|
38
38
|
manifest = await BuildPipeline.retrieveManifest(options, internals);
|
|
39
39
|
} else {
|
|
40
|
-
const baseDirectory = getOutputDirectory(options.settings
|
|
40
|
+
const baseDirectory = getOutputDirectory(options.settings);
|
|
41
41
|
const renderersEntryUrl = new URL("renderers.mjs", baseDirectory);
|
|
42
42
|
const renderers = await import(renderersEntryUrl.toString());
|
|
43
43
|
let middleware = (_, next) => next();
|
|
@@ -59,7 +59,6 @@ async function generatePages(options, internals) {
|
|
|
59
59
|
const { config, logger } = pipeline;
|
|
60
60
|
if (ssr && !hasPrerenderedPages(internals)) {
|
|
61
61
|
delete globalThis?.astroAsset?.addStaticImage;
|
|
62
|
-
return;
|
|
63
62
|
}
|
|
64
63
|
const verb = ssr ? "prerendering" : "generating";
|
|
65
64
|
logger.info("SKIP_FORMAT", `
|
|
@@ -108,7 +107,7 @@ ${bgGreen(black(` ${verb} static routes `))}`);
|
|
|
108
107
|
`));
|
|
109
108
|
delete globalThis?.astroAsset?.addStaticImage;
|
|
110
109
|
}
|
|
111
|
-
await runHookBuildGenerated({
|
|
110
|
+
await runHookBuildGenerated({ settings: options.settings, logger });
|
|
112
111
|
}
|
|
113
112
|
const THRESHOLD_SLOW_RENDER_TIME_MS = 500;
|
|
114
113
|
async function generatePage(pageData, ssrEntry, builtPaths, pipeline) {
|
|
@@ -288,7 +287,7 @@ async function generatePath(pathname, pipeline, gopts, route) {
|
|
|
288
287
|
url,
|
|
289
288
|
headers: new Headers(),
|
|
290
289
|
logger,
|
|
291
|
-
|
|
290
|
+
isPrerendered: true
|
|
292
291
|
});
|
|
293
292
|
const renderContext = RenderContext.create({ pipeline, pathname, request, routeData: route });
|
|
294
293
|
let body;
|
|
@@ -328,7 +327,7 @@ async function generatePath(pathname, pipeline, gopts, route) {
|
|
|
328
327
|
if (!response.body) return;
|
|
329
328
|
body = Buffer.from(await response.arrayBuffer());
|
|
330
329
|
}
|
|
331
|
-
const outFolder = getOutFolder(
|
|
330
|
+
const outFolder = getOutFolder(pipeline.settings, pathname, route);
|
|
332
331
|
const outFile = getOutFile(config, outFolder, pathname, route);
|
|
333
332
|
route.distURL = outFile;
|
|
334
333
|
await fs.promises.mkdir(outFolder, { recursive: true });
|
package/dist/core/build/index.js
CHANGED
|
@@ -16,12 +16,13 @@ import { createNodeLogger } from "../config/logging.js";
|
|
|
16
16
|
import { createSettings } from "../config/settings.js";
|
|
17
17
|
import { createVite } from "../create-vite.js";
|
|
18
18
|
import { createKey } from "../encryption.js";
|
|
19
|
+
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
19
20
|
import { levels, timerMessage } from "../logger/core.js";
|
|
20
21
|
import { apply as applyPolyfill } from "../polyfill.js";
|
|
21
22
|
import { createRouteManifest } from "../routing/index.js";
|
|
22
23
|
import { getServerIslandRouteData } from "../server-islands/endpoint.js";
|
|
23
24
|
import { clearContentLayerCache } from "../sync/index.js";
|
|
24
|
-
import { ensureProcessNodeEnv
|
|
25
|
+
import { ensureProcessNodeEnv } from "../util.js";
|
|
25
26
|
import { collectPagesData } from "./page-data.js";
|
|
26
27
|
import { staticBuild, viteBuild } from "./static-build.js";
|
|
27
28
|
import { getTimeStat } from "./util.js";
|
|
@@ -79,10 +80,14 @@ class AstroBuilder {
|
|
|
79
80
|
command: "build",
|
|
80
81
|
logger
|
|
81
82
|
});
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
this.manifest = await createRouteManifest({ settings: this.settings }, this.logger);
|
|
84
|
+
if (this.settings.buildOutput === "server") {
|
|
85
|
+
injectImageEndpoint(this.settings, this.manifest, "build");
|
|
86
|
+
}
|
|
87
|
+
await runHookConfigDone({ settings: this.settings, logger, command: "build" });
|
|
88
|
+
if (!this.settings.config.adapter && this.settings.buildOutput === "server") {
|
|
89
|
+
throw new AstroError(AstroErrorData.NoAdapterInstalled);
|
|
84
90
|
}
|
|
85
|
-
this.manifest = createRouteManifest({ settings: this.settings }, this.logger);
|
|
86
91
|
const viteConfig = await createVite(
|
|
87
92
|
{
|
|
88
93
|
mode: this.mode,
|
|
@@ -96,15 +101,16 @@ class AstroBuilder {
|
|
|
96
101
|
logger: this.logger,
|
|
97
102
|
mode: "build",
|
|
98
103
|
command: "build",
|
|
99
|
-
sync: false
|
|
104
|
+
sync: false,
|
|
105
|
+
manifest: this.manifest
|
|
100
106
|
}
|
|
101
107
|
);
|
|
102
|
-
await runHookConfigDone({ settings: this.settings, logger });
|
|
103
108
|
const { syncInternal } = await import("../sync/index.js");
|
|
104
109
|
await syncInternal({
|
|
105
110
|
settings: this.settings,
|
|
106
111
|
logger,
|
|
107
|
-
fs
|
|
112
|
+
fs,
|
|
113
|
+
manifest: this.manifest
|
|
108
114
|
});
|
|
109
115
|
return { viteConfig };
|
|
110
116
|
}
|
|
@@ -155,7 +161,7 @@ class AstroBuilder {
|
|
|
155
161
|
});
|
|
156
162
|
this.logger.debug("build", timerMessage("Additional assets copied", this.timer.assetsStart));
|
|
157
163
|
await runHookBuildDone({
|
|
158
|
-
|
|
164
|
+
settings: this.settings,
|
|
159
165
|
pages: pageNames,
|
|
160
166
|
routes: Object.values(allPages).flat().map((pageData) => pageData.route).concat(
|
|
161
167
|
this.settings.config.experimental.serverIslands ? [getServerIslandRouteData(this.settings.config)] : []
|
|
@@ -168,7 +174,8 @@ class AstroBuilder {
|
|
|
168
174
|
logger: this.logger,
|
|
169
175
|
timeStart: this.timer.init,
|
|
170
176
|
pageCount: pageNames.length,
|
|
171
|
-
buildMode: this.settings.
|
|
177
|
+
buildMode: this.settings.buildOutput
|
|
178
|
+
// buildOutput is always set at this point
|
|
172
179
|
});
|
|
173
180
|
}
|
|
174
181
|
}
|
|
@@ -6,7 +6,6 @@ import { Pipeline } from "../render/index.js";
|
|
|
6
6
|
import { createAssetLink, createStylesheetElementSet } from "../render/ssr-element.js";
|
|
7
7
|
import { createDefaultRoutes } from "../routing/default.js";
|
|
8
8
|
import { findRouteToRewrite } from "../routing/rewrite.js";
|
|
9
|
-
import { isServerLikeOutput } from "../util.js";
|
|
10
9
|
import { getOutDirWithinCwd } from "./common.js";
|
|
11
10
|
import { cssOrder, getPageData, mergeInlineCss } from "./internal.js";
|
|
12
11
|
import { ASTRO_PAGE_MODULE_ID, ASTRO_PAGE_RESOLVED_MODULE_ID } from "./plugins/plugin-pages.js";
|
|
@@ -31,7 +30,7 @@ class BuildPipeline extends Pipeline {
|
|
|
31
30
|
resolveCache.set(specifier, assetLink);
|
|
32
31
|
return assetLink;
|
|
33
32
|
}
|
|
34
|
-
const serverLike =
|
|
33
|
+
const serverLike = settings.buildOutput === "server";
|
|
35
34
|
const streaming = serverLike;
|
|
36
35
|
super(
|
|
37
36
|
options.logger,
|
|
@@ -56,8 +55,7 @@ class BuildPipeline extends Pipeline {
|
|
|
56
55
|
*/
|
|
57
56
|
#routesByFilePath = /* @__PURE__ */ new WeakMap();
|
|
58
57
|
get outFolder() {
|
|
59
|
-
|
|
60
|
-
return ssr ? this.settings.config.build.server : getOutDirWithinCwd(this.settings.config.outDir);
|
|
58
|
+
return this.settings.buildOutput === "server" ? this.settings.config.build.server : getOutDirWithinCwd(this.settings.config.outDir);
|
|
61
59
|
}
|
|
62
60
|
static create({
|
|
63
61
|
internals,
|
|
@@ -80,8 +78,7 @@ class BuildPipeline extends Pipeline {
|
|
|
80
78
|
* @param staticBuildOptions
|
|
81
79
|
*/
|
|
82
80
|
static async retrieveManifest(staticBuildOptions, internals) {
|
|
83
|
-
const
|
|
84
|
-
const baseDirectory = getOutputDirectory(config);
|
|
81
|
+
const baseDirectory = getOutputDirectory(staticBuildOptions.settings);
|
|
85
82
|
const manifestEntryUrl = new URL(
|
|
86
83
|
`${internals.manifestFileName}?time=${Date.now()}`,
|
|
87
84
|
baseDirectory
|
|
@@ -365,7 +365,7 @@ function pluginContent(opts, internals) {
|
|
|
365
365
|
targets: ["server"],
|
|
366
366
|
hooks: {
|
|
367
367
|
async "build:before"() {
|
|
368
|
-
if (!isContentCollectionsCacheEnabled(opts.settings
|
|
368
|
+
if (!isContentCollectionsCacheEnabled(opts.settings)) {
|
|
369
369
|
return { vitePlugin: void 0 };
|
|
370
370
|
}
|
|
371
371
|
const lookupMap = await generateLookupMap({ settings: opts.settings, fs: fsMod });
|
|
@@ -374,7 +374,7 @@ function pluginContent(opts, internals) {
|
|
|
374
374
|
};
|
|
375
375
|
},
|
|
376
376
|
async "build:post"() {
|
|
377
|
-
if (!isContentCollectionsCacheEnabled(opts.settings
|
|
377
|
+
if (!isContentCollectionsCacheEnabled(opts.settings)) {
|
|
378
378
|
return;
|
|
379
379
|
}
|
|
380
380
|
const promises = [];
|
|
@@ -132,7 +132,7 @@ function buildManifest(opts, internals, staticFiles, encodedKey) {
|
|
|
132
132
|
for (const route of opts.manifest.routes) {
|
|
133
133
|
if (!route.prerender) continue;
|
|
134
134
|
if (!route.pathname) continue;
|
|
135
|
-
const outFolder = getOutFolder(opts.settings
|
|
135
|
+
const outFolder = getOutFolder(opts.settings, route.pathname, route);
|
|
136
136
|
const outFile = getOutFile(opts.settings.config, outFolder, route.pathname, route);
|
|
137
137
|
const file = outFile.toString().replace(opts.settings.config.build.client.toString(), "");
|
|
138
138
|
routes.push({
|
|
@@ -8,7 +8,7 @@ function vitePluginPages(opts, internals) {
|
|
|
8
8
|
return {
|
|
9
9
|
name: "@astro/plugin-build-pages",
|
|
10
10
|
options(options) {
|
|
11
|
-
if (opts.settings.
|
|
11
|
+
if (opts.settings.buildOutput === "static") {
|
|
12
12
|
const inputs = /* @__PURE__ */ new Set();
|
|
13
13
|
for (const pageData of Object.values(opts.allPages)) {
|
|
14
14
|
if (routeIsRedirect(pageData.route)) {
|