astro 2.9.6 → 2.10.0

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.
Files changed (67) hide show
  1. package/components/ViewTransitions.astro +65 -12
  2. package/dist/@types/astro.d.ts +13 -1
  3. package/dist/assets/vite-plugin-assets.js +1 -1
  4. package/dist/cli/add/index.d.ts +1 -3
  5. package/dist/cli/add/index.js +11 -4
  6. package/dist/cli/build/index.d.ts +1 -3
  7. package/dist/cli/build/index.js +19 -9
  8. package/dist/cli/check/index.d.ts +4 -9
  9. package/dist/cli/check/index.js +23 -11
  10. package/dist/cli/dev/index.d.ts +1 -3
  11. package/dist/cli/dev/index.js +24 -20
  12. package/dist/cli/flags.d.ts +9 -0
  13. package/dist/cli/flags.js +40 -0
  14. package/dist/cli/index.js +7 -14
  15. package/dist/cli/info/index.js +4 -6
  16. package/dist/cli/preview/index.d.ts +1 -3
  17. package/dist/cli/preview/index.js +21 -5
  18. package/dist/cli/sync/index.d.ts +1 -3
  19. package/dist/cli/sync/index.js +17 -8
  20. package/dist/cli/throw-and-exit.js +3 -0
  21. package/dist/config/index.js +2 -2
  22. package/dist/content/vite-plugin-content-virtual-mod.js +1 -1
  23. package/dist/core/app/index.d.ts +6 -1
  24. package/dist/core/app/index.js +84 -62
  25. package/dist/core/build/index.d.ts +2 -7
  26. package/dist/core/build/index.js +18 -20
  27. package/dist/core/compile/compile.js +1 -0
  28. package/dist/core/config/config.d.ts +6 -22
  29. package/dist/core/config/config.js +55 -54
  30. package/dist/core/config/index.d.ts +3 -2
  31. package/dist/core/config/index.js +6 -14
  32. package/dist/core/config/logging.d.ts +3 -0
  33. package/dist/core/config/logging.js +12 -0
  34. package/dist/core/config/settings.d.ts +1 -2
  35. package/dist/core/config/settings.js +0 -9
  36. package/dist/core/constants.js +1 -1
  37. package/dist/core/dev/container.d.ts +6 -17
  38. package/dist/core/dev/container.js +8 -32
  39. package/dist/core/dev/dev.d.ts +2 -12
  40. package/dist/core/dev/dev.js +12 -43
  41. package/dist/core/dev/index.d.ts +1 -1
  42. package/dist/core/dev/index.js +1 -3
  43. package/dist/core/dev/restart.d.ts +9 -18
  44. package/dist/core/dev/restart.js +49 -74
  45. package/dist/core/errors/errors.d.ts +10 -0
  46. package/dist/core/errors/errors.js +10 -1
  47. package/dist/core/messages.js +2 -2
  48. package/dist/core/preview/index.d.ts +2 -9
  49. package/dist/core/preview/index.js +12 -21
  50. package/dist/core/sync/index.d.ts +14 -10
  51. package/dist/core/sync/index.js +19 -20
  52. package/dist/core/util.js +2 -2
  53. package/dist/runtime/server/astro-island.js +16 -1
  54. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  55. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  56. package/dist/runtime/server/hydration.js +9 -0
  57. package/dist/runtime/server/render/component.js +11 -8
  58. package/dist/runtime/server/transition.d.ts +1 -0
  59. package/dist/runtime/server/transition.js +1 -0
  60. package/dist/vite-plugin-astro-postprocess/index.js +1 -1
  61. package/dist/vite-plugin-env/index.js +1 -1
  62. package/dist/vite-plugin-html/transform/index.js +1 -1
  63. package/dist/vite-plugin-scanner/index.js +4 -1
  64. package/dist/vite-plugin-scripts/page-ssr.js +1 -1
  65. package/package.json +3 -3
  66. package/dist/cli/load-settings.d.ts +0 -15
  67. package/dist/cli/load-settings.js +0 -39
