astro 5.5.5 → 5.6.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 -16
- package/dist/actions/runtime/utils.d.ts +8 -2
- package/dist/assets/runtime.js +5 -29
- package/dist/assets/utils/svg.d.ts +1 -4
- package/dist/assets/utils/svg.js +2 -2
- package/dist/assets/vite-plugin-assets.js +1 -3
- package/dist/cli/add/index.js +1 -1
- package/dist/container/index.js +1 -1
- package/dist/content/content-layer.js +3 -3
- package/dist/core/app/index.d.ts +15 -0
- package/dist/core/app/index.js +27 -7
- package/dist/core/build/index.js +2 -2
- package/dist/core/config/index.d.ts +1 -1
- package/dist/core/config/schemas/base.d.ts +1110 -0
- package/dist/core/config/{schema.js → schemas/base.js} +8 -254
- package/dist/core/config/schemas/index.d.ts +3 -0
- package/dist/core/config/schemas/index.js +9 -0
- package/dist/core/config/schemas/refined.d.ts +3 -0
- package/dist/core/config/schemas/refined.js +148 -0
- package/dist/core/config/schemas/relative.d.ts +1462 -0
- package/dist/core/config/schemas/relative.js +93 -0
- package/dist/core/config/validate.d.ts +6 -0
- package/dist/core/config/validate.js +9 -3
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +1 -1
- package/dist/core/errors/errors-data.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.js +5 -2
- package/dist/core/session.d.ts +8 -0
- package/dist/core/session.js +13 -0
- package/dist/events/session.js +1 -1
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +12 -0
- package/dist/i18n/utils.js +7 -11
- package/dist/integrations/hooks.d.ts +4 -4
- package/dist/integrations/hooks.js +273 -280
- package/dist/prefetch/index.d.ts +8 -0
- package/dist/prefetch/index.js +6 -4
- package/dist/types/public/config.d.ts +3 -25
- package/dist/types/public/context.d.ts +1 -1
- package/package.json +11 -11
- package/dist/core/config/schema.d.ts +0 -3402
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { appendForwardSlash, prependForwardSlash, removeTrailingForwardSlash } from "../../path.js";
|
|
5
|
+
import { ASTRO_CONFIG_DEFAULTS, AstroConfigSchema } from "./base.js";
|
|
6
|
+
function resolveDirAsUrl(dir, root) {
|
|
7
|
+
let resolvedDir = path.resolve(root, dir);
|
|
8
|
+
if (!resolvedDir.endsWith(path.sep)) {
|
|
9
|
+
resolvedDir += path.sep;
|
|
10
|
+
}
|
|
11
|
+
return pathToFileURL(resolvedDir);
|
|
12
|
+
}
|
|
13
|
+
function createRelativeSchema(cmd, fileProtocolRoot) {
|
|
14
|
+
let originalBuildClient;
|
|
15
|
+
let originalBuildServer;
|
|
16
|
+
const AstroConfigRelativeSchema = AstroConfigSchema.extend({
|
|
17
|
+
root: z.string().default(ASTRO_CONFIG_DEFAULTS.root).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
|
|
18
|
+
srcDir: z.string().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
|
|
19
|
+
compressHTML: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compressHTML),
|
|
20
|
+
publicDir: z.string().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
|
|
21
|
+
outDir: z.string().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
|
|
22
|
+
cacheDir: z.string().default(ASTRO_CONFIG_DEFAULTS.cacheDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
|
|
23
|
+
build: z.object({
|
|
24
|
+
format: z.union([z.literal("file"), z.literal("directory"), z.literal("preserve")]).optional().default(ASTRO_CONFIG_DEFAULTS.build.format),
|
|
25
|
+
// NOTE: `client` and `server` are transformed relative to the default outDir first,
|
|
26
|
+
// later we'll fix this to be relative to the actual `outDir`
|
|
27
|
+
client: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.client).transform((val) => {
|
|
28
|
+
originalBuildClient = val;
|
|
29
|
+
return resolveDirAsUrl(
|
|
30
|
+
val,
|
|
31
|
+
path.resolve(fileProtocolRoot, ASTRO_CONFIG_DEFAULTS.outDir)
|
|
32
|
+
);
|
|
33
|
+
}),
|
|
34
|
+
server: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.server).transform((val) => {
|
|
35
|
+
originalBuildServer = val;
|
|
36
|
+
return resolveDirAsUrl(
|
|
37
|
+
val,
|
|
38
|
+
path.resolve(fileProtocolRoot, ASTRO_CONFIG_DEFAULTS.outDir)
|
|
39
|
+
);
|
|
40
|
+
}),
|
|
41
|
+
assets: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.assets),
|
|
42
|
+
assetsPrefix: z.string().optional().or(z.object({ fallback: z.string() }).and(z.record(z.string())).optional()),
|
|
43
|
+
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry),
|
|
44
|
+
redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.redirects),
|
|
45
|
+
inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets),
|
|
46
|
+
concurrency: z.number().min(1).optional().default(ASTRO_CONFIG_DEFAULTS.build.concurrency)
|
|
47
|
+
}).optional().default({}),
|
|
48
|
+
server: z.preprocess(
|
|
49
|
+
// preprocess
|
|
50
|
+
(val) => {
|
|
51
|
+
if (typeof val === "function") {
|
|
52
|
+
return val({ command: cmd === "dev" ? "dev" : "preview" });
|
|
53
|
+
} else {
|
|
54
|
+
return val;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
// validate
|
|
58
|
+
z.object({
|
|
59
|
+
open: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.open),
|
|
60
|
+
host: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.host),
|
|
61
|
+
port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port),
|
|
62
|
+
headers: z.custom().optional(),
|
|
63
|
+
streaming: z.boolean().optional().default(true),
|
|
64
|
+
allowedHosts: z.union([z.array(z.string()), z.literal(true)]).optional().default(ASTRO_CONFIG_DEFAULTS.server.allowedHosts)
|
|
65
|
+
}).optional().default({})
|
|
66
|
+
)
|
|
67
|
+
}).transform((config) => {
|
|
68
|
+
if (config.outDir.toString() !== resolveDirAsUrl(ASTRO_CONFIG_DEFAULTS.outDir, fileProtocolRoot).toString()) {
|
|
69
|
+
const outDirPath = fileURLToPath(config.outDir);
|
|
70
|
+
config.build.client = resolveDirAsUrl(originalBuildClient, outDirPath);
|
|
71
|
+
config.build.server = resolveDirAsUrl(originalBuildServer, outDirPath);
|
|
72
|
+
}
|
|
73
|
+
if (config.trailingSlash === "never") {
|
|
74
|
+
config.base = prependForwardSlash(removeTrailingForwardSlash(config.base));
|
|
75
|
+
config.image.endpoint.route = prependForwardSlash(
|
|
76
|
+
removeTrailingForwardSlash(config.image.endpoint.route)
|
|
77
|
+
);
|
|
78
|
+
} else if (config.trailingSlash === "always") {
|
|
79
|
+
config.base = prependForwardSlash(appendForwardSlash(config.base));
|
|
80
|
+
config.image.endpoint.route = prependForwardSlash(
|
|
81
|
+
appendForwardSlash(config.image.endpoint.route)
|
|
82
|
+
);
|
|
83
|
+
} else {
|
|
84
|
+
config.base = prependForwardSlash(config.base);
|
|
85
|
+
config.image.endpoint.route = prependForwardSlash(config.image.endpoint.route);
|
|
86
|
+
}
|
|
87
|
+
return config;
|
|
88
|
+
});
|
|
89
|
+
return AstroConfigRelativeSchema;
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
createRelativeSchema
|
|
93
|
+
};
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { AstroConfig } from '../../types/public/config.js';
|
|
2
2
|
/** Turn raw config values into normalized values */
|
|
3
3
|
export declare function validateConfig(userConfig: any, root: string, cmd: string): Promise<AstroConfig>;
|
|
4
|
+
/**
|
|
5
|
+
* Used twice:
|
|
6
|
+
* - To validate the user config
|
|
7
|
+
* - To validate the config after all integrations (that may have updated it)
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateConfigRefined(updatedConfig: AstroConfig): Promise<AstroConfig>;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { errorMap } from "../errors/index.js";
|
|
2
|
-
import { createRelativeSchema } from "./
|
|
2
|
+
import { AstroConfigRefinedSchema, createRelativeSchema } from "./schemas/index.js";
|
|
3
3
|
async function validateConfig(userConfig, root, cmd) {
|
|
4
4
|
const AstroConfigRelativeSchema = createRelativeSchema(cmd, root);
|
|
5
|
-
return await
|
|
5
|
+
return await validateConfigRefined(
|
|
6
|
+
await AstroConfigRelativeSchema.parseAsync(userConfig, { errorMap })
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
async function validateConfigRefined(updatedConfig) {
|
|
10
|
+
return await AstroConfigRefinedSchema.parseAsync(updatedConfig, { errorMap });
|
|
6
11
|
}
|
|
7
12
|
export {
|
|
8
|
-
validateConfig
|
|
13
|
+
validateConfig,
|
|
14
|
+
validateConfigRefined
|
|
9
15
|
};
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -22,7 +22,7 @@ async function dev(inlineConfig) {
|
|
|
22
22
|
await telemetry.record([]);
|
|
23
23
|
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
24
24
|
const logger = restart.container.logger;
|
|
25
|
-
const currentVersion = "5.
|
|
25
|
+
const currentVersion = "5.6.0";
|
|
26
26
|
const isPrerelease = currentVersion.includes("-");
|
|
27
27
|
if (!isPrerelease) {
|
|
28
28
|
try {
|
|
@@ -16,7 +16,7 @@ const ClientAddressNotAvailable = {
|
|
|
16
16
|
const PrerenderClientAddressNotAvailable = {
|
|
17
17
|
name: "PrerenderClientAddressNotAvailable",
|
|
18
18
|
title: "`Astro.clientAddress` cannot be used inside prerendered routes.",
|
|
19
|
-
message: `\`Astro.clientAddress\` cannot be used inside prerendered
|
|
19
|
+
message: (name) => `\`Astro.clientAddress\` cannot be used inside prerendered route ${name}`
|
|
20
20
|
};
|
|
21
21
|
const StaticClientAddressNotAvailable = {
|
|
22
22
|
name: "StaticClientAddressNotAvailable",
|
package/dist/core/messages.js
CHANGED
|
@@ -38,7 +38,7 @@ function serverStart({
|
|
|
38
38
|
host,
|
|
39
39
|
base
|
|
40
40
|
}) {
|
|
41
|
-
const version = "5.
|
|
41
|
+
const version = "5.6.0";
|
|
42
42
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
43
43
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
44
44
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -282,7 +282,7 @@ function printHelp({
|
|
|
282
282
|
message.push(
|
|
283
283
|
linebreak(),
|
|
284
284
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
285
|
-
`v${"5.
|
|
285
|
+
`v${"5.6.0"}`
|
|
286
286
|
)} ${headline}`
|
|
287
287
|
);
|
|
288
288
|
}
|
|
@@ -238,7 +238,7 @@ class RenderContext {
|
|
|
238
238
|
reroutePayload,
|
|
239
239
|
this.request
|
|
240
240
|
);
|
|
241
|
-
if (this.pipeline.serverLike
|
|
241
|
+
if (this.pipeline.serverLike && !this.routeData.prerender && routeData.prerender) {
|
|
242
242
|
throw new AstroError({
|
|
243
243
|
...ForbiddenRewrite,
|
|
244
244
|
message: ForbiddenRewrite.message(this.pathname, pathname, routeData.component),
|
|
@@ -463,7 +463,10 @@ class RenderContext {
|
|
|
463
463
|
getClientAddress() {
|
|
464
464
|
const { pipeline, request, routeData, clientAddress } = this;
|
|
465
465
|
if (routeData.prerender) {
|
|
466
|
-
throw new AstroError(
|
|
466
|
+
throw new AstroError({
|
|
467
|
+
...AstroErrorData.PrerenderClientAddressNotAvailable,
|
|
468
|
+
message: AstroErrorData.PrerenderClientAddressNotAvailable.message(routeData.component)
|
|
469
|
+
});
|
|
467
470
|
}
|
|
468
471
|
if (clientAddress) {
|
|
469
472
|
return clientAddress;
|
package/dist/core/session.d.ts
CHANGED
|
@@ -45,6 +45,14 @@ export declare class AstroSession<TDriver extends SessionDriverName = any> {
|
|
|
45
45
|
regenerate(): Promise<void>;
|
|
46
46
|
[PERSIST_SYMBOL](): Promise<void>;
|
|
47
47
|
get sessionID(): string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Loads a session from storage with the given ID, and replaces the current session.
|
|
50
|
+
* Any changes made to the current session will be lost.
|
|
51
|
+
* This is not normally needed, as the session is automatically loaded using the cookie.
|
|
52
|
+
* However it can be used to restore a session where the ID has been recorded somewhere
|
|
53
|
+
* else (e.g. in a database).
|
|
54
|
+
*/
|
|
55
|
+
load(sessionID: string): Promise<void>;
|
|
48
56
|
}
|
|
49
57
|
export declare function resolveSessionDriver(driver: string | undefined): Promise<string | null>;
|
|
50
58
|
export declare function validateSessionConfig(settings: AstroSettings): void;
|
package/dist/core/session.js
CHANGED
|
@@ -221,6 +221,19 @@ class AstroSession {
|
|
|
221
221
|
get sessionID() {
|
|
222
222
|
return this.#sessionID;
|
|
223
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Loads a session from storage with the given ID, and replaces the current session.
|
|
226
|
+
* Any changes made to the current session will be lost.
|
|
227
|
+
* This is not normally needed, as the session is automatically loaded using the cookie.
|
|
228
|
+
* However it can be used to restore a session where the ID has been recorded somewhere
|
|
229
|
+
* else (e.g. in a database).
|
|
230
|
+
*/
|
|
231
|
+
async load(sessionID) {
|
|
232
|
+
this.#sessionID = sessionID;
|
|
233
|
+
this.#data = void 0;
|
|
234
|
+
await this.#setCookie();
|
|
235
|
+
await this.#ensureData();
|
|
236
|
+
}
|
|
224
237
|
/**
|
|
225
238
|
* Sets the session cookie.
|
|
226
239
|
*/
|
package/dist/events/session.js
CHANGED
package/dist/i18n/index.d.ts
CHANGED
|
@@ -78,6 +78,7 @@ export declare function normalizeTheLocale(locale: string): string;
|
|
|
78
78
|
* Returns an array of only locales, by picking the `code`
|
|
79
79
|
* @param locales
|
|
80
80
|
*/
|
|
81
|
+
export declare function getAllCodes(locales: Locales): string[];
|
|
81
82
|
export declare function toCodes(locales: Locales): string[];
|
|
82
83
|
/**
|
|
83
84
|
* It returns the array of paths
|
package/dist/i18n/index.js
CHANGED
|
@@ -132,6 +132,17 @@ function getLocaleByPath(path, locales) {
|
|
|
132
132
|
function normalizeTheLocale(locale) {
|
|
133
133
|
return locale.replaceAll("_", "-").toLowerCase();
|
|
134
134
|
}
|
|
135
|
+
function getAllCodes(locales) {
|
|
136
|
+
const result = [];
|
|
137
|
+
for (const loopLocale of locales) {
|
|
138
|
+
if (typeof loopLocale === "string") {
|
|
139
|
+
result.push(loopLocale);
|
|
140
|
+
} else {
|
|
141
|
+
result.push(...loopLocale.codes);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
135
146
|
function toCodes(locales) {
|
|
136
147
|
return locales.map((loopLocale) => {
|
|
137
148
|
if (typeof loopLocale === "string") {
|
|
@@ -258,6 +269,7 @@ function createMiddleware(i18nManifest, base, trailingSlash, format) {
|
|
|
258
269
|
}
|
|
259
270
|
export {
|
|
260
271
|
createMiddleware,
|
|
272
|
+
getAllCodes,
|
|
261
273
|
getLocaleAbsoluteUrl,
|
|
262
274
|
getLocaleAbsoluteUrlList,
|
|
263
275
|
getLocaleByPath,
|
package/dist/i18n/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAllCodes, normalizeTheLocale } from "./index.js";
|
|
2
2
|
function parseLocale(header) {
|
|
3
3
|
if (header === "*") {
|
|
4
4
|
return [{ locale: header, qualityValue: void 0 }];
|
|
@@ -35,7 +35,7 @@ function parseLocale(header) {
|
|
|
35
35
|
return result;
|
|
36
36
|
}
|
|
37
37
|
function sortAndFilterLocales(browserLocaleList, locales) {
|
|
38
|
-
const normalizedLocales =
|
|
38
|
+
const normalizedLocales = getAllCodes(locales).map(normalizeTheLocale);
|
|
39
39
|
return browserLocaleList.filter((browserLocale) => {
|
|
40
40
|
if (browserLocale.locale !== "*") {
|
|
41
41
|
return normalizedLocales.includes(normalizeTheLocale(browserLocale.locale));
|
|
@@ -59,11 +59,13 @@ function computePreferredLocale(request, locales) {
|
|
|
59
59
|
if (typeof currentLocale === "string") {
|
|
60
60
|
if (normalizeTheLocale(currentLocale) === normalizeTheLocale(firstResult.locale)) {
|
|
61
61
|
result = currentLocale;
|
|
62
|
+
break;
|
|
62
63
|
}
|
|
63
64
|
} else {
|
|
64
65
|
for (const currentCode of currentLocale.codes) {
|
|
65
66
|
if (normalizeTheLocale(currentCode) === normalizeTheLocale(firstResult.locale)) {
|
|
66
|
-
result =
|
|
67
|
+
result = currentCode;
|
|
68
|
+
break;
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -78,13 +80,7 @@ function computePreferredLocaleList(request, locales) {
|
|
|
78
80
|
if (acceptHeader) {
|
|
79
81
|
const browserLocaleList = sortAndFilterLocales(parseLocale(acceptHeader), locales);
|
|
80
82
|
if (browserLocaleList.length === 1 && browserLocaleList.at(0).locale === "*") {
|
|
81
|
-
return locales
|
|
82
|
-
if (typeof locale === "string") {
|
|
83
|
-
return locale;
|
|
84
|
-
} else {
|
|
85
|
-
return locale.codes.at(0);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
83
|
+
return getAllCodes(locales);
|
|
88
84
|
} else if (browserLocaleList.length > 0) {
|
|
89
85
|
for (const browserLocale of browserLocaleList) {
|
|
90
86
|
for (const loopLocale of locales) {
|
|
@@ -95,7 +91,7 @@ function computePreferredLocaleList(request, locales) {
|
|
|
95
91
|
} else {
|
|
96
92
|
for (const code of loopLocale.codes) {
|
|
97
93
|
if (code === browserLocale.locale) {
|
|
98
|
-
result.push(
|
|
94
|
+
result.push(code);
|
|
99
95
|
}
|
|
100
96
|
}
|
|
101
97
|
}
|
|
@@ -64,9 +64,9 @@ export declare function runHookServerDone({ config, logger, }: {
|
|
|
64
64
|
config: AstroConfig;
|
|
65
65
|
logger: Logger;
|
|
66
66
|
}): Promise<void>;
|
|
67
|
-
export declare function runHookBuildStart({ config,
|
|
67
|
+
export declare function runHookBuildStart({ config, logger, }: {
|
|
68
68
|
config: AstroConfig;
|
|
69
|
-
|
|
69
|
+
logger: Logger;
|
|
70
70
|
}): Promise<void>;
|
|
71
71
|
export declare function runHookBuildSetup({ config, vite, pages, target, logger, }: {
|
|
72
72
|
config: AstroConfig;
|
|
@@ -91,9 +91,9 @@ type RunHookBuildDone = {
|
|
|
91
91
|
settings: AstroSettings;
|
|
92
92
|
pages: string[];
|
|
93
93
|
routes: RouteData[];
|
|
94
|
-
|
|
94
|
+
logger: Logger;
|
|
95
95
|
};
|
|
96
|
-
export declare function runHookBuildDone({ settings, pages, routes,
|
|
96
|
+
export declare function runHookBuildDone({ settings, pages, routes, logger }: RunHookBuildDone): Promise<void>;
|
|
97
97
|
export declare function runHookRouteSetup({ route, settings, logger, }: {
|
|
98
98
|
route: RouteOptions;
|
|
99
99
|
settings: AstroSettings;
|