astro 1.2.5 → 1.2.7
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 +14 -13
- package/dist/cli/check/index.d.ts +2 -2
- package/dist/cli/check/index.js +2 -2
- package/dist/cli/index.js +28 -9
- package/dist/core/add/index.js +1 -1
- package/dist/core/build/generate.d.ts +3 -3
- package/dist/core/build/generate.js +27 -27
- package/dist/core/build/index.d.ts +2 -2
- package/dist/core/build/index.js +23 -19
- package/dist/core/build/internal.js +5 -2
- package/dist/core/build/page-data.d.ts +2 -2
- package/dist/core/build/page-data.js +2 -2
- package/dist/core/build/static-build.js +26 -28
- package/dist/core/build/types.d.ts +2 -2
- package/dist/core/build/vite-plugin-css.d.ts +0 -2
- package/dist/core/build/vite-plugin-css.js +3 -3
- package/dist/core/build/vite-plugin-hoisted-scripts.d.ts +2 -2
- package/dist/core/build/vite-plugin-hoisted-scripts.js +3 -3
- package/dist/core/build/vite-plugin-pages.js +2 -2
- package/dist/core/build/vite-plugin-ssr.js +15 -11
- package/dist/core/config/config.d.ts +41 -0
- package/dist/core/{config.js → config/config.js} +5 -166
- package/dist/core/config/index.d.ts +4 -0
- package/dist/core/config/index.js +18 -0
- package/dist/core/config/schema.d.ts +478 -0
- package/dist/core/config/schema.js +148 -0
- package/dist/core/config/settings.d.ts +8 -0
- package/dist/core/config/settings.js +16 -0
- package/dist/core/config/tsconfig.d.ts +2 -0
- package/dist/core/config/tsconfig.js +13 -0
- package/dist/core/create-vite.d.ts +3 -3
- package/dist/core/create-vite.js +21 -21
- package/dist/core/dev/index.d.ts +2 -2
- package/dist/core/dev/index.js +16 -12
- package/dist/core/endpoint/dev/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/preview/index.d.ts +2 -2
- package/dist/core/preview/index.js +9 -9
- package/dist/core/render/dev/index.d.ts +5 -5
- package/dist/core/render/dev/index.js +14 -14
- package/dist/core/render/dev/scripts.d.ts +2 -2
- package/dist/core/render/dev/scripts.js +4 -7
- package/dist/core/routing/manifest/create.d.ts +3 -3
- package/dist/core/routing/manifest/create.js +9 -12
- package/dist/core/util.d.ts +3 -3
- package/dist/core/util.js +9 -9
- package/dist/integrations/index.d.ts +6 -6
- package/dist/integrations/index.js +19 -17
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/vite-plugin-astro/index.d.ts +3 -3
- package/dist/vite-plugin-astro/index.js +2 -1
- package/dist/vite-plugin-astro-postprocess/index.d.ts +3 -3
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/index.d.ts +4 -4
- package/dist/vite-plugin-astro-server/index.js +27 -24
- package/dist/vite-plugin-config-alias/index.d.ts +3 -3
- package/dist/vite-plugin-config-alias/index.js +6 -5
- package/dist/vite-plugin-env/index.d.ts +3 -3
- package/dist/vite-plugin-env/index.js +2 -3
- package/dist/vite-plugin-integrations-container/index.d.ts +3 -3
- package/dist/vite-plugin-integrations-container/index.js +2 -2
- package/dist/vite-plugin-jsx/index.d.ts +3 -3
- package/dist/vite-plugin-jsx/index.js +3 -3
- package/dist/vite-plugin-markdown/index.d.ts +3 -3
- package/dist/vite-plugin-markdown/index.js +3 -3
- package/dist/vite-plugin-markdown-legacy/index.d.ts +3 -3
- package/dist/vite-plugin-markdown-legacy/index.js +2 -1
- package/dist/vite-plugin-scripts/index.d.ts +3 -3
- package/dist/vite-plugin-scripts/index.js +5 -5
- package/dist/vite-plugin-scripts/page-ssr.d.ts +3 -3
- package/dist/vite-plugin-scripts/page-ssr.js +7 -5
- package/package.json +2 -2
- package/dist/core/config.d.ts +0 -260
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AstroConfig } from '../../@types/astro';
|
|
2
1
|
import type { BuildInternals } from './internal';
|
|
3
2
|
import type { StaticBuildOptions } from './types';
|
|
4
3
|
import { Plugin as VitePlugin } from 'vite';
|
|
@@ -6,7 +5,6 @@ interface PluginOptions {
|
|
|
6
5
|
internals: BuildInternals;
|
|
7
6
|
buildOptions: StaticBuildOptions;
|
|
8
7
|
target: 'client' | 'server';
|
|
9
|
-
astroConfig: AstroConfig;
|
|
10
8
|
}
|
|
11
9
|
export declare function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[];
|
|
12
10
|
export {};
|
|
@@ -14,10 +14,10 @@ import {
|
|
|
14
14
|
const MAX_NAME_LENGTH = 70;
|
|
15
15
|
function rollupPluginAstroBuildCSS(options) {
|
|
16
16
|
const { internals, buildOptions } = options;
|
|
17
|
-
const {
|
|
17
|
+
const { settings } = buildOptions;
|
|
18
18
|
let resolvedConfig;
|
|
19
19
|
function nameifyPage(id) {
|
|
20
|
-
let rel = relativeToSrcDir(
|
|
20
|
+
let rel = relativeToSrcDir(settings.config, id);
|
|
21
21
|
if (rel.startsWith("pages/")) {
|
|
22
22
|
rel = rel.slice(6);
|
|
23
23
|
}
|
|
@@ -163,7 +163,7 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
163
163
|
for (const [, output] of Object.entries(bundle)) {
|
|
164
164
|
if (output.type === "asset") {
|
|
165
165
|
if (((_a = output.name) == null ? void 0 : _a.endsWith(".css")) && typeof output.source === "string") {
|
|
166
|
-
const cssTarget = (_b =
|
|
166
|
+
const cssTarget = (_b = settings.config.vite.build) == null ? void 0 : _b.cssTarget;
|
|
167
167
|
const { code: minifiedCSS } = await esbuild.transform(output.source, {
|
|
168
168
|
loader: "css",
|
|
169
169
|
minify: true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Plugin as VitePlugin } from 'vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AstroSettings } from '../../@types/astro';
|
|
3
3
|
import type { BuildInternals } from '../../core/build/internal.js';
|
|
4
|
-
export declare function vitePluginHoistedScripts(
|
|
4
|
+
export declare function vitePluginHoistedScripts(settings: AstroSettings, internals: BuildInternals): VitePlugin;
|
|
@@ -3,7 +3,7 @@ import { getPageDataByViteID } from "./internal.js";
|
|
|
3
3
|
function virtualHoistedEntry(id) {
|
|
4
4
|
return id.startsWith("/astro/hoisted.js?q=");
|
|
5
5
|
}
|
|
6
|
-
function vitePluginHoistedScripts(
|
|
6
|
+
function vitePluginHoistedScripts(settings, internals) {
|
|
7
7
|
return {
|
|
8
8
|
name: "@astro/rollup-plugin-astro-hoisted-scripts",
|
|
9
9
|
resolveId(id) {
|
|
@@ -29,7 +29,7 @@ function vitePluginHoistedScripts(astroConfig, internals) {
|
|
|
29
29
|
},
|
|
30
30
|
async generateBundle(_options, bundle) {
|
|
31
31
|
var _a, _b;
|
|
32
|
-
let assetInlineLimit = ((_b = (_a =
|
|
32
|
+
let assetInlineLimit = ((_b = (_a = settings.config.vite) == null ? void 0 : _a.build) == null ? void 0 : _b.assetsInlineLimit) || 4096;
|
|
33
33
|
for (const [id, output] of Object.entries(bundle)) {
|
|
34
34
|
if (output.type === "chunk" && output.facadeModuleId && virtualHoistedEntry(output.facadeModuleId)) {
|
|
35
35
|
const canBeInlined = output.imports.length === 0 && output.dynamicImports.length === 0 && Buffer.byteLength(output.code) <= assetInlineLimit;
|
|
@@ -37,7 +37,7 @@ function vitePluginHoistedScripts(astroConfig, internals) {
|
|
|
37
37
|
const facadeId = output.facadeModuleId;
|
|
38
38
|
const pages = internals.hoistedScriptIdToPagesMap.get(facadeId);
|
|
39
39
|
for (const pathname of pages) {
|
|
40
|
-
const vid = viteID(new URL("." + pathname,
|
|
40
|
+
const vid = viteID(new URL("." + pathname, settings.config.root));
|
|
41
41
|
const pageInfo = getPageDataByViteID(internals, vid);
|
|
42
42
|
if (pageInfo) {
|
|
43
43
|
if (canBeInlined) {
|
|
@@ -5,7 +5,7 @@ function vitePluginPages(opts, internals) {
|
|
|
5
5
|
return {
|
|
6
6
|
name: "@astro/plugin-build-pages",
|
|
7
7
|
options(options) {
|
|
8
|
-
if (opts.
|
|
8
|
+
if (opts.settings.config.output === "static") {
|
|
9
9
|
return addRollupInput(options, [pagesVirtualModuleId]);
|
|
10
10
|
}
|
|
11
11
|
},
|
|
@@ -27,7 +27,7 @@ function vitePluginPages(opts, internals) {
|
|
|
27
27
|
}
|
|
28
28
|
i = 0;
|
|
29
29
|
let rendererItems = "";
|
|
30
|
-
for (const renderer of opts.
|
|
30
|
+
for (const renderer of opts.settings.renderers) {
|
|
31
31
|
const variable = `_renderer${i}`;
|
|
32
32
|
imports.unshift(`import ${variable} from '${renderer.serverEntrypoint}';`);
|
|
33
33
|
rendererItems += `Object.assign(${JSON.stringify(renderer)}, { ssr: ${variable} }),`;
|
|
@@ -83,7 +83,11 @@ async function injectManifest(buildOpts, internals) {
|
|
|
83
83
|
}
|
|
84
84
|
const staticFiles = internals.staticFiles;
|
|
85
85
|
const manifest = buildManifest(buildOpts, internals, Array.from(staticFiles));
|
|
86
|
-
await runHookBuildSsr({
|
|
86
|
+
await runHookBuildSsr({
|
|
87
|
+
config: buildOpts.settings.config,
|
|
88
|
+
manifest,
|
|
89
|
+
logging: buildOpts.logging
|
|
90
|
+
});
|
|
87
91
|
const chunk = internals.ssrEntryChunk;
|
|
88
92
|
const code = chunk.code;
|
|
89
93
|
chunk.code = code.replace(replaceExp, () => {
|
|
@@ -94,10 +98,10 @@ async function injectManifest(buildOpts, internals) {
|
|
|
94
98
|
await fs.promises.writeFile(serverEntryURL, chunk.code, "utf-8");
|
|
95
99
|
}
|
|
96
100
|
function buildManifest(opts, internals, staticFiles) {
|
|
97
|
-
const {
|
|
101
|
+
const { settings } = opts;
|
|
98
102
|
const routes = [];
|
|
99
103
|
const entryModules = Object.fromEntries(internals.entrySpecifierToBundleMap.entries());
|
|
100
|
-
if (
|
|
104
|
+
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
101
105
|
staticFiles.push(entryModules[PAGE_SCRIPT_ID]);
|
|
102
106
|
}
|
|
103
107
|
for (const pageData of eachPageData(internals)) {
|
|
@@ -105,7 +109,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
105
109
|
if (pageData.hoistedScript) {
|
|
106
110
|
scripts.unshift(pageData.hoistedScript);
|
|
107
111
|
}
|
|
108
|
-
if (
|
|
112
|
+
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
109
113
|
scripts.push({ type: "external", value: entryModules[PAGE_SCRIPT_ID] });
|
|
110
114
|
}
|
|
111
115
|
routes.push({
|
|
@@ -113,22 +117,22 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
113
117
|
links: sortedCSS(pageData),
|
|
114
118
|
scripts: [
|
|
115
119
|
...scripts,
|
|
116
|
-
...
|
|
120
|
+
...settings.scripts.filter((script) => script.stage === "head-inline").map(({ stage, content }) => ({ stage, children: content }))
|
|
117
121
|
],
|
|
118
|
-
routeData: serializeRouteData(pageData.route,
|
|
122
|
+
routeData: serializeRouteData(pageData.route, settings.config.trailingSlash)
|
|
119
123
|
});
|
|
120
124
|
}
|
|
121
125
|
if (!(BEFORE_HYDRATION_SCRIPT_ID in entryModules)) {
|
|
122
126
|
entryModules[BEFORE_HYDRATION_SCRIPT_ID] = "";
|
|
123
127
|
}
|
|
124
128
|
const ssrManifest = {
|
|
125
|
-
adapterName: opts.
|
|
129
|
+
adapterName: opts.settings.adapter.name,
|
|
126
130
|
routes,
|
|
127
|
-
site:
|
|
128
|
-
base:
|
|
131
|
+
site: settings.config.site,
|
|
132
|
+
base: settings.config.base,
|
|
129
133
|
markdown: {
|
|
130
|
-
...
|
|
131
|
-
isAstroFlavoredMd:
|
|
134
|
+
...settings.config.markdown,
|
|
135
|
+
isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown
|
|
132
136
|
},
|
|
133
137
|
pageMap: null,
|
|
134
138
|
renderers: [],
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Arguments as Flags } from 'yargs-parser';
|
|
2
|
+
import type { AstroConfig, AstroUserConfig, CLIFlags } from '../../@types/astro';
|
|
3
|
+
import { LogOptions } from '../logger/core.js';
|
|
4
|
+
export declare const LEGACY_ASTRO_CONFIG_KEYS: Set<string>;
|
|
5
|
+
/** Turn raw config values into normalized values */
|
|
6
|
+
export declare function validateConfig(userConfig: any, root: string, cmd: string, logging: LogOptions): Promise<AstroConfig>;
|
|
7
|
+
/** Convert the generic "yargs" flag object into our own, custom TypeScript object. */
|
|
8
|
+
export declare function resolveFlags(flags: Partial<Flags>): CLIFlags;
|
|
9
|
+
export declare function resolveRoot(cwd?: string): string;
|
|
10
|
+
interface LoadConfigOptions {
|
|
11
|
+
cwd?: string;
|
|
12
|
+
flags?: Flags;
|
|
13
|
+
cmd: string;
|
|
14
|
+
validate?: boolean;
|
|
15
|
+
logging: LogOptions;
|
|
16
|
+
/** Invalidate when reloading a previously loaded config */
|
|
17
|
+
isConfigReload?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the file URL of the user's `astro.config.js|cjs|mjs|ts` file
|
|
21
|
+
* Note: currently the same as loadConfig but only returns the `filePath`
|
|
22
|
+
* instead of the resolved config
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveConfigPath(configOptions: Pick<LoadConfigOptions, 'cwd' | 'flags'>): Promise<string | undefined>;
|
|
25
|
+
interface OpenConfigResult {
|
|
26
|
+
userConfig: AstroUserConfig;
|
|
27
|
+
astroConfig: AstroConfig;
|
|
28
|
+
flags: CLIFlags;
|
|
29
|
+
root: string;
|
|
30
|
+
}
|
|
31
|
+
/** Load a configuration file, returning both the userConfig and astroConfig */
|
|
32
|
+
export declare function openConfig(configOptions: LoadConfigOptions): Promise<OpenConfigResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Attempt to load an `astro.config.mjs` file
|
|
35
|
+
* @deprecated
|
|
36
|
+
*/
|
|
37
|
+
export declare function loadConfig(configOptions: LoadConfigOptions): Promise<AstroConfig>;
|
|
38
|
+
/** Attempt to resolve an Astro configuration object. Normalize, validate, and return. */
|
|
39
|
+
export declare function resolveConfig(userConfig: AstroUserConfig, root: string, flags: CLIFlags | undefined, cmd: string, logging: LogOptions): Promise<AstroConfig>;
|
|
40
|
+
export declare function mergeConfig(defaults: Record<string, any>, overrides: Record<string, any>, isRoot?: boolean): Record<string, any>;
|
|
41
|
+
export {};
|
|
@@ -1,73 +1,14 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
1
|
import load, { ProloadError, resolve } from "@proload/core";
|
|
3
2
|
import loadTypeScript from "@proload/plugin-tsm";
|
|
3
|
+
import fs from "fs";
|
|
4
4
|
import * as colors from "kleur/colors";
|
|
5
5
|
import path from "path";
|
|
6
|
-
import postcssrc from "postcss-load-config";
|
|
7
|
-
import { BUNDLED_THEMES } from "shiki";
|
|
8
|
-
import * as tsr from "tsconfig-resolver";
|
|
9
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
10
7
|
import * as vite from "vite";
|
|
11
8
|
import { mergeConfig as mergeViteConfig } from "vite";
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import { appendForwardSlash, prependForwardSlash, trimSlashes } from "./path.js";
|
|
15
|
-
import { arraify, isObject } from "./util.js";
|
|
9
|
+
import { arraify, isObject } from "../util.js";
|
|
10
|
+
import { createRelativeSchema } from "./schema.js";
|
|
16
11
|
load.use([loadTypeScript]);
|
|
17
|
-
const ASTRO_CONFIG_DEFAULTS = {
|
|
18
|
-
root: ".",
|
|
19
|
-
srcDir: "./src",
|
|
20
|
-
publicDir: "./public",
|
|
21
|
-
outDir: "./dist",
|
|
22
|
-
base: "/",
|
|
23
|
-
trailingSlash: "ignore",
|
|
24
|
-
build: { format: "directory" },
|
|
25
|
-
server: {
|
|
26
|
-
host: false,
|
|
27
|
-
port: 3e3,
|
|
28
|
-
streaming: true
|
|
29
|
-
},
|
|
30
|
-
style: { postcss: { options: {}, plugins: [] } },
|
|
31
|
-
integrations: [],
|
|
32
|
-
markdown: {
|
|
33
|
-
drafts: false,
|
|
34
|
-
syntaxHighlight: "shiki",
|
|
35
|
-
shikiConfig: {
|
|
36
|
-
langs: [],
|
|
37
|
-
theme: "github-dark",
|
|
38
|
-
wrap: false
|
|
39
|
-
},
|
|
40
|
-
remarkPlugins: [],
|
|
41
|
-
rehypePlugins: [],
|
|
42
|
-
remarkRehype: {}
|
|
43
|
-
},
|
|
44
|
-
vite: {},
|
|
45
|
-
legacy: {
|
|
46
|
-
astroFlavoredMarkdown: false
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
async function resolvePostcssConfig(inlineOptions, root) {
|
|
50
|
-
if (isObject(inlineOptions)) {
|
|
51
|
-
const options = { ...inlineOptions };
|
|
52
|
-
delete options.plugins;
|
|
53
|
-
return {
|
|
54
|
-
options,
|
|
55
|
-
plugins: inlineOptions.plugins || []
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const searchPath = typeof inlineOptions === "string" ? inlineOptions : fileURLToPath(root);
|
|
59
|
-
try {
|
|
60
|
-
return await postcssrc({}, searchPath);
|
|
61
|
-
} catch (err) {
|
|
62
|
-
if (!/No PostCSS Config found/.test(err.message)) {
|
|
63
|
-
throw err;
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
options: {},
|
|
67
|
-
plugins: []
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
12
|
const LEGACY_ASTRO_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
72
13
|
"projectRoot",
|
|
73
14
|
"src",
|
|
@@ -79,64 +20,6 @@ const LEGACY_ASTRO_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
79
20
|
"buildOptions",
|
|
80
21
|
"devOptions"
|
|
81
22
|
]);
|
|
82
|
-
const AstroConfigSchema = z.object({
|
|
83
|
-
root: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.root).transform((val) => new URL(val)),
|
|
84
|
-
srcDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => new URL(val)),
|
|
85
|
-
publicDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => new URL(val)),
|
|
86
|
-
outDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => new URL(val)),
|
|
87
|
-
site: z.string().url().optional().transform((val) => val ? appendForwardSlash(val) : val),
|
|
88
|
-
base: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.base).transform((val) => prependForwardSlash(appendForwardSlash(trimSlashes(val)))),
|
|
89
|
-
trailingSlash: z.union([z.literal("always"), z.literal("never"), z.literal("ignore")]).optional().default(ASTRO_CONFIG_DEFAULTS.trailingSlash),
|
|
90
|
-
output: z.union([z.literal("static"), z.literal("server")]).optional().default("static"),
|
|
91
|
-
adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(),
|
|
92
|
-
integrations: z.preprocess(
|
|
93
|
-
(val) => Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val,
|
|
94
|
-
z.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) })).default(ASTRO_CONFIG_DEFAULTS.integrations)
|
|
95
|
-
),
|
|
96
|
-
build: z.object({
|
|
97
|
-
format: z.union([z.literal("file"), z.literal("directory")]).optional().default(ASTRO_CONFIG_DEFAULTS.build.format)
|
|
98
|
-
}).optional().default({}),
|
|
99
|
-
server: z.preprocess(
|
|
100
|
-
(val) => typeof val === "function" ? val({ command: "error" }) : val,
|
|
101
|
-
z.object({
|
|
102
|
-
host: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.host),
|
|
103
|
-
port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port)
|
|
104
|
-
}).optional().default({})
|
|
105
|
-
),
|
|
106
|
-
style: z.object({
|
|
107
|
-
postcss: z.object({
|
|
108
|
-
options: z.any(),
|
|
109
|
-
plugins: z.array(z.any())
|
|
110
|
-
}).optional().default(ASTRO_CONFIG_DEFAULTS.style.postcss)
|
|
111
|
-
}).optional().default({}),
|
|
112
|
-
markdown: z.object({
|
|
113
|
-
drafts: z.boolean().default(false),
|
|
114
|
-
syntaxHighlight: z.union([z.literal("shiki"), z.literal("prism"), z.literal(false)]).default(ASTRO_CONFIG_DEFAULTS.markdown.syntaxHighlight),
|
|
115
|
-
shikiConfig: z.object({
|
|
116
|
-
langs: z.custom().array().default([]),
|
|
117
|
-
theme: z.enum(BUNDLED_THEMES).or(z.custom()).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.theme),
|
|
118
|
-
wrap: z.boolean().or(z.null()).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.wrap)
|
|
119
|
-
}).default({}),
|
|
120
|
-
remarkPlugins: z.union([
|
|
121
|
-
z.string(),
|
|
122
|
-
z.tuple([z.string(), z.any()]),
|
|
123
|
-
z.custom((data) => typeof data === "function"),
|
|
124
|
-
z.tuple([z.custom((data) => typeof data === "function"), z.any()])
|
|
125
|
-
]).array().default(ASTRO_CONFIG_DEFAULTS.markdown.remarkPlugins),
|
|
126
|
-
rehypePlugins: z.union([
|
|
127
|
-
z.string(),
|
|
128
|
-
z.tuple([z.string(), z.any()]),
|
|
129
|
-
z.custom((data) => typeof data === "function"),
|
|
130
|
-
z.tuple([z.custom((data) => typeof data === "function"), z.any()])
|
|
131
|
-
]).array().default(ASTRO_CONFIG_DEFAULTS.markdown.rehypePlugins),
|
|
132
|
-
remarkRehype: z.custom((data) => data instanceof Object && !Array.isArray(data)).optional().default(ASTRO_CONFIG_DEFAULTS.markdown.remarkRehype),
|
|
133
|
-
extendDefaultPlugins: z.boolean().default(false)
|
|
134
|
-
}).default({}),
|
|
135
|
-
vite: z.custom((data) => data instanceof Object && !Array.isArray(data)).default(ASTRO_CONFIG_DEFAULTS.vite),
|
|
136
|
-
legacy: z.object({
|
|
137
|
-
astroFlavoredMarkdown: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.legacy.astroFlavoredMarkdown)
|
|
138
|
-
}).optional().default({})
|
|
139
|
-
});
|
|
140
23
|
async function validateConfig(userConfig, root, cmd, logging) {
|
|
141
24
|
const fileProtocolRoot = pathToFileURL(root + path.sep);
|
|
142
25
|
if (userConfig.hasOwnProperty("renderers")) {
|
|
@@ -181,42 +64,8 @@ Please update your configuration to the new format!
|
|
|
181
64
|
See https://astro.build/config for more information.`
|
|
182
65
|
);
|
|
183
66
|
}
|
|
184
|
-
const AstroConfigRelativeSchema =
|
|
185
|
-
|
|
186
|
-
srcDir: z.string().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
|
|
187
|
-
publicDir: z.string().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
|
|
188
|
-
outDir: z.string().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
|
|
189
|
-
server: z.preprocess(
|
|
190
|
-
(val) => typeof val === "function" ? val({ command: cmd === "dev" ? "dev" : "preview" }) : val,
|
|
191
|
-
z.object({
|
|
192
|
-
host: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.host),
|
|
193
|
-
port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port),
|
|
194
|
-
streaming: z.boolean().optional().default(true)
|
|
195
|
-
}).optional().default({})
|
|
196
|
-
),
|
|
197
|
-
style: z.object({
|
|
198
|
-
postcss: z.preprocess(
|
|
199
|
-
(val) => resolvePostcssConfig(val, fileProtocolRoot),
|
|
200
|
-
z.object({
|
|
201
|
-
options: z.any(),
|
|
202
|
-
plugins: z.array(z.any())
|
|
203
|
-
}).optional().default(ASTRO_CONFIG_DEFAULTS.style.postcss)
|
|
204
|
-
)
|
|
205
|
-
}).optional().default({})
|
|
206
|
-
});
|
|
207
|
-
const tsconfig = loadTSConfig(root);
|
|
208
|
-
const result = {
|
|
209
|
-
...await AstroConfigRelativeSchema.parseAsync(userConfig),
|
|
210
|
-
_ctx: {
|
|
211
|
-
pageExtensions: [".astro", ".md", ".html"],
|
|
212
|
-
tsConfig: tsconfig == null ? void 0 : tsconfig.config,
|
|
213
|
-
tsConfigPath: tsconfig == null ? void 0 : tsconfig.path,
|
|
214
|
-
scripts: [],
|
|
215
|
-
renderers: [jsxRenderer],
|
|
216
|
-
injectedRoutes: [],
|
|
217
|
-
adapter: void 0
|
|
218
|
-
}
|
|
219
|
-
};
|
|
67
|
+
const AstroConfigRelativeSchema = createRelativeSchema(cmd, fileProtocolRoot);
|
|
68
|
+
const result = await AstroConfigRelativeSchema.parseAsync(userConfig);
|
|
220
69
|
return result;
|
|
221
70
|
}
|
|
222
71
|
function resolveFlags(flags) {
|
|
@@ -350,15 +199,6 @@ async function tryLoadConfig(configOptions, flags, root) {
|
|
|
350
199
|
await finallyCleanup();
|
|
351
200
|
}
|
|
352
201
|
}
|
|
353
|
-
function loadTSConfig(cwd) {
|
|
354
|
-
for (const searchName of ["tsconfig.json", "jsconfig.json"]) {
|
|
355
|
-
const config = tsr.tsconfigResolverSync({ cwd, searchName });
|
|
356
|
-
if (config.exists) {
|
|
357
|
-
return config;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return void 0;
|
|
361
|
-
}
|
|
362
202
|
async function loadConfig(configOptions) {
|
|
363
203
|
const root = resolveRoot(configOptions.cwd);
|
|
364
204
|
const flags = resolveFlags(configOptions.flags || {});
|
|
@@ -406,7 +246,6 @@ function mergeConfig(defaults, overrides, isRoot = true) {
|
|
|
406
246
|
return mergeConfigRecursively(defaults, overrides, isRoot ? "" : ".");
|
|
407
247
|
}
|
|
408
248
|
export {
|
|
409
|
-
AstroConfigSchema,
|
|
410
249
|
LEGACY_ASTRO_CONFIG_KEYS,
|
|
411
250
|
loadConfig,
|
|
412
251
|
mergeConfig,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
openConfig,
|
|
3
|
+
resolveConfigPath,
|
|
4
|
+
resolveFlags,
|
|
5
|
+
resolveRoot,
|
|
6
|
+
validateConfig
|
|
7
|
+
} from "./config.js";
|
|
8
|
+
import { createSettings } from "./settings.js";
|
|
9
|
+
import { loadTSConfig } from "./tsconfig.js";
|
|
10
|
+
export {
|
|
11
|
+
createSettings,
|
|
12
|
+
loadTSConfig,
|
|
13
|
+
openConfig,
|
|
14
|
+
resolveConfigPath,
|
|
15
|
+
resolveFlags,
|
|
16
|
+
resolveRoot,
|
|
17
|
+
validateConfig
|
|
18
|
+
};
|