full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -1,7 +1,6 @@
import fs from 'node:fs';
import type { AstroConfig, AstroInlineConfig, AstroUserConfig } from '../../@types/astro.js';
import type { AstroConfig, AstroInlineConfig, AstroUserConfig } from '../../types/public/config.js';
export declare function resolveRoot(cwd?: string | URL): string;
export declare const configPaths: readonly string[];
interface ResolveConfigPathOptions {
root: string;
configFile?: string | false;

View File

@@ -101,7 +101,6 @@ async function resolveConfig(inlineConfig, command, fsMod = fs) {
return { userConfig: mergedConfig, astroConfig };
}
export {
configPaths,
resolveConfig,
resolveConfigPath,
resolveRoot

View File

@@ -1,6 +1,5 @@
export { configPaths, resolveConfig, resolveConfigPath, resolveRoot, } from './config.js';
export { resolveConfig, resolveConfigPath, resolveRoot, } from './config.js';
export { createNodeLogger } from './logging.js';
export { mergeConfig } from './merge.js';
export type { AstroConfigType } from './schema.js';
export { createSettings } from './settings.js';
export { loadTSConfig, updateTSConfigForFramework } from './tsconfig.js';

View File

@@ -1,5 +1,4 @@
import {
configPaths,
resolveConfig,
resolveConfigPath,
resolveRoot
@@ -9,7 +8,6 @@ import { mergeConfig } from "./merge.js";
import { createSettings } from "./settings.js";
import { loadTSConfig, updateTSConfigForFramework } from "./tsconfig.js";
export {
configPaths,
createNodeLogger,
createSettings,
loadTSConfig,

View File

@@ -1,3 +1,3 @@
import type { AstroInlineConfig } from '../../@types/astro.js';
import type { AstroInlineConfig } from '../../types/public/config.js';
import { Logger } from '../logger/core.js';
export declare function createNodeLogger(inlineConfig: AstroInlineConfig): Logger;

View File

@@ -1 +1,3 @@
export declare function mergeConfig(defaults: Record<string, any>, overrides: Record<string, any>, isRoot?: boolean): Record<string, any>;
import type { DeepPartial } from '../../type-utils.js';
import type { AstroConfig, AstroInlineConfig } from '../../types/public/index.js';
export declare function mergeConfig<C extends AstroConfig | AstroInlineConfig>(defaults: C, overrides: DeepPartial<C>): C;

View File

@@ -7,7 +7,7 @@ function mergeConfigRecursively(defaults, overrides, rootPath) {
if (value == null) {
continue;
}
let existing = merged[key];
const existing = merged[key];
if (existing == null) {
merged[key] = value;
continue;
@@ -26,10 +26,8 @@ function mergeConfigRecursively(defaults, overrides, rootPath) {
continue;
}
}
if (key === "data" && rootPath === "db") {
if (!Array.isArray(existing) && !Array.isArray(value)) {
existing = [existing];
}
if (key === "allowedHosts" && rootPath === "server" && typeof existing === "boolean") {
continue;
}
if (Array.isArray(existing) || Array.isArray(value)) {
merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])];
@@ -47,8 +45,8 @@ function mergeConfigRecursively(defaults, overrides, rootPath) {
}
return merged;
}
function mergeConfig(defaults, overrides, isRoot = true) {
return mergeConfigRecursively(defaults, overrides, isRoot ? "" : ".");
function mergeConfig(defaults, overrides) {
return mergeConfigRecursively(defaults, overrides, "");
}
export {
mergeConfig

File diff suppressed because it is too large Load Diff

View File

@@ -1,446 +0,0 @@
import { markdownConfigDefaults } from "@astrojs/markdown-remark";
import { bundledThemes } from "shiki";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { z } from "zod";
import { EnvSchema } from "../../env/schema.js";
import { appendForwardSlash, prependForwardSlash, removeTrailingForwardSlash } from "../path.js";
const ASTRO_CONFIG_DEFAULTS = {
root: ".",
srcDir: "./src",
publicDir: "./public",
outDir: "./dist",
cacheDir: "./node_modules/.astro",
base: "/",
trailingSlash: "ignore",
build: {
format: "directory",
client: "./dist/client/",
server: "./dist/server/",
assets: "_astro",
serverEntry: "entry.mjs",
redirects: true,
inlineStylesheets: "auto",
concurrency: 1
},
image: {
service: { entrypoint: "astro/assets/services/sharp", config: {} }
},
devToolbar: {
enabled: true
},
compressHTML: true,
server: {
host: false,
port: 4321,
open: false
},
integrations: [],
markdown: markdownConfigDefaults,
vite: {},
legacy: {},
redirects: {},
security: {},
experimental: {
directRenderScript: false,
contentCollectionCache: false,
clientPrerender: false,
globalRoutePriority: false,
serverIslands: false,
contentIntellisense: false,
env: {
validateSecrets: false
},
contentLayer: false
}
};
const AstroConfigSchema = z.object({
root: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.root).transform((val) => new URL(val)),
srcDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => new URL(val)),
publicDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => new URL(val)),
outDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => new URL(val)),
cacheDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.cacheDir).transform((val) => new URL(val)),
site: z.string().url().optional(),
compressHTML: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compressHTML),
base: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.base),
trailingSlash: z.union([z.literal("always"), z.literal("never"), z.literal("ignore")]).optional().default(ASTRO_CONFIG_DEFAULTS.trailingSlash),
output: z.union([z.literal("static"), z.literal("server"), z.literal("hybrid")]).optional().default("static"),
scopedStyleStrategy: z.union([z.literal("where"), z.literal("class"), z.literal("attribute")]).optional().default("attribute"),
adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(),
integrations: z.preprocess(
// preprocess
(val) => Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val,
// validate
z.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) })).default(ASTRO_CONFIG_DEFAULTS.integrations)
),
build: z.object({
format: z.union([z.literal("file"), z.literal("directory"), z.literal("preserve")]).optional().default(ASTRO_CONFIG_DEFAULTS.build.format),
client: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.client).transform((val) => new URL(val)),
server: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.server).transform((val) => new URL(val)),
assets: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.assets),
assetsPrefix: z.string().optional().or(z.object({ fallback: z.string() }).and(z.record(z.string())).optional()).refine(
(value) => {
if (value && typeof value !== "string") {
if (!value.fallback) {
return false;
}
}
return true;
},
{
message: "The `fallback` is mandatory when defining the option as an object."
}
),
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry),
redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.redirects),
inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets),
concurrency: z.number().min(1).optional().default(ASTRO_CONFIG_DEFAULTS.build.concurrency)
}).default({}),
server: z.preprocess(
// preprocess
// NOTE: Uses the "error" command here because this is overwritten by the
// individualized schema parser with the correct command.
(val) => typeof val === "function" ? val({ command: "error" }) : val,
// validate
z.object({
open: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.open),
host: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.host),
port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port),
headers: z.custom().optional()
}).default({})
),
redirects: z.record(
z.string(),
z.union([
z.string(),
z.object({
status: z.union([
z.literal(300),
z.literal(301),
z.literal(302),
z.literal(303),
z.literal(304),
z.literal(307),
z.literal(308)
]),
destination: z.string()
})
])
).default(ASTRO_CONFIG_DEFAULTS.redirects),
prefetch: z.union([
z.boolean(),
z.object({
prefetchAll: z.boolean().optional(),
defaultStrategy: z.enum(["tap", "hover", "viewport", "load"]).optional()
})
]).optional(),
image: z.object({
endpoint: z.string().optional(),
service: z.object({
entrypoint: z.union([
z.literal("astro/assets/services/sharp"),
z.literal("astro/assets/services/squoosh"),
z.string()
]).default(ASTRO_CONFIG_DEFAULTS.image.service.entrypoint),
config: z.record(z.any()).default({})
}).default(ASTRO_CONFIG_DEFAULTS.image.service),
domains: z.array(z.string()).default([]),
remotePatterns: z.array(
z.object({
protocol: z.string().optional(),
hostname: z.string().refine(
(val) => !val.includes("*") || val.startsWith("*.") || val.startsWith("**."),
{
message: "wildcards can only be placed at the beginning of the hostname"
}
).optional(),
port: z.string().optional(),
pathname: z.string().refine((val) => !val.includes("*") || val.endsWith("/*") || val.endsWith("/**"), {
message: "wildcards can only be placed at the end of a pathname"
}).optional()
})
).default([])
}).default(ASTRO_CONFIG_DEFAULTS.image),
devToolbar: z.object({
enabled: z.boolean().default(ASTRO_CONFIG_DEFAULTS.devToolbar.enabled)
}).default(ASTRO_CONFIG_DEFAULTS.devToolbar),
markdown: z.object({
syntaxHighlight: z.union([z.literal("shiki"), z.literal("prism"), z.literal(false)]).default(ASTRO_CONFIG_DEFAULTS.markdown.syntaxHighlight),
shikiConfig: z.object({
langs: z.custom().array().transform((langs) => {
for (const lang of langs) {
if (typeof lang === "object") {
if (lang.id) {
lang.name = lang.id;
}
if (lang.grammar) {
Object.assign(lang, lang.grammar);
}
}
}
return langs;
}).default([]),
langAlias: z.record(z.string(), z.string()).optional().default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.langAlias),
theme: z.enum(Object.keys(bundledThemes)).or(z.custom()).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.theme),
themes: z.record(
z.enum(Object.keys(bundledThemes)).or(z.custom())
).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.themes),
defaultColor: z.union([z.literal("light"), z.literal("dark"), z.string(), z.literal(false)]).optional(),
wrap: z.boolean().or(z.null()).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.wrap),
transformers: z.custom().array().transform((transformers) => {
for (const transformer of transformers) {
if (transformer.token && !("span" in transformer)) {
transformer.span = transformer.token;
}
}
return transformers;
}).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.transformers)
}).default({}),
remarkPlugins: z.union([
z.string(),
z.tuple([z.string(), z.any()]),
z.custom((data) => typeof data === "function"),
z.tuple([z.custom((data) => typeof data === "function"), z.any()])
]).array().default(ASTRO_CONFIG_DEFAULTS.markdown.remarkPlugins),
rehypePlugins: z.union([
z.string(),
z.tuple([z.string(), z.any()]),
z.custom((data) => typeof data === "function"),
z.tuple([z.custom((data) => typeof data === "function"), z.any()])
]).array().default(ASTRO_CONFIG_DEFAULTS.markdown.rehypePlugins),
remarkRehype: z.custom((data) => data instanceof Object && !Array.isArray(data)).default(ASTRO_CONFIG_DEFAULTS.markdown.remarkRehype),
gfm: z.boolean().default(ASTRO_CONFIG_DEFAULTS.markdown.gfm),
smartypants: z.boolean().default(ASTRO_CONFIG_DEFAULTS.markdown.smartypants)
}).default({}),
vite: z.custom((data) => data instanceof Object && !Array.isArray(data)).default(ASTRO_CONFIG_DEFAULTS.vite),
i18n: z.optional(
z.object({
defaultLocale: z.string(),
locales: z.array(
z.union([
z.string(),
z.object({
path: z.string(),
codes: z.string().array().nonempty()
})
])
),
domains: z.record(
z.string(),
z.string().url(
"The domain value must be a valid URL, and it has to start with 'https' or 'http'."
)
).optional(),
fallback: z.record(z.string(), z.string()).optional(),
routing: z.literal("manual").or(
z.object({
prefixDefaultLocale: z.boolean().optional().default(false),
redirectToDefaultLocale: z.boolean().optional().default(true),
fallbackType: z.enum(["redirect", "rewrite"]).optional().default("redirect")
}).refine(
({ prefixDefaultLocale, redirectToDefaultLocale }) => {
return !(prefixDefaultLocale === false && redirectToDefaultLocale === false);
},
{
message: "The option `i18n.redirectToDefaultLocale` is only useful when the `i18n.prefixDefaultLocale` is set to `true`. Remove the option `i18n.redirectToDefaultLocale`, or change its value to `true`."
}
)
).optional().default({})
}).optional().superRefine((i18n, ctx) => {
if (i18n) {
const { defaultLocale, locales: _locales, fallback, domains } = i18n;
const locales = _locales.map((locale) => {
if (typeof locale === "string") {
return locale;
} else {
return locale.path;
}
});
if (!locales.includes(defaultLocale)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The default locale \`${defaultLocale}\` is not present in the \`i18n.locales\` array.`
});
}
if (fallback) {
for (const [fallbackFrom, fallbackTo] of Object.entries(fallback)) {
if (!locales.includes(fallbackFrom)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The locale \`${fallbackFrom}\` key in the \`i18n.fallback\` record doesn't exist in the \`i18n.locales\` array.`
});
}
if (fallbackFrom === defaultLocale) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `You can't use the default locale as a key. The default locale can only be used as value.`
});
}
if (!locales.includes(fallbackTo)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The locale \`${fallbackTo}\` value in the \`i18n.fallback\` record doesn't exist in the \`i18n.locales\` array.`
});
}
}
}
if (domains) {
const entries = Object.entries(domains);
const hasDomains = domains ? Object.keys(domains).length > 0 : false;
if (entries.length > 0 && !hasDomains) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `When specifying some domains, the property \`i18n.routingStrategy\` must be set to \`"domains"\`.`
});
}
for (const [domainKey, domainValue] of entries) {
if (!locales.includes(domainKey)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The locale \`${domainKey}\` key in the \`i18n.domains\` record doesn't exist in the \`i18n.locales\` array.`
});
}
if (!domainValue.startsWith("https") && !domainValue.startsWith("http")) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "The domain value must be a valid URL, and it has to start with 'https' or 'http'.",
path: ["domains"]
});
} else {
try {
const domainUrl = new URL(domainValue);
if (domainUrl.pathname !== "/") {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The URL \`${domainValue}\` must contain only the origin. A subsequent pathname isn't allowed here. Remove \`${domainUrl.pathname}\`.`,
path: ["domains"]
});
}
} catch {
}
}
}
}
}
})
),
security: z.object({
checkOrigin: z.boolean().default(false)
}).optional().default(ASTRO_CONFIG_DEFAULTS.security),
experimental: z.object({
directRenderScript: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.directRenderScript),
contentCollectionCache: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.contentCollectionCache),
clientPrerender: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.clientPrerender),
globalRoutePriority: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.globalRoutePriority),
env: z.object({
schema: EnvSchema.optional(),
validateSecrets: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.env.validateSecrets)
}).strict().optional(),
serverIslands: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.serverIslands),
contentIntellisense: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.contentIntellisense),
contentLayer: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.contentLayer)
}).strict(
`Invalid or outdated experimental feature.
Check for incorrect spelling or outdated Astro version.
See https://docs.astro.build/en/reference/configuration-reference/#experimental-flags for a list of all current experiments.`
).default({}),
legacy: z.object({}).default({})
});
function createRelativeSchema(cmd, fileProtocolRoot) {
const AstroConfigRelativeSchema = AstroConfigSchema.extend({
root: z.string().default(ASTRO_CONFIG_DEFAULTS.root).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
srcDir: z.string().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
compressHTML: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compressHTML),
publicDir: z.string().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
outDir: z.string().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
cacheDir: z.string().default(ASTRO_CONFIG_DEFAULTS.cacheDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
build: z.object({
format: z.union([z.literal("file"), z.literal("directory"), z.literal("preserve")]).optional().default(ASTRO_CONFIG_DEFAULTS.build.format),
client: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.client).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
server: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.server).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
assets: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.assets),
assetsPrefix: z.string().optional().or(z.object({ fallback: z.string() }).and(z.record(z.string())).optional()).refine(
(value) => {
if (value && typeof value !== "string") {
if (!value.fallback) {
return false;
}
}
return true;
},
{
message: "The `fallback` is mandatory when defining the option as an object."
}
),
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry),
redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.redirects),
inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets),
concurrency: z.number().min(1).optional().default(ASTRO_CONFIG_DEFAULTS.build.concurrency)
}).optional().default({}),
server: z.preprocess(
// preprocess
(val) => {
if (typeof val === "function") {
return val({ command: cmd === "dev" ? "dev" : "preview" });
} else {
return val;
}
},
// validate
z.object({
open: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.open),
host: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.host),
port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port),
headers: z.custom().optional(),
streaming: z.boolean().optional().default(true)
}).optional().default({})
)
}).transform((config) => {
if (!config.build.server.toString().startsWith(config.outDir.toString()) && config.build.server.toString().endsWith("dist/server/")) {
config.build.server = new URL("./dist/server/", config.outDir);
}
if (!config.build.client.toString().startsWith(config.outDir.toString()) && config.build.client.toString().endsWith("dist/client/")) {
config.build.client = new URL("./dist/client/", config.outDir);
}
if (config.trailingSlash === "never") {
config.base = prependForwardSlash(removeTrailingForwardSlash(config.base));
} else if (config.trailingSlash === "always") {
config.base = prependForwardSlash(appendForwardSlash(config.base));
} else {
config.base = prependForwardSlash(config.base);
}
return config;
}).refine((obj) => !obj.outDir.toString().startsWith(obj.publicDir.toString()), {
message: "The value of `outDir` must not point to a path within the folder set as `publicDir`, this will cause an infinite loop"
}).superRefine((configuration, ctx) => {
const { site, i18n, output } = configuration;
const hasDomains = i18n?.domains ? Object.keys(i18n.domains).length > 0 : false;
if (hasDomains) {
if (!site) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "The option `site` isn't set. When using the 'domains' strategy for `i18n`, `site` is required to create absolute URLs for locales that aren't mapped to a domain."
});
}
if (output !== "server") {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Domain support is only available when `output` is `"server"`.'
});
}
}
});
return AstroConfigRelativeSchema;
}
function resolveDirAsUrl(dir, root) {
let resolvedDir = path.resolve(root, dir);
if (!resolvedDir.endsWith(path.sep)) {
resolvedDir += path.sep;
}
return pathToFileURL(resolvedDir);
}
export {
ASTRO_CONFIG_DEFAULTS,
AstroConfigSchema,
createRelativeSchema
};