@@ -1,4 +1,3 @@
1
- import type { AstroConfig, AstroSettings, AstroUserConfig } from '../../@types/astro';
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
  };
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "2.9.6";
1
+ const ASTRO_VERSION = "2.10.0";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -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 { AstroSettings, AstroUserConfig } from '../../@types/astro';
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,18 @@ 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
- resolvedRoot: string;
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(params?: CreateContainerParams): Promise<Container>;
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
- 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>;
@@ -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
- const defaultLogging = {
16
- dest: nodeLogDestination,
17
- level: "error"
18
- };
19
- async function createContainer(params = {}) {
20
- let {
21
- isRestart = false,
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
- configFlag: params.configFlag,
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);
@@ -89,21 +79,7 @@ async function startContainer({
89
79
  });
90
80
  return devServerAddressInfo;
91
81
  }
92
- function isStarted(container) {
93
- var _a;
94
- return !!((_a = container.viteServer.httpServer) == null ? void 0 : _a.listening);
95
- }
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
82
  export {
105
83
  createContainer,
106
- isStarted,
107
- runInContainer,
108
84
  startContainer
109
85
  };
@@ -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 yargs from 'yargs-parser';
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(settings: AstroSettings, options: DevOptions): Promise<DevServer | undefined>;
14
+ export default function dev(inlineConfig: AstroInlineConfig): Promise<DevServer>;
@@ -1,65 +1,34 @@
1
- import { cyan } from "kleur/colors";
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(settings, options) {
11
- var _a, _b, _c, _d, _e;
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
- flags: options.flags ?? {},
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
- options.logging,
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.6";
26
+ const currentVersion = "2.10.0";
58
27
  if (currentVersion.includes("-")) {
59
- warn(options.logging, null, msg.prerelease({ currentVersion }));
28
+ warn(logging, null, msg.prerelease({ currentVersion }));
60
29
  }
61
- if (((_e = (_d = restart.container.viteConfig.server) == null ? void 0 : _d.fs) == null ? void 0 : _e.strict) === false) {
62
- warn(options.logging, null, msg.fsStrictWarning());
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 {
@@ -1,3 +1,3 @@
1
- export { createContainer, isStarted, runInContainer, startContainer } from './container.js';
1
+ export { createContainer, startContainer } from './container.js';
2
2
  export { default } from './dev.js';
3
3
  export { createContainerWithAutomaticRestart } from './restart.js';
@@ -1,11 +1,9 @@
1
- import { createContainer, isStarted, runInContainer, startContainer } from "./container.js";
1
+ import { createContainer, startContainer } from "./container.js";
2
2
  import { default as default2 } from "./dev.js";
3
3
  import { createContainerWithAutomaticRestart } from "./restart.js";
4
4
  export {
5
5
  createContainer,
6
6
  createContainerWithAutomaticRestart,
7
7
  default2 as default,
8
- isStarted,
9
- runInContainer,
10
8
  startContainer
11
9
  };
@@ -1,25 +1,16 @@
1
- import type { Container, CreateContainerParams } from './container';
2
- export declare function shouldRestartContainer({ settings, configFlag, configFlagPath, restartInFlight }: Container, changedFile: string): boolean;
3
- interface RestartContainerParams {
4
- container: Container;
5
- flags: any;
6
- logMsg: string;
7
- handleConfigError: (err: Error) => Promise<void> | void;
8
- beforeRestart?: () => void;
9
- }
10
- export declare function restartContainer({ container, flags, logMsg, handleConfigError, beforeRestart, }: RestartContainerParams): Promise<{
11
- container: Container;
12
- error: Error | null;
13
- }>;
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<Container | Error>;
14
7
  export interface CreateContainerWithAutomaticRestart {
15
- flags: any;
16
- params: CreateContainerParams;
17
- handleConfigError?: (error: Error) => void | Promise<void>;
18
- beforeRestart?: () => void;
8
+ inlineConfig?: AstroInlineConfig;
9
+ fs: typeof nodeFs;
19
10
  }
20
11
  interface Restart {
21
12
  container: Container;
22
13
  restarted: () => Promise<Error | null>;
23
14
  }
24
- export declare function createContainerWithAutomaticRestart({ flags, handleConfigError, beforeRestart, params, }: CreateContainerWithAutomaticRestart): Promise<Restart>;
15
+ export declare function createContainerWithAutomaticRestart({ inlineConfig, fs, }: CreateContainerWithAutomaticRestart): Promise<Restart>;
25
16
  export {};
@@ -1,32 +1,31 @@
1
+ import { fileURLToPath } from "node:url";
1
2
  import * as vite from "vite";
2
- import { createSettings, openConfig } from "../config/index.js";
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";
5
- import { createContainer, isStarted, startContainer } from "./container.js";
6
- async function createRestartedContainer(container, settings, needsStart) {
7
- const { logging, fs, resolvedRoot, configFlag, configFlagPath } = container;
8
+ import { info, error as logError } from "../logger/core.js";
9
+ import { formatErrorMessage } from "../messages.js";
10
+ import { createContainer, startContainer } from "./container.js";
11
+ async function createRestartedContainer(container, settings) {
12
+ const { logging, fs, inlineConfig } = container;
8
13
  const newContainer = await createContainer({
9
14
  isRestart: true,
10
15
  logging,
11
16
  settings,
12
- fs,
13
- root: resolvedRoot,
14
- configFlag,
15
- configFlagPath
17
+ inlineConfig,
18
+ fs
16
19
  });
17
- if (needsStart) {
18
- await startContainer(newContainer);
19
- }
20
+ await startContainer(newContainer);
20
21
  return newContainer;
21
22
  }
22
- function shouldRestartContainer({ settings, configFlag, configFlagPath, restartInFlight }, changedFile) {
23
+ function shouldRestartContainer({ settings, inlineConfig, restartInFlight }, changedFile) {
23
24
  if (restartInFlight)
24
25
  return false;
25
26
  let shouldRestart = false;
26
- if (configFlag) {
27
- if (!!configFlagPath) {
28
- shouldRestart = vite.normalizePath(configFlagPath) === vite.normalizePath(changedFile);
29
- }
27
+ if (inlineConfig.configFile) {
28
+ shouldRestart = vite.normalizePath(inlineConfig.configFile) === vite.normalizePath(changedFile);
30
29
  } else {
31
30
  const exp = new RegExp(`.*astro.config.((mjs)|(cjs)|(js)|(ts))$`);
32
31
  const normalizedChangedFile = vite.normalizePath(changedFile);
@@ -39,54 +38,40 @@ function shouldRestartContainer({ settings, configFlag, configFlagPath, restartI
39
38
  }
40
39
  return shouldRestart;
41
40
  }
42
- async function restartContainer({
43
- container,
44
- flags,
45
- logMsg,
46
- handleConfigError,
47
- beforeRestart
48
- }) {
49
- const { logging, close, resolvedRoot, settings: existingSettings } = container;
41
+ async function restartContainer(container) {
42
+ const { logging, close, settings: existingSettings } = container;
50
43
  container.restartInFlight = true;
51
- if (beforeRestart) {
52
- beforeRestart();
53
- }
54
- const needsStart = isStarted(container);
55
44
  try {
56
- const newConfig = await openConfig({
57
- cwd: resolvedRoot,
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);
45
+ const { astroConfig } = await resolveConfig(container.inlineConfig, "dev", container.fs);
46
+ const settings = createSettings(astroConfig, fileURLToPath(existingSettings.config.root));
66
47
  await close();
67
- return {
68
- container: await createRestartedContainer(container, settings, needsStart),
69
- error: null
70
- };
48
+ return await createRestartedContainer(container, settings);
71
49
  } catch (_err) {
72
50
  const error = createSafeError(_err);
73
- await handleConfigError(error);
74
- await close();
51
+ if (!isAstroConfigZodError(_err)) {
52
+ logError(logging, "config", formatErrorMessage(collectErrorMetadata(error)) + "\n");
53
+ }
54
+ container.viteServer.ws.send({
55
+ type: "error",
56
+ err: {
57
+ message: error.message,
58
+ stack: error.stack || ""
59
+ }
60
+ });
61
+ container.restartInFlight = false;
75
62
  info(logging, "astro", "Continuing with previous valid configuration\n");
76
- return {
77
- container: await createRestartedContainer(container, existingSettings, needsStart),
78
- error
79
- };
63
+ return error;
80
64
  }
81
65
  }
82
66
  async function createContainerWithAutomaticRestart({
83
- flags,
84
- handleConfigError = () => {
85
- },
86
- beforeRestart,
87
- params
67
+ inlineConfig,
68
+ fs
88
69
  }) {
89
- const initialContainer = await createContainer(params);
70
+ const logging = createNodeLogging(inlineConfig ?? {});
71
+ const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, "dev", fs);
72
+ telemetry.record(eventCliSession("dev", userConfig));
73
+ const settings = createSettings(astroConfig, fileURLToPath(astroConfig.root));
74
+ const initialContainer = await createContainer({ settings, logging, inlineConfig, fs });
90
75
  let resolveRestart;
91
76
  let restartComplete = new Promise((resolve) => {
92
77
  resolveRestart = resolve;
@@ -98,26 +83,16 @@ async function createContainerWithAutomaticRestart({
98
83
  }
99
84
  };
100
85
  async function handleServerRestart(logMsg) {
86
+ info(logging, "astro", logMsg + "\n");
101
87
  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
- });
118
- restart.container = newContainer;
119
- addWatches();
120
- resolveRestart(error);
88
+ const result = await restartContainer(container);
89
+ if (result instanceof Error) {
90
+ resolveRestart(result);
91
+ } else {
92
+ restart.container = result;
93
+ addWatches();
94
+ resolveRestart(null);
95
+ }
121
96
  restartComplete = new Promise((resolve) => {
122
97
  resolveRestart = resolve;
123
98
  });
@@ -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
- isAstroError
110
+ isAstroConfigZodError,
111
+ isAstroError,
112
+ trackAstroConfigZodError
104
113
  };
@@ -47,7 +47,7 @@ function serverStart({
47
47
  base,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "2.9.6";
50
+ const version = "2.10.0";
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.6"}`
236
+ `v${"2.10.0"}`
237
237
  )} ${headline}`
238
238
  );
239
239
  }
@@ -1,10 +1,3 @@
1
- import type { Arguments } from 'yargs-parser';
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(_settings: AstroSettings, { logging, flags }: PreviewOptions): Promise<PreviewServer | undefined>;
10
- export {};
3
+ export default function preview(inlineConfig: AstroInlineConfig): Promise<PreviewServer | undefined>;
@@ -1,27 +1,18 @@
1
- import { cyan } from "kleur/colors";
2
- import { createRequire } from "module";
3
- import { pathToFileURL } from "node:url";
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 { printHelp } from "../messages.js";
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(_settings, { logging, flags }) {
9
- if ((flags == null ? void 0 : flags.help) || (flags == null ? void 0 : flags.h)) {
10
- printHelp({
11
- commandName: "astro preview",
12
- usage: "[...flags]",
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",
@@ -1,27 +1,31 @@
1
1
  /// <reference types="node" />
2
- import type fsMod from 'node:fs';
3
- import type { Arguments } from 'yargs-parser';
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
- logging: LogOptions;
9
- fs: typeof fsMod;
7
+ /**
8
+ * Only used for testing
9
+ * @internal
10
+ */
11
+ fs?: typeof fsMod;
10
12
  };
11
- export declare function syncCli(settings: AstroSettings, { logging, fs, flags }: {
13
+ export type SyncInternalOptions = SyncOptions & {
12
14
  logging: LogOptions;
13
- fs: typeof fsMod;
14
- flags?: Arguments;
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 sync(settings: AstroSettings, { logging, fs }: SyncOptions): Promise<ProcessExit>;
31
+ export declare function syncInternal(settings: AstroSettings, { logging, fs }: SyncInternalOptions): Promise<ProcessExit>;