astro 2.8.1 → 2.8.2
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 +1 -1
- package/dist/cli/build/index.d.ts +8 -0
- package/dist/cli/build/index.js +16 -0
- package/dist/cli/check/index.d.ts +1 -2
- package/dist/cli/check/index.js +5 -1
- package/dist/cli/dev/index.d.ts +8 -0
- package/dist/cli/dev/index.js +26 -0
- package/dist/cli/index.js +29 -76
- package/dist/cli/load-settings.d.ts +15 -0
- package/dist/cli/load-settings.js +39 -0
- package/dist/cli/preview/index.d.ts +8 -0
- package/dist/cli/preview/index.js +11 -0
- package/dist/cli/sync/index.d.ts +8 -0
- package/dist/cli/sync/index.js +13 -0
- package/dist/core/config/config.d.ts +0 -1
- package/dist/core/config/config.js +14 -78
- package/dist/core/config/index.d.ts +1 -0
- package/dist/core/config/index.js +2 -0
- package/dist/core/config/merge.d.ts +1 -0
- package/dist/core/config/merge.js +40 -0
- package/dist/core/config/vite-load.d.ts +2 -10
- package/dist/core/config/vite-load.js +15 -28
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/events/error.js +1 -5
- package/dist/integrations/index.js +1 -1
- package/dist/runtime/server/response.js +7 -0
- package/package.json +1 -1
package/dist/@types/astro.d.ts
CHANGED
|
@@ -788,7 +788,7 @@ export interface AstroUserConfig {
|
|
|
788
788
|
* @docs
|
|
789
789
|
* @name build.excludeMiddleware
|
|
790
790
|
* @type {boolean}
|
|
791
|
-
* @default
|
|
791
|
+
* @default `false`
|
|
792
792
|
* @version 2.8.0
|
|
793
793
|
* @description
|
|
794
794
|
* Defines whether or not any SSR middleware code will be bundled when built.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type yargs from 'yargs-parser';
|
|
2
|
+
import type { LogOptions } from '../../core/logger/core.js';
|
|
3
|
+
interface BuildOptions {
|
|
4
|
+
flags: yargs.Arguments;
|
|
5
|
+
logging: LogOptions;
|
|
6
|
+
}
|
|
7
|
+
export declare function build({ flags, logging }: BuildOptions): Promise<void>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _build from "../../core/build/index.js";
|
|
2
|
+
import { loadSettings } from "../load-settings.js";
|
|
3
|
+
async function build({ flags, logging }) {
|
|
4
|
+
const settings = await loadSettings({ cmd: "build", flags, logging });
|
|
5
|
+
if (!settings)
|
|
6
|
+
return;
|
|
7
|
+
await _build(settings, {
|
|
8
|
+
flags,
|
|
9
|
+
logging,
|
|
10
|
+
teardownCompiler: true,
|
|
11
|
+
mode: flags.mode
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
build
|
|
16
|
+
};
|
|
@@ -41,12 +41,11 @@ export declare enum CheckResult {
|
|
|
41
41
|
*
|
|
42
42
|
* Every time an astro files is modified, content collections are also generated.
|
|
43
43
|
*
|
|
44
|
-
* @param {AstroSettings} settings
|
|
45
44
|
* @param {CheckPayload} options Options passed {@link AstroChecker}
|
|
46
45
|
* @param {Flags} options.flags Flags coming from the CLI
|
|
47
46
|
* @param {LogOptions} options.logging Logging options
|
|
48
47
|
*/
|
|
49
|
-
export declare function check(
|
|
48
|
+
export declare function check({ logging, flags }: CheckPayload): Promise<AstroChecker | undefined>;
|
|
50
49
|
type CheckerConstructor = {
|
|
51
50
|
diagnosticChecker: AstroCheck;
|
|
52
51
|
isWatchMode: boolean;
|
package/dist/cli/check/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import ora from "ora";
|
|
|
11
11
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
12
12
|
import { debug, info } from "../../core/logger/core.js";
|
|
13
13
|
import { printHelp } from "../../core/messages.js";
|
|
14
|
+
import { loadSettings } from "../load-settings.js";
|
|
14
15
|
import { printDiagnostic } from "./print.js";
|
|
15
16
|
var CheckResult = /* @__PURE__ */ ((CheckResult2) => {
|
|
16
17
|
CheckResult2[CheckResult2["ExitWithSuccess"] = 0] = "ExitWithSuccess";
|
|
@@ -19,7 +20,7 @@ var CheckResult = /* @__PURE__ */ ((CheckResult2) => {
|
|
|
19
20
|
return CheckResult2;
|
|
20
21
|
})(CheckResult || {});
|
|
21
22
|
const ASTRO_GLOB_PATTERN = "**/*.astro";
|
|
22
|
-
async function check(
|
|
23
|
+
async function check({ logging, flags }) {
|
|
23
24
|
if (flags.help || flags.h) {
|
|
24
25
|
printHelp({
|
|
25
26
|
commandName: "astro check",
|
|
@@ -34,6 +35,9 @@ async function check(settings, { logging, flags }) {
|
|
|
34
35
|
});
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
38
|
+
const settings = await loadSettings({ cmd: "check", flags, logging });
|
|
39
|
+
if (!settings)
|
|
40
|
+
return;
|
|
37
41
|
const checkFlags = parseFlags(flags);
|
|
38
42
|
if (checkFlags.watch) {
|
|
39
43
|
info(logging, "check", "Checking files in watch mode");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type yargs from 'yargs-parser';
|
|
2
|
+
import { type LogOptions } from '../../core/logger/core.js';
|
|
3
|
+
interface DevOptions {
|
|
4
|
+
flags: yargs.Arguments;
|
|
5
|
+
logging: LogOptions;
|
|
6
|
+
}
|
|
7
|
+
export declare function dev({ flags, logging }: DevOptions): Promise<import("../../core/dev/dev.js").DevServer | undefined>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { resolveConfigPath, resolveFlags } from "../../core/config/index.js";
|
|
3
|
+
import devServer from "../../core/dev/index.js";
|
|
4
|
+
import { info } from "../../core/logger/core.js";
|
|
5
|
+
import { handleConfigError, loadSettings } from "../load-settings.js";
|
|
6
|
+
async function dev({ flags, logging }) {
|
|
7
|
+
const settings = await loadSettings({ cmd: "dev", flags, logging });
|
|
8
|
+
if (!settings)
|
|
9
|
+
return;
|
|
10
|
+
const root = flags.root;
|
|
11
|
+
const configFlag = resolveFlags(flags).config;
|
|
12
|
+
const configFlagPath = configFlag ? await resolveConfigPath({ cwd: root, flags, fs }) : void 0;
|
|
13
|
+
return await devServer(settings, {
|
|
14
|
+
configFlag,
|
|
15
|
+
configFlagPath,
|
|
16
|
+
flags,
|
|
17
|
+
logging,
|
|
18
|
+
handleConfigError(e) {
|
|
19
|
+
handleConfigError(e, { cmd: "dev", cwd: root, flags, logging });
|
|
20
|
+
info(logging, "astro", "Continuing with previous valid configuration\n");
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
dev
|
|
26
|
+
};
|
package/dist/cli/index.js
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
1
|
import * as colors from "kleur/colors";
|
|
3
2
|
import yargs from "yargs-parser";
|
|
4
|
-
import { ZodError } from "zod";
|
|
5
|
-
import {
|
|
6
|
-
createSettings,
|
|
7
|
-
openConfig,
|
|
8
|
-
resolveConfigPath,
|
|
9
|
-
resolveFlags
|
|
10
|
-
} from "../core/config/index.js";
|
|
11
3
|
import { ASTRO_VERSION } from "../core/constants.js";
|
|
12
4
|
import { collectErrorMetadata } from "../core/errors/dev/index.js";
|
|
13
5
|
import { createSafeError } from "../core/errors/index.js";
|
|
14
|
-
import { debug
|
|
6
|
+
import { debug } from "../core/logger/core.js";
|
|
15
7
|
import { enableVerboseLogging, nodeLogDestination } from "../core/logger/node.js";
|
|
16
|
-
import {
|
|
8
|
+
import { formatErrorMessage, printHelp } from "../core/messages.js";
|
|
17
9
|
import * as event from "../events/index.js";
|
|
18
|
-
import {
|
|
10
|
+
import { eventError, telemetry } from "../events/index.js";
|
|
19
11
|
function printAstroHelp() {
|
|
20
12
|
printHelp({
|
|
21
13
|
commandName: "astro",
|
|
@@ -70,20 +62,6 @@ function resolveCommand(flags) {
|
|
|
70
62
|
}
|
|
71
63
|
return "help";
|
|
72
64
|
}
|
|
73
|
-
async function handleConfigError(e, { cmd, cwd, flags, logging }) {
|
|
74
|
-
const path = await resolveConfigPath({ cwd, flags, fs });
|
|
75
|
-
error(logging, "astro", `Unable to load ${path ? colors.bold(path) : "your Astro config"}
|
|
76
|
-
`);
|
|
77
|
-
if (e instanceof ZodError) {
|
|
78
|
-
console.error(formatConfigErrorMessage(e) + "\n");
|
|
79
|
-
} else if (e instanceof Error) {
|
|
80
|
-
console.error(formatErrorMessage(collectErrorMetadata(e)) + "\n");
|
|
81
|
-
}
|
|
82
|
-
const telemetryPromise = telemetry.record(eventConfigError({ cmd, err: e, isFatal: true }));
|
|
83
|
-
await telemetryPromise.catch(
|
|
84
|
-
(err2) => debug("telemetry", `record() error: ${err2.message}`)
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
65
|
async function runCommand(cmd, flags) {
|
|
88
66
|
var _a;
|
|
89
67
|
const root = flags.root;
|
|
@@ -122,6 +100,9 @@ async function runCommand(cmd, flags) {
|
|
|
122
100
|
} else if (flags.silent) {
|
|
123
101
|
logging.level = "silent";
|
|
124
102
|
}
|
|
103
|
+
if (!process.env.NODE_ENV) {
|
|
104
|
+
process.env.NODE_ENV = cmd === "dev" ? "development" : "production";
|
|
105
|
+
}
|
|
125
106
|
switch (cmd) {
|
|
126
107
|
case "add": {
|
|
127
108
|
telemetry.record(event.eventCliSession(cmd));
|
|
@@ -130,52 +111,31 @@ async function runCommand(cmd, flags) {
|
|
|
130
111
|
await add(packages, { cwd: root, flags, logging });
|
|
131
112
|
return;
|
|
132
113
|
}
|
|
133
|
-
}
|
|
134
|
-
if (!process.env.NODE_ENV) {
|
|
135
|
-
process.env.NODE_ENV = cmd === "dev" ? "development" : "production";
|
|
136
|
-
}
|
|
137
|
-
let { astroConfig: initialAstroConfig, userConfig: initialUserConfig } = await openConfig({
|
|
138
|
-
cwd: root,
|
|
139
|
-
flags,
|
|
140
|
-
cmd
|
|
141
|
-
}).catch(async (e) => {
|
|
142
|
-
await handleConfigError(e, { cmd, cwd: root, flags, logging });
|
|
143
|
-
return {};
|
|
144
|
-
});
|
|
145
|
-
if (!initialAstroConfig)
|
|
146
|
-
return;
|
|
147
|
-
telemetry.record(event.eventCliSession(cmd, initialUserConfig, flags));
|
|
148
|
-
let settings = createSettings(initialAstroConfig, root);
|
|
149
|
-
switch (cmd) {
|
|
150
114
|
case "dev": {
|
|
151
|
-
const {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
logging,
|
|
159
|
-
handleConfigError(e) {
|
|
160
|
-
handleConfigError(e, { cmd, cwd: root, flags, logging });
|
|
161
|
-
info(logging, "astro", "Continuing with previous valid configuration\n");
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
return await new Promise(() => {
|
|
165
|
-
});
|
|
115
|
+
const { dev } = await import("./dev/index.js");
|
|
116
|
+
const server = await dev({ flags, logging });
|
|
117
|
+
if (server) {
|
|
118
|
+
return await new Promise(() => {
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
166
122
|
}
|
|
167
123
|
case "build": {
|
|
168
|
-
const {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
});
|
|
124
|
+
const { build } = await import("./build/index.js");
|
|
125
|
+
await build({ flags, logging });
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
case "preview": {
|
|
129
|
+
const { preview } = await import("./preview/index.js");
|
|
130
|
+
const server = await preview({ flags, logging });
|
|
131
|
+
if (server) {
|
|
132
|
+
return await server.closed();
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
175
135
|
}
|
|
176
136
|
case "check": {
|
|
177
137
|
const { check } = await import("./check/index.js");
|
|
178
|
-
const checkServer = await check(
|
|
138
|
+
const checkServer = await check({ flags, logging });
|
|
179
139
|
if (checkServer) {
|
|
180
140
|
if (checkServer.isWatchMode) {
|
|
181
141
|
await checkServer.watch();
|
|
@@ -186,19 +146,12 @@ async function runCommand(cmd, flags) {
|
|
|
186
146
|
return process.exit(checkResult);
|
|
187
147
|
}
|
|
188
148
|
}
|
|
149
|
+
return;
|
|
189
150
|
}
|
|
190
151
|
case "sync": {
|
|
191
|
-
const {
|
|
192
|
-
const
|
|
193
|
-
return process.exit(
|
|
194
|
-
}
|
|
195
|
-
case "preview": {
|
|
196
|
-
const { default: preview } = await import("../core/preview/index.js");
|
|
197
|
-
const server = await preview(settings, { logging, flags });
|
|
198
|
-
if (server) {
|
|
199
|
-
return await server.closed();
|
|
200
|
-
}
|
|
201
|
-
return;
|
|
152
|
+
const { sync } = await import("./sync/index.js");
|
|
153
|
+
const exitCode = await sync({ flags, logging });
|
|
154
|
+
return process.exit(exitCode);
|
|
202
155
|
}
|
|
203
156
|
}
|
|
204
157
|
throw new Error(`Error running ${cmd} -- no command found.`);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Arguments as Flags } from 'yargs-parser';
|
|
2
|
+
import { type LogOptions } from '../core/logger/core.js';
|
|
3
|
+
interface LoadSettingsOptions {
|
|
4
|
+
cmd: string;
|
|
5
|
+
flags: Flags;
|
|
6
|
+
logging: LogOptions;
|
|
7
|
+
}
|
|
8
|
+
export declare function loadSettings({ cmd, flags, logging }: LoadSettingsOptions): Promise<import("../@types/astro.js").AstroSettings | undefined>;
|
|
9
|
+
export declare function handleConfigError(e: any, { cmd, cwd, flags, logging }: {
|
|
10
|
+
cmd: string;
|
|
11
|
+
cwd?: string;
|
|
12
|
+
flags?: Flags;
|
|
13
|
+
logging: LogOptions;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import * as colors from "kleur/colors";
|
|
3
|
+
import { ZodError } from "zod";
|
|
4
|
+
import { createSettings, openConfig, resolveConfigPath } from "../core/config/index.js";
|
|
5
|
+
import { collectErrorMetadata } from "../core/errors/dev/index.js";
|
|
6
|
+
import { error } from "../core/logger/core.js";
|
|
7
|
+
import { formatConfigErrorMessage, formatErrorMessage } from "../core/messages.js";
|
|
8
|
+
import * as event from "../events/index.js";
|
|
9
|
+
import { eventConfigError, telemetry } from "../events/index.js";
|
|
10
|
+
async function loadSettings({ cmd, flags, logging }) {
|
|
11
|
+
const root = flags.root;
|
|
12
|
+
const { astroConfig: initialAstroConfig, userConfig: initialUserConfig } = await openConfig({
|
|
13
|
+
cwd: root,
|
|
14
|
+
flags,
|
|
15
|
+
cmd
|
|
16
|
+
}).catch(async (e) => {
|
|
17
|
+
await handleConfigError(e, { cmd, cwd: root, flags, logging });
|
|
18
|
+
return {};
|
|
19
|
+
});
|
|
20
|
+
if (!initialAstroConfig)
|
|
21
|
+
return;
|
|
22
|
+
telemetry.record(event.eventCliSession(cmd, initialUserConfig, flags));
|
|
23
|
+
return createSettings(initialAstroConfig, root);
|
|
24
|
+
}
|
|
25
|
+
async function handleConfigError(e, { cmd, cwd, flags, logging }) {
|
|
26
|
+
const path = await resolveConfigPath({ cwd, flags, fs });
|
|
27
|
+
error(logging, "astro", `Unable to load ${path ? colors.bold(path) : "your Astro config"}
|
|
28
|
+
`);
|
|
29
|
+
if (e instanceof ZodError) {
|
|
30
|
+
console.error(formatConfigErrorMessage(e) + "\n");
|
|
31
|
+
telemetry.record(eventConfigError({ cmd, err: e, isFatal: true }));
|
|
32
|
+
} else if (e instanceof Error) {
|
|
33
|
+
console.error(formatErrorMessage(collectErrorMetadata(e)) + "\n");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
handleConfigError,
|
|
38
|
+
loadSettings
|
|
39
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type yargs from 'yargs-parser';
|
|
2
|
+
import type { LogOptions } from '../../core/logger/core.js';
|
|
3
|
+
interface PreviewOptions {
|
|
4
|
+
flags: yargs.Arguments;
|
|
5
|
+
logging: LogOptions;
|
|
6
|
+
}
|
|
7
|
+
export declare function preview({ flags, logging }: PreviewOptions): Promise<import("../../@types/astro.js").PreviewServer | undefined>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import previewServer from "../../core/preview/index.js";
|
|
2
|
+
import { loadSettings } from "../load-settings.js";
|
|
3
|
+
async function preview({ flags, logging }) {
|
|
4
|
+
const settings = await loadSettings({ cmd: "preview", flags, logging });
|
|
5
|
+
if (!settings)
|
|
6
|
+
return;
|
|
7
|
+
return await previewServer(settings, { flags, logging });
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
preview
|
|
11
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type yargs from 'yargs-parser';
|
|
2
|
+
import type { LogOptions } from '../../core/logger/core.js';
|
|
3
|
+
interface SyncOptions {
|
|
4
|
+
flags: yargs.Arguments;
|
|
5
|
+
logging: LogOptions;
|
|
6
|
+
}
|
|
7
|
+
export declare function sync({ flags, logging }: SyncOptions): Promise<import("../../core/sync/index.js").ProcessExit | undefined>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { syncCli } from "../../core/sync/index.js";
|
|
3
|
+
import { loadSettings } from "../load-settings.js";
|
|
4
|
+
async function sync({ flags, logging }) {
|
|
5
|
+
const settings = await loadSettings({ cmd: "sync", flags, logging });
|
|
6
|
+
if (!settings)
|
|
7
|
+
return;
|
|
8
|
+
const exitCode = await syncCli(settings, { logging, fs, flags });
|
|
9
|
+
return exitCode;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
sync
|
|
13
|
+
};
|
|
@@ -37,5 +37,4 @@ export declare function openConfig(configOptions: LoadConfigOptions): Promise<Op
|
|
|
37
37
|
/** Attempt to resolve an Astro configuration object. Normalize, validate, and return. */
|
|
38
38
|
export declare function resolveConfig(userConfig: AstroUserConfig, root: string, flags: CLIFlags | undefined, cmd: string): Promise<AstroConfig>;
|
|
39
39
|
export declare function createDefaultDevConfig(userConfig?: AstroUserConfig, root?: string): Promise<AstroConfig>;
|
|
40
|
-
export declare function mergeConfig(defaults: Record<string, any>, overrides: Record<string, any>, isRoot?: boolean): Record<string, any>;
|
|
41
40
|
export {};
|
|
@@ -2,9 +2,7 @@ import fs from "fs";
|
|
|
2
2
|
import * as colors from "kleur/colors";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
5
|
-
import { mergeConfig as mergeViteConfig } from "vite";
|
|
6
5
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
7
|
-
import { arraify, isObject, isURL } from "../util.js";
|
|
8
6
|
import { createRelativeSchema } from "./schema.js";
|
|
9
7
|
import { loadConfigWithVite } from "./vite-load.js";
|
|
10
8
|
const LEGACY_ASTRO_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -142,11 +140,7 @@ async function resolveConfigPath(configOptions) {
|
|
|
142
140
|
async function openConfig(configOptions) {
|
|
143
141
|
const root = resolveRoot(configOptions.cwd);
|
|
144
142
|
const flags = resolveFlags(configOptions.flags || {});
|
|
145
|
-
|
|
146
|
-
const config = await tryLoadConfig(configOptions, root);
|
|
147
|
-
if (config) {
|
|
148
|
-
userConfig = config.value;
|
|
149
|
-
}
|
|
143
|
+
const userConfig = await loadConfig(configOptions, root);
|
|
150
144
|
const astroConfig = await resolveConfig(userConfig, root, flags, configOptions.cmd);
|
|
151
145
|
return {
|
|
152
146
|
astroConfig,
|
|
@@ -155,42 +149,20 @@ async function openConfig(configOptions) {
|
|
|
155
149
|
root
|
|
156
150
|
};
|
|
157
151
|
}
|
|
158
|
-
async function
|
|
152
|
+
async function loadConfig(configOptions, root) {
|
|
159
153
|
const fsMod = configOptions.fsMod ?? fs;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
root,
|
|
173
|
-
`.temp.${Date.now()}.config${path.extname(configPath)}`
|
|
174
|
-
);
|
|
175
|
-
const currentConfigContent = await fsMod.promises.readFile(configPath, "utf-8");
|
|
176
|
-
await fs.promises.writeFile(tempConfigPath, currentConfigContent);
|
|
177
|
-
finallyCleanup = async () => {
|
|
178
|
-
try {
|
|
179
|
-
await fs.promises.unlink(tempConfigPath);
|
|
180
|
-
} catch {
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
configPath = tempConfigPath;
|
|
184
|
-
}
|
|
185
|
-
const config = await loadConfigWithVite({
|
|
186
|
-
configPath,
|
|
187
|
-
fs: fsMod,
|
|
188
|
-
root
|
|
189
|
-
});
|
|
190
|
-
return config;
|
|
191
|
-
} finally {
|
|
192
|
-
await finallyCleanup();
|
|
193
|
-
}
|
|
154
|
+
const configPath = await resolveConfigPath({
|
|
155
|
+
cwd: configOptions.cwd,
|
|
156
|
+
flags: configOptions.flags,
|
|
157
|
+
fs: fsMod
|
|
158
|
+
});
|
|
159
|
+
if (!configPath)
|
|
160
|
+
return {};
|
|
161
|
+
return await loadConfigWithVite({
|
|
162
|
+
configPath,
|
|
163
|
+
fs: fsMod,
|
|
164
|
+
root
|
|
165
|
+
});
|
|
194
166
|
}
|
|
195
167
|
async function resolveConfig(userConfig, root, flags = {}, cmd) {
|
|
196
168
|
const mergedConfig = mergeCLIFlags(userConfig, flags);
|
|
@@ -200,45 +172,9 @@ async function resolveConfig(userConfig, root, flags = {}, cmd) {
|
|
|
200
172
|
function createDefaultDevConfig(userConfig = {}, root = process.cwd()) {
|
|
201
173
|
return resolveConfig(userConfig, root, void 0, "dev");
|
|
202
174
|
}
|
|
203
|
-
function mergeConfigRecursively(defaults, overrides, rootPath) {
|
|
204
|
-
const merged = { ...defaults };
|
|
205
|
-
for (const key in overrides) {
|
|
206
|
-
const value = overrides[key];
|
|
207
|
-
if (value == null) {
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
const existing = merged[key];
|
|
211
|
-
if (existing == null) {
|
|
212
|
-
merged[key] = value;
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
if (key === "vite" && rootPath === "") {
|
|
216
|
-
merged[key] = mergeViteConfig(existing, value);
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
if (Array.isArray(existing) || Array.isArray(value)) {
|
|
220
|
-
merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])];
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
if (isURL(existing) && isURL(value)) {
|
|
224
|
-
merged[key] = value;
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (isObject(existing) && isObject(value)) {
|
|
228
|
-
merged[key] = mergeConfigRecursively(existing, value, rootPath ? `${rootPath}.${key}` : key);
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
merged[key] = value;
|
|
232
|
-
}
|
|
233
|
-
return merged;
|
|
234
|
-
}
|
|
235
|
-
function mergeConfig(defaults, overrides, isRoot = true) {
|
|
236
|
-
return mergeConfigRecursively(defaults, overrides, isRoot ? "" : ".");
|
|
237
|
-
}
|
|
238
175
|
export {
|
|
239
176
|
LEGACY_ASTRO_CONFIG_KEYS,
|
|
240
177
|
createDefaultDevConfig,
|
|
241
|
-
mergeConfig,
|
|
242
178
|
openConfig,
|
|
243
179
|
resolveConfig,
|
|
244
180
|
resolveConfigPath,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createDefaultDevConfig, openConfig, resolveConfigPath, resolveFlags, resolveRoot, validateConfig, } from './config.js';
|
|
2
|
+
export { mergeConfig } from './merge.js';
|
|
2
3
|
export type { AstroConfigSchema } from './schema';
|
|
3
4
|
export { createDefaultDevSettings, createSettings } from './settings.js';
|
|
4
5
|
export { loadTSConfig, updateTSConfigForFramework } from './tsconfig.js';
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
resolveRoot,
|
|
7
7
|
validateConfig
|
|
8
8
|
} from "./config.js";
|
|
9
|
+
import { mergeConfig } from "./merge.js";
|
|
9
10
|
import { createDefaultDevSettings, createSettings } from "./settings.js";
|
|
10
11
|
import { loadTSConfig, updateTSConfigForFramework } from "./tsconfig.js";
|
|
11
12
|
export {
|
|
@@ -13,6 +14,7 @@ export {
|
|
|
13
14
|
createDefaultDevSettings,
|
|
14
15
|
createSettings,
|
|
15
16
|
loadTSConfig,
|
|
17
|
+
mergeConfig,
|
|
16
18
|
openConfig,
|
|
17
19
|
resolveConfigPath,
|
|
18
20
|
resolveFlags,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mergeConfig(defaults: Record<string, any>, overrides: Record<string, any>, isRoot?: boolean): Record<string, any>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { mergeConfig as mergeViteConfig } from "vite";
|
|
2
|
+
import { arraify, isObject, isURL } from "../util.js";
|
|
3
|
+
function mergeConfigRecursively(defaults, overrides, rootPath) {
|
|
4
|
+
const merged = { ...defaults };
|
|
5
|
+
for (const key in overrides) {
|
|
6
|
+
const value = overrides[key];
|
|
7
|
+
if (value == null) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
const existing = merged[key];
|
|
11
|
+
if (existing == null) {
|
|
12
|
+
merged[key] = value;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (key === "vite" && rootPath === "") {
|
|
16
|
+
merged[key] = mergeViteConfig(existing, value);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(existing) || Array.isArray(value)) {
|
|
20
|
+
merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])];
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (isURL(existing) && isURL(value)) {
|
|
24
|
+
merged[key] = value;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (isObject(existing) && isObject(value)) {
|
|
28
|
+
merged[key] = mergeConfigRecursively(existing, value, rootPath ? `${rootPath}.${key}` : key);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
merged[key] = value;
|
|
32
|
+
}
|
|
33
|
+
return merged;
|
|
34
|
+
}
|
|
35
|
+
function mergeConfig(defaults, overrides, isRoot = true) {
|
|
36
|
+
return mergeConfigRecursively(defaults, overrides, isRoot ? "" : ".");
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
mergeConfig
|
|
40
|
+
};
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type fsType from 'fs';
|
|
3
|
-
import * as vite from 'vite';
|
|
4
|
-
export interface ViteLoader {
|
|
5
|
-
root: string;
|
|
6
|
-
viteServer: vite.ViteDevServer;
|
|
7
|
-
}
|
|
8
3
|
interface LoadConfigWithViteOptions {
|
|
9
4
|
root: string;
|
|
10
|
-
configPath: string
|
|
5
|
+
configPath: string;
|
|
11
6
|
fs: typeof fsType;
|
|
12
7
|
}
|
|
13
|
-
export declare function loadConfigWithVite({ configPath, fs, root, }: LoadConfigWithViteOptions): Promise<
|
|
14
|
-
value: Record<string, any>;
|
|
15
|
-
filePath?: string;
|
|
16
|
-
}>;
|
|
8
|
+
export declare function loadConfigWithVite({ configPath, fs, root, }: LoadConfigWithViteOptions): Promise<Record<string, any>>;
|
|
17
9
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { pathToFileURL } from "url";
|
|
2
|
-
import
|
|
2
|
+
import { createServer } from "vite";
|
|
3
3
|
import loadFallbackPlugin from "../../vite-plugin-load-fallback/index.js";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { debug } from "../logger/core.js";
|
|
5
|
+
async function createViteServer(root, fs) {
|
|
6
|
+
const viteServer = await createServer({
|
|
6
7
|
server: { middlewareMode: true, hmr: false, watch: { ignored: ["**"] } },
|
|
7
8
|
optimizeDeps: { disabled: true },
|
|
8
9
|
clearScreen: false,
|
|
@@ -22,43 +23,29 @@ async function createViteLoader(root, fs) {
|
|
|
22
23
|
},
|
|
23
24
|
plugins: [loadFallbackPlugin({ fs, root: pathToFileURL(root) })]
|
|
24
25
|
});
|
|
25
|
-
return
|
|
26
|
-
root,
|
|
27
|
-
viteServer
|
|
28
|
-
};
|
|
26
|
+
return viteServer;
|
|
29
27
|
}
|
|
30
28
|
async function loadConfigWithVite({
|
|
31
29
|
configPath,
|
|
32
30
|
fs,
|
|
33
31
|
root
|
|
34
32
|
}) {
|
|
35
|
-
if (!configPath) {
|
|
36
|
-
return {
|
|
37
|
-
value: {},
|
|
38
|
-
filePath: void 0
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
33
|
if (/\.[cm]?js$/.test(configPath)) {
|
|
42
34
|
try {
|
|
43
|
-
const config = await import(pathToFileURL(configPath).toString());
|
|
44
|
-
return {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
} catch {
|
|
35
|
+
const config = await import(pathToFileURL(configPath).toString() + "?t=" + Date.now());
|
|
36
|
+
return config.default ?? {};
|
|
37
|
+
} catch (e) {
|
|
38
|
+
debug("Failed to load config with Node", e);
|
|
49
39
|
}
|
|
50
40
|
}
|
|
51
|
-
let
|
|
41
|
+
let server;
|
|
52
42
|
try {
|
|
53
|
-
|
|
54
|
-
const mod = await
|
|
55
|
-
return {
|
|
56
|
-
value: mod.default ?? {},
|
|
57
|
-
filePath: configPath
|
|
58
|
-
};
|
|
43
|
+
server = await createViteServer(root, fs);
|
|
44
|
+
const mod = await server.ssrLoadModule(configPath, { fixStacktrace: true });
|
|
45
|
+
return mod.default ?? {};
|
|
59
46
|
} finally {
|
|
60
|
-
if (
|
|
61
|
-
await
|
|
47
|
+
if (server) {
|
|
48
|
+
await server.close();
|
|
62
49
|
}
|
|
63
50
|
}
|
|
64
51
|
}
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -54,7 +54,7 @@ async function dev(settings, options) {
|
|
|
54
54
|
isRestart: options.isRestart
|
|
55
55
|
})
|
|
56
56
|
);
|
|
57
|
-
const currentVersion = "2.8.
|
|
57
|
+
const currentVersion = "2.8.2";
|
|
58
58
|
if (currentVersion.includes("-")) {
|
|
59
59
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
60
60
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
base,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "2.8.
|
|
50
|
+
const version = "2.8.2";
|
|
51
51
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
52
52
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
53
53
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -233,7 +233,7 @@ function printHelp({
|
|
|
233
233
|
message.push(
|
|
234
234
|
linebreak(),
|
|
235
235
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
236
|
-
`v${"2.8.
|
|
236
|
+
`v${"2.8.2"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
package/dist/events/error.js
CHANGED
|
@@ -33,11 +33,7 @@ function eventError({
|
|
|
33
33
|
plugin: err.plugin,
|
|
34
34
|
cliCommand: cmd,
|
|
35
35
|
isFatal,
|
|
36
|
-
anonymousMessageHint: (
|
|
37
|
-
// https://github.com/typescript-eslint/typescript-eslint/issues/4820
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- errorData may be false
|
|
39
|
-
errorData && errorData.message ? getSafeErrorMessage(errorData.message) : anonymizeErrorMessage(err.message)
|
|
40
|
-
)
|
|
36
|
+
anonymousMessageHint: errorData && errorData.message ? getSafeErrorMessage(errorData.message) : anonymizeErrorMessage(err.message)
|
|
41
37
|
};
|
|
42
38
|
return [{ eventName: EVENT_ERROR, payload }];
|
|
43
39
|
}
|
|
@@ -2,7 +2,7 @@ import { bold } from "kleur/colors";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { buildClientDirectiveEntrypoint } from "../core/client-directive/index.js";
|
|
5
|
-
import { mergeConfig } from "../core/config/
|
|
5
|
+
import { mergeConfig } from "../core/config/index.js";
|
|
6
6
|
import { info } from "../core/logger/core.js";
|
|
7
7
|
import { isServerLikeOutput } from "../prerender/utils.js";
|
|
8
8
|
async function withTakingALongTimeMsg({
|
|
@@ -45,6 +45,13 @@ function createResponseClass() {
|
|
|
45
45
|
}
|
|
46
46
|
return super.arrayBuffer();
|
|
47
47
|
}
|
|
48
|
+
clone() {
|
|
49
|
+
return new StreamingCompatibleResponse(this.#body, {
|
|
50
|
+
status: this.status,
|
|
51
|
+
statusText: this.statusText,
|
|
52
|
+
headers: this.headers
|
|
53
|
+
});
|
|
54
|
+
}
|
|
48
55
|
};
|
|
49
56
|
return StreamingCompatibleResponse;
|
|
50
57
|
}
|