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
|
@@ -7,22 +7,15 @@ import {
|
|
|
7
7
|
runHookServerDone,
|
|
8
8
|
runHookServerStart
|
|
9
9
|
} from "../../integrations/index.js";
|
|
10
|
-
import { createDefaultDevSettings, resolveRoot } from "../config/index.js";
|
|
11
10
|
import { createVite } from "../create-vite.js";
|
|
12
|
-
import { nodeLogDestination } from "../logger/node.js";
|
|
13
|
-
import { appendForwardSlash } from "../path.js";
|
|
14
11
|
import { apply as applyPolyfill } from "../polyfill.js";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
logging = defaultLogging,
|
|
23
|
-
settings = await createDefaultDevSettings(params.userConfig, params.root),
|
|
24
|
-
fs = nodeFs
|
|
25
|
-
} = params;
|
|
12
|
+
async function createContainer({
|
|
13
|
+
isRestart = false,
|
|
14
|
+
logging,
|
|
15
|
+
inlineConfig,
|
|
16
|
+
settings,
|
|
17
|
+
fs = nodeFs
|
|
18
|
+
}) {
|
|
26
19
|
applyPolyfill();
|
|
27
20
|
settings = await runHookConfigSetup({
|
|
28
21
|
settings,
|
|
@@ -48,14 +41,11 @@ async function createContainer(params = {}) {
|
|
|
48
41
|
await runHookConfigDone({ settings, logging });
|
|
49
42
|
const viteServer = await vite.createServer(viteConfig);
|
|
50
43
|
const container = {
|
|
51
|
-
|
|
52
|
-
configFlagPath: params.configFlagPath,
|
|
44
|
+
inlineConfig: inlineConfig ?? {},
|
|
53
45
|
fs,
|
|
54
46
|
logging,
|
|
55
|
-
resolvedRoot: appendForwardSlash(resolveRoot(params.root)),
|
|
56
47
|
restartInFlight: false,
|
|
57
48
|
settings,
|
|
58
|
-
viteConfig,
|
|
59
49
|
viteServer,
|
|
60
50
|
handle(req, res) {
|
|
61
51
|
viteServer.middlewares.handle(req, res, Function.prototype);
|
|
@@ -93,17 +83,8 @@ function isStarted(container) {
|
|
|
93
83
|
var _a;
|
|
94
84
|
return !!((_a = container.viteServer.httpServer) == null ? void 0 : _a.listening);
|
|
95
85
|
}
|
|
96
|
-
async function runInContainer(params, callback) {
|
|
97
|
-
const container = await createContainer(params);
|
|
98
|
-
try {
|
|
99
|
-
await callback(container);
|
|
100
|
-
} finally {
|
|
101
|
-
await container.close();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
86
|
export {
|
|
105
87
|
createContainer,
|
|
106
88
|
isStarted,
|
|
107
|
-
runInContainer,
|
|
108
89
|
startContainer
|
|
109
90
|
};
|
package/dist/core/dev/dev.d.ts
CHANGED
|
@@ -3,17 +3,7 @@
|
|
|
3
3
|
import type http from 'node:http';
|
|
4
4
|
import type { AddressInfo } from 'node:net';
|
|
5
5
|
import type * as vite from 'vite';
|
|
6
|
-
import type
|
|
7
|
-
import type { AstroSettings } from '../../@types/astro';
|
|
8
|
-
import { type LogOptions } from '../logger/core.js';
|
|
9
|
-
export interface DevOptions {
|
|
10
|
-
configFlag: string | undefined;
|
|
11
|
-
configFlagPath: string | undefined;
|
|
12
|
-
flags?: yargs.Arguments;
|
|
13
|
-
logging: LogOptions;
|
|
14
|
-
handleConfigError: (error: Error) => void;
|
|
15
|
-
isRestart?: boolean;
|
|
16
|
-
}
|
|
6
|
+
import type { AstroInlineConfig } from '../../@types/astro';
|
|
17
7
|
export interface DevServer {
|
|
18
8
|
address: AddressInfo;
|
|
19
9
|
handle: (req: http.IncomingMessage, res: http.ServerResponse<http.IncomingMessage>) => void;
|
|
@@ -21,4 +11,4 @@ export interface DevServer {
|
|
|
21
11
|
stop(): Promise<void>;
|
|
22
12
|
}
|
|
23
13
|
/** `astro dev` */
|
|
24
|
-
export default function dev(
|
|
14
|
+
export default function dev(inlineConfig: AstroInlineConfig): Promise<DevServer>;
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -1,65 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from "node:fs";
|
|
2
2
|
import { performance } from "perf_hooks";
|
|
3
3
|
import { attachContentServerListeners } from "../../content/index.js";
|
|
4
4
|
import { telemetry } from "../../events/index.js";
|
|
5
5
|
import { info, warn } from "../logger/core.js";
|
|
6
6
|
import * as msg from "../messages.js";
|
|
7
|
-
import { printHelp } from "../messages.js";
|
|
8
7
|
import { startContainer } from "./container.js";
|
|
9
8
|
import { createContainerWithAutomaticRestart } from "./restart.js";
|
|
10
|
-
async function dev(
|
|
11
|
-
var _a, _b
|
|
12
|
-
if (((_a = options.flags) == null ? void 0 : _a.help) || ((_b = options.flags) == null ? void 0 : _b.h)) {
|
|
13
|
-
printHelp({
|
|
14
|
-
commandName: "astro dev",
|
|
15
|
-
usage: "[...flags]",
|
|
16
|
-
tables: {
|
|
17
|
-
Flags: [
|
|
18
|
-
["--port", `Specify which port to run on. Defaults to 3000.`],
|
|
19
|
-
["--host", `Listen on all addresses, including LAN and public addresses.`],
|
|
20
|
-
["--host <custom-address>", `Expose on a network IP address at <custom-address>`],
|
|
21
|
-
["--open", "Automatically open the app in the browser on server start"],
|
|
22
|
-
["--help (-h)", "See all available flags."]
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
|
-
description: `Check ${cyan(
|
|
26
|
-
"https://docs.astro.build/en/reference/cli-reference/#astro-dev"
|
|
27
|
-
)} for more information.`
|
|
28
|
-
});
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
9
|
+
async function dev(inlineConfig) {
|
|
10
|
+
var _a, _b;
|
|
31
11
|
const devStart = performance.now();
|
|
32
12
|
await telemetry.record([]);
|
|
33
|
-
const restart = await createContainerWithAutomaticRestart({
|
|
34
|
-
|
|
35
|
-
handleConfigError: options.handleConfigError,
|
|
36
|
-
// eslint-disable-next-line no-console
|
|
37
|
-
beforeRestart: () => console.clear(),
|
|
38
|
-
params: {
|
|
39
|
-
settings,
|
|
40
|
-
root: (_c = options.flags) == null ? void 0 : _c.root,
|
|
41
|
-
logging: options.logging,
|
|
42
|
-
isRestart: options.isRestart
|
|
43
|
-
}
|
|
44
|
-
});
|
|
13
|
+
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
14
|
+
const logging = restart.container.logging;
|
|
45
15
|
const devServerAddressInfo = await startContainer(restart.container);
|
|
46
16
|
info(
|
|
47
|
-
|
|
17
|
+
logging,
|
|
48
18
|
null,
|
|
49
19
|
msg.serverStart({
|
|
50
20
|
startupTime: performance.now() - devStart,
|
|
51
21
|
resolvedUrls: restart.container.viteServer.resolvedUrls || { local: [], network: [] },
|
|
52
|
-
host: settings.config.server.host,
|
|
53
|
-
base: settings.config.base
|
|
54
|
-
isRestart: options.isRestart
|
|
22
|
+
host: restart.container.settings.config.server.host,
|
|
23
|
+
base: restart.container.settings.config.base
|
|
55
24
|
})
|
|
56
25
|
);
|
|
57
|
-
const currentVersion = "2.9.
|
|
26
|
+
const currentVersion = "2.9.7";
|
|
58
27
|
if (currentVersion.includes("-")) {
|
|
59
|
-
warn(
|
|
28
|
+
warn(logging, null, msg.prerelease({ currentVersion }));
|
|
60
29
|
}
|
|
61
|
-
if (((
|
|
62
|
-
warn(
|
|
30
|
+
if (((_b = (_a = restart.container.viteServer.config.server) == null ? void 0 : _a.fs) == null ? void 0 : _b.strict) === false) {
|
|
31
|
+
warn(logging, null, msg.fsStrictWarning());
|
|
63
32
|
}
|
|
64
33
|
await attachContentServerListeners(restart.container);
|
|
65
34
|
return {
|
package/dist/core/dev/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createContainer, isStarted,
|
|
1
|
+
export { createContainer, isStarted, startContainer } from './container.js';
|
|
2
2
|
export { default } from './dev.js';
|
|
3
3
|
export { createContainerWithAutomaticRestart } from './restart.js';
|
package/dist/core/dev/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContainer, isStarted,
|
|
1
|
+
import { createContainer, isStarted, startContainer } from "./container.js";
|
|
2
2
|
import { default as default2 } from "./dev.js";
|
|
3
3
|
import { createContainerWithAutomaticRestart } from "./restart.js";
|
|
4
4
|
export {
|
|
@@ -6,6 +6,5 @@ export {
|
|
|
6
6
|
createContainerWithAutomaticRestart,
|
|
7
7
|
default2 as default,
|
|
8
8
|
isStarted,
|
|
9
|
-
runInContainer,
|
|
10
9
|
startContainer
|
|
11
10
|
};
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
handleConfigError: (err: Error) => Promise<void> | void;
|
|
8
|
-
beforeRestart?: () => void;
|
|
9
|
-
}
|
|
10
|
-
export declare function restartContainer({ container, flags, logMsg, handleConfigError, beforeRestart, }: RestartContainerParams): Promise<{
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import nodeFs from 'node:fs';
|
|
3
|
+
import type { AstroInlineConfig } from '../../@types/astro';
|
|
4
|
+
import type { Container } from './container';
|
|
5
|
+
export declare function shouldRestartContainer({ settings, inlineConfig, restartInFlight }: Container, changedFile: string): boolean;
|
|
6
|
+
export declare function restartContainer(container: Container): Promise<{
|
|
11
7
|
container: Container;
|
|
12
8
|
error: Error | null;
|
|
13
9
|
}>;
|
|
14
10
|
export interface CreateContainerWithAutomaticRestart {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
handleConfigError?: (error: Error) => void | Promise<void>;
|
|
18
|
-
beforeRestart?: () => void;
|
|
11
|
+
inlineConfig?: AstroInlineConfig;
|
|
12
|
+
fs: typeof nodeFs;
|
|
19
13
|
}
|
|
20
14
|
interface Restart {
|
|
21
15
|
container: Container;
|
|
22
16
|
restarted: () => Promise<Error | null>;
|
|
23
17
|
}
|
|
24
|
-
export declare function createContainerWithAutomaticRestart({
|
|
18
|
+
export declare function createContainerWithAutomaticRestart({ inlineConfig, fs, }: CreateContainerWithAutomaticRestart): Promise<Restart>;
|
|
25
19
|
export {};
|
package/dist/core/dev/restart.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
1
2
|
import * as vite from "vite";
|
|
2
|
-
import {
|
|
3
|
+
import { eventCliSession, telemetry } from "../../events/index.js";
|
|
4
|
+
import { createNodeLogging, createSettings, resolveConfig } from "../config/index.js";
|
|
5
|
+
import { collectErrorMetadata } from "../errors/dev/utils.js";
|
|
6
|
+
import { isAstroConfigZodError } from "../errors/errors.js";
|
|
3
7
|
import { createSafeError } from "../errors/index.js";
|
|
4
|
-
import { info } from "../logger/core.js";
|
|
8
|
+
import { info, error as logError } from "../logger/core.js";
|
|
9
|
+
import { formatErrorMessage } from "../messages.js";
|
|
5
10
|
import { createContainer, isStarted, startContainer } from "./container.js";
|
|
6
11
|
async function createRestartedContainer(container, settings, needsStart) {
|
|
7
|
-
const { logging, fs,
|
|
12
|
+
const { logging, fs, inlineConfig } = container;
|
|
8
13
|
const newContainer = await createContainer({
|
|
9
14
|
isRestart: true,
|
|
10
15
|
logging,
|
|
11
16
|
settings,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
configFlag,
|
|
15
|
-
configFlagPath
|
|
17
|
+
inlineConfig,
|
|
18
|
+
fs
|
|
16
19
|
});
|
|
17
20
|
if (needsStart) {
|
|
18
21
|
await startContainer(newContainer);
|
|
19
22
|
}
|
|
20
23
|
return newContainer;
|
|
21
24
|
}
|
|
22
|
-
function shouldRestartContainer({ settings,
|
|
25
|
+
function shouldRestartContainer({ settings, inlineConfig, restartInFlight }, changedFile) {
|
|
23
26
|
if (restartInFlight)
|
|
24
27
|
return false;
|
|
25
28
|
let shouldRestart = false;
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
shouldRestart = vite.normalizePath(configFlagPath) === vite.normalizePath(changedFile);
|
|
29
|
-
}
|
|
29
|
+
if (inlineConfig.configFile) {
|
|
30
|
+
shouldRestart = vite.normalizePath(inlineConfig.configFile) === vite.normalizePath(changedFile);
|
|
30
31
|
} else {
|
|
31
32
|
const exp = new RegExp(`.*astro.config.((mjs)|(cjs)|(js)|(ts))$`);
|
|
32
33
|
const normalizedChangedFile = vite.normalizePath(changedFile);
|
|
@@ -39,30 +40,13 @@ function shouldRestartContainer({ settings, configFlag, configFlagPath, restartI
|
|
|
39
40
|
}
|
|
40
41
|
return shouldRestart;
|
|
41
42
|
}
|
|
42
|
-
async function restartContainer({
|
|
43
|
-
container
|
|
44
|
-
flags,
|
|
45
|
-
logMsg,
|
|
46
|
-
handleConfigError,
|
|
47
|
-
beforeRestart
|
|
48
|
-
}) {
|
|
49
|
-
const { logging, close, resolvedRoot, settings: existingSettings } = container;
|
|
43
|
+
async function restartContainer(container) {
|
|
44
|
+
const { logging, close, settings: existingSettings } = container;
|
|
50
45
|
container.restartInFlight = true;
|
|
51
|
-
if (beforeRestart) {
|
|
52
|
-
beforeRestart();
|
|
53
|
-
}
|
|
54
46
|
const needsStart = isStarted(container);
|
|
55
47
|
try {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
flags,
|
|
59
|
-
cmd: "dev",
|
|
60
|
-
isRestart: true,
|
|
61
|
-
fsMod: container.fs
|
|
62
|
-
});
|
|
63
|
-
info(logging, "astro", logMsg + "\n");
|
|
64
|
-
let astroConfig = newConfig.astroConfig;
|
|
65
|
-
const settings = createSettings(astroConfig, resolvedRoot);
|
|
48
|
+
const { astroConfig } = await resolveConfig(container.inlineConfig, "dev", container.fs);
|
|
49
|
+
const settings = createSettings(astroConfig, fileURLToPath(existingSettings.config.root));
|
|
66
50
|
await close();
|
|
67
51
|
return {
|
|
68
52
|
container: await createRestartedContainer(container, settings, needsStart),
|
|
@@ -70,7 +54,16 @@ async function restartContainer({
|
|
|
70
54
|
};
|
|
71
55
|
} catch (_err) {
|
|
72
56
|
const error = createSafeError(_err);
|
|
73
|
-
|
|
57
|
+
if (!isAstroConfigZodError(_err)) {
|
|
58
|
+
logError(logging, "config", formatErrorMessage(collectErrorMetadata(error)) + "\n");
|
|
59
|
+
}
|
|
60
|
+
container.viteServer.ws.send({
|
|
61
|
+
type: "error",
|
|
62
|
+
err: {
|
|
63
|
+
message: error.message,
|
|
64
|
+
stack: error.stack || ""
|
|
65
|
+
}
|
|
66
|
+
});
|
|
74
67
|
await close();
|
|
75
68
|
info(logging, "astro", "Continuing with previous valid configuration\n");
|
|
76
69
|
return {
|
|
@@ -80,13 +73,14 @@ async function restartContainer({
|
|
|
80
73
|
}
|
|
81
74
|
}
|
|
82
75
|
async function createContainerWithAutomaticRestart({
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
beforeRestart,
|
|
87
|
-
params
|
|
76
|
+
inlineConfig,
|
|
77
|
+
fs
|
|
88
78
|
}) {
|
|
89
|
-
const
|
|
79
|
+
const logging = createNodeLogging(inlineConfig ?? {});
|
|
80
|
+
const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, "dev", fs);
|
|
81
|
+
telemetry.record(eventCliSession("dev", userConfig));
|
|
82
|
+
const settings = createSettings(astroConfig, fileURLToPath(astroConfig.root));
|
|
83
|
+
const initialContainer = await createContainer({ settings, logging, inlineConfig, fs });
|
|
90
84
|
let resolveRestart;
|
|
91
85
|
let restartComplete = new Promise((resolve) => {
|
|
92
86
|
resolveRestart = resolve;
|
|
@@ -98,23 +92,9 @@ async function createContainerWithAutomaticRestart({
|
|
|
98
92
|
}
|
|
99
93
|
};
|
|
100
94
|
async function handleServerRestart(logMsg) {
|
|
95
|
+
info(logging, "astro", logMsg + "\n");
|
|
101
96
|
const container = restart.container;
|
|
102
|
-
const { container: newContainer, error } = await restartContainer(
|
|
103
|
-
beforeRestart,
|
|
104
|
-
container,
|
|
105
|
-
flags,
|
|
106
|
-
logMsg,
|
|
107
|
-
async handleConfigError(err) {
|
|
108
|
-
await handleConfigError(err);
|
|
109
|
-
container.viteServer.ws.send({
|
|
110
|
-
type: "error",
|
|
111
|
-
err: {
|
|
112
|
-
message: err.message,
|
|
113
|
-
stack: err.stack || ""
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
});
|
|
97
|
+
const { container: newContainer, error } = await restartContainer(container);
|
|
118
98
|
restart.container = newContainer;
|
|
119
99
|
addWatches();
|
|
120
100
|
resolveRestart(error);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ZodError } from 'zod';
|
|
1
2
|
interface ErrorProperties {
|
|
2
3
|
title?: string;
|
|
3
4
|
name?: string;
|
|
@@ -53,6 +54,15 @@ export declare class AggregateError extends AstroError {
|
|
|
53
54
|
}, ...params: any);
|
|
54
55
|
static is(err: unknown): err is AggregateError;
|
|
55
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if an error is a ZodError from an AstroConfig validation.
|
|
59
|
+
* Used to suppress formatting a ZodError if needed.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isAstroConfigZodError(error: unknown): error is ZodError;
|
|
62
|
+
/**
|
|
63
|
+
* Track that a ZodError comes from an AstroConfig validation.
|
|
64
|
+
*/
|
|
65
|
+
export declare function trackAstroConfigZodError(error: ZodError): void;
|
|
56
66
|
/**
|
|
57
67
|
* Generic object representing an error with all possible data
|
|
58
68
|
* Compatible with both Astro's and Vite's errors
|
|
@@ -93,6 +93,13 @@ class AggregateError extends AstroError {
|
|
|
93
93
|
return err.type === "AggregateError";
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
+
const astroConfigZodErrors = /* @__PURE__ */ new WeakSet();
|
|
97
|
+
function isAstroConfigZodError(error) {
|
|
98
|
+
return astroConfigZodErrors.has(error);
|
|
99
|
+
}
|
|
100
|
+
function trackAstroConfigZodError(error) {
|
|
101
|
+
astroConfigZodErrors.add(error);
|
|
102
|
+
}
|
|
96
103
|
export {
|
|
97
104
|
AggregateError,
|
|
98
105
|
AstroError,
|
|
@@ -100,5 +107,7 @@ export {
|
|
|
100
107
|
CompilerError,
|
|
101
108
|
InternalError,
|
|
102
109
|
MarkdownError,
|
|
103
|
-
|
|
110
|
+
isAstroConfigZodError,
|
|
111
|
+
isAstroError,
|
|
112
|
+
trackAstroConfigZodError
|
|
104
113
|
};
|
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.9.
|
|
50
|
+
const version = "2.9.7";
|
|
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.9.
|
|
236
|
+
`v${"2.9.7"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AstroSettings, PreviewServer } from '../../@types/astro';
|
|
3
|
-
import type { LogOptions } from '../logger/core';
|
|
4
|
-
interface PreviewOptions {
|
|
5
|
-
logging: LogOptions;
|
|
6
|
-
flags?: Arguments;
|
|
7
|
-
}
|
|
1
|
+
import type { AstroInlineConfig, PreviewServer } from '../../@types/astro';
|
|
8
2
|
/** The primary dev action */
|
|
9
|
-
export default function preview(
|
|
10
|
-
export {};
|
|
3
|
+
export default function preview(inlineConfig: AstroInlineConfig): Promise<PreviewServer | undefined>;
|
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
+
import { telemetry } from "../../events/index.js";
|
|
4
|
+
import { eventCliSession } from "../../events/session.js";
|
|
4
5
|
import { runHookConfigDone, runHookConfigSetup } from "../../integrations/index.js";
|
|
5
|
-
import {
|
|
6
|
+
import { resolveConfig } from "../config/config.js";
|
|
7
|
+
import { createNodeLogging } from "../config/logging.js";
|
|
8
|
+
import { createSettings } from "../config/settings.js";
|
|
6
9
|
import createStaticPreviewServer from "./static-preview-server.js";
|
|
7
10
|
import { getResolvedHostForHttpServer } from "./util.js";
|
|
8
|
-
async function preview(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
tables: {
|
|
14
|
-
Flags: [
|
|
15
|
-
["--open", "Automatically open the app in the browser on server start"],
|
|
16
|
-
["--help (-h)", "See all available flags."]
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
description: `Starts a local server to serve your static dist/ directory. Check ${cyan(
|
|
20
|
-
"https://docs.astro.build/en/reference/cli-reference/#astro-preview"
|
|
21
|
-
)} for more information.`
|
|
22
|
-
});
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
11
|
+
async function preview(inlineConfig) {
|
|
12
|
+
const logging = createNodeLogging(inlineConfig);
|
|
13
|
+
const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, "preview");
|
|
14
|
+
telemetry.record(eventCliSession("preview", userConfig));
|
|
15
|
+
const _settings = createSettings(astroConfig, fileURLToPath(astroConfig.root));
|
|
25
16
|
const settings = await runHookConfigSetup({
|
|
26
17
|
settings: _settings,
|
|
27
18
|
command: "preview",
|
|
@@ -4,6 +4,7 @@ function serializeRouteData(routeData, trailingSlash) {
|
|
|
4
4
|
...routeData,
|
|
5
5
|
generate: void 0,
|
|
6
6
|
pattern: routeData.pattern.source,
|
|
7
|
+
redirectRoute: routeData.redirectRoute ? serializeRouteData(routeData.redirectRoute, trailingSlash) : void 0,
|
|
7
8
|
_meta: { trailingSlash }
|
|
8
9
|
};
|
|
9
10
|
}
|
|
@@ -17,7 +18,9 @@ function deserializeRouteData(rawRouteData) {
|
|
|
17
18
|
generate: getRouteGenerator(rawRouteData.segments, rawRouteData._meta.trailingSlash),
|
|
18
19
|
pathname: rawRouteData.pathname || void 0,
|
|
19
20
|
segments: rawRouteData.segments,
|
|
20
|
-
prerender: rawRouteData.prerender
|
|
21
|
+
prerender: rawRouteData.prerender,
|
|
22
|
+
redirect: rawRouteData.redirect,
|
|
23
|
+
redirectRoute: rawRouteData.redirectRoute ? deserializeRouteData(rawRouteData.redirectRoute) : void 0
|
|
21
24
|
};
|
|
22
25
|
}
|
|
23
26
|
export {
|
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import type { AstroSettings } from '../../@types/astro';
|
|
2
|
+
import fsMod from 'node:fs';
|
|
3
|
+
import type { AstroInlineConfig, AstroSettings } from '../../@types/astro';
|
|
5
4
|
import { type LogOptions } from '../logger/core.js';
|
|
6
5
|
export type ProcessExit = 0 | 1;
|
|
7
6
|
export type SyncOptions = {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Only used for testing
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
fs?: typeof fsMod;
|
|
10
12
|
};
|
|
11
|
-
export
|
|
13
|
+
export type SyncInternalOptions = SyncOptions & {
|
|
12
14
|
logging: LogOptions;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}): Promise<ProcessExit>;
|
|
15
|
+
};
|
|
16
|
+
export declare function sync(inlineConfig: AstroInlineConfig, options?: SyncOptions): Promise<ProcessExit>;
|
|
16
17
|
/**
|
|
17
18
|
* Generate content collection types, and then returns the process exit signal.
|
|
18
19
|
*
|
|
19
20
|
* A non-zero process signal is emitted in case there's an error while generating content collection types.
|
|
20
21
|
*
|
|
22
|
+
* This should only be used when the callee already has an `AstroSetting`, otherwise use `sync()` instead.
|
|
23
|
+
* @internal
|
|
24
|
+
*
|
|
21
25
|
* @param {SyncOptions} options
|
|
22
26
|
* @param {AstroSettings} settings Astro settings
|
|
23
27
|
* @param {typeof fsMod} options.fs The file system
|
|
24
28
|
* @param {LogOptions} options.logging Logging options
|
|
25
29
|
* @return {Promise<ProcessExit>}
|
|
26
30
|
*/
|
|
27
|
-
export declare function
|
|
31
|
+
export declare function syncInternal(settings: AstroSettings, { logging, fs }: SyncInternalOptions): Promise<ProcessExit>;
|
package/dist/core/sync/index.js
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
import { dim } from "kleur/colors";
|
|
2
|
+
import fsMod from "node:fs";
|
|
2
3
|
import { performance } from "node:perf_hooks";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
3
5
|
import { createServer } from "vite";
|
|
4
6
|
import { createContentTypesGenerator } from "../../content/index.js";
|
|
5
7
|
import { globalContentConfigObserver } from "../../content/utils.js";
|
|
8
|
+
import { telemetry } from "../../events/index.js";
|
|
9
|
+
import { eventCliSession } from "../../events/session.js";
|
|
6
10
|
import { runHookConfigSetup } from "../../integrations/index.js";
|
|
7
11
|
import { setUpEnvTs } from "../../vite-plugin-inject-env-ts/index.js";
|
|
8
12
|
import { getTimeStat } from "../build/util.js";
|
|
13
|
+
import { resolveConfig } from "../config/config.js";
|
|
14
|
+
import { createNodeLogging } from "../config/logging.js";
|
|
15
|
+
import { createSettings } from "../config/settings.js";
|
|
9
16
|
import { createVite } from "../create-vite.js";
|
|
10
17
|
import { AstroError, AstroErrorData, createSafeError, isAstroError } from "../errors/index.js";
|
|
11
18
|
import { info } from "../logger/core.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Flags: [["--help (-h)", "See all available flags."]]
|
|
20
|
-
},
|
|
21
|
-
description: `Generates TypeScript types for all Astro modules.`
|
|
22
|
-
});
|
|
23
|
-
return 0;
|
|
24
|
-
}
|
|
25
|
-
const resolvedSettings = await runHookConfigSetup({
|
|
26
|
-
settings,
|
|
19
|
+
async function sync(inlineConfig, options) {
|
|
20
|
+
const logging = createNodeLogging(inlineConfig);
|
|
21
|
+
const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, "sync");
|
|
22
|
+
telemetry.record(eventCliSession("sync", userConfig));
|
|
23
|
+
const _settings = createSettings(astroConfig, fileURLToPath(astroConfig.root));
|
|
24
|
+
const settings = await runHookConfigSetup({
|
|
25
|
+
settings: _settings,
|
|
27
26
|
logging,
|
|
28
27
|
command: "build"
|
|
29
28
|
});
|
|
30
|
-
return
|
|
29
|
+
return await syncInternal(settings, { logging, fs: options == null ? void 0 : options.fs });
|
|
31
30
|
}
|
|
32
|
-
async function
|
|
31
|
+
async function syncInternal(settings, { logging, fs }) {
|
|
33
32
|
const timerStart = performance.now();
|
|
34
33
|
const tempViteServer = await createServer(
|
|
35
34
|
await createVite(
|
|
@@ -53,7 +52,7 @@ async function sync(settings, { logging, fs }) {
|
|
|
53
52
|
const contentTypesGenerator = await createContentTypesGenerator({
|
|
54
53
|
contentConfigObserver: globalContentConfigObserver,
|
|
55
54
|
logging,
|
|
56
|
-
fs,
|
|
55
|
+
fs: fs ?? fsMod,
|
|
57
56
|
settings,
|
|
58
57
|
viteServer: tempViteServer
|
|
59
58
|
});
|
|
@@ -86,10 +85,10 @@ async function sync(settings, { logging, fs }) {
|
|
|
86
85
|
await tempViteServer.close();
|
|
87
86
|
}
|
|
88
87
|
info(logging, "content", `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`);
|
|
89
|
-
await setUpEnvTs({ settings, logging, fs });
|
|
88
|
+
await setUpEnvTs({ settings, logging, fs: fs ?? fsMod });
|
|
90
89
|
return 0;
|
|
91
90
|
}
|
|
92
91
|
export {
|
|
93
92
|
sync,
|
|
94
|
-
|
|
93
|
+
syncInternal
|
|
95
94
|
};
|
package/dist/core/util.js
CHANGED
|
@@ -27,7 +27,7 @@ function padMultilineString(source, n = 2) {
|
|
|
27
27
|
return lines.map((l) => ` `.repeat(n) + l).join(`
|
|
28
28
|
`);
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const STATUS_CODE_PAGES = /* @__PURE__ */ new Set(["/404", "/500"]);
|
|
31
31
|
function getOutputFilename(astroConfig, name, type) {
|
|
32
32
|
if (type === "endpoint") {
|
|
33
33
|
return name;
|
|
@@ -35,7 +35,7 @@ function getOutputFilename(astroConfig, name, type) {
|
|
|
35
35
|
if (name === "/" || name === "") {
|
|
36
36
|
return path.posix.join(name, "index.html");
|
|
37
37
|
}
|
|
38
|
-
if (astroConfig.build.format === "file" ||
|
|
38
|
+
if (astroConfig.build.format === "file" || STATUS_CODE_PAGES.has(name)) {
|
|
39
39
|
return `${removeTrailingForwardSlash(name || "index")}.html`;
|
|
40
40
|
}
|
|
41
41
|
return path.posix.join(name, "index.html");
|