astro 2.5.7 → 2.6.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/dist/@types/astro.d.ts +109 -90
- package/dist/assets/generate.js +2 -2
- package/dist/core/app/index.js +27 -18
- package/dist/core/app/types.d.ts +1 -2
- package/dist/core/build/common.js +2 -0
- package/dist/core/build/generate.js +76 -13
- package/dist/core/build/internal.d.ts +2 -0
- package/dist/core/build/internal.js +18 -1
- package/dist/core/build/plugins/plugin-css.js +1 -1
- package/dist/core/build/plugins/plugin-middleware.js +1 -7
- package/dist/core/build/plugins/plugin-pages.d.ts +1 -0
- package/dist/core/build/plugins/plugin-pages.js +14 -4
- package/dist/core/build/plugins/plugin-ssr.js +10 -14
- package/dist/core/build/static-build.js +9 -10
- package/dist/core/config/config.js +1 -10
- package/dist/core/config/schema.d.ts +48 -64
- package/dist/core/config/schema.js +13 -11
- package/dist/core/config/settings.js +2 -2
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/index.js +2 -2
- package/dist/core/errors/errors-data.d.ts +13 -21
- package/dist/core/errors/errors-data.js +14 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/path.d.ts +1 -15
- package/dist/core/path.js +1 -80
- package/dist/core/redirects/component.d.ts +4 -0
- package/dist/core/redirects/component.js +19 -0
- package/dist/core/redirects/helpers.d.ts +4 -0
- package/dist/core/redirects/helpers.js +29 -0
- package/dist/core/redirects/index.d.ts +3 -0
- package/dist/core/redirects/index.js +11 -0
- package/dist/core/redirects/validate.d.ts +1 -0
- package/dist/core/redirects/validate.js +13 -0
- package/dist/core/render/context.d.ts +2 -1
- package/dist/core/render/core.d.ts +2 -1
- package/dist/core/render/core.js +18 -1
- package/dist/core/render/dev/environment.js +2 -2
- package/dist/core/render/result.d.ts +2 -0
- package/dist/core/render/result.js +3 -3
- package/dist/core/routing/manifest/create.js +50 -4
- package/dist/core/util.js +10 -3
- package/dist/integrations/index.js +3 -8
- package/dist/prerender/utils.d.ts +2 -2
- package/dist/prerender/utils.js +6 -6
- package/dist/runtime/server/astro-island.js +7 -4
- 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/render/astro/instance.js +0 -3
- package/dist/runtime/server/render/common.js +6 -0
- package/dist/runtime/server/render/component.js +2 -2
- package/dist/runtime/server/render/page.d.ts +1 -1
- package/dist/runtime/server/render/page.js +10 -6
- package/dist/vite-plugin-astro-server/request.js +2 -2
- package/dist/vite-plugin-astro-server/route.js +16 -9
- package/dist/vite-plugin-html/transform/index.js +3 -7
- package/dist/vite-plugin-scanner/index.js +4 -4
- package/env.d.ts +2 -2
- package/package.json +2 -1
- package/tsconfigs/base.json +3 -1
- package/tsconfigs/strictest.json +3 -1
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { MIDDLEWARE_PATH_SEGMENT_NAME } from "../../constants.js";
|
|
2
|
-
import { addRollupInput } from "../add-rollup-input.js";
|
|
3
2
|
const MIDDLEWARE_MODULE_ID = "@astro-middleware";
|
|
4
3
|
function vitePluginMiddleware(opts, _internals) {
|
|
5
4
|
return {
|
|
6
5
|
name: "@astro/plugin-middleware",
|
|
7
|
-
options(options) {
|
|
8
|
-
if (opts.settings.config.experimental.middleware) {
|
|
9
|
-
return addRollupInput(options, [MIDDLEWARE_MODULE_ID]);
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
6
|
async resolveId(id) {
|
|
13
|
-
if (id === MIDDLEWARE_MODULE_ID
|
|
7
|
+
if (id === MIDDLEWARE_MODULE_ID) {
|
|
14
8
|
const middlewareId = await this.resolve(
|
|
15
9
|
`${opts.settings.config.srcDir.pathname}/${MIDDLEWARE_PATH_SEGMENT_NAME}`
|
|
16
10
|
);
|
|
@@ -11,4 +11,5 @@ export declare const ASTRO_PAGE_EXTENSION_POST_PATTERN = "@_@";
|
|
|
11
11
|
* @param path
|
|
12
12
|
*/
|
|
13
13
|
export declare function getVirtualModulePageNameFromPath(path: string): string;
|
|
14
|
+
export declare function getVirtualModulePageIdFromPath(path: string): string;
|
|
14
15
|
export declare function pluginPages(opts: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { extname } from "node:path";
|
|
2
|
+
import { routeIsRedirect } from "../../redirects/index.js";
|
|
2
3
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
3
4
|
import { MIDDLEWARE_MODULE_ID } from "./plugin-middleware.js";
|
|
4
5
|
import { RENDERERS_MODULE_ID } from "./plugin-renderers.js";
|
|
@@ -12,13 +13,20 @@ function getVirtualModulePageNameFromPath(path) {
|
|
|
12
13
|
extension.replace(".", ASTRO_PAGE_EXTENSION_POST_PATTERN)
|
|
13
14
|
)}`;
|
|
14
15
|
}
|
|
16
|
+
function getVirtualModulePageIdFromPath(path) {
|
|
17
|
+
const name = getVirtualModulePageNameFromPath(path);
|
|
18
|
+
return "\0" + name;
|
|
19
|
+
}
|
|
15
20
|
function vitePluginPages(opts, internals) {
|
|
16
21
|
return {
|
|
17
22
|
name: "@astro/plugin-build-pages",
|
|
18
23
|
options(options) {
|
|
19
24
|
if (opts.settings.config.output === "static") {
|
|
20
25
|
const inputs = /* @__PURE__ */ new Set();
|
|
21
|
-
for (const path of Object.
|
|
26
|
+
for (const [path, pageData] of Object.entries(opts.allPages)) {
|
|
27
|
+
if (routeIsRedirect(pageData.route)) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
22
30
|
inputs.add(getVirtualModulePageNameFromPath(path));
|
|
23
31
|
}
|
|
24
32
|
return addRollupInput(options, Array.from(inputs));
|
|
@@ -44,9 +52,10 @@ function vitePluginPages(opts, internals) {
|
|
|
44
52
|
exports.push(`export { page }`);
|
|
45
53
|
imports.push(`import { renderers } from "${RENDERERS_MODULE_ID}";`);
|
|
46
54
|
exports.push(`export { renderers };`);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
const middlewareModule = await this.resolve(MIDDLEWARE_MODULE_ID);
|
|
56
|
+
if (middlewareModule) {
|
|
57
|
+
imports.push(`import * as middleware from "${middlewareModule.id}";`);
|
|
58
|
+
exports.push(`export { middleware };`);
|
|
50
59
|
}
|
|
51
60
|
return `${imports.join("\n")}${exports.join("\n")}`;
|
|
52
61
|
}
|
|
@@ -71,6 +80,7 @@ export {
|
|
|
71
80
|
ASTRO_PAGE_EXTENSION_POST_PATTERN,
|
|
72
81
|
ASTRO_PAGE_MODULE_ID,
|
|
73
82
|
ASTRO_PAGE_RESOLVED_MODULE_ID,
|
|
83
|
+
getVirtualModulePageIdFromPath,
|
|
74
84
|
getVirtualModulePageNameFromPath,
|
|
75
85
|
pluginPages
|
|
76
86
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import glob from "fast-glob";
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import { runHookBuildSsr } from "../../../integrations/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isServerLikeOutput } from "../../../prerender/utils.js";
|
|
5
5
|
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../../vite-plugin-scripts/index.js";
|
|
6
6
|
import { joinPaths, prependForwardSlash } from "../../path.js";
|
|
7
|
+
import { routeIsRedirect } from "../../redirects/index.js";
|
|
7
8
|
import { serializeRouteData } from "../../routing/index.js";
|
|
8
9
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
9
10
|
import { getOutFile, getOutFolder } from "../common.js";
|
|
10
11
|
import { cssOrder, mergeInlineCss } from "../internal.js";
|
|
11
|
-
import { MIDDLEWARE_MODULE_ID } from "./plugin-middleware.js";
|
|
12
12
|
import { getVirtualModulePageNameFromPath } from "./plugin-pages.js";
|
|
13
13
|
import { RENDERERS_MODULE_ID } from "./plugin-renderers.js";
|
|
14
14
|
const SSR_VIRTUAL_MODULE_ID = "@astrojs-ssr-virtual-entry";
|
|
@@ -28,7 +28,6 @@ function vitePluginSSR(internals, adapter, options) {
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
async load(id) {
|
|
31
|
-
var _a;
|
|
32
31
|
if (id === RESOLVED_SSR_VIRTUAL_MODULE_ID) {
|
|
33
32
|
const {
|
|
34
33
|
settings: { config },
|
|
@@ -37,22 +36,20 @@ function vitePluginSSR(internals, adapter, options) {
|
|
|
37
36
|
const imports = [];
|
|
38
37
|
const contents = [];
|
|
39
38
|
const exports = [];
|
|
40
|
-
let middleware;
|
|
41
|
-
if (((_a = config.experimental) == null ? void 0 : _a.middleware) === true) {
|
|
42
|
-
imports.push(`import * as _middleware from "${MIDDLEWARE_MODULE_ID}"`);
|
|
43
|
-
middleware = "middleware: _middleware";
|
|
44
|
-
}
|
|
45
39
|
let i = 0;
|
|
46
40
|
const pageMap = [];
|
|
47
|
-
for (const path of Object.
|
|
41
|
+
for (const [path, pageData] of Object.entries(allPages)) {
|
|
42
|
+
if (routeIsRedirect(pageData.route)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
48
45
|
const virtualModuleName = getVirtualModulePageNameFromPath(path);
|
|
49
46
|
let module = await this.resolve(virtualModuleName);
|
|
50
47
|
if (module) {
|
|
51
48
|
const variable = `_page${i}`;
|
|
52
49
|
imports.push(`const ${variable} = () => import("${virtualModuleName}");`);
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
pageMap.push(`[${JSON.stringify(
|
|
50
|
+
const pageData2 = internals.pagesByComponent.get(path);
|
|
51
|
+
if (pageData2) {
|
|
52
|
+
pageMap.push(`[${JSON.stringify(pageData2.component)}, ${variable}]`);
|
|
56
53
|
}
|
|
57
54
|
i++;
|
|
58
55
|
}
|
|
@@ -66,7 +63,6 @@ import { _privateSetManifestDontUseThis } from 'astro:ssr-manifest';
|
|
|
66
63
|
const _manifest = Object.assign(_deserializeManifest('${manifestReplace}'), {
|
|
67
64
|
pageMap,
|
|
68
65
|
renderers,
|
|
69
|
-
${middleware}
|
|
70
66
|
});
|
|
71
67
|
_privateSetManifestDontUseThis(_manifest);
|
|
72
68
|
const _args = ${adapter.args ? JSON.stringify(adapter.args) : "undefined"};
|
|
@@ -217,7 +213,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
217
213
|
return ssrManifest;
|
|
218
214
|
}
|
|
219
215
|
function pluginSSR(options, internals) {
|
|
220
|
-
const ssr =
|
|
216
|
+
const ssr = isServerLikeOutput(options.settings.config);
|
|
221
217
|
return {
|
|
222
218
|
build: "ssr",
|
|
223
219
|
hooks: {
|
|
@@ -14,7 +14,7 @@ import { emptyDir, removeEmptyDirs } from "../../core/fs/index.js";
|
|
|
14
14
|
import { appendForwardSlash, prependForwardSlash } from "../../core/path.js";
|
|
15
15
|
import { isModeServerWithNoAdapter } from "../../core/util.js";
|
|
16
16
|
import { runHookBuildSetup } from "../../integrations/index.js";
|
|
17
|
-
import {
|
|
17
|
+
import { isServerLikeOutput } from "../../prerender/utils.js";
|
|
18
18
|
import { PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
19
19
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
20
20
|
import { info } from "../logger/core.js";
|
|
@@ -79,7 +79,6 @@ async function viteBuild(opts) {
|
|
|
79
79
|
}
|
|
80
80
|
async function staticBuild(opts, internals) {
|
|
81
81
|
const { settings } = opts;
|
|
82
|
-
const hybridOutput = isHybridOutput(settings.config);
|
|
83
82
|
switch (true) {
|
|
84
83
|
case settings.config.output === "static": {
|
|
85
84
|
settings.timer.start("Static generate");
|
|
@@ -88,7 +87,7 @@ async function staticBuild(opts, internals) {
|
|
|
88
87
|
settings.timer.end("Static generate");
|
|
89
88
|
return;
|
|
90
89
|
}
|
|
91
|
-
case (settings.config
|
|
90
|
+
case isServerLikeOutput(settings.config): {
|
|
92
91
|
settings.timer.start("Server generate");
|
|
93
92
|
await generatePages(opts, internals);
|
|
94
93
|
await cleanStaticOutput(opts, internals);
|
|
@@ -104,7 +103,7 @@ ${bgMagenta(black(" finalizing server assets "))}
|
|
|
104
103
|
async function ssrBuild(opts, internals, input, container) {
|
|
105
104
|
var _a, _b, _c, _d, _e;
|
|
106
105
|
const { settings, viteConfig } = opts;
|
|
107
|
-
const ssr =
|
|
106
|
+
const ssr = isServerLikeOutput(settings.config);
|
|
108
107
|
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(settings.config.outDir);
|
|
109
108
|
const { lastVitePlugins, vitePlugins } = container.runBeforeHook("ssr", input);
|
|
110
109
|
const viteBuildConfig = {
|
|
@@ -132,13 +131,13 @@ async function ssrBuild(opts, internals, input, container) {
|
|
|
132
131
|
assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`,
|
|
133
132
|
...(_e = (_d = viteConfig.build) == null ? void 0 : _d.rollupOptions) == null ? void 0 : _e.output,
|
|
134
133
|
entryFileNames(chunkInfo) {
|
|
135
|
-
var _a2
|
|
134
|
+
var _a2;
|
|
136
135
|
if ((_a2 = chunkInfo.facadeModuleId) == null ? void 0 : _a2.startsWith(ASTRO_PAGE_RESOLVED_MODULE_ID)) {
|
|
137
136
|
return makeAstroPageEntryPointFileName(chunkInfo.facadeModuleId);
|
|
138
137
|
} else if (
|
|
139
138
|
// checks if the path of the module we have middleware, e.g. middleware.js / middleware/index.js
|
|
140
|
-
((
|
|
141
|
-
chunkInfo.exports.includes("
|
|
139
|
+
chunkInfo.moduleIds.find((m) => m.includes("middleware")) !== void 0 && // checks if the file actually export the `onRequest` function
|
|
140
|
+
chunkInfo.exports.includes("_middleware")
|
|
142
141
|
) {
|
|
143
142
|
return "middleware.mjs";
|
|
144
143
|
} else if (chunkInfo.facadeModuleId === SSR_VIRTUAL_MODULE_ID) {
|
|
@@ -175,7 +174,7 @@ async function clientBuild(opts, internals, input, container) {
|
|
|
175
174
|
var _a, _b, _c;
|
|
176
175
|
const { settings, viteConfig } = opts;
|
|
177
176
|
const timer = performance.now();
|
|
178
|
-
const ssr =
|
|
177
|
+
const ssr = isServerLikeOutput(settings.config);
|
|
179
178
|
const out = ssr ? opts.buildConfig.client : getOutDirWithinCwd(settings.config.outDir);
|
|
180
179
|
if (!input.size) {
|
|
181
180
|
if (ssr) {
|
|
@@ -229,7 +228,7 @@ async function runPostBuildHooks(container, ssrReturn, clientReturn) {
|
|
|
229
228
|
const config = container.options.settings.config;
|
|
230
229
|
const buildConfig = container.options.settings.config.build;
|
|
231
230
|
for (const [fileName, mutation] of mutations) {
|
|
232
|
-
const root =
|
|
231
|
+
const root = isServerLikeOutput(config) ? mutation.build === "server" ? buildConfig.server : buildConfig.client : config.outDir;
|
|
233
232
|
const fileURL = new URL(fileName, root);
|
|
234
233
|
await fs.promises.mkdir(new URL("./", fileURL), { recursive: true });
|
|
235
234
|
await fs.promises.writeFile(fileURL, mutation.code, "utf-8");
|
|
@@ -241,7 +240,7 @@ async function cleanStaticOutput(opts, internals) {
|
|
|
241
240
|
if (pageData.route.prerender)
|
|
242
241
|
allStaticFiles.add(internals.pageToBundleMap.get(pageData.moduleSpecifier));
|
|
243
242
|
}
|
|
244
|
-
const ssr =
|
|
243
|
+
const ssr = isServerLikeOutput(opts.settings.config);
|
|
245
244
|
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir);
|
|
246
245
|
const files = await glob("**/*.mjs", {
|
|
247
246
|
cwd: fileURLToPath(out)
|
|
@@ -3,7 +3,6 @@ import * as colors from "kleur/colors";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
5
5
|
import { mergeConfig as mergeViteConfig } from "vite";
|
|
6
|
-
import { isHybridMalconfigured } from "../../prerender/utils.js";
|
|
7
6
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
8
7
|
import { arraify, isObject, isURL } from "../util.js";
|
|
9
8
|
import { createRelativeSchema } from "./schema.js";
|
|
@@ -77,7 +76,7 @@ function resolveFlags(flags) {
|
|
|
77
76
|
host: typeof flags.host === "string" || typeof flags.host === "boolean" ? flags.host : void 0,
|
|
78
77
|
drafts: typeof flags.drafts === "boolean" ? flags.drafts : void 0,
|
|
79
78
|
experimentalAssets: typeof flags.experimentalAssets === "boolean" ? flags.experimentalAssets : void 0,
|
|
80
|
-
|
|
79
|
+
experimentalRedirects: typeof flags.experimentalRedirects === "boolean" ? flags.experimentalRedirects : void 0
|
|
81
80
|
};
|
|
82
81
|
}
|
|
83
82
|
function resolveRoot(cwd) {
|
|
@@ -105,9 +104,6 @@ function mergeCLIFlags(astroConfig, flags) {
|
|
|
105
104
|
if (typeof flags.open === "boolean") {
|
|
106
105
|
astroConfig.server.open = flags.open;
|
|
107
106
|
}
|
|
108
|
-
if (typeof flags.experimentalMiddleware === "boolean") {
|
|
109
|
-
astroConfig.experimental.middleware = true;
|
|
110
|
-
}
|
|
111
107
|
return astroConfig;
|
|
112
108
|
}
|
|
113
109
|
async function search(fsMod, root) {
|
|
@@ -152,11 +148,6 @@ async function openConfig(configOptions) {
|
|
|
152
148
|
userConfig = config.value;
|
|
153
149
|
}
|
|
154
150
|
const astroConfig = await resolveConfig(userConfig, root, flags, configOptions.cmd);
|
|
155
|
-
if (isHybridMalconfigured(astroConfig)) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
`The "output" config option must be set to "hybrid" and "experimental.hybridOutput" must be set to true to use the hybrid output mode. Falling back to "static" output mode.`
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
151
|
return {
|
|
161
152
|
astroConfig,
|
|
162
153
|
userConfig,
|
|
@@ -46,6 +46,8 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
46
46
|
assets: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
47
47
|
assetsPrefix: z.ZodOptional<z.ZodString>;
|
|
48
48
|
serverEntry: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
49
|
+
redirects: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
50
|
+
inlineStylesheets: z.ZodDefault<z.ZodOptional<z.ZodEnum<["always", "auto", "never"]>>>;
|
|
49
51
|
}, "strip", z.ZodTypeAny, {
|
|
50
52
|
assetsPrefix?: string | undefined;
|
|
51
53
|
server: URL;
|
|
@@ -53,6 +55,8 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
53
55
|
client: URL;
|
|
54
56
|
assets: string;
|
|
55
57
|
serverEntry: string;
|
|
58
|
+
redirects: boolean;
|
|
59
|
+
inlineStylesheets: "never" | "always" | "auto";
|
|
56
60
|
}, {
|
|
57
61
|
server?: string | undefined;
|
|
58
62
|
format?: "file" | "directory" | undefined;
|
|
@@ -60,6 +64,8 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
60
64
|
assets?: string | undefined;
|
|
61
65
|
assetsPrefix?: string | undefined;
|
|
62
66
|
serverEntry?: string | undefined;
|
|
67
|
+
redirects?: boolean | undefined;
|
|
68
|
+
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
63
69
|
}>>>;
|
|
64
70
|
server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
65
71
|
open: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -82,6 +88,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
82
88
|
host: string | boolean;
|
|
83
89
|
port: number;
|
|
84
90
|
}, unknown>;
|
|
91
|
+
redirects: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
85
92
|
image: z.ZodDefault<z.ZodObject<{
|
|
86
93
|
service: z.ZodObject<{
|
|
87
94
|
entrypoint: z.ZodUnion<[z.ZodLiteral<"astro/assets/services/sharp">, z.ZodLiteral<"astro/assets/services/squoosh">, z.ZodString]>;
|
|
@@ -155,34 +162,19 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
155
162
|
vite: z.ZodDefault<z.ZodType<ViteUserConfig, z.ZodTypeDef, ViteUserConfig>>;
|
|
156
163
|
experimental: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
|
157
164
|
assets: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
158
|
-
|
|
159
|
-
inlineStylesheets: z.ZodDefault<z.ZodOptional<z.ZodEnum<["always", "auto", "never"]>>>;
|
|
160
|
-
middleware: z.ZodDefault<z.ZodOptional<z.ZodOptional<z.ZodBoolean>>>;
|
|
161
|
-
hybridOutput: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
165
|
+
redirects: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
162
166
|
}, "passthrough", z.ZodTypeAny, {
|
|
163
167
|
assets: boolean;
|
|
164
|
-
|
|
165
|
-
inlineStylesheets: "never" | "always" | "auto";
|
|
166
|
-
middleware: boolean;
|
|
167
|
-
hybridOutput: boolean;
|
|
168
|
+
redirects: boolean;
|
|
168
169
|
}, {
|
|
169
170
|
assets?: boolean | undefined;
|
|
170
|
-
|
|
171
|
-
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
172
|
-
middleware?: boolean | undefined;
|
|
173
|
-
hybridOutput?: boolean | undefined;
|
|
171
|
+
redirects?: boolean | undefined;
|
|
174
172
|
}>, {
|
|
175
173
|
assets: boolean;
|
|
176
|
-
|
|
177
|
-
inlineStylesheets: "never" | "always" | "auto";
|
|
178
|
-
middleware: boolean;
|
|
179
|
-
hybridOutput: boolean;
|
|
174
|
+
redirects: boolean;
|
|
180
175
|
}, {
|
|
181
176
|
assets?: boolean | undefined;
|
|
182
|
-
|
|
183
|
-
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
184
|
-
middleware?: boolean | undefined;
|
|
185
|
-
hybridOutput?: boolean | undefined;
|
|
177
|
+
redirects?: boolean | undefined;
|
|
186
178
|
}>>>;
|
|
187
179
|
legacy: z.ZodDefault<z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>>;
|
|
188
180
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -211,6 +203,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
211
203
|
name: string;
|
|
212
204
|
hooks: {};
|
|
213
205
|
}[];
|
|
206
|
+
redirects: Record<string, string>;
|
|
214
207
|
build: {
|
|
215
208
|
assetsPrefix?: string | undefined;
|
|
216
209
|
server: URL;
|
|
@@ -218,6 +211,8 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
218
211
|
client: URL;
|
|
219
212
|
assets: string;
|
|
220
213
|
serverEntry: string;
|
|
214
|
+
redirects: boolean;
|
|
215
|
+
inlineStylesheets: "never" | "always" | "auto";
|
|
221
216
|
};
|
|
222
217
|
image: {
|
|
223
218
|
service: {
|
|
@@ -242,10 +237,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
242
237
|
vite: ViteUserConfig;
|
|
243
238
|
experimental: {
|
|
244
239
|
assets: boolean;
|
|
245
|
-
|
|
246
|
-
inlineStylesheets: "never" | "always" | "auto";
|
|
247
|
-
middleware: boolean;
|
|
248
|
-
hybridOutput: boolean;
|
|
240
|
+
redirects: boolean;
|
|
249
241
|
};
|
|
250
242
|
legacy: {};
|
|
251
243
|
}, {
|
|
@@ -266,6 +258,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
266
258
|
name: string;
|
|
267
259
|
} | undefined;
|
|
268
260
|
integrations?: unknown;
|
|
261
|
+
redirects?: Record<string, string> | undefined;
|
|
269
262
|
build?: {
|
|
270
263
|
server?: string | undefined;
|
|
271
264
|
format?: "file" | "directory" | undefined;
|
|
@@ -273,6 +266,8 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
273
266
|
assets?: string | undefined;
|
|
274
267
|
assetsPrefix?: string | undefined;
|
|
275
268
|
serverEntry?: string | undefined;
|
|
269
|
+
redirects?: boolean | undefined;
|
|
270
|
+
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
276
271
|
} | undefined;
|
|
277
272
|
image?: {
|
|
278
273
|
service: {
|
|
@@ -297,10 +292,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
297
292
|
vite?: ViteUserConfig | undefined;
|
|
298
293
|
experimental?: {
|
|
299
294
|
assets?: boolean | undefined;
|
|
300
|
-
|
|
301
|
-
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
302
|
-
middleware?: boolean | undefined;
|
|
303
|
-
hybridOutput?: boolean | undefined;
|
|
295
|
+
redirects?: boolean | undefined;
|
|
304
296
|
} | undefined;
|
|
305
297
|
legacy?: {} | undefined;
|
|
306
298
|
}>;
|
|
@@ -333,6 +325,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
333
325
|
name: string;
|
|
334
326
|
hooks: {};
|
|
335
327
|
}[], unknown>;
|
|
328
|
+
redirects: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
336
329
|
image: z.ZodDefault<z.ZodObject<{
|
|
337
330
|
service: z.ZodObject<{
|
|
338
331
|
entrypoint: z.ZodUnion<[z.ZodLiteral<"astro/assets/services/sharp">, z.ZodLiteral<"astro/assets/services/squoosh">, z.ZodString]>;
|
|
@@ -406,34 +399,19 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
406
399
|
vite: z.ZodDefault<z.ZodType<ViteUserConfig, z.ZodTypeDef, ViteUserConfig>>;
|
|
407
400
|
experimental: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
|
408
401
|
assets: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
409
|
-
|
|
410
|
-
inlineStylesheets: z.ZodDefault<z.ZodOptional<z.ZodEnum<["always", "auto", "never"]>>>;
|
|
411
|
-
middleware: z.ZodDefault<z.ZodOptional<z.ZodOptional<z.ZodBoolean>>>;
|
|
412
|
-
hybridOutput: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
402
|
+
redirects: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
413
403
|
}, "passthrough", z.ZodTypeAny, {
|
|
414
404
|
assets: boolean;
|
|
415
|
-
|
|
416
|
-
inlineStylesheets: "never" | "always" | "auto";
|
|
417
|
-
middleware: boolean;
|
|
418
|
-
hybridOutput: boolean;
|
|
405
|
+
redirects: boolean;
|
|
419
406
|
}, {
|
|
420
407
|
assets?: boolean | undefined;
|
|
421
|
-
|
|
422
|
-
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
423
|
-
middleware?: boolean | undefined;
|
|
424
|
-
hybridOutput?: boolean | undefined;
|
|
408
|
+
redirects?: boolean | undefined;
|
|
425
409
|
}>, {
|
|
426
410
|
assets: boolean;
|
|
427
|
-
|
|
428
|
-
inlineStylesheets: "never" | "always" | "auto";
|
|
429
|
-
middleware: boolean;
|
|
430
|
-
hybridOutput: boolean;
|
|
411
|
+
redirects: boolean;
|
|
431
412
|
}, {
|
|
432
413
|
assets?: boolean | undefined;
|
|
433
|
-
|
|
434
|
-
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
435
|
-
middleware?: boolean | undefined;
|
|
436
|
-
hybridOutput?: boolean | undefined;
|
|
414
|
+
redirects?: boolean | undefined;
|
|
437
415
|
}>>>;
|
|
438
416
|
legacy: z.ZodDefault<z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>>;
|
|
439
417
|
root: z.ZodEffects<z.ZodDefault<z.ZodString>, URL, string | undefined>;
|
|
@@ -449,6 +427,8 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
449
427
|
assets: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
450
428
|
assetsPrefix: z.ZodOptional<z.ZodString>;
|
|
451
429
|
serverEntry: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
430
|
+
redirects: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
431
|
+
inlineStylesheets: z.ZodDefault<z.ZodOptional<z.ZodEnum<["always", "auto", "never"]>>>;
|
|
452
432
|
}, "strip", z.ZodTypeAny, {
|
|
453
433
|
assetsPrefix?: string | undefined;
|
|
454
434
|
server: URL;
|
|
@@ -456,6 +436,8 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
456
436
|
client: URL;
|
|
457
437
|
assets: string;
|
|
458
438
|
serverEntry: string;
|
|
439
|
+
redirects: boolean;
|
|
440
|
+
inlineStylesheets: "never" | "always" | "auto";
|
|
459
441
|
}, {
|
|
460
442
|
server?: string | undefined;
|
|
461
443
|
format?: "file" | "directory" | undefined;
|
|
@@ -463,6 +445,8 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
463
445
|
assets?: string | undefined;
|
|
464
446
|
assetsPrefix?: string | undefined;
|
|
465
447
|
serverEntry?: string | undefined;
|
|
448
|
+
redirects?: boolean | undefined;
|
|
449
|
+
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
466
450
|
}>>>;
|
|
467
451
|
server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
468
452
|
host: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>>;
|
|
@@ -516,6 +500,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
516
500
|
name: string;
|
|
517
501
|
hooks: {};
|
|
518
502
|
}[];
|
|
503
|
+
redirects: Record<string, string>;
|
|
519
504
|
build: {
|
|
520
505
|
assetsPrefix?: string | undefined;
|
|
521
506
|
server: URL;
|
|
@@ -523,6 +508,8 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
523
508
|
client: URL;
|
|
524
509
|
assets: string;
|
|
525
510
|
serverEntry: string;
|
|
511
|
+
redirects: boolean;
|
|
512
|
+
inlineStylesheets: "never" | "always" | "auto";
|
|
526
513
|
};
|
|
527
514
|
image: {
|
|
528
515
|
service: {
|
|
@@ -547,10 +534,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
547
534
|
vite: ViteUserConfig;
|
|
548
535
|
experimental: {
|
|
549
536
|
assets: boolean;
|
|
550
|
-
|
|
551
|
-
inlineStylesheets: "never" | "always" | "auto";
|
|
552
|
-
middleware: boolean;
|
|
553
|
-
hybridOutput: boolean;
|
|
537
|
+
redirects: boolean;
|
|
554
538
|
};
|
|
555
539
|
legacy: {};
|
|
556
540
|
}, {
|
|
@@ -571,6 +555,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
571
555
|
name: string;
|
|
572
556
|
} | undefined;
|
|
573
557
|
integrations?: unknown;
|
|
558
|
+
redirects?: Record<string, string> | undefined;
|
|
574
559
|
build?: {
|
|
575
560
|
server?: string | undefined;
|
|
576
561
|
format?: "file" | "directory" | undefined;
|
|
@@ -578,6 +563,8 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
578
563
|
assets?: string | undefined;
|
|
579
564
|
assetsPrefix?: string | undefined;
|
|
580
565
|
serverEntry?: string | undefined;
|
|
566
|
+
redirects?: boolean | undefined;
|
|
567
|
+
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
581
568
|
} | undefined;
|
|
582
569
|
image?: {
|
|
583
570
|
service: {
|
|
@@ -602,10 +589,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
602
589
|
vite?: ViteUserConfig | undefined;
|
|
603
590
|
experimental?: {
|
|
604
591
|
assets?: boolean | undefined;
|
|
605
|
-
|
|
606
|
-
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
607
|
-
middleware?: boolean | undefined;
|
|
608
|
-
hybridOutput?: boolean | undefined;
|
|
592
|
+
redirects?: boolean | undefined;
|
|
609
593
|
} | undefined;
|
|
610
594
|
legacy?: {} | undefined;
|
|
611
595
|
}>, {
|
|
@@ -635,6 +619,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
635
619
|
name: string;
|
|
636
620
|
hooks: {};
|
|
637
621
|
}[];
|
|
622
|
+
redirects: Record<string, string>;
|
|
638
623
|
build: {
|
|
639
624
|
assetsPrefix?: string | undefined;
|
|
640
625
|
server: URL;
|
|
@@ -642,6 +627,8 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
642
627
|
client: URL;
|
|
643
628
|
assets: string;
|
|
644
629
|
serverEntry: string;
|
|
630
|
+
redirects: boolean;
|
|
631
|
+
inlineStylesheets: "never" | "always" | "auto";
|
|
645
632
|
};
|
|
646
633
|
image: {
|
|
647
634
|
service: {
|
|
@@ -666,10 +653,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
666
653
|
vite: ViteUserConfig;
|
|
667
654
|
experimental: {
|
|
668
655
|
assets: boolean;
|
|
669
|
-
|
|
670
|
-
inlineStylesheets: "never" | "always" | "auto";
|
|
671
|
-
middleware: boolean;
|
|
672
|
-
hybridOutput: boolean;
|
|
656
|
+
redirects: boolean;
|
|
673
657
|
};
|
|
674
658
|
legacy: {};
|
|
675
659
|
}, {
|
|
@@ -690,6 +674,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
690
674
|
name: string;
|
|
691
675
|
} | undefined;
|
|
692
676
|
integrations?: unknown;
|
|
677
|
+
redirects?: Record<string, string> | undefined;
|
|
693
678
|
build?: {
|
|
694
679
|
server?: string | undefined;
|
|
695
680
|
format?: "file" | "directory" | undefined;
|
|
@@ -697,6 +682,8 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
697
682
|
assets?: string | undefined;
|
|
698
683
|
assetsPrefix?: string | undefined;
|
|
699
684
|
serverEntry?: string | undefined;
|
|
685
|
+
redirects?: boolean | undefined;
|
|
686
|
+
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
700
687
|
} | undefined;
|
|
701
688
|
image?: {
|
|
702
689
|
service: {
|
|
@@ -721,10 +708,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
721
708
|
vite?: ViteUserConfig | undefined;
|
|
722
709
|
experimental?: {
|
|
723
710
|
assets?: boolean | undefined;
|
|
724
|
-
|
|
725
|
-
inlineStylesheets?: "never" | "always" | "auto" | undefined;
|
|
726
|
-
middleware?: boolean | undefined;
|
|
727
|
-
hybridOutput?: boolean | undefined;
|
|
711
|
+
redirects?: boolean | undefined;
|
|
728
712
|
} | undefined;
|
|
729
713
|
legacy?: {} | undefined;
|
|
730
714
|
}>;
|
|
@@ -15,7 +15,9 @@ const ASTRO_CONFIG_DEFAULTS = {
|
|
|
15
15
|
client: "./dist/client/",
|
|
16
16
|
server: "./dist/server/",
|
|
17
17
|
assets: "_astro",
|
|
18
|
-
serverEntry: "entry.mjs"
|
|
18
|
+
serverEntry: "entry.mjs",
|
|
19
|
+
redirects: true,
|
|
20
|
+
inlineStylesheets: "never"
|
|
19
21
|
},
|
|
20
22
|
compressHTML: false,
|
|
21
23
|
server: {
|
|
@@ -31,12 +33,10 @@ const ASTRO_CONFIG_DEFAULTS = {
|
|
|
31
33
|
},
|
|
32
34
|
vite: {},
|
|
33
35
|
legacy: {},
|
|
36
|
+
redirects: {},
|
|
34
37
|
experimental: {
|
|
35
38
|
assets: false,
|
|
36
|
-
|
|
37
|
-
customClientDirectives: false,
|
|
38
|
-
inlineStylesheets: "never",
|
|
39
|
-
middleware: false
|
|
39
|
+
redirects: false
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
const AstroConfigSchema = z.object({
|
|
@@ -64,7 +64,9 @@ const AstroConfigSchema = z.object({
|
|
|
64
64
|
server: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.server).transform((val) => new URL(val)),
|
|
65
65
|
assets: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.assets),
|
|
66
66
|
assetsPrefix: z.string().optional(),
|
|
67
|
-
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry)
|
|
67
|
+
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry),
|
|
68
|
+
redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.redirects),
|
|
69
|
+
inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets)
|
|
68
70
|
}).optional().default({}),
|
|
69
71
|
server: z.preprocess(
|
|
70
72
|
// preprocess
|
|
@@ -79,6 +81,7 @@ const AstroConfigSchema = z.object({
|
|
|
79
81
|
headers: z.custom().optional()
|
|
80
82
|
}).optional().default({})
|
|
81
83
|
),
|
|
84
|
+
redirects: z.record(z.string(), z.string()).default(ASTRO_CONFIG_DEFAULTS.redirects),
|
|
82
85
|
image: z.object({
|
|
83
86
|
service: z.object({
|
|
84
87
|
entrypoint: z.union([
|
|
@@ -118,10 +121,7 @@ const AstroConfigSchema = z.object({
|
|
|
118
121
|
vite: z.custom((data) => data instanceof Object && !Array.isArray(data)).default(ASTRO_CONFIG_DEFAULTS.vite),
|
|
119
122
|
experimental: z.object({
|
|
120
123
|
assets: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.assets),
|
|
121
|
-
|
|
122
|
-
inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.experimental.inlineStylesheets),
|
|
123
|
-
middleware: z.oboolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.middleware),
|
|
124
|
-
hybridOutput: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.hybridOutput)
|
|
124
|
+
redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.redirects)
|
|
125
125
|
}).passthrough().refine(
|
|
126
126
|
(d) => {
|
|
127
127
|
const validKeys = Object.keys(ASTRO_CONFIG_DEFAULTS.experimental);
|
|
@@ -158,7 +158,9 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
|
|
|
158
158
|
server: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.server).transform((val) => new URL(val, fileProtocolRoot)),
|
|
159
159
|
assets: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.assets),
|
|
160
160
|
assetsPrefix: z.string().optional(),
|
|
161
|
-
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry)
|
|
161
|
+
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry),
|
|
162
|
+
redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.redirects),
|
|
163
|
+
inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets)
|
|
162
164
|
}).optional().default({}),
|
|
163
165
|
server: z.preprocess(
|
|
164
166
|
// preprocess
|
|
@@ -3,7 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
4
4
|
import { getContentPaths } from "../../content/index.js";
|
|
5
5
|
import jsxRenderer from "../../jsx/renderer.js";
|
|
6
|
-
import {
|
|
6
|
+
import { isServerLikeOutput } from "../../prerender/utils.js";
|
|
7
7
|
import { markdownContentEntryType } from "../../vite-plugin-markdown/content-entry-type.js";
|
|
8
8
|
import { getDefaultClientDirectives } from "../client-directive/index.js";
|
|
9
9
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
@@ -19,7 +19,7 @@ function createBaseSettings(config) {
|
|
|
19
19
|
tsConfig: void 0,
|
|
20
20
|
tsConfigPath: void 0,
|
|
21
21
|
adapter: void 0,
|
|
22
|
-
injectedRoutes: config.experimental.assets && (config
|
|
22
|
+
injectedRoutes: config.experimental.assets && isServerLikeOutput(config) ? [{ pattern: "/_image", entryPoint: "astro/assets/image-endpoint" }] : [],
|
|
23
23
|
pageExtensions: [".astro", ".html", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
|
|
24
24
|
contentEntryTypes: [markdownContentEntryType],
|
|
25
25
|
dataEntryTypes: [
|