1625
node_modules/astro/dist/core/config/schemas/base.d.ts generated vendored Normal file

File diff suppressed because it is too large Load Diff

301
node_modules/astro/dist/core/config/schemas/base.js generated vendored Normal file
View File

@@ -0,0 +1,301 @@
import { markdownConfigDefaults, syntaxHighlightDefaults } from "@astrojs/markdown-remark";
import { bundledThemes } from "shiki";
import { z } from "zod";
import { localFontFamilySchema, remoteFontFamilySchema } from "../../../assets/fonts/config.js";
import { EnvSchema } from "../../../env/schema.js";
import { allowedDirectivesSchema, cspAlgorithmSchema, cspHashSchema } from "../../csp/config.js";
const ASTRO_CONFIG_DEFAULTS = {
root: ".",
srcDir: "./src",
publicDir: "./public",
outDir: "./dist",
cacheDir: "./node_modules/.astro",
base: "/",
trailingSlash: "ignore",
build: {
format: "directory",
client: "./client/",
server: "./server/",
assets: "_astro",
serverEntry: "entry.mjs",
redirects: true,
inlineStylesheets: "auto",
concurrency: 1
},
image: {
endpoint: { entrypoint: void 0, route: "/_image" },
service: { entrypoint: "astro/assets/services/sharp", config: {} },
responsiveStyles: false
},
devToolbar: {
enabled: true
},
compressHTML: true,
server: {
host: false,
port: 4321,
open: false,
allowedHosts: []
},
integrations: [],
markdown: markdownConfigDefaults,
vite: {},
legacy: {
collections: false
},
redirects: {},
security: {
checkOrigin: true
},
env: {
schema: {},
validateSecrets: false
},
session: void 0,
experimental: {
clientPrerender: false,
contentIntellisense: false,
headingIdCompat: false,
preserveScriptOrder: false,
liveContentCollections: false,
csp: false,
rawEnvValues: false
}
};
const highlighterTypesSchema = z.union([z.literal("shiki"), z.literal("prism")]).default(syntaxHighlightDefaults.type);
const AstroConfigSchema = z.object({
root: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.root).transform((val) => new URL(val)),
srcDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => new URL(val)),
publicDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => new URL(val)),
outDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => new URL(val)),
cacheDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.cacheDir).transform((val) => new URL(val)),
site: z.string().url().optional(),
compressHTML: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compressHTML),
base: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.base),
trailingSlash: z.union([z.literal("always"), z.literal("never"), z.literal("ignore")]).optional().default(ASTRO_CONFIG_DEFAULTS.trailingSlash),
output: z.union([z.literal("static"), z.literal("server")]).optional().default("static"),
scopedStyleStrategy: z.union([z.literal("where"), z.literal("class"), z.literal("attribute")]).optional().default("attribute"),
adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(),
integrations: z.preprocess(
// preprocess
(val) => Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val,
// validate
z.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) })).default(ASTRO_CONFIG_DEFAULTS.integrations)
),
build: z.object({
format: z.union([z.literal("file"), z.literal("directory"), z.literal("preserve")]).optional().default(ASTRO_CONFIG_DEFAULTS.build.format),
client: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.client).transform((val) => new URL(val)),
server: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.server).transform((val) => new URL(val)),
assets: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.assets),
assetsPrefix: z.string().optional().or(z.object({ fallback: z.string() }).and(z.record(z.string())).optional()),
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry),
redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.redirects),
inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets),
concurrency: z.number().min(1).optional().default(ASTRO_CONFIG_DEFAULTS.build.concurrency)
}).default({}),
server: z.preprocess(
// preprocess
// NOTE: Uses the "error" command here because this is overwritten by the
// individualized schema parser with the correct command.
(val) => typeof val === "function" ? val({ command: "error" }) : val,
// validate
z.object({
open: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.open),
host: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.host),
port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port),
headers: z.custom().optional(),
allowedHosts: z.union([z.array(z.string()), z.literal(true)]).optional().default(ASTRO_CONFIG_DEFAULTS.server.allowedHosts)
}).default({})
),
redirects: z.record(
z.string(),
z.union([
z.string(),
z.object({
status: z.union([
z.literal(300),
z.literal(301),
z.literal(302),
z.literal(303),
z.literal(304),
z.literal(307),
z.literal(308)
]),
destination: z.string()
})
])
).default(ASTRO_CONFIG_DEFAULTS.redirects),
prefetch: z.union([
z.boolean(),
z.object({
prefetchAll: z.boolean().optional(),
defaultStrategy: z.enum(["tap", "hover", "viewport", "load"]).optional()
})
]).optional(),
image: z.object({
endpoint: z.object({
route: z.literal("/_image").or(z.string()).default(ASTRO_CONFIG_DEFAULTS.image.endpoint.route),
entrypoint: z.string().optional()
}).default(ASTRO_CONFIG_DEFAULTS.image.endpoint),
service: z.object({
entrypoint: z.union([z.literal("astro/assets/services/sharp"), z.string()]).default(ASTRO_CONFIG_DEFAULTS.image.service.entrypoint),
config: z.record(z.any()).default({})
}).default(ASTRO_CONFIG_DEFAULTS.image.service),
domains: z.array(z.string()).default([]),
remotePatterns: z.array(
z.object({
protocol: z.string().optional(),
hostname: z.string().optional(),
port: z.string().optional(),
pathname: z.string().optional()
})
).default([]),
layout: z.enum(["constrained", "fixed", "full-width", "none"]).optional(),
objectFit: z.string().optional(),
objectPosition: z.string().optional(),
breakpoints: z.array(z.number()).optional(),
responsiveStyles: z.boolean().default(ASTRO_CONFIG_DEFAULTS.image.responsiveStyles)
}).default(ASTRO_CONFIG_DEFAULTS.image),
devToolbar: z.object({
enabled: z.boolean().default(ASTRO_CONFIG_DEFAULTS.devToolbar.enabled)
}).default(ASTRO_CONFIG_DEFAULTS.devToolbar),
markdown: z.object({
syntaxHighlight: z.union([
z.object({
type: highlighterTypesSchema,
excludeLangs: z.array(z.string()).optional().default(syntaxHighlightDefaults.excludeLangs)
}).default(syntaxHighlightDefaults),
highlighterTypesSchema,
z.literal(false)
]).default(ASTRO_CONFIG_DEFAULTS.markdown.syntaxHighlight),
shikiConfig: z.object({
langs: z.custom().array().transform((langs) => {
for (const lang of langs) {
if (typeof lang === "object") {
if (lang.id) {
lang.name = lang.id;
}
if (lang.grammar) {
Object.assign(lang, lang.grammar);
}
}
}
return langs;
}).default([]),
langAlias: z.record(z.string(), z.string()).optional().default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.langAlias),
theme: z.enum(Object.keys(bundledThemes)).or(z.custom()).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.theme),
themes: z.record(
z.enum(Object.keys(bundledThemes)).or(z.custom())
).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.themes),
defaultColor: z.union([z.literal("light"), z.literal("dark"), z.string(), z.literal(false)]).optional(),
wrap: z.boolean().or(z.null()).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.wrap),
transformers: z.custom().array().default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.transformers)
}).default({}),
remarkPlugins: z.union([
z.string(),
z.tuple([z.string(), z.any()]),
z.custom((data) => typeof data === "function"),
z.tuple([z.custom((data) => typeof data === "function"), z.any()])
]).array().default(ASTRO_CONFIG_DEFAULTS.markdown.remarkPlugins),
rehypePlugins: z.union([
z.string(),
z.tuple([z.string(), z.any()]),
z.custom((data) => typeof data === "function"),
z.tuple([z.custom((data) => typeof data === "function"), z.any()])
]).array().default(ASTRO_CONFIG_DEFAULTS.markdown.rehypePlugins),
remarkRehype: z.custom((data) => data instanceof Object && !Array.isArray(data)).default(ASTRO_CONFIG_DEFAULTS.markdown.remarkRehype),
gfm: z.boolean().default(ASTRO_CONFIG_DEFAULTS.markdown.gfm),
smartypants: z.boolean().default(ASTRO_CONFIG_DEFAULTS.markdown.smartypants)
}).default({}),
vite: z.custom((data) => data instanceof Object && !Array.isArray(data)).default(ASTRO_CONFIG_DEFAULTS.vite),
i18n: z.optional(
z.object({
defaultLocale: z.string(),
locales: z.array(
z.union([
z.string(),
z.object({
path: z.string(),
codes: z.string().array().nonempty()
})
])
),
domains: z.record(
z.string(),
z.string().url(
"The domain value must be a valid URL, and it has to start with 'https' or 'http'."
)
).optional(),
fallback: z.record(z.string(), z.string()).optional(),
routing: z.literal("manual").or(
z.object({
prefixDefaultLocale: z.boolean().optional().default(false),
// TODO: Astro 6.0 change to false
redirectToDefaultLocale: z.boolean().optional().default(true),
fallbackType: z.enum(["redirect", "rewrite"]).optional().default("redirect")
})
).optional().default({})
}).optional()
),
security: z.object({
checkOrigin: z.boolean().default(ASTRO_CONFIG_DEFAULTS.security.checkOrigin)
}).optional().default(ASTRO_CONFIG_DEFAULTS.security),
env: z.object({
schema: EnvSchema.optional().default(ASTRO_CONFIG_DEFAULTS.env.schema),
validateSecrets: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.env.validateSecrets)
}).strict().optional().default(ASTRO_CONFIG_DEFAULTS.env),
session: z.object({
driver: z.string().optional(),
options: z.record(z.any()).optional(),
cookie: z.object({
name: z.string().optional(),
domain: z.string().optional(),
path: z.string().optional(),
maxAge: z.number().optional(),
sameSite: z.union([z.enum(["strict", "lax", "none"]), z.boolean()]).optional(),
secure: z.boolean().optional()
}).or(z.string()).transform((val) => {
if (typeof val === "string") {
return { name: val };
}
return val;
}).optional(),
ttl: z.number().optional()
}).optional(),
experimental: z.object({
clientPrerender: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.clientPrerender),
contentIntellisense: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.contentIntellisense),
headingIdCompat: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.headingIdCompat),
preserveScriptOrder: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.preserveScriptOrder),
fonts: z.array(z.union([localFontFamilySchema, remoteFontFamilySchema])).optional(),
liveContentCollections: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.liveContentCollections),
csp: z.union([
z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.csp),
z.object({
algorithm: cspAlgorithmSchema,
directives: z.array(allowedDirectivesSchema).optional(),
styleDirective: z.object({
resources: z.array(z.string()).optional(),
hashes: z.array(cspHashSchema).optional()
}).optional(),
scriptDirective: z.object({
resources: z.array(z.string()).optional(),
hashes: z.array(cspHashSchema).optional(),
strictDynamic: z.boolean().optional()
}).optional()
})
]).optional().default(ASTRO_CONFIG_DEFAULTS.experimental.csp),
rawEnvValues: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.rawEnvValues)
}).strict(
`Invalid or outdated experimental feature.
Check for incorrect spelling or outdated Astro version.
See https://docs.astro.build/en/reference/experimental-flags/ for a list of all current experiments.`
).default({}),
legacy: z.object({
collections: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.legacy.collections)
}).default({})
});
export {
ASTRO_CONFIG_DEFAULTS,
AstroConfigSchema
};

View File

@@ -0,0 +1,3 @@
export { ASTRO_CONFIG_DEFAULTS, AstroConfigSchema, type AstroConfigType, } from './base.js';
export { AstroConfigRefinedSchema } from './refined.js';
export { createRelativeSchema } from './relative.js';

12
node_modules/astro/dist/core/config/schemas/index.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import {
ASTRO_CONFIG_DEFAULTS,
AstroConfigSchema
} from "./base.js";
import { AstroConfigRefinedSchema } from "./refined.js";
import { createRelativeSchema } from "./relative.js";
export {
ASTRO_CONFIG_DEFAULTS,
AstroConfigRefinedSchema,
AstroConfigSchema,
createRelativeSchema
};

View File

@@ -0,0 +1,3 @@
import { z } from 'zod';
import type { AstroConfig } from '../../../types/public/config.js';
export declare const AstroConfigRefinedSchema: z.ZodEffects<z.ZodType<AstroConfig, z.ZodTypeDef, AstroConfig>, AstroConfig, AstroConfig>;

146
node_modules/astro/dist/core/config/schemas/refined.js generated vendored Normal file
View File

@@ -0,0 +1,146 @@
import { z } from "zod";
const AstroConfigRefinedSchema = z.custom().superRefine((config, ctx) => {
if (config.build.assetsPrefix && typeof config.build.assetsPrefix !== "string" && !config.build.assetsPrefix.fallback) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "The `fallback` is mandatory when defining the option as an object.",
path: ["build", "assetsPrefix"]
});
}
for (let i = 0; i < config.image.remotePatterns.length; i++) {
const { hostname, pathname } = config.image.remotePatterns[i];
if (hostname && hostname.includes("*") && !(hostname.startsWith("*.") || hostname.startsWith("**."))) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "wildcards can only be placed at the beginning of the hostname",
path: ["image", "remotePatterns", i, "hostname"]
});
}
if (pathname && pathname.includes("*") && !(pathname.endsWith("/*") || pathname.endsWith("/**"))) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "wildcards can only be placed at the end of a pathname",
path: ["image", "remotePatterns", i, "pathname"]
});
}
}
if (config.outDir.toString().startsWith(config.publicDir.toString())) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "The value of `outDir` must not point to a path within the folder set as `publicDir`, this will cause an infinite loop",
path: ["outDir"]
});
}
if (config.i18n) {
const { defaultLocale, locales: _locales, fallback, domains } = config.i18n;
const locales = _locales.map((locale) => {
if (typeof locale === "string") {
return locale;
} else {
return locale.path;
}
});
if (!locales.includes(defaultLocale)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The default locale \`${defaultLocale}\` is not present in the \`i18n.locales\` array.`,
path: ["i18n", "locales"]
});
}
if (fallback) {
for (const [fallbackFrom, fallbackTo] of Object.entries(fallback)) {
if (!locales.includes(fallbackFrom)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The locale \`${fallbackFrom}\` key in the \`i18n.fallback\` record doesn't exist in the \`i18n.locales\` array.`,
path: ["i18n", "fallbacks"]
});
}
if (fallbackFrom === defaultLocale) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `You can't use the default locale as a key. The default locale can only be used as value.`,
path: ["i18n", "fallbacks"]
});
}
if (!locales.includes(fallbackTo)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The locale \`${fallbackTo}\` value in the \`i18n.fallback\` record doesn't exist in the \`i18n.locales\` array.`,
path: ["i18n", "fallbacks"]
});
}
}
}
if (domains) {
const entries = Object.entries(domains);
const hasDomains = domains ? Object.keys(domains).length > 0 : false;
if (entries.length > 0 && !hasDomains) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `When specifying some domains, the property \`i18n.routing.strategy\` must be set to \`"domains"\`.`,
path: ["i18n", "routing", "strategy"]
});
}
if (hasDomains) {
if (!config.site) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "The option `site` isn't set. When using the 'domains' strategy for `i18n`, `site` is required to create absolute URLs for locales that aren't mapped to a domain.",
path: ["site"]
});
}
if (config.output !== "server") {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Domain support is only available when `output` is `"server"`.',
path: ["output"]
});
}
}
for (const [domainKey, domainValue] of entries) {
if (!locales.includes(domainKey)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The locale \`${domainKey}\` key in the \`i18n.domains\` record doesn't exist in the \`i18n.locales\` array.`,
path: ["i18n", "domains"]
});
}
if (!domainValue.startsWith("https") && !domainValue.startsWith("http")) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "The domain value must be a valid URL, and it has to start with 'https' or 'http'.",
path: ["i18n", "domains"]
});
} else {
try {
const domainUrl = new URL(domainValue);
if (domainUrl.pathname !== "/") {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `The URL \`${domainValue}\` must contain only the origin. A subsequent pathname isn't allowed here. Remove \`${domainUrl.pathname}\`.`,
path: ["i18n", "domains"]
});
}
} catch {
}
}
}
}
}
if (config.experimental.fonts && config.experimental.fonts.length > 0) {
for (let i = 0; i < config.experimental.fonts.length; i++) {
const { cssVariable } = config.experimental.fonts[i];
if (!cssVariable.startsWith("--") || cssVariable.includes(" ") || cssVariable.includes(":")) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `**cssVariable** property "${cssVariable}" contains invalid characters for CSS variable generation. It must start with -- and be a valid indent: https://developer.mozilla.org/en-US/docs/Web/CSS/ident.`,
path: ["fonts", i, "cssVariable"]
});
}
}
}
});
export {
AstroConfigRefinedSchema
};

2109
node_modules/astro/dist/core/config/schemas/relative.d.ts generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,92 @@
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { z } from "zod";
import { appendForwardSlash, prependForwardSlash, removeTrailingForwardSlash } from "../../path.js";
import { ASTRO_CONFIG_DEFAULTS, AstroConfigSchema } from "./base.js";
function resolveDirAsUrl(dir, root) {
let resolvedDir = path.resolve(root, dir);
if (!resolvedDir.endsWith(path.sep)) {
resolvedDir += path.sep;
}
return pathToFileURL(resolvedDir);
}
function createRelativeSchema(cmd, fileProtocolRoot) {
let originalBuildClient;
let originalBuildServer;
const AstroConfigRelativeSchema = AstroConfigSchema.extend({
root: z.string().default(ASTRO_CONFIG_DEFAULTS.root).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
srcDir: z.string().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
compressHTML: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compressHTML),
publicDir: z.string().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
outDir: z.string().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
cacheDir: z.string().default(ASTRO_CONFIG_DEFAULTS.cacheDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
build: z.object({
format: z.union([z.literal("file"), z.literal("directory"), z.literal("preserve")]).optional().default(ASTRO_CONFIG_DEFAULTS.build.format),
// NOTE: `client` and `server` are transformed relative to the default outDir first,
// later we'll fix this to be relative to the actual `outDir`
client: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.client).transform((val) => {
originalBuildClient = val;
return resolveDirAsUrl(
val,
path.resolve(fileProtocolRoot, ASTRO_CONFIG_DEFAULTS.outDir)
);
}),
server: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.server).transform((val) => {
originalBuildServer = val;
return resolveDirAsUrl(
val,
path.resolve(fileProtocolRoot, ASTRO_CONFIG_DEFAULTS.outDir)
);
}),
assets: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.assets),
assetsPrefix: z.string().optional().or(z.object({ fallback: z.string() }).and(z.record(z.string())).optional()),
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry),
redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.redirects),
inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets),
concurrency: z.number().min(1).optional().default(ASTRO_CONFIG_DEFAULTS.build.concurrency)
}).optional().default({}),
server: z.preprocess(
// preprocess
(val) => {
if (typeof val === "function") {
return val({ command: cmd === "dev" ? "dev" : "preview" });
}
return val;
},
// validate
z.object({
open: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.open),
host: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.host),
port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port),
headers: z.custom().optional(),
streaming: z.boolean().optional().default(true),
allowedHosts: z.union([z.array(z.string()), z.literal(true)]).optional().default(ASTRO_CONFIG_DEFAULTS.server.allowedHosts)
}).optional().default({})
)
}).transform((config) => {
if (config.outDir.toString() !== resolveDirAsUrl(ASTRO_CONFIG_DEFAULTS.outDir, fileProtocolRoot).toString()) {
const outDirPath = fileURLToPath(config.outDir);
config.build.client = resolveDirAsUrl(originalBuildClient, outDirPath);
config.build.server = resolveDirAsUrl(originalBuildServer, outDirPath);
}
if (config.trailingSlash === "never") {
config.base = prependForwardSlash(removeTrailingForwardSlash(config.base));
config.image.endpoint.route = prependForwardSlash(
removeTrailingForwardSlash(config.image.endpoint.route)
);
} else if (config.trailingSlash === "always") {
config.base = prependForwardSlash(appendForwardSlash(config.base));
config.image.endpoint.route = prependForwardSlash(
appendForwardSlash(config.image.endpoint.route)
);
} else {
config.base = prependForwardSlash(config.base);
config.image.endpoint.route = prependForwardSlash(config.image.endpoint.route);
}
return config;
});
return AstroConfigRelativeSchema;
}
export {
createRelativeSchema
};

View File

@@ -1,3 +1,4 @@
import type { AstroConfig, AstroSettings } from '../../@types/astro.js';
import type { AstroSettings } from '../../types/astro.js';
import type { AstroConfig } from '../../types/public/config.js';
export declare function createBaseSettings(config: AstroConfig): AstroSettings;
export declare function createSettings(config: AstroConfig, cwd?: string): Promise<AstroSettings>;

View File

@@ -1,13 +1,19 @@
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import yaml from "js-yaml";
import toml from "smol-toml";
import { getContentPaths } from "../../content/index.js";
import createPreferences from "../../preferences/index.js";
import { markdownContentEntryType } from "../../vite-plugin-markdown/content-entry-type.js";
import { getDefaultClientDirectives } from "../client-directive/index.js";
import { AstroError, AstroErrorData } from "../errors/index.js";
import { formatYAMLException, isYAMLException } from "../errors/utils.js";
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./../constants.js";
import { AstroError, AstroErrorData } from "../errors/index.js";
import {
formatTOMLError,
formatYAMLException,
isTOMLError,
isYAMLException
} from "../errors/utils.js";
import { AstroTimer } from "./timer.js";
import { loadTSConfig } from "./tsconfig.js";
function createBaseSettings(config) {
@@ -86,6 +92,31 @@ function createBaseSettings(config) {
});
}
}
},
{
extensions: [".toml"],
getEntryInfo({ contents, fileUrl }) {
try {
const data = toml.parse(contents);
const rawData = contents;
return { data, rawData };
} catch (e) {
const pathRelToContentDir = path.relative(
fileURLToPath(contentDir),
fileURLToPath(fileUrl)
);
const formattedError = isTOMLError(e) ? formatTOMLError(e) : new Error("contains invalid TOML.");
throw new AstroError({
...AstroErrorData.DataCollectionEntryParseError,
message: AstroErrorData.DataCollectionEntryParseError.message(
pathRelToContentDir,
formattedError.message
),
stack: formattedError.stack,
location: "loc" in formattedError ? { file: fileUrl.pathname, ...formattedError.loc } : { file: fileUrl.pathname }
});
}
}
}
],
renderers: [],
@@ -98,7 +129,8 @@ function createBaseSettings(config) {
dotAstroDir,
latestAstroVersion: void 0,
// Will be set later if applicable when the dev server starts
injectedTypes: []
injectedTypes: [],
buildOutput: void 0
};
}
async function createSettings(config, cwd) {

View File

@@ -1,8 +1,3 @@
export interface Stat {
elapsedTime: number;
heapUsedChange: number;
heapUsedTotal: number;
}
/**
* Timer to track certain operations' performance. Used by Astro's scripts only.
* Set `process.env.ASTRO_TIMER_PATH` truthy to enable.

View File

@@ -13,7 +13,7 @@ export declare function loadTSConfig(root: string | undefined, findUp?: boolean)
rawConfig: TSConfig;
}>>;
export declare function updateTSConfigForFramework(target: TSConfig, framework: frameworkWithTSSettings): TSConfig;
export type StripEnums<T extends Record<string, any>> = {
type StripEnums<T extends Record<string, any>> = {
[K in keyof T]: T[K] extends boolean ? T[K] : T[K] extends string ? T[K] : T[K] extends object ? T[K] : T[K] extends Array<any> ? T[K] : T[K] extends undefined ? undefined : any;
};
export interface TSConfig {

View File

@@ -1,9 +1,9 @@
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import {
TSConfckParseError,
find,
parse,
TSConfckParseError,
toJson
} from "tsconfck";
const defaultTSConfig = { extends: "astro/tsconfigs/base" };

View File

@@ -1,3 +1,9 @@
import type { AstroConfig } from '../../@types/astro.js';
import type { AstroConfig } from '../../types/public/config.js';
/** Turn raw config values into normalized values */
export declare function validateConfig(userConfig: any, root: string, cmd: string): Promise<AstroConfig>;
/**
* Used twice:
* - To validate the user config
* - To validate the config after all integrations (that may have updated it)
*/
export declare function validateConfigRefined(updatedConfig: AstroConfig): Promise<AstroConfig>;

View File

@@ -1,8 +1,15 @@
import { createRelativeSchema } from "./schema.js";
import { errorMap } from "../errors/index.js";
import { AstroConfigRefinedSchema, createRelativeSchema } from "./schemas/index.js";
async function validateConfig(userConfig, root, cmd) {
const AstroConfigRelativeSchema = createRelativeSchema(cmd, root);
return await AstroConfigRelativeSchema.parseAsync(userConfig);
return await validateConfigRefined(
await AstroConfigRelativeSchema.parseAsync(userConfig, { errorMap })
);
}
async function validateConfigRefined(updatedConfig) {
return await AstroConfigRefinedSchema.parseAsync(updatedConfig, { errorMap });
}
export {
validateConfig
validateConfig,
validateConfigRefined
};

View File

@@ -9,20 +9,7 @@ async function createViteServer(root, fs) {
optimizeDeps: { noDiscovery: true },
clearScreen: false,
appType: "custom",
ssr: {
// NOTE: Vite doesn't externalize linked packages by default. During testing locally,
// these dependencies trip up Vite's dev SSR transform. Awaiting upstream feature:
// https://github.com/vitejs/vite/pull/10939
external: [
"@astrojs/tailwind",
"@astrojs/mdx",
"@astrojs/react",
"@astrojs/preact",
"@astrojs/sitemap",
"@astrojs/markdoc",
"@astrojs/db"
]
},
ssr: { external: true },
plugins: [loadFallbackPlugin({ fs, root: pathToFileURL(root) })]
});
return viteServer;
@@ -37,6 +24,9 @@ async function loadConfigWithVite({
const config = await import(pathToFileURL(configPath).toString() + "?t=" + Date.now());
return config.default ?? {};
} catch (e) {
if (e && typeof e === "object" && "code" in e && e.code === "ERR_DLOPEN_DISABLED") {
throw e;
}
debug("Failed to load config with Node", e);
}
}