astro 2.9.5 → 2.9.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 -2
- package/dist/cli/add/index.d.ts +1 -3
- package/dist/cli/add/index.js +11 -4
- package/dist/cli/build/index.d.ts +1 -3
- package/dist/cli/build/index.js +19 -9
- package/dist/cli/check/index.d.ts +4 -9
- package/dist/cli/check/index.js +23 -11
- package/dist/cli/dev/index.d.ts +1 -3
- package/dist/cli/dev/index.js +24 -20
- package/dist/cli/flags.d.ts +9 -0
- package/dist/cli/flags.js +40 -0
- package/dist/cli/index.js +7 -14
- package/dist/cli/info/index.js +4 -6
- package/dist/cli/preview/index.d.ts +1 -3
- package/dist/cli/preview/index.js +21 -5
- package/dist/cli/sync/index.d.ts +1 -3
- package/dist/cli/sync/index.js +17 -8
- package/dist/cli/throw-and-exit.js +3 -0
- package/dist/config/index.js +2 -2
- package/dist/core/app/index.d.ts +6 -1
- package/dist/core/app/index.js +81 -61
- package/dist/core/build/index.d.ts +2 -7
- package/dist/core/build/index.js +18 -20
- package/dist/core/config/config.d.ts +6 -22
- package/dist/core/config/config.js +55 -54
- package/dist/core/config/index.d.ts +3 -2
- package/dist/core/config/index.js +6 -14
- package/dist/core/config/logging.d.ts +3 -0
- package/dist/core/config/logging.js +12 -0
- package/dist/core/config/settings.d.ts +1 -2
- package/dist/core/config/settings.js +0 -9
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/container.d.ts +6 -16
- package/dist/core/dev/container.js +8 -27
- package/dist/core/dev/dev.d.ts +2 -12
- package/dist/core/dev/dev.js +12 -43
- package/dist/core/dev/index.d.ts +1 -1
- package/dist/core/dev/index.js +1 -2
- package/dist/core/dev/restart.d.ts +9 -15
- package/dist/core/dev/restart.js +36 -56
- package/dist/core/errors/errors.d.ts +10 -0
- package/dist/core/errors/errors.js +10 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/preview/index.d.ts +2 -9
- package/dist/core/preview/index.js +12 -21
- package/dist/core/routing/manifest/serialization.js +4 -1
- package/dist/core/sync/index.d.ts +14 -10
- package/dist/core/sync/index.js +19 -20
- package/dist/core/util.js +2 -2
- package/dist/runtime/server/astro-island.js +16 -1
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/render/component.js +11 -8
- package/dist/vite-plugin-scanner/index.js +4 -1
- package/package.json +1 -1
- package/dist/cli/load-settings.d.ts +0 -15
- package/dist/cli/load-settings.js +0 -39
package/dist/core/app/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import { matchRoute } from "../routing/match.js";
|
|
|
20
20
|
import { deserializeManifest } from "./common.js";
|
|
21
21
|
const clientLocalsSymbol = Symbol.for("astro.locals");
|
|
22
22
|
const responseSentSymbol = Symbol.for("astro.responseSent");
|
|
23
|
+
const STATUS_CODES = /* @__PURE__ */ new Set([404, 500]);
|
|
23
24
|
class App {
|
|
24
25
|
/**
|
|
25
26
|
* The current environment of the application
|
|
@@ -91,46 +92,28 @@ class App {
|
|
|
91
92
|
}
|
|
92
93
|
return pathname;
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
// Disable no-unused-vars to avoid breaking signature change
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
97
|
+
match(request, _opts = {}) {
|
|
95
98
|
const url = new URL(request.url);
|
|
96
|
-
if (this.#manifest.assets.has(url.pathname))
|
|
99
|
+
if (this.#manifest.assets.has(url.pathname))
|
|
97
100
|
return void 0;
|
|
98
|
-
}
|
|
99
101
|
let pathname = prependForwardSlash(this.removeBase(url.pathname));
|
|
100
102
|
let routeData = matchRoute(pathname, this.#manifestData);
|
|
101
|
-
if (routeData)
|
|
102
|
-
if (routeData.prerender)
|
|
103
|
-
return void 0;
|
|
104
|
-
return routeData;
|
|
105
|
-
} else if (matchNotFound) {
|
|
106
|
-
const notFoundRouteData = matchRoute("/404", this.#manifestData);
|
|
107
|
-
if (notFoundRouteData == null ? void 0 : notFoundRouteData.prerender)
|
|
108
|
-
return void 0;
|
|
109
|
-
return notFoundRouteData;
|
|
110
|
-
} else {
|
|
103
|
+
if (!routeData || routeData.prerender)
|
|
111
104
|
return void 0;
|
|
112
|
-
|
|
105
|
+
return routeData;
|
|
113
106
|
}
|
|
114
107
|
async render(request, routeData, locals) {
|
|
115
|
-
let defaultStatus = 200;
|
|
116
108
|
if (!routeData) {
|
|
117
109
|
routeData = this.match(request);
|
|
118
|
-
if (!routeData) {
|
|
119
|
-
defaultStatus = 404;
|
|
120
|
-
routeData = this.match(request, { matchNotFound: true });
|
|
121
|
-
}
|
|
122
|
-
if (!routeData) {
|
|
123
|
-
return new Response(null, {
|
|
124
|
-
status: 404,
|
|
125
|
-
statusText: "Not found"
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
110
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
defaultStatus = 404;
|
|
111
|
+
if (!routeData) {
|
|
112
|
+
return this.#renderError(request, { routeData, status: 404 });
|
|
132
113
|
}
|
|
133
|
-
|
|
114
|
+
Reflect.set(request, clientLocalsSymbol, locals ?? {});
|
|
115
|
+
const defaultStatus = this.#getDefaultStatusCode(routeData.route);
|
|
116
|
+
const mod = await this.#getModuleForRoute(routeData);
|
|
134
117
|
const pageModule = await mod.page();
|
|
135
118
|
const url = new URL(request.url);
|
|
136
119
|
const renderContext = await this.#createRenderContext(
|
|
@@ -151,46 +134,26 @@ class App {
|
|
|
151
134
|
);
|
|
152
135
|
} catch (err) {
|
|
153
136
|
error(this.#logging, "ssr", err.stack || err.message || String(err));
|
|
154
|
-
|
|
155
|
-
status: 500,
|
|
156
|
-
statusText: "Internal server error"
|
|
157
|
-
});
|
|
137
|
+
return this.#renderError(request, { routeData, status: 500 });
|
|
158
138
|
}
|
|
159
139
|
if (isResponse(response, routeData.type)) {
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
url,
|
|
167
|
-
request,
|
|
168
|
-
routeData,
|
|
169
|
-
mod,
|
|
170
|
-
response.status
|
|
171
|
-
);
|
|
172
|
-
const page = await mod.page();
|
|
173
|
-
const errorResponse = await tryRenderRoute(
|
|
174
|
-
routeData.type,
|
|
175
|
-
newRenderContext,
|
|
176
|
-
this.#env,
|
|
177
|
-
page
|
|
178
|
-
);
|
|
179
|
-
return errorResponse;
|
|
180
|
-
} catch {
|
|
181
|
-
}
|
|
182
|
-
}
|
|
140
|
+
if (STATUS_CODES.has(response.status)) {
|
|
141
|
+
return this.#renderError(request, {
|
|
142
|
+
routeData,
|
|
143
|
+
response,
|
|
144
|
+
status: response.status
|
|
145
|
+
});
|
|
183
146
|
}
|
|
184
147
|
Reflect.set(response, responseSentSymbol, true);
|
|
185
148
|
return response;
|
|
186
149
|
} else {
|
|
187
150
|
if (response.type === "response") {
|
|
188
151
|
if (response.response.headers.get("X-Astro-Response") === "Not-Found") {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
152
|
+
return this.#renderError(request, {
|
|
153
|
+
routeData,
|
|
154
|
+
response: response.response,
|
|
155
|
+
status: 404
|
|
156
|
+
});
|
|
194
157
|
}
|
|
195
158
|
return response.response;
|
|
196
159
|
} else {
|
|
@@ -265,6 +228,63 @@ class App {
|
|
|
265
228
|
});
|
|
266
229
|
}
|
|
267
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* If is a known error code, try sending the according page (e.g. 404.astro / 500.astro).
|
|
233
|
+
* This also handles pre-rendered /404 or /500 routes
|
|
234
|
+
*/
|
|
235
|
+
async #renderError(request, { routeData, status, response: originalResponse }) {
|
|
236
|
+
const errorRouteData = matchRoute("/" + status, this.#manifestData);
|
|
237
|
+
const url = new URL(request.url);
|
|
238
|
+
if (errorRouteData) {
|
|
239
|
+
if (errorRouteData.prerender && !errorRouteData.route.endsWith(`/${status}`)) {
|
|
240
|
+
const statusURL = new URL(`${this.#baseWithoutTrailingSlash}/${status}`, url);
|
|
241
|
+
const response2 = await fetch(statusURL.toString());
|
|
242
|
+
return this.#mergeResponses(response2, originalResponse);
|
|
243
|
+
}
|
|
244
|
+
const finalRouteData = routeData ?? errorRouteData;
|
|
245
|
+
const mod = await this.#getModuleForRoute(errorRouteData);
|
|
246
|
+
try {
|
|
247
|
+
const newRenderContext = await this.#createRenderContext(
|
|
248
|
+
url,
|
|
249
|
+
request,
|
|
250
|
+
finalRouteData,
|
|
251
|
+
mod,
|
|
252
|
+
status
|
|
253
|
+
);
|
|
254
|
+
const page = await mod.page();
|
|
255
|
+
const response2 = await tryRenderRoute(
|
|
256
|
+
"page",
|
|
257
|
+
// this is hardcoded to ensure proper behavior for missing endpoints
|
|
258
|
+
newRenderContext,
|
|
259
|
+
this.#env,
|
|
260
|
+
page
|
|
261
|
+
);
|
|
262
|
+
return this.#mergeResponses(response2, originalResponse);
|
|
263
|
+
} catch {
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const response = this.#mergeResponses(new Response(null, { status }), originalResponse);
|
|
267
|
+
Reflect.set(response, responseSentSymbol, true);
|
|
268
|
+
return response;
|
|
269
|
+
}
|
|
270
|
+
#mergeResponses(newResponse, oldResponse) {
|
|
271
|
+
if (!oldResponse)
|
|
272
|
+
return newResponse;
|
|
273
|
+
const { status, statusText, headers } = oldResponse;
|
|
274
|
+
return new Response(newResponse.body, {
|
|
275
|
+
status: status === 200 ? newResponse.status : status,
|
|
276
|
+
statusText,
|
|
277
|
+
headers: new Headers(Array.from(headers))
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
#getDefaultStatusCode(route) {
|
|
281
|
+
route = removeTrailingForwardSlash(route);
|
|
282
|
+
if (route.endsWith("/404"))
|
|
283
|
+
return 404;
|
|
284
|
+
if (route.endsWith("/500"))
|
|
285
|
+
return 500;
|
|
286
|
+
return 200;
|
|
287
|
+
}
|
|
268
288
|
async #getModuleForRoute(route) {
|
|
269
289
|
if (route.type === "redirect") {
|
|
270
290
|
return RedirectSinglePageBuiltModule;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { AstroSettings, RuntimeMode } from '../../@types/astro';
|
|
3
|
-
import { type LogOptions } from '../logger/core.js';
|
|
1
|
+
import type { AstroInlineConfig } from '../../@types/astro';
|
|
4
2
|
export interface BuildOptions {
|
|
5
|
-
mode?: RuntimeMode;
|
|
6
|
-
logging: LogOptions;
|
|
7
3
|
/**
|
|
8
4
|
* Teardown the compiler WASM instance after build. This can improve performance when
|
|
9
5
|
* building once, but may cause a performance hit if building multiple times in a row.
|
|
10
6
|
*/
|
|
11
7
|
teardownCompiler?: boolean;
|
|
12
|
-
flags?: yargs.Arguments;
|
|
13
8
|
}
|
|
14
9
|
/** `astro build` */
|
|
15
|
-
export default function build(
|
|
10
|
+
export default function build(inlineConfig: AstroInlineConfig, options: BuildOptions): Promise<void>;
|
package/dist/core/build/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as colors from "kleur/colors";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { performance } from "node:perf_hooks";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { injectImageEndpoint } from "../../assets/internal.js";
|
|
6
|
+
import { telemetry } from "../../events/index.js";
|
|
7
|
+
import { eventCliSession } from "../../events/session.js";
|
|
5
8
|
import {
|
|
6
9
|
runHookBuildDone,
|
|
7
10
|
runHookBuildStart,
|
|
@@ -9,33 +12,28 @@ import {
|
|
|
9
12
|
runHookConfigSetup
|
|
10
13
|
} from "../../integrations/index.js";
|
|
11
14
|
import { isServerLikeOutput } from "../../prerender/utils.js";
|
|
15
|
+
import { resolveConfig } from "../config/config.js";
|
|
16
|
+
import { createNodeLogging } from "../config/logging.js";
|
|
17
|
+
import { createSettings } from "../config/settings.js";
|
|
12
18
|
import { createVite } from "../create-vite.js";
|
|
13
19
|
import { debug, info, levels, timerMessage, warn } from "../logger/core.js";
|
|
14
|
-
import { printHelp } from "../messages.js";
|
|
15
20
|
import { apply as applyPolyfill } from "../polyfill.js";
|
|
16
21
|
import { RouteCache } from "../render/route-cache.js";
|
|
17
22
|
import { createRouteManifest } from "../routing/index.js";
|
|
18
23
|
import { collectPagesData } from "./page-data.js";
|
|
19
24
|
import { staticBuild, viteBuild } from "./static-build.js";
|
|
20
25
|
import { getTimeStat } from "./util.js";
|
|
21
|
-
async function build(
|
|
22
|
-
var _a, _b;
|
|
26
|
+
async function build(inlineConfig, options) {
|
|
23
27
|
applyPolyfill();
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
description: `Builds your site for deployment.`
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const builder = new AstroBuilder(settings, options);
|
|
28
|
+
const logging = createNodeLogging(inlineConfig);
|
|
29
|
+
const { userConfig, astroConfig } = await resolveConfig(inlineConfig, "build");
|
|
30
|
+
telemetry.record(eventCliSession("build", userConfig));
|
|
31
|
+
const settings = createSettings(astroConfig, fileURLToPath(astroConfig.root));
|
|
32
|
+
const builder = new AstroBuilder(settings, {
|
|
33
|
+
...options,
|
|
34
|
+
logging,
|
|
35
|
+
mode: inlineConfig.mode
|
|
36
|
+
});
|
|
39
37
|
await builder.run();
|
|
40
38
|
}
|
|
41
39
|
class AstroBuilder {
|
|
@@ -77,8 +75,8 @@ class AstroBuilder {
|
|
|
77
75
|
{ settings: this.settings, logging, mode: "build", command: "build" }
|
|
78
76
|
);
|
|
79
77
|
await runHookConfigDone({ settings: this.settings, logging });
|
|
80
|
-
const {
|
|
81
|
-
const syncRet = await
|
|
78
|
+
const { syncInternal } = await import("../sync/index.js");
|
|
79
|
+
const syncRet = await syncInternal(this.settings, { logging, fs });
|
|
82
80
|
if (syncRet !== 0) {
|
|
83
81
|
return process.exit(syncRet);
|
|
84
82
|
}
|
|
@@ -1,40 +1,24 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Arguments as Flags } from 'yargs-parser';
|
|
3
|
-
import type { AstroConfig, AstroUserConfig, CLIFlags } from '../../@types/astro';
|
|
3
|
+
import type { AstroConfig, AstroInlineConfig, AstroUserConfig, CLIFlags } from '../../@types/astro';
|
|
4
4
|
import fs from 'node:fs';
|
|
5
|
-
export declare const LEGACY_ASTRO_CONFIG_KEYS: Set<string>;
|
|
6
5
|
/** Turn raw config values into normalized values */
|
|
7
6
|
export declare function validateConfig(userConfig: any, root: string, cmd: string): Promise<AstroConfig>;
|
|
8
7
|
/** Convert the generic "yargs" flag object into our own, custom TypeScript object. */
|
|
9
8
|
export declare function resolveFlags(flags: Partial<Flags>): CLIFlags;
|
|
10
9
|
export declare function resolveRoot(cwd?: string | URL): string;
|
|
11
|
-
interface LoadConfigOptions {
|
|
12
|
-
cwd?: string;
|
|
13
|
-
flags?: Flags;
|
|
14
|
-
cmd: string;
|
|
15
|
-
validate?: boolean;
|
|
16
|
-
/** Invalidate when reloading a previously loaded config */
|
|
17
|
-
isRestart?: boolean;
|
|
18
|
-
fsMod?: typeof fs;
|
|
19
|
-
}
|
|
20
10
|
interface ResolveConfigPathOptions {
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
root: string;
|
|
12
|
+
configFile?: string;
|
|
23
13
|
fs: typeof fs;
|
|
24
14
|
}
|
|
25
15
|
/**
|
|
26
16
|
* Resolve the file URL of the user's `astro.config.js|cjs|mjs|ts` file
|
|
27
17
|
*/
|
|
28
|
-
export declare function resolveConfigPath(
|
|
29
|
-
interface
|
|
18
|
+
export declare function resolveConfigPath(options: ResolveConfigPathOptions): Promise<string | undefined>;
|
|
19
|
+
interface ResolveConfigResult {
|
|
30
20
|
userConfig: AstroUserConfig;
|
|
31
21
|
astroConfig: AstroConfig;
|
|
32
|
-
flags: CLIFlags;
|
|
33
|
-
root: string;
|
|
34
22
|
}
|
|
35
|
-
|
|
36
|
-
export declare function openConfig(configOptions: LoadConfigOptions): Promise<OpenConfigResult>;
|
|
37
|
-
/** Attempt to resolve an Astro configuration object. Normalize, validate, and return. */
|
|
38
|
-
export declare function resolveConfig(userConfig: AstroUserConfig, root: string, flags: CLIFlags | undefined, cmd: string): Promise<AstroConfig>;
|
|
39
|
-
export declare function createDefaultDevConfig(userConfig?: AstroUserConfig, root?: string): Promise<AstroConfig>;
|
|
23
|
+
export declare function resolveConfig(inlineConfig: AstroInlineConfig, command: string, fsMod?: typeof fs): Promise<ResolveConfigResult>;
|
|
40
24
|
export {};
|
|
@@ -2,7 +2,11 @@ import * as colors from "kleur/colors";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { ZodError } from "zod";
|
|
6
|
+
import { eventConfigError, telemetry } from "../../events/index.js";
|
|
7
|
+
import { trackAstroConfigZodError } from "../errors/errors.js";
|
|
5
8
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
9
|
+
import { formatConfigErrorMessage } from "../messages.js";
|
|
6
10
|
import { mergeConfig } from "./merge.js";
|
|
7
11
|
import { createRelativeSchema } from "./schema.js";
|
|
8
12
|
import { loadConfigWithVite } from "./vite-load.js";
|
|
@@ -60,7 +64,17 @@ async function validateConfig(userConfig, root, cmd) {
|
|
|
60
64
|
});
|
|
61
65
|
}
|
|
62
66
|
const AstroConfigRelativeSchema = createRelativeSchema(cmd, root);
|
|
63
|
-
|
|
67
|
+
let result;
|
|
68
|
+
try {
|
|
69
|
+
result = await AstroConfigRelativeSchema.parseAsync(userConfig);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
if (e instanceof ZodError) {
|
|
72
|
+
trackAstroConfigZodError(e);
|
|
73
|
+
console.error(formatConfigErrorMessage(e) + "\n");
|
|
74
|
+
telemetry.record(eventConfigError({ cmd, err: e, isFatal: true }));
|
|
75
|
+
}
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
64
78
|
return result;
|
|
65
79
|
}
|
|
66
80
|
function resolveFlags(flags) {
|
|
@@ -82,20 +96,6 @@ function resolveRoot(cwd) {
|
|
|
82
96
|
}
|
|
83
97
|
return cwd ? path.resolve(cwd) : process.cwd();
|
|
84
98
|
}
|
|
85
|
-
function mergeCLIFlags(astroConfig, flags) {
|
|
86
|
-
return mergeConfig(astroConfig, {
|
|
87
|
-
site: flags.site,
|
|
88
|
-
base: flags.base,
|
|
89
|
-
markdown: {
|
|
90
|
-
drafts: flags.drafts
|
|
91
|
-
},
|
|
92
|
-
server: {
|
|
93
|
-
port: flags.port,
|
|
94
|
-
host: flags.host,
|
|
95
|
-
open: flags.open
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
99
|
async function search(fsMod, root) {
|
|
100
100
|
const paths = [
|
|
101
101
|
"astro.config.mjs",
|
|
@@ -111,63 +111,64 @@ async function search(fsMod, root) {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
async function resolveConfigPath(
|
|
115
|
-
const root = resolveRoot(configOptions.cwd);
|
|
116
|
-
const flags = resolveFlags(configOptions.flags || {});
|
|
114
|
+
async function resolveConfigPath(options) {
|
|
117
115
|
let userConfigPath;
|
|
118
|
-
if (
|
|
119
|
-
userConfigPath =
|
|
120
|
-
|
|
121
|
-
if (!configOptions.fs.existsSync(userConfigPath)) {
|
|
116
|
+
if (options.configFile) {
|
|
117
|
+
userConfigPath = path.join(options.root, options.configFile);
|
|
118
|
+
if (!options.fs.existsSync(userConfigPath)) {
|
|
122
119
|
throw new AstroError({
|
|
123
120
|
...AstroErrorData.ConfigNotFound,
|
|
124
|
-
message: AstroErrorData.ConfigNotFound.message(
|
|
121
|
+
message: AstroErrorData.ConfigNotFound.message(options.configFile)
|
|
125
122
|
});
|
|
126
123
|
}
|
|
127
124
|
} else {
|
|
128
|
-
userConfigPath = await search(
|
|
125
|
+
userConfigPath = await search(options.fs, options.root);
|
|
129
126
|
}
|
|
130
127
|
return userConfigPath;
|
|
131
128
|
}
|
|
132
|
-
async function
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const userConfig = await loadConfig(configOptions, root);
|
|
136
|
-
const astroConfig = await resolveConfig(userConfig, root, flags, configOptions.cmd);
|
|
137
|
-
return {
|
|
138
|
-
astroConfig,
|
|
139
|
-
userConfig,
|
|
140
|
-
flags,
|
|
141
|
-
root
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
async function loadConfig(configOptions, root) {
|
|
145
|
-
const fsMod = configOptions.fsMod ?? fs;
|
|
129
|
+
async function loadConfig(root, configFile, fsMod = fs) {
|
|
130
|
+
if (configFile === false)
|
|
131
|
+
return {};
|
|
146
132
|
const configPath = await resolveConfigPath({
|
|
147
|
-
|
|
148
|
-
|
|
133
|
+
root,
|
|
134
|
+
configFile,
|
|
149
135
|
fs: fsMod
|
|
150
136
|
});
|
|
151
137
|
if (!configPath)
|
|
152
138
|
return {};
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
139
|
+
try {
|
|
140
|
+
return await loadConfigWithVite({
|
|
141
|
+
root,
|
|
142
|
+
configPath,
|
|
143
|
+
fs: fsMod
|
|
144
|
+
});
|
|
145
|
+
} catch (e) {
|
|
146
|
+
const configPathText = configFile ? colors.bold(configFile) : "your Astro config";
|
|
147
|
+
console.error(`${colors.bold(colors.red("[astro]"))} Unable to load ${configPathText}
|
|
148
|
+
`);
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
158
151
|
}
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
function splitInlineConfig(inlineConfig) {
|
|
153
|
+
const { configFile, mode, logLevel, ...inlineUserConfig } = inlineConfig;
|
|
154
|
+
return {
|
|
155
|
+
inlineUserConfig,
|
|
156
|
+
inlineOnlyConfig: {
|
|
157
|
+
configFile,
|
|
158
|
+
mode,
|
|
159
|
+
logLevel
|
|
160
|
+
}
|
|
161
|
+
};
|
|
163
162
|
}
|
|
164
|
-
function
|
|
165
|
-
|
|
163
|
+
async function resolveConfig(inlineConfig, command, fsMod = fs) {
|
|
164
|
+
const root = resolveRoot(inlineConfig.root);
|
|
165
|
+
const { inlineUserConfig, inlineOnlyConfig } = splitInlineConfig(inlineConfig);
|
|
166
|
+
const userConfig = await loadConfig(root, inlineOnlyConfig.configFile, fsMod);
|
|
167
|
+
const mergedConfig = mergeConfig(userConfig, inlineUserConfig);
|
|
168
|
+
const astroConfig = await validateConfig(mergedConfig, root, command);
|
|
169
|
+
return { userConfig, astroConfig };
|
|
166
170
|
}
|
|
167
171
|
export {
|
|
168
|
-
LEGACY_ASTRO_CONFIG_KEYS,
|
|
169
|
-
createDefaultDevConfig,
|
|
170
|
-
openConfig,
|
|
171
172
|
resolveConfig,
|
|
172
173
|
resolveConfigPath,
|
|
173
174
|
resolveFlags,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { resolveConfig, resolveConfigPath, resolveFlags, resolveRoot } from './config.js';
|
|
2
|
+
export { createNodeLogging } from './logging.js';
|
|
2
3
|
export { mergeConfig } from './merge.js';
|
|
3
4
|
export type { AstroConfigSchema } from './schema';
|
|
4
|
-
export {
|
|
5
|
+
export { createSettings } from './settings.js';
|
|
5
6
|
export { loadTSConfig, updateTSConfigForFramework } from './tsconfig.js';
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
openConfig,
|
|
4
|
-
resolveConfigPath,
|
|
5
|
-
resolveFlags,
|
|
6
|
-
resolveRoot,
|
|
7
|
-
validateConfig
|
|
8
|
-
} from "./config.js";
|
|
1
|
+
import { resolveConfig, resolveConfigPath, resolveFlags, resolveRoot } from "./config.js";
|
|
2
|
+
import { createNodeLogging } from "./logging.js";
|
|
9
3
|
import { mergeConfig } from "./merge.js";
|
|
10
|
-
import {
|
|
4
|
+
import { createSettings } from "./settings.js";
|
|
11
5
|
import { loadTSConfig, updateTSConfigForFramework } from "./tsconfig.js";
|
|
12
6
|
export {
|
|
13
|
-
|
|
14
|
-
createDefaultDevSettings,
|
|
7
|
+
createNodeLogging,
|
|
15
8
|
createSettings,
|
|
16
9
|
loadTSConfig,
|
|
17
10
|
mergeConfig,
|
|
18
|
-
|
|
11
|
+
resolveConfig,
|
|
19
12
|
resolveConfigPath,
|
|
20
13
|
resolveFlags,
|
|
21
14
|
resolveRoot,
|
|
22
|
-
updateTSConfigForFramework
|
|
23
|
-
validateConfig
|
|
15
|
+
updateTSConfigForFramework
|
|
24
16
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { nodeLogDestination } from "../logger/node.js";
|
|
2
|
+
function createNodeLogging(inlineConfig) {
|
|
3
|
+
if (inlineConfig.logging)
|
|
4
|
+
return inlineConfig.logging;
|
|
5
|
+
return {
|
|
6
|
+
dest: nodeLogDestination,
|
|
7
|
+
level: inlineConfig.logLevel ?? "info"
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
createNodeLogging
|
|
12
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AstroConfig, AstroSettings
|
|
1
|
+
import type { AstroConfig, AstroSettings } from '../../@types/astro';
|
|
2
2
|
export declare function createBaseSettings(config: AstroConfig): AstroSettings;
|
|
3
3
|
export declare function createSettings(config: AstroConfig, cwd?: string): AstroSettings;
|
|
4
|
-
export declare function createDefaultDevSettings(userConfig?: AstroUserConfig, root?: string | URL): Promise<AstroSettings>;
|
|
@@ -8,7 +8,6 @@ import { getDefaultClientDirectives } from "../client-directive/index.js";
|
|
|
8
8
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
9
9
|
import { formatYAMLException, isYAMLException } from "../errors/utils.js";
|
|
10
10
|
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./../constants.js";
|
|
11
|
-
import { createDefaultDevConfig } from "./config.js";
|
|
12
11
|
import { AstroTimer } from "./timer.js";
|
|
13
12
|
import { loadTSConfig } from "./tsconfig.js";
|
|
14
13
|
function createBaseSettings(config) {
|
|
@@ -103,15 +102,7 @@ function createSettings(config, cwd) {
|
|
|
103
102
|
settings.watchFiles = watchFiles;
|
|
104
103
|
return settings;
|
|
105
104
|
}
|
|
106
|
-
async function createDefaultDevSettings(userConfig = {}, root) {
|
|
107
|
-
if (root && typeof root !== "string") {
|
|
108
|
-
root = fileURLToPath(root);
|
|
109
|
-
}
|
|
110
|
-
const config = await createDefaultDevConfig(userConfig, root);
|
|
111
|
-
return createBaseSettings(config);
|
|
112
|
-
}
|
|
113
105
|
export {
|
|
114
106
|
createBaseSettings,
|
|
115
|
-
createDefaultDevSettings,
|
|
116
107
|
createSettings
|
|
117
108
|
};
|
package/dist/core/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import type * as http from 'node:http';
|
|
5
5
|
import type { AddressInfo } from 'node:net';
|
|
6
|
-
import type {
|
|
6
|
+
import type { AstroInlineConfig, AstroSettings } from '../../@types/astro';
|
|
7
7
|
import nodeFs from 'node:fs';
|
|
8
8
|
import * as vite from 'vite';
|
|
9
9
|
import type { LogOptions } from '../logger/core.js';
|
|
@@ -11,29 +11,19 @@ export interface Container {
|
|
|
11
11
|
fs: typeof nodeFs;
|
|
12
12
|
logging: LogOptions;
|
|
13
13
|
settings: AstroSettings;
|
|
14
|
-
viteConfig: vite.InlineConfig;
|
|
15
14
|
viteServer: vite.ViteDevServer;
|
|
16
|
-
|
|
17
|
-
configFlag: string | undefined;
|
|
18
|
-
configFlagPath: string | undefined;
|
|
15
|
+
inlineConfig: AstroInlineConfig;
|
|
19
16
|
restartInFlight: boolean;
|
|
20
17
|
handle: (req: http.IncomingMessage, res: http.ServerResponse) => void;
|
|
21
18
|
close: () => Promise<void>;
|
|
22
19
|
}
|
|
23
20
|
export interface CreateContainerParams {
|
|
21
|
+
logging: LogOptions;
|
|
22
|
+
settings: AstroSettings;
|
|
23
|
+
inlineConfig?: AstroInlineConfig;
|
|
24
24
|
isRestart?: boolean;
|
|
25
|
-
logging?: LogOptions;
|
|
26
|
-
userConfig?: AstroUserConfig;
|
|
27
|
-
settings?: AstroSettings;
|
|
28
25
|
fs?: typeof nodeFs;
|
|
29
|
-
root?: string | URL;
|
|
30
|
-
configFlag?: string;
|
|
31
|
-
configFlagPath?: string;
|
|
32
26
|
}
|
|
33
|
-
export declare function createContainer(
|
|
27
|
+
export declare function createContainer({ isRestart, logging, inlineConfig, settings, fs, }: CreateContainerParams): Promise<Container>;
|
|
34
28
|
export declare function startContainer({ settings, viteServer, logging, }: Container): Promise<AddressInfo>;
|
|
35
29
|
export declare function isStarted(container: Container): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Only used in tests
|
|
38
|
-
*/
|
|
39
|
-
export declare function runInContainer(params: CreateContainerParams, callback: (container: Container) => Promise<void> | void): Promise<void>;
|