astro 2.8.0 → 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.
Files changed (48) hide show
  1. package/dist/@types/astro.d.ts +1 -1
  2. package/dist/{core → cli}/add/index.d.ts +5 -4
  3. package/dist/{core → cli}/add/index.js +11 -10
  4. package/dist/cli/build/index.d.ts +8 -0
  5. package/dist/cli/build/index.js +16 -0
  6. package/dist/cli/check/index.d.ts +1 -2
  7. package/dist/cli/check/index.js +5 -1
  8. package/dist/cli/dev/index.d.ts +8 -0
  9. package/dist/cli/dev/index.js +26 -0
  10. package/dist/cli/docs/index.d.ts +6 -0
  11. package/dist/cli/docs/index.js +18 -0
  12. package/dist/cli/index.js +54 -151
  13. package/dist/cli/info/index.d.ts +7 -0
  14. package/dist/cli/info/index.js +45 -0
  15. package/dist/cli/load-settings.d.ts +15 -0
  16. package/dist/cli/load-settings.js +39 -0
  17. package/dist/cli/preview/index.d.ts +8 -0
  18. package/dist/cli/preview/index.js +11 -0
  19. package/dist/cli/sync/index.d.ts +8 -0
  20. package/dist/cli/sync/index.js +13 -0
  21. package/dist/cli/{telemetry.d.ts → telemetry/index.d.ts} +2 -1
  22. package/dist/cli/{telemetry.js → telemetry/index.js} +2 -2
  23. package/dist/config/index.js +1 -4
  24. package/dist/content/vite-plugin-content-virtual-mod.js +2 -2
  25. package/dist/core/config/config.d.ts +0 -3
  26. package/dist/core/config/config.js +14 -78
  27. package/dist/core/config/index.d.ts +1 -0
  28. package/dist/core/config/index.js +2 -0
  29. package/dist/core/config/merge.d.ts +1 -0
  30. package/dist/core/config/merge.js +40 -0
  31. package/dist/core/config/vite-load.d.ts +2 -10
  32. package/dist/core/config/vite-load.js +15 -28
  33. package/dist/core/constants.js +1 -1
  34. package/dist/core/dev/dev.js +1 -1
  35. package/dist/core/dev/restart.js +0 -1
  36. package/dist/core/messages.js +2 -2
  37. package/dist/events/error.js +1 -5
  38. package/dist/integrations/index.js +1 -1
  39. package/dist/runtime/server/response.js +7 -0
  40. package/package.json +1 -1
  41. /package/dist/{core → cli}/add/babel.d.ts +0 -0
  42. /package/dist/{core → cli}/add/babel.js +0 -0
  43. /package/dist/{core → cli}/add/imports.d.ts +0 -0
  44. /package/dist/{core → cli}/add/imports.js +0 -0
  45. /package/dist/{core → cli}/add/wrapper.d.ts +0 -0
  46. /package/dist/{core → cli}/add/wrapper.js +0 -0
  47. /package/dist/cli/{open.d.ts → docs/open.d.ts} +0 -0
  48. /package/dist/cli/{open.js → docs/open.js} +0 -0
@@ -788,7 +788,7 @@ export interface AstroUserConfig {
788
788
  * @docs
789
789
  * @name build.excludeMiddleware
790
790
  * @type {boolean}
791
- * @default {false}
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.
@@ -1,15 +1,16 @@
1
1
  import type yargs from 'yargs-parser';
2
- import { type LogOptions } from '../logger/core.js';
3
- export interface AddOptions {
2
+ import { type LogOptions } from '../../core/logger/core.js';
3
+ interface AddOptions {
4
4
  logging: LogOptions;
5
5
  flags: yargs.Arguments;
6
6
  cwd?: string;
7
7
  }
8
- export interface IntegrationInfo {
8
+ interface IntegrationInfo {
9
9
  id: string;
10
10
  packageName: string;
11
11
  dependencies: [name: string, version: string][];
12
12
  type: 'integration' | 'adapter';
13
13
  }
14
- export default function add(names: string[], { cwd, flags, logging }: AddOptions): Promise<void>;
14
+ export declare function add(names: string[], { cwd, flags, logging }: AddOptions): Promise<void>;
15
15
  export declare function validateIntegrations(integrations: string[]): Promise<IntegrationInfo[]>;
16
+ export {};
@@ -8,18 +8,18 @@ import path from "path";
8
8
  import preferredPM from "preferred-pm";
9
9
  import prompts from "prompts";
10
10
  import { fileURLToPath, pathToFileURL } from "url";
11
- import { loadTSConfig, resolveConfigPath } from "../config/index.js";
11
+ import { loadTSConfig, resolveConfigPath } from "../../core/config/index.js";
12
12
  import {
13
13
  defaultTSConfig,
14
14
  presets,
15
15
  updateTSConfigForFramework
16
- } from "../config/tsconfig.js";
17
- import { debug, info } from "../logger/core.js";
18
- import * as msg from "../messages.js";
19
- import { printHelp } from "../messages.js";
20
- import { appendForwardSlash } from "../path.js";
21
- import { apply as applyPolyfill } from "../polyfill.js";
22
- import { parseNpmName } from "../util.js";
16
+ } from "../../core/config/tsconfig.js";
17
+ import { debug, info } from "../../core/logger/core.js";
18
+ import * as msg from "../../core/messages.js";
19
+ import { printHelp } from "../../core/messages.js";
20
+ import { appendForwardSlash } from "../../core/path.js";
21
+ import { apply as applyPolyfill } from "../../core/polyfill.js";
22
+ import { parseNpmName } from "../../core/util.js";
23
23
  import { generate, parse, t, visit } from "./babel.js";
24
24
  import { ensureImport } from "./imports.js";
25
25
  import { wrapDefaultExport } from "./wrapper.js";
@@ -637,7 +637,8 @@ async function validateIntegrations(integrations) {
637
637
  const meta = pkgJson["peerDependenciesMeta"] || {};
638
638
  for (const peer in pkgJson["peerDependencies"]) {
639
639
  const optional = ((_a = meta[peer]) == null ? void 0 : _a.optional) || false;
640
- if (!optional) {
640
+ const isAstro = peer === "astro";
641
+ if (!optional && !isAstro) {
641
642
  dependencies.push([peer, pkgJson["peerDependencies"][peer]]);
642
643
  }
643
644
  }
@@ -824,6 +825,6 @@ async function setupIntegrationConfig(opts) {
824
825
  }
825
826
  }
826
827
  export {
827
- add as default,
828
+ add,
828
829
  validateIntegrations
829
830
  };
@@ -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(settings: AstroSettings, { logging, flags }: CheckPayload): Promise<AstroChecker | undefined>;
48
+ export declare function check({ logging, flags }: CheckPayload): Promise<AstroChecker | undefined>;
50
49
  type CheckerConstructor = {
51
50
  diagnosticChecker: AstroCheck;
52
51
  isWatchMode: boolean;
@@ -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(settings, { logging, flags }) {
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
+ };
@@ -0,0 +1,6 @@
1
+ import type yargs from 'yargs-parser';
2
+ interface DocsOptions {
3
+ flags: yargs.Arguments;
4
+ }
5
+ export declare function docs({ flags }: DocsOptions): Promise<import("execa").ExecaReturnValue<string> | undefined>;
6
+ export {};
@@ -0,0 +1,18 @@
1
+ import { printHelp } from "../../core/messages.js";
2
+ import { openInBrowser } from "./open.js";
3
+ async function docs({ flags }) {
4
+ if (flags.help || flags.h) {
5
+ printHelp({
6
+ commandName: "astro docs",
7
+ tables: {
8
+ Flags: [["--help (-h)", "See all available flags."]]
9
+ },
10
+ description: `Launches the Astro Docs website directly from the terminal.`
11
+ });
12
+ return;
13
+ }
14
+ return await openInBrowser("https://docs.astro.build/");
15
+ }
16
+ export {
17
+ docs
18
+ };
package/dist/cli/index.js CHANGED
@@ -1,23 +1,13 @@
1
- import fs from "fs";
2
1
  import * as colors from "kleur/colors";
3
- import { arch, platform } from "node:os";
4
2
  import yargs from "yargs-parser";
5
- import { ZodError } from "zod";
6
- import {
7
- createSettings,
8
- openConfig,
9
- resolveConfigPath,
10
- resolveFlags
11
- } from "../core/config/index.js";
12
3
  import { ASTRO_VERSION } from "../core/constants.js";
13
4
  import { collectErrorMetadata } from "../core/errors/dev/index.js";
14
5
  import { createSafeError } from "../core/errors/index.js";
15
- import { debug, error, info } from "../core/logger/core.js";
6
+ import { debug } from "../core/logger/core.js";
16
7
  import { enableVerboseLogging, nodeLogDestination } from "../core/logger/node.js";
17
- import { formatConfigErrorMessage, formatErrorMessage, printHelp } from "../core/messages.js";
8
+ import { formatErrorMessage, printHelp } from "../core/messages.js";
18
9
  import * as event from "../events/index.js";
19
- import { eventConfigError, eventError, telemetry } from "../events/index.js";
20
- import { openInBrowser } from "./open.js";
10
+ import { eventError, telemetry } from "../events/index.js";
21
11
  function printAstroHelp() {
22
12
  printHelp({
23
13
  commandName: "astro",
@@ -48,52 +38,10 @@ function printAstroHelp() {
48
38
  }
49
39
  });
50
40
  }
51
- async function printVersion() {
41
+ function printVersion() {
52
42
  console.log();
53
43
  console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${ASTRO_VERSION}`)}`);
54
44
  }
55
- async function printInfo({
56
- cwd,
57
- flags,
58
- logging
59
- }) {
60
- var _a;
61
- const whichPm = await import("which-pm");
62
- const packageManager = await whichPm.default(process.cwd());
63
- let adapter = "Couldn't determine.";
64
- let integrations = [];
65
- const MAX_PADDING = 25;
66
- function printRow(label, value) {
67
- const padding = MAX_PADDING - label.length;
68
- console.log(`${colors.bold(label)}` + " ".repeat(padding) + `${colors.green(value)}`);
69
- }
70
- try {
71
- const { userConfig } = await openConfig({
72
- cwd,
73
- flags,
74
- cmd: "info",
75
- logging
76
- });
77
- if ((_a = userConfig.adapter) == null ? void 0 : _a.name) {
78
- adapter = userConfig.adapter.name;
79
- }
80
- if (userConfig.integrations) {
81
- integrations = ((userConfig == null ? void 0 : userConfig.integrations) ?? []).filter(Boolean).flat().map((i) => i == null ? void 0 : i.name);
82
- }
83
- } catch (_e) {
84
- }
85
- console.log();
86
- printRow("Astro version", `v${ASTRO_VERSION}`);
87
- printRow("Package manager", packageManager.name);
88
- printRow("Platform", platform());
89
- printRow("Architecture", arch());
90
- printRow("Adapter", adapter);
91
- let integrationsString = "None or couldn't determine.";
92
- if (integrations.length > 0) {
93
- integrationsString = integrations.join(", ");
94
- }
95
- printRow("Integrations", integrationsString);
96
- }
97
45
  function resolveCommand(flags) {
98
46
  const cmd = flags._[2];
99
47
  if (flags.version)
@@ -114,118 +62,80 @@ function resolveCommand(flags) {
114
62
  }
115
63
  return "help";
116
64
  }
117
- async function handleConfigError(e, { cmd, cwd, flags, logging }) {
118
- const path = await resolveConfigPath({ cwd, flags, fs });
119
- error(logging, "astro", `Unable to load ${path ? colors.bold(path) : "your Astro config"}
120
- `);
121
- if (e instanceof ZodError) {
122
- console.error(formatConfigErrorMessage(e) + "\n");
123
- } else if (e instanceof Error) {
124
- console.error(formatErrorMessage(collectErrorMetadata(e)) + "\n");
125
- }
126
- const telemetryPromise = telemetry.record(eventConfigError({ cmd, err: e, isFatal: true }));
127
- await telemetryPromise.catch(
128
- (err2) => debug("telemetry", `record() error: ${err2.message}`)
129
- );
130
- }
131
65
  async function runCommand(cmd, flags) {
132
66
  var _a;
133
67
  const root = flags.root;
134
- let logging = {
135
- dest: nodeLogDestination,
136
- level: "info"
137
- };
138
68
  switch (cmd) {
139
69
  case "help":
140
70
  printAstroHelp();
141
- return process.exit(0);
71
+ return;
142
72
  case "version":
143
- await printVersion();
144
- return process.exit(0);
73
+ printVersion();
74
+ return;
145
75
  case "info": {
146
- await printInfo({ cwd: root, flags, logging });
147
- return process.exit(0);
76
+ const { printInfo } = await import("./info/index.js");
77
+ await printInfo({ cwd: root, flags });
78
+ return;
79
+ }
80
+ case "docs": {
81
+ telemetry.record(event.eventCliSession(cmd));
82
+ const { docs } = await import("./docs/index.js");
83
+ await docs({ flags });
84
+ return;
85
+ }
86
+ case "telemetry": {
87
+ const { update } = await import("./telemetry/index.js");
88
+ const subcommand = (_a = flags._[3]) == null ? void 0 : _a.toString();
89
+ await update(subcommand, { flags });
90
+ return;
148
91
  }
149
92
  }
93
+ const logging = {
94
+ dest: nodeLogDestination,
95
+ level: "info"
96
+ };
150
97
  if (flags.verbose) {
151
98
  logging.level = "debug";
152
99
  enableVerboseLogging();
153
100
  } else if (flags.silent) {
154
101
  logging.level = "silent";
155
102
  }
103
+ if (!process.env.NODE_ENV) {
104
+ process.env.NODE_ENV = cmd === "dev" ? "development" : "production";
105
+ }
156
106
  switch (cmd) {
157
107
  case "add": {
158
- const { default: add } = await import("../core/add/index.js");
159
108
  telemetry.record(event.eventCliSession(cmd));
109
+ const { add } = await import("./add/index.js");
160
110
  const packages = flags._.slice(3);
161
- return await add(packages, { cwd: root, flags, logging });
111
+ await add(packages, { cwd: root, flags, logging });
112
+ return;
162
113
  }
163
- case "docs": {
164
- telemetry.record(event.eventCliSession(cmd));
165
- if (flags.help || flags.h) {
166
- printHelp({
167
- commandName: "astro docs",
168
- tables: {
169
- Flags: [["--help (-h)", "See all available flags."]]
170
- },
171
- description: `Launches the Astro Docs website directly from the terminal.`
114
+ case "dev": {
115
+ const { dev } = await import("./dev/index.js");
116
+ const server = await dev({ flags, logging });
117
+ if (server) {
118
+ return await new Promise(() => {
172
119
  });
173
- return;
174
120
  }
175
- return await openInBrowser("https://docs.astro.build/");
176
- }
177
- case "telemetry": {
178
- const telemetryHandler = await import("./telemetry.js");
179
- const subcommand = (_a = flags._[3]) == null ? void 0 : _a.toString();
180
- return await telemetryHandler.update(subcommand, { flags });
181
- }
182
- }
183
- if (!process.env.NODE_ENV) {
184
- process.env.NODE_ENV = cmd === "dev" ? "development" : "production";
185
- }
186
- let { astroConfig: initialAstroConfig, userConfig: initialUserConfig } = await openConfig({
187
- cwd: root,
188
- flags,
189
- cmd,
190
- logging
191
- }).catch(async (e) => {
192
- await handleConfigError(e, { cmd, cwd: root, flags, logging });
193
- return {};
194
- });
195
- if (!initialAstroConfig)
196
- return;
197
- telemetry.record(event.eventCliSession(cmd, initialUserConfig, flags));
198
- let settings = createSettings(initialAstroConfig, root);
199
- switch (cmd) {
200
- case "dev": {
201
- const { default: devServer } = await import("../core/dev/index.js");
202
- const configFlag = resolveFlags(flags).config;
203
- const configFlagPath = configFlag ? await resolveConfigPath({ cwd: root, flags, fs }) : void 0;
204
- await devServer(settings, {
205
- configFlag,
206
- configFlagPath,
207
- flags,
208
- logging,
209
- handleConfigError(e) {
210
- handleConfigError(e, { cmd, cwd: root, flags, logging });
211
- info(logging, "astro", "Continuing with previous valid configuration\n");
212
- }
213
- });
214
- return await new Promise(() => {
215
- });
121
+ return;
216
122
  }
217
123
  case "build": {
218
- const { default: build } = await import("../core/build/index.js");
219
- return await build(settings, {
220
- flags,
221
- logging,
222
- teardownCompiler: true,
223
- mode: flags.mode
224
- });
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;
225
135
  }
226
136
  case "check": {
227
137
  const { check } = await import("./check/index.js");
228
- const checkServer = await check(settings, { flags, logging });
138
+ const checkServer = await check({ flags, logging });
229
139
  if (checkServer) {
230
140
  if (checkServer.isWatchMode) {
231
141
  await checkServer.watch();
@@ -236,19 +146,12 @@ async function runCommand(cmd, flags) {
236
146
  return process.exit(checkResult);
237
147
  }
238
148
  }
149
+ return;
239
150
  }
240
151
  case "sync": {
241
- const { syncCli } = await import("../core/sync/index.js");
242
- const result = await syncCli(settings, { logging, fs, flags });
243
- return process.exit(result);
244
- }
245
- case "preview": {
246
- const { default: preview } = await import("../core/preview/index.js");
247
- const server = await preview(settings, { logging, flags });
248
- if (server) {
249
- return await server.closed();
250
- }
251
- return;
152
+ const { sync } = await import("./sync/index.js");
153
+ const exitCode = await sync({ flags, logging });
154
+ return process.exit(exitCode);
252
155
  }
253
156
  }
254
157
  throw new Error(`Error running ${cmd} -- no command found.`);
@@ -0,0 +1,7 @@
1
+ import type yargs from 'yargs-parser';
2
+ interface InfoOptions {
3
+ cwd?: string;
4
+ flags: yargs.Arguments;
5
+ }
6
+ export declare function printInfo({ cwd, flags }: InfoOptions): Promise<void>;
7
+ export {};
@@ -0,0 +1,45 @@
1
+ import * as colors from "kleur/colors";
2
+ import { arch, platform } from "node:os";
3
+ import whichPm from "which-pm";
4
+ import { openConfig } from "../../core/config/index.js";
5
+ import { ASTRO_VERSION } from "../../core/constants.js";
6
+ async function printInfo({ cwd, flags }) {
7
+ var _a;
8
+ const packageManager = await whichPm(process.cwd());
9
+ let adapter = "Couldn't determine.";
10
+ let integrations = [];
11
+ const MAX_PADDING = 25;
12
+ function printRow(label, value) {
13
+ const padding = MAX_PADDING - label.length;
14
+ console.log(`${colors.bold(label)}` + " ".repeat(padding) + `${colors.green(value)}`);
15
+ }
16
+ try {
17
+ const { userConfig } = await openConfig({
18
+ cwd,
19
+ flags,
20
+ cmd: "info"
21
+ });
22
+ if ((_a = userConfig.adapter) == null ? void 0 : _a.name) {
23
+ adapter = userConfig.adapter.name;
24
+ }
25
+ if (userConfig.integrations) {
26
+ integrations = ((userConfig == null ? void 0 : userConfig.integrations) ?? []).filter(Boolean).flat().map((i) => i == null ? void 0 : i.name);
27
+ }
28
+ } catch (_e) {
29
+ }
30
+ console.log();
31
+ const packageManagerName = (packageManager == null ? void 0 : packageManager.name) ?? "Couldn't determine.";
32
+ printRow("Astro version", `v${ASTRO_VERSION}`);
33
+ printRow("Package manager", packageManagerName);
34
+ printRow("Platform", platform());
35
+ printRow("Architecture", arch());
36
+ printRow("Adapter", adapter);
37
+ let integrationsString = "None or couldn't determine.";
38
+ if (integrations.length > 0) {
39
+ integrationsString = integrations.join(", ");
40
+ }
41
+ printRow("Integrations", integrationsString);
42
+ }
43
+ export {
44
+ printInfo
45
+ };
@@ -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
+ };
@@ -1,5 +1,6 @@
1
1
  import type yargs from 'yargs-parser';
2
- export interface TelemetryOptions {
2
+ interface TelemetryOptions {
3
3
  flags: yargs.Arguments;
4
4
  }
5
5
  export declare function update(subcommand: string, { flags }: TelemetryOptions): Promise<void>;
6
+ export {};
@@ -1,5 +1,5 @@
1
- import * as msg from "../core/messages.js";
2
- import { telemetry } from "../events/index.js";
1
+ import * as msg from "../../core/messages.js";
2
+ import { telemetry } from "../../events/index.js";
3
3
  async function update(subcommand, { flags }) {
4
4
  const isValid = ["enable", "disable", "reset"].includes(subcommand);
5
5
  if (flags.help || flags.h || !isValid) {
@@ -25,10 +25,7 @@ function getViteConfig(inlineConfig) {
25
25
  dest: nodeLogDestination,
26
26
  level: "info"
27
27
  };
28
- const { astroConfig: config } = await openConfig({
29
- cmd,
30
- logging
31
- });
28
+ const { astroConfig: config } = await openConfig({ cmd });
32
29
  const settings = createSettings(config, inlineConfig.root);
33
30
  await runHookConfigSetup({ settings, command: cmd, logging });
34
31
  const viteConfig = await createVite(
@@ -168,8 +168,8 @@ function globWithUnderscoresIgnored(relContentDir, exts) {
168
168
  const contentDir = appendForwardSlash(relContentDir);
169
169
  return [
170
170
  `${contentDir}**/*${extGlob}`,
171
- `!${contentDir}_*/**${extGlob}`,
172
- `!${contentDir}_*${extGlob}`
171
+ `!${contentDir}**/_*/**${extGlob}`,
172
+ `!${contentDir}**/_*${extGlob}`
173
173
  ];
174
174
  }
175
175
  export {
@@ -2,7 +2,6 @@
2
2
  import type { Arguments as Flags } from 'yargs-parser';
3
3
  import type { AstroConfig, AstroUserConfig, CLIFlags } from '../../@types/astro';
4
4
  import fs from 'fs';
5
- import type { LogOptions } from '../logger/core.js';
6
5
  export declare const LEGACY_ASTRO_CONFIG_KEYS: Set<string>;
7
6
  /** Turn raw config values into normalized values */
8
7
  export declare function validateConfig(userConfig: any, root: string, cmd: string): Promise<AstroConfig>;
@@ -14,7 +13,6 @@ interface LoadConfigOptions {
14
13
  flags?: Flags;
15
14
  cmd: string;
16
15
  validate?: boolean;
17
- logging: LogOptions;
18
16
  /** Invalidate when reloading a previously loaded config */
19
17
  isRestart?: boolean;
20
18
  fsMod?: typeof fs;
@@ -39,5 +37,4 @@ export declare function openConfig(configOptions: LoadConfigOptions): Promise<Op
39
37
  /** Attempt to resolve an Astro configuration object. Normalize, validate, and return. */
40
38
  export declare function resolveConfig(userConfig: AstroUserConfig, root: string, flags: CLIFlags | undefined, cmd: string): Promise<AstroConfig>;
41
39
  export declare function createDefaultDevConfig(userConfig?: AstroUserConfig, root?: string): Promise<AstroConfig>;
42
- export declare function mergeConfig(defaults: Record<string, any>, overrides: Record<string, any>, isRoot?: boolean): Record<string, any>;
43
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
- let userConfig = {};
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 tryLoadConfig(configOptions, root) {
152
+ async function loadConfig(configOptions, root) {
159
153
  const fsMod = configOptions.fsMod ?? fs;
160
- let finallyCleanup = async () => {
161
- };
162
- try {
163
- let configPath = await resolveConfigPath({
164
- cwd: configOptions.cwd,
165
- flags: configOptions.flags,
166
- fs: fsMod
167
- });
168
- if (!configPath)
169
- return void 0;
170
- if (configOptions.isRestart) {
171
- const tempConfigPath = path.join(
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 | undefined;
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 * as vite from "vite";
2
+ import { createServer } from "vite";
3
3
  import loadFallbackPlugin from "../../vite-plugin-load-fallback/index.js";
4
- async function createViteLoader(root, fs) {
5
- const viteServer = await vite.createServer({
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
- value: config.default ?? {},
46
- filePath: configPath
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 loader;
41
+ let server;
52
42
  try {
53
- loader = await createViteLoader(root, fs);
54
- const mod = await loader.viteServer.ssrLoadModule(configPath);
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 (loader) {
61
- await loader.viteServer.close();
47
+ if (server) {
48
+ await server.close();
62
49
  }
63
50
  }
64
51
  }
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "2.8.0";
1
+ const ASTRO_VERSION = "2.8.2";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -54,7 +54,7 @@ async function dev(settings, options) {
54
54
  isRestart: options.isRestart
55
55
  })
56
56
  );
57
- const currentVersion = "2.8.0";
57
+ const currentVersion = "2.8.2";
58
58
  if (currentVersion.includes("-")) {
59
59
  warn(options.logging, null, msg.prerelease({ currentVersion }));
60
60
  }
@@ -57,7 +57,6 @@ async function restartContainer({
57
57
  cwd: resolvedRoot,
58
58
  flags,
59
59
  cmd: "dev",
60
- logging,
61
60
  isRestart: true,
62
61
  fsMod: container.fs
63
62
  });
@@ -47,7 +47,7 @@ function serverStart({
47
47
  base,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "2.8.0";
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.0"}`
236
+ `v${"2.8.2"}`
237
237
  )} ${headline}`
238
238
  );
239
239
  }
@@ -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/config.js";
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes