astro 1.6.1 → 1.6.3
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/typed-emitter.d.ts +42 -0
- package/dist/@types/typed-emitter.js +0 -0
- package/dist/cli/index.js +13 -51
- package/dist/core/build/generate.js +10 -6
- package/dist/core/compile/compile.d.ts +3 -3
- package/dist/core/compile/compile.js +15 -10
- package/dist/core/compile/style.d.ts +7 -4
- package/dist/core/compile/style.js +65 -12
- package/dist/core/config/config.d.ts +7 -3
- package/dist/core/config/config.js +15 -12
- package/dist/core/config/index.d.ts +2 -2
- package/dist/core/config/index.js +4 -1
- package/dist/core/config/schema.d.ts +69 -69
- package/dist/core/config/settings.d.ts +3 -1
- package/dist/core/config/settings.js +23 -5
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.d.ts +4 -1
- package/dist/core/create-vite.js +7 -4
- package/dist/core/dev/container.d.ts +36 -0
- package/dist/core/dev/container.js +109 -0
- package/dist/core/dev/dev.d.ts +24 -0
- package/dist/core/dev/dev.js +55 -0
- package/dist/core/dev/index.d.ts +3 -18
- package/dist/core/dev/index.js +8 -81
- package/dist/core/dev/restart.d.ts +25 -0
- package/dist/core/dev/restart.js +143 -0
- package/dist/core/endpoint/index.d.ts +2 -1
- package/dist/core/endpoint/index.js +12 -1
- package/dist/core/errors/dev/vite.d.ts +3 -2
- package/dist/core/errors/dev/vite.js +4 -6
- package/dist/core/messages.js +2 -2
- package/dist/core/module-loader/index.d.ts +3 -0
- package/dist/core/module-loader/index.js +6 -0
- package/dist/core/module-loader/loader.d.ts +42 -0
- package/dist/core/module-loader/loader.js +39 -0
- package/dist/core/module-loader/vite.d.ts +3 -0
- package/dist/core/module-loader/vite.js +62 -0
- package/dist/core/render/dev/css.d.ts +2 -2
- package/dist/core/render/dev/css.js +3 -3
- package/dist/core/render/dev/environment.d.ts +3 -3
- package/dist/core/render/dev/environment.js +3 -3
- package/dist/core/render/dev/index.d.ts +4 -4
- package/dist/core/render/dev/index.js +8 -8
- package/dist/core/render/dev/resolve.d.ts +2 -2
- package/dist/core/render/dev/resolve.js +2 -2
- package/dist/core/render/dev/scripts.d.ts +2 -2
- package/dist/core/render/dev/scripts.js +4 -4
- package/dist/core/render/dev/vite.d.ts +2 -2
- package/dist/core/render/dev/vite.js +5 -5
- package/dist/core/routing/manifest/create.d.ts +10 -3
- package/dist/core/routing/manifest/create.js +7 -6
- package/dist/core/util.d.ts +3 -4
- package/dist/core/util.js +10 -17
- package/dist/vite-plugin-astro/index.js +9 -20
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/base.d.ts +4 -0
- package/dist/vite-plugin-astro-server/base.js +36 -0
- package/dist/vite-plugin-astro-server/common.d.ts +2 -0
- package/dist/vite-plugin-astro-server/common.js +8 -0
- package/dist/vite-plugin-astro-server/controller.d.ts +26 -0
- package/dist/vite-plugin-astro-server/controller.js +77 -0
- package/dist/vite-plugin-astro-server/index.d.ts +3 -10
- package/dist/vite-plugin-astro-server/index.js +7 -336
- package/dist/vite-plugin-astro-server/plugin.d.ts +11 -0
- package/dist/vite-plugin-astro-server/plugin.js +54 -0
- package/dist/vite-plugin-astro-server/request.d.ts +7 -0
- package/dist/vite-plugin-astro-server/request.js +52 -0
- package/dist/vite-plugin-astro-server/response.d.ts +9 -0
- package/dist/vite-plugin-astro-server/response.js +85 -0
- package/dist/vite-plugin-astro-server/route.d.ts +13 -0
- package/dist/vite-plugin-astro-server/route.js +144 -0
- package/dist/vite-plugin-astro-server/server-state.d.ts +15 -0
- package/dist/vite-plugin-astro-server/server-state.js +42 -0
- package/dist/vite-plugin-jsx/index.js +2 -2
- package/dist/vite-plugin-load-fallback/index.d.ts +9 -0
- package/dist/vite-plugin-load-fallback/index.js +26 -0
- package/dist/vite-plugin-markdown/index.js +1 -1
- package/dist/vite-plugin-markdown-legacy/index.js +8 -24
- package/package.json +7 -5
- package/types.d.ts +1 -1
- package/dist/vite-style-transform/index.d.ts +0 -2
- package/dist/vite-style-transform/index.js +0 -5
- package/dist/vite-style-transform/style-transform.d.ts +0 -10
- package/dist/vite-style-transform/style-transform.js +0 -80
- package/dist/vite-style-transform/transform-with-vite.d.ts +0 -18
- package/dist/vite-style-transform/transform-with-vite.js +0 -33
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
* Copyright (c) 2018 Andy Wermke
|
|
4
|
+
* https://github.com/andywer/typed-emitter/blob/9a139b6fa0ec6b0db6141b5b756b784e4f7ef4e4/LICENSE
|
|
5
|
+
*/
|
|
6
|
+
export declare type EventMap = {
|
|
7
|
+
[key: string]: (...args: any[]) => void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Type-safe event emitter.
|
|
11
|
+
*
|
|
12
|
+
* Use it like this:
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* type MyEvents = {
|
|
16
|
+
* error: (error: Error) => void;
|
|
17
|
+
* message: (from: string, content: string) => void;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* const myEmitter = new EventEmitter() as TypedEmitter<MyEvents>;
|
|
21
|
+
*
|
|
22
|
+
* myEmitter.emit("error", "x") // <- Will catch this type error;
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
interface TypedEventEmitter<Events extends EventMap> {
|
|
26
|
+
addListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
27
|
+
on<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
28
|
+
once<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
29
|
+
prependListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
30
|
+
prependOnceListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
31
|
+
off<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
32
|
+
removeAllListeners<E extends keyof Events>(event?: E): this;
|
|
33
|
+
removeListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
34
|
+
emit<E extends keyof Events>(event: E, ...args: Parameters<Events[E]>): boolean;
|
|
35
|
+
eventNames(): (keyof Events | string | symbol)[];
|
|
36
|
+
rawListeners<E extends keyof Events>(event: E): Events[E][];
|
|
37
|
+
listeners<E extends keyof Events>(event: E): Events[E][];
|
|
38
|
+
listenerCount<E extends keyof Events>(event: E): number;
|
|
39
|
+
getMaxListeners(): number;
|
|
40
|
+
setMaxListeners(maxListeners: number): this;
|
|
41
|
+
}
|
|
42
|
+
export default TypedEventEmitter;
|
|
File without changes
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as colors from "kleur/colors";
|
|
2
2
|
import { pathToFileURL } from "url";
|
|
3
|
-
import { normalizePath } from "vite";
|
|
4
3
|
import yargs from "yargs-parser";
|
|
5
4
|
import { z } from "zod";
|
|
6
5
|
import add from "../core/add/index.js";
|
|
@@ -9,8 +8,7 @@ import {
|
|
|
9
8
|
createSettings,
|
|
10
9
|
openConfig,
|
|
11
10
|
resolveConfigPath,
|
|
12
|
-
resolveFlags
|
|
13
|
-
resolveRoot
|
|
11
|
+
resolveFlags
|
|
14
12
|
} from "../core/config/index.js";
|
|
15
13
|
import { ASTRO_VERSION } from "../core/constants.js";
|
|
16
14
|
import devServer from "../core/dev/index.js";
|
|
@@ -19,7 +17,6 @@ import { createSafeError } from "../core/errors/index.js";
|
|
|
19
17
|
import { debug, error, info } from "../core/logger/core.js";
|
|
20
18
|
import { enableVerboseLogging, nodeLogDestination } from "../core/logger/node.js";
|
|
21
19
|
import { formatConfigErrorMessage, formatErrorMessage, printHelp } from "../core/messages.js";
|
|
22
|
-
import { appendForwardSlash } from "../core/path.js";
|
|
23
20
|
import preview from "../core/preview/index.js";
|
|
24
21
|
import * as event from "../events/index.js";
|
|
25
22
|
import { eventConfigError, eventError, telemetry } from "../events/index.js";
|
|
@@ -137,53 +134,18 @@ async function runCommand(cmd, flags) {
|
|
|
137
134
|
let settings = createSettings(initialAstroConfig, root);
|
|
138
135
|
switch (cmd) {
|
|
139
136
|
case "dev": {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
).test(normalizePath(changedFile));
|
|
153
|
-
if (!shouldRestart && settings.watchFiles.length > 0) {
|
|
154
|
-
shouldRestart = settings.watchFiles.some(
|
|
155
|
-
(path) => normalizePath(path) === normalizePath(changedFile)
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
if (!shouldRestart)
|
|
159
|
-
return;
|
|
160
|
-
restartInFlight = true;
|
|
161
|
-
console.clear();
|
|
162
|
-
try {
|
|
163
|
-
const newConfig = await openConfig({
|
|
164
|
-
cwd: root,
|
|
165
|
-
flags,
|
|
166
|
-
cmd,
|
|
167
|
-
logging,
|
|
168
|
-
isRestart: true
|
|
169
|
-
});
|
|
170
|
-
info(logging, "astro", logMsg + "\n");
|
|
171
|
-
let astroConfig = newConfig.astroConfig;
|
|
172
|
-
settings = createSettings(astroConfig, root);
|
|
173
|
-
await stop();
|
|
174
|
-
await startDevServer({ isRestart: true });
|
|
175
|
-
} catch (e) {
|
|
176
|
-
await handleConfigError(e, { cwd: root, flags, logging });
|
|
177
|
-
await stop();
|
|
178
|
-
info(logging, "astro", "Continuing with previous valid configuration\n");
|
|
179
|
-
await startDevServer({ isRestart: true });
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
watcher.on("change", handleServerRestart("Configuration updated. Restarting..."));
|
|
183
|
-
watcher.on("unlink", handleServerRestart("Configuration removed. Restarting..."));
|
|
184
|
-
watcher.on("add", handleServerRestart("Configuration added. Restarting..."));
|
|
185
|
-
}
|
|
186
|
-
await startDevServer({ isRestart: false });
|
|
137
|
+
const configFlag = resolveFlags(flags).config;
|
|
138
|
+
const configFlagPath = configFlag ? await resolveConfigPath({ cwd: root, flags }) : void 0;
|
|
139
|
+
await devServer(settings, {
|
|
140
|
+
configFlag,
|
|
141
|
+
configFlagPath,
|
|
142
|
+
logging,
|
|
143
|
+
telemetry,
|
|
144
|
+
handleConfigError(e) {
|
|
145
|
+
handleConfigError(e, { cwd: root, flags, logging });
|
|
146
|
+
info(logging, "astro", "Continuing with previous valid configuration\n");
|
|
147
|
+
}
|
|
148
|
+
});
|
|
187
149
|
return await new Promise(() => {
|
|
188
150
|
});
|
|
189
151
|
}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "../../core/path.js";
|
|
12
12
|
import { runHookBuildGenerated } from "../../integrations/index.js";
|
|
13
13
|
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
14
|
-
import { call as callEndpoint } from "../endpoint/index.js";
|
|
14
|
+
import { call as callEndpoint, throwIfRedirectNotAllowed } from "../endpoint/index.js";
|
|
15
15
|
import { debug, info } from "../logger/core.js";
|
|
16
16
|
import { createEnvironment, createRenderContext, renderPage } from "../render/index.js";
|
|
17
17
|
import { callGetStaticPaths } from "../render/route-cache.js";
|
|
@@ -254,15 +254,19 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
254
254
|
const endpointHandler = mod;
|
|
255
255
|
const result = await callEndpoint(endpointHandler, env, ctx);
|
|
256
256
|
if (result.type === "response") {
|
|
257
|
-
|
|
257
|
+
throwIfRedirectNotAllowed(result.response, opts.settings.config);
|
|
258
|
+
if (!result.response.body)
|
|
259
|
+
return;
|
|
260
|
+
body = await result.response.text();
|
|
261
|
+
} else {
|
|
262
|
+
body = result.body;
|
|
263
|
+
encoding = result.encoding;
|
|
258
264
|
}
|
|
259
|
-
body = result.body;
|
|
260
|
-
encoding = result.encoding;
|
|
261
265
|
} else {
|
|
262
266
|
const response = await renderPage(mod, ctx, env);
|
|
263
|
-
|
|
267
|
+
throwIfRedirectNotAllowed(response, opts.settings.config);
|
|
268
|
+
if (!response.body)
|
|
264
269
|
return;
|
|
265
|
-
}
|
|
266
270
|
body = await response.text();
|
|
267
271
|
}
|
|
268
272
|
const outFolder = getOutFolder(settings.config, pathname, pageData.route.type);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { TransformResult } from '@astrojs/compiler';
|
|
2
|
+
import type { ResolvedConfig } from 'vite';
|
|
2
3
|
import type { AstroConfig } from '../../@types/astro';
|
|
3
|
-
import type { TransformStyle } from './types';
|
|
4
4
|
declare type CompileResult = TransformResult & {
|
|
5
5
|
cssDeps: Set<string>;
|
|
6
6
|
source: string;
|
|
7
7
|
};
|
|
8
8
|
export interface CompileProps {
|
|
9
|
-
|
|
9
|
+
astroConfig: AstroConfig;
|
|
10
|
+
viteConfig: ResolvedConfig;
|
|
10
11
|
filename: string;
|
|
11
12
|
source: string;
|
|
12
|
-
transformStyle: TransformStyle;
|
|
13
13
|
}
|
|
14
14
|
export declare function isCached(config: AstroConfig, filename: string): boolean;
|
|
15
15
|
export declare function getCachedSource(config: AstroConfig, filename: string): string | null;
|
|
@@ -6,25 +6,30 @@ import { resolvePath, viteID } from "../util.js";
|
|
|
6
6
|
import { createStylePreprocessor } from "./style.js";
|
|
7
7
|
const configCache = /* @__PURE__ */ new WeakMap();
|
|
8
8
|
async function compile({
|
|
9
|
-
|
|
9
|
+
astroConfig,
|
|
10
|
+
viteConfig,
|
|
10
11
|
filename,
|
|
11
|
-
source
|
|
12
|
-
transformStyle
|
|
12
|
+
source
|
|
13
13
|
}) {
|
|
14
14
|
var _a;
|
|
15
15
|
let cssDeps = /* @__PURE__ */ new Set();
|
|
16
16
|
let cssTransformErrors = [];
|
|
17
17
|
const transformResult = await transform(source, {
|
|
18
18
|
pathname: filename,
|
|
19
|
-
projectRoot:
|
|
20
|
-
site: (_a =
|
|
19
|
+
projectRoot: astroConfig.root.toString(),
|
|
20
|
+
site: (_a = astroConfig.site) == null ? void 0 : _a.toString(),
|
|
21
21
|
sourcefile: filename,
|
|
22
22
|
sourcemap: "both",
|
|
23
23
|
internalURL: `/@fs${prependForwardSlash(
|
|
24
24
|
viteID(new URL("../../runtime/server/index.js", import.meta.url))
|
|
25
25
|
)}`,
|
|
26
26
|
experimentalStaticExtraction: true,
|
|
27
|
-
preprocessStyle: createStylePreprocessor(
|
|
27
|
+
preprocessStyle: createStylePreprocessor({
|
|
28
|
+
filename,
|
|
29
|
+
viteConfig,
|
|
30
|
+
cssDeps,
|
|
31
|
+
cssTransformErrors
|
|
32
|
+
}),
|
|
28
33
|
async resolvePath(specifier) {
|
|
29
34
|
return resolvePath(specifier, filename);
|
|
30
35
|
}
|
|
@@ -96,13 +101,13 @@ function invalidateCompilation(config, filename) {
|
|
|
96
101
|
}
|
|
97
102
|
}
|
|
98
103
|
async function cachedCompilation(props) {
|
|
99
|
-
const {
|
|
104
|
+
const { astroConfig, filename } = props;
|
|
100
105
|
let cache;
|
|
101
|
-
if (!configCache.has(
|
|
106
|
+
if (!configCache.has(astroConfig)) {
|
|
102
107
|
cache = /* @__PURE__ */ new Map();
|
|
103
|
-
configCache.set(
|
|
108
|
+
configCache.set(astroConfig, cache);
|
|
104
109
|
} else {
|
|
105
|
-
cache = configCache.get(
|
|
110
|
+
cache = configCache.get(astroConfig);
|
|
106
111
|
}
|
|
107
112
|
if (cache.has(filename)) {
|
|
108
113
|
return cache.get(filename);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { TransformOptions } from '@astrojs/compiler';
|
|
2
|
-
import
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { ResolvedConfig } from 'vite';
|
|
3
|
+
export declare function createStylePreprocessor({ filename, viteConfig, cssDeps, cssTransformErrors, }: {
|
|
4
|
+
filename: string;
|
|
5
|
+
viteConfig: ResolvedConfig;
|
|
6
|
+
cssDeps: Set<string>;
|
|
7
|
+
cssTransformErrors: Error[];
|
|
8
|
+
}): TransformOptions['preprocessStyle'];
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { preprocessCSS } from "vite";
|
|
3
|
+
import { AstroErrorCodes } from "../errors/codes.js";
|
|
4
|
+
import { CSSError } from "../errors/errors.js";
|
|
5
|
+
import { positionAt } from "../errors/index.js";
|
|
6
|
+
function createStylePreprocessor({
|
|
7
|
+
filename,
|
|
8
|
+
viteConfig,
|
|
9
|
+
cssDeps,
|
|
10
|
+
cssTransformErrors
|
|
11
|
+
}) {
|
|
12
|
+
return async (content, attrs) => {
|
|
13
|
+
var _a;
|
|
3
14
|
const lang = `.${(attrs == null ? void 0 : attrs.lang) || "css"}`.toLowerCase();
|
|
15
|
+
const id = `${filename}?astro&type=style&lang${lang}`;
|
|
4
16
|
try {
|
|
5
|
-
const result = await
|
|
6
|
-
|
|
7
|
-
return null;
|
|
8
|
-
for (const dep of result.deps) {
|
|
17
|
+
const result = await preprocessCSS(content, id, viteConfig);
|
|
18
|
+
(_a = result.deps) == null ? void 0 : _a.forEach((dep) => {
|
|
9
19
|
cssDeps.add(dep);
|
|
10
|
-
}
|
|
20
|
+
});
|
|
11
21
|
let map;
|
|
12
22
|
if (result.map) {
|
|
13
23
|
if (typeof result.map === "string") {
|
|
@@ -18,13 +28,56 @@ function createStylePreprocessor(transformStyle, cssDeps, errors) {
|
|
|
18
28
|
}
|
|
19
29
|
return { code: result.code, map };
|
|
20
30
|
} catch (err) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
31
|
+
try {
|
|
32
|
+
err = enhanceCSSError(err, filename);
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
cssTransformErrors.push(err);
|
|
36
|
+
return { error: err + "" };
|
|
25
37
|
}
|
|
26
38
|
};
|
|
27
|
-
|
|
39
|
+
}
|
|
40
|
+
function enhanceCSSError(err, filename) {
|
|
41
|
+
var _a;
|
|
42
|
+
const fileContent = fs.readFileSync(filename).toString();
|
|
43
|
+
const styleTagBeginning = fileContent.indexOf(((_a = err.input) == null ? void 0 : _a.source) ?? err.code);
|
|
44
|
+
if (err.name === "CssSyntaxError") {
|
|
45
|
+
const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);
|
|
46
|
+
return new CSSError({
|
|
47
|
+
errorCode: AstroErrorCodes.CssSyntaxError,
|
|
48
|
+
message: err.reason,
|
|
49
|
+
location: {
|
|
50
|
+
file: filename,
|
|
51
|
+
line: errorLine,
|
|
52
|
+
column: err.column
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (err.line && err.column) {
|
|
57
|
+
const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);
|
|
58
|
+
return new CSSError({
|
|
59
|
+
errorCode: AstroErrorCodes.CssUnknownError,
|
|
60
|
+
message: err.message,
|
|
61
|
+
location: {
|
|
62
|
+
file: filename,
|
|
63
|
+
line: errorLine,
|
|
64
|
+
column: err.column
|
|
65
|
+
},
|
|
66
|
+
frame: err.frame
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const errorPosition = positionAt(styleTagBeginning, fileContent);
|
|
70
|
+
errorPosition.line += 1;
|
|
71
|
+
return new CSSError({
|
|
72
|
+
errorCode: AstroErrorCodes.CssUnknownError,
|
|
73
|
+
message: err.message,
|
|
74
|
+
location: {
|
|
75
|
+
file: filename,
|
|
76
|
+
line: errorPosition.line,
|
|
77
|
+
column: 0
|
|
78
|
+
},
|
|
79
|
+
frame: err.frame
|
|
80
|
+
});
|
|
28
81
|
}
|
|
29
82
|
export {
|
|
30
83
|
createStylePreprocessor
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { Arguments as Flags } from 'yargs-parser';
|
|
2
3
|
import type { AstroConfig, AstroUserConfig, CLIFlags } from '../../@types/astro';
|
|
4
|
+
import fs from 'fs';
|
|
3
5
|
import { LogOptions } from '../logger/core.js';
|
|
4
6
|
export declare const LEGACY_ASTRO_CONFIG_KEYS: Set<string>;
|
|
5
7
|
/** Turn raw config values into normalized values */
|
|
6
|
-
export declare function validateConfig(userConfig: any, root: string, cmd: string
|
|
8
|
+
export declare function validateConfig(userConfig: any, root: string, cmd: string): Promise<AstroConfig>;
|
|
7
9
|
/** Convert the generic "yargs" flag object into our own, custom TypeScript object. */
|
|
8
10
|
export declare function resolveFlags(flags: Partial<Flags>): CLIFlags;
|
|
9
|
-
export declare function resolveRoot(cwd?: string): string;
|
|
11
|
+
export declare function resolveRoot(cwd?: string | URL): string;
|
|
10
12
|
interface LoadConfigOptions {
|
|
11
13
|
cwd?: string;
|
|
12
14
|
flags?: Flags;
|
|
@@ -15,6 +17,7 @@ interface LoadConfigOptions {
|
|
|
15
17
|
logging: LogOptions;
|
|
16
18
|
/** Invalidate when reloading a previously loaded config */
|
|
17
19
|
isRestart?: boolean;
|
|
20
|
+
fsMod?: typeof fs;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
23
|
* Resolve the file URL of the user's `astro.config.js|cjs|mjs|ts` file
|
|
@@ -36,6 +39,7 @@ export declare function openConfig(configOptions: LoadConfigOptions): Promise<Op
|
|
|
36
39
|
*/
|
|
37
40
|
export declare function loadConfig(configOptions: LoadConfigOptions): Promise<AstroConfig>;
|
|
38
41
|
/** 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
|
|
42
|
+
export declare function resolveConfig(userConfig: AstroUserConfig, root: string, flags: CLIFlags | undefined, cmd: string): Promise<AstroConfig>;
|
|
43
|
+
export declare function createDefaultDevConfig(userConfig?: AstroUserConfig, root?: string): Promise<AstroConfig>;
|
|
40
44
|
export declare function mergeConfig(defaults: Record<string, any>, overrides: Record<string, any>, isRoot?: boolean): Record<string, any>;
|
|
41
45
|
export {};
|
|
@@ -20,7 +20,7 @@ const LEGACY_ASTRO_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
20
20
|
"buildOptions",
|
|
21
21
|
"devOptions"
|
|
22
22
|
]);
|
|
23
|
-
async function validateConfig(userConfig, root, cmd
|
|
23
|
+
async function validateConfig(userConfig, root, cmd) {
|
|
24
24
|
const fileProtocolRoot = pathToFileURL(root + path.sep);
|
|
25
25
|
if (userConfig.hasOwnProperty("renderers")) {
|
|
26
26
|
console.error('Astro "renderers" are now "integrations"!');
|
|
@@ -80,6 +80,9 @@ function resolveFlags(flags) {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
function resolveRoot(cwd) {
|
|
83
|
+
if (cwd instanceof URL) {
|
|
84
|
+
cwd = fileURLToPath(cwd);
|
|
85
|
+
}
|
|
83
86
|
return cwd ? path.resolve(cwd) : process.cwd();
|
|
84
87
|
}
|
|
85
88
|
function mergeCLIFlags(astroConfig, flags, cmd) {
|
|
@@ -129,13 +132,7 @@ async function openConfig(configOptions) {
|
|
|
129
132
|
if (config) {
|
|
130
133
|
userConfig = config.value;
|
|
131
134
|
}
|
|
132
|
-
const astroConfig = await resolveConfig(
|
|
133
|
-
userConfig,
|
|
134
|
-
root,
|
|
135
|
-
flags,
|
|
136
|
-
configOptions.cmd,
|
|
137
|
-
configOptions.logging
|
|
138
|
-
);
|
|
135
|
+
const astroConfig = await resolveConfig(userConfig, root, flags, configOptions.cmd);
|
|
139
136
|
return {
|
|
140
137
|
astroConfig,
|
|
141
138
|
userConfig,
|
|
@@ -144,6 +141,7 @@ async function openConfig(configOptions) {
|
|
|
144
141
|
};
|
|
145
142
|
}
|
|
146
143
|
async function tryLoadConfig(configOptions, flags, root) {
|
|
144
|
+
const fsMod = configOptions.fsMod ?? fs;
|
|
147
145
|
let finallyCleanup = async () => {
|
|
148
146
|
};
|
|
149
147
|
try {
|
|
@@ -158,7 +156,8 @@ async function tryLoadConfig(configOptions, flags, root) {
|
|
|
158
156
|
root,
|
|
159
157
|
`.temp.${Date.now()}.config${path.extname(configPath)}`
|
|
160
158
|
);
|
|
161
|
-
|
|
159
|
+
const currentConfigContent = await fsMod.promises.readFile(configPath, "utf-8");
|
|
160
|
+
await fs.promises.writeFile(tempConfigPath, currentConfigContent);
|
|
162
161
|
finallyCleanup = async () => {
|
|
163
162
|
try {
|
|
164
163
|
await fs.promises.unlink(tempConfigPath);
|
|
@@ -213,13 +212,16 @@ async function loadConfig(configOptions) {
|
|
|
213
212
|
if (config) {
|
|
214
213
|
userConfig = config.value;
|
|
215
214
|
}
|
|
216
|
-
return resolveConfig(userConfig, root, flags, configOptions.cmd
|
|
215
|
+
return resolveConfig(userConfig, root, flags, configOptions.cmd);
|
|
217
216
|
}
|
|
218
|
-
async function resolveConfig(userConfig, root, flags = {}, cmd
|
|
217
|
+
async function resolveConfig(userConfig, root, flags = {}, cmd) {
|
|
219
218
|
const mergedConfig = mergeCLIFlags(userConfig, flags, cmd);
|
|
220
|
-
const validatedConfig = await validateConfig(mergedConfig, root, cmd
|
|
219
|
+
const validatedConfig = await validateConfig(mergedConfig, root, cmd);
|
|
221
220
|
return validatedConfig;
|
|
222
221
|
}
|
|
222
|
+
function createDefaultDevConfig(userConfig = {}, root = process.cwd()) {
|
|
223
|
+
return resolveConfig(userConfig, root, void 0, "dev");
|
|
224
|
+
}
|
|
223
225
|
function mergeConfigRecursively(defaults, overrides, rootPath) {
|
|
224
226
|
const merged = { ...defaults };
|
|
225
227
|
for (const key in overrides) {
|
|
@@ -257,6 +259,7 @@ function mergeConfig(defaults, overrides, isRoot = true) {
|
|
|
257
259
|
}
|
|
258
260
|
export {
|
|
259
261
|
LEGACY_ASTRO_CONFIG_KEYS,
|
|
262
|
+
createDefaultDevConfig,
|
|
260
263
|
loadConfig,
|
|
261
264
|
mergeConfig,
|
|
262
265
|
openConfig,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { openConfig, resolveConfigPath, resolveFlags, resolveRoot, validateConfig, } from './config.js';
|
|
1
|
+
export { createDefaultDevConfig, openConfig, resolveConfigPath, resolveFlags, resolveRoot, validateConfig, } from './config.js';
|
|
2
2
|
export type { AstroConfigSchema } from './schema';
|
|
3
|
-
export { createSettings } from './settings.js';
|
|
3
|
+
export { createDefaultDevSettings, createSettings } from './settings.js';
|
|
4
4
|
export { loadTSConfig, updateTSConfigForFramework } from './tsconfig.js';
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
+
createDefaultDevConfig,
|
|
2
3
|
openConfig,
|
|
3
4
|
resolveConfigPath,
|
|
4
5
|
resolveFlags,
|
|
5
6
|
resolveRoot,
|
|
6
7
|
validateConfig
|
|
7
8
|
} from "./config.js";
|
|
8
|
-
import { createSettings } from "./settings.js";
|
|
9
|
+
import { createDefaultDevSettings, createSettings } from "./settings.js";
|
|
9
10
|
import { loadTSConfig, updateTSConfigForFramework } from "./tsconfig.js";
|
|
10
11
|
export {
|
|
12
|
+
createDefaultDevConfig,
|
|
13
|
+
createDefaultDevSettings,
|
|
11
14
|
createSettings,
|
|
12
15
|
loadTSConfig,
|
|
13
16
|
openConfig,
|