astro 4.11.1 → 4.11.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.
@@ -647,8 +647,11 @@ export interface AstroUserConfig {
647
647
  * @type {boolean}
648
648
  * @default `true`
649
649
  * @description
650
- * This is an option to minify your HTML output and reduce the size of your HTML files. By default, Astro removes all whitespace from your HTML, including line breaks, from `.astro` components. This occurs both in development mode and in the final build.
651
- * To disable HTML compression, set the `compressHTML` flag to `false`.
650
+ *
651
+ * This is an option to minify your HTML output and reduce the size of your HTML files, occuring both in development mode and in the final build.
652
+ * By default, Astro removes whitespace from your HTML, including line breaks, from .astro components in a lossless manner.
653
+ * It is important to note that some whitespace may be kept to preserve the visual rendering of your HTML.
654
+ * To disable HTML compression, set the compressHTML flag to false.
652
655
  *
653
656
  * ```js
654
657
  * {
@@ -14,7 +14,7 @@ export type ActionClient<TOutput, TAccept extends Accept, TInputSchema extends I
14
14
  } : ((input?: any) => Promise<Awaited<TOutput>>) & {
15
15
  safe: (input?: any) => Promise<SafeResult<never, Awaited<TOutput>>>;
16
16
  };
17
- export declare function defineAction<TOutput, TAccept extends Accept, TInputSchema extends InputSchema<Accept> | undefined = TAccept extends 'form' ? z.ZodType<FormData> : undefined>({ accept, input: inputSchema, handler, }: {
17
+ export declare function defineAction<TOutput, TAccept extends Accept = 'json', TInputSchema extends InputSchema<Accept> | undefined = TAccept extends 'form' ? z.ZodType<FormData> : undefined>({ accept, input: inputSchema, handler, }: {
18
18
  input?: TInputSchema;
19
19
  accept?: TAccept;
20
20
  handler: Handler<TInputSchema, TOutput>;
@@ -1,4 +1,4 @@
1
- import { type Logger } from '../core/logger/core.js';
1
+ import type { Logger } from '../core/logger/core.js';
2
2
  type GetPackageOptions = {
3
3
  skipAsk?: boolean;
4
4
  optional?: boolean;
@@ -1,5 +1,4 @@
1
1
  import { createRequire } from "node:module";
2
- import { pathToFileURL } from "node:url";
3
2
  import boxen from "boxen";
4
3
  import ci from "ci-info";
5
4
  import { execa } from "execa";
@@ -7,21 +6,10 @@ import { bold, cyan, dim, magenta } from "kleur/colors";
7
6
  import ora from "ora";
8
7
  import preferredPM from "preferred-pm";
9
8
  import prompts from "prompts";
10
- import resolvePackage from "resolve";
11
9
  import whichPm from "which-pm";
12
- import {} from "../core/logger/core.js";
13
- const require2 = createRequire(import.meta.url);
14
10
  async function getPackage(packageName, logger, options, otherDeps = []) {
15
11
  try {
16
- if (packageName === "@astrojs/db") {
17
- const packageJsonLoc = require2.resolve(packageName + "/package.json", {
18
- paths: [options.cwd ?? process.cwd()]
19
- });
20
- const packageLoc = pathToFileURL(packageJsonLoc.replace(`package.json`, "dist/index.js"));
21
- const packageImport2 = await import(packageLoc.toString());
22
- return packageImport2;
23
- }
24
- await tryResolve(packageName, options.cwd ?? process.cwd());
12
+ createRequire(options.cwd ?? process.cwd()).resolve(packageName);
25
13
  const packageImport = await import(packageName);
26
14
  return packageImport;
27
15
  } catch (e) {
@@ -45,23 +33,6 @@ async function getPackage(packageName, logger, options, otherDeps = []) {
45
33
  }
46
34
  }
47
35
  }
48
- function tryResolve(packageName, cwd) {
49
- return new Promise((resolve, reject) => {
50
- resolvePackage(
51
- packageName,
52
- {
53
- basedir: cwd
54
- },
55
- (err) => {
56
- if (err) {
57
- reject(err);
58
- } else {
59
- resolve(0);
60
- }
61
- }
62
- );
63
- });
64
- }
65
36
  function getInstallCommand(packages, packageManager) {
66
37
  switch (packageManager) {
67
38
  case "npm":
@@ -37,7 +37,7 @@ function getViteConfig(userViteConfig, inlineAstroConfig = {}) {
37
37
  astroContentListenPlugin({ settings, logger, fs })
38
38
  ]
39
39
  },
40
- { settings, logger, mode }
40
+ { settings, logger, mode, sync: false }
41
41
  );
42
42
  await runHookConfigDone({ settings, logger });
43
43
  return mergeConfig(viteConfig, userViteConfig);
@@ -85,7 +85,7 @@ class AstroBuilder {
85
85
  middlewareMode: true
86
86
  }
87
87
  },
88
- { settings: this.settings, logger: this.logger, mode: "build", command: "build" }
88
+ { settings: this.settings, logger: this.logger, mode: "build", command: "build", sync: false }
89
89
  );
90
90
  await runHookConfigDone({ settings: this.settings, logger });
91
91
  const { syncContentCollections } = await import("../sync/index.js");
@@ -378,11 +378,13 @@ function pluginContent(opts, internals) {
378
378
  if (!isContentCollectionsCacheEnabled(opts.settings.config)) {
379
379
  return;
380
380
  }
381
+ const promises = [];
381
382
  for (const { cached, dist } of cachedBuildOutput) {
382
383
  if (fsMod.existsSync(dist)) {
383
- await copyFiles(dist, cached, true);
384
+ promises.push(copyFiles(dist, cached, true));
384
385
  }
385
386
  }
387
+ if (promises.length) await Promise.all(promises);
386
388
  }
387
389
  }
388
390
  };
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.11.1";
1
+ const ASTRO_VERSION = "4.11.2";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
4
4
  const DEFAULT_404_COMPONENT = "astro-default-404.astro";
@@ -8,7 +8,8 @@ interface CreateViteOptions {
8
8
  mode: 'dev' | 'build' | string;
9
9
  command?: 'dev' | 'build';
10
10
  fs?: typeof nodeFs;
11
+ sync: boolean;
11
12
  }
12
13
  /** Return a base vite config as a common starting point for all Vite commands. */
13
- export declare function createVite(commandConfig: vite.InlineConfig, { settings, logger, mode, command, fs }: CreateViteOptions): Promise<vite.InlineConfig>;
14
+ export declare function createVite(commandConfig: vite.InlineConfig, { settings, logger, mode, command, fs, sync }: CreateViteOptions): Promise<vite.InlineConfig>;
14
15
  export {};
@@ -54,7 +54,7 @@ const ONLY_DEV_EXTERNAL = [
54
54
  // Imported by `astro/assets` -> `packages/astro/src/core/logger/core.ts`
55
55
  "string-width"
56
56
  ];
57
- async function createVite(commandConfig, { settings, logger, mode, command, fs = nodeFs }) {
57
+ async function createVite(commandConfig, { settings, logger, mode, command, fs = nodeFs, sync }) {
58
58
  const astroPkgsConfig = await crawlFrameworkPkgs({
59
59
  root: fileURLToPath(settings.config.root),
60
60
  isBuild: mode === "build",
@@ -112,7 +112,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
112
112
  // the build to run very slow as the filewatcher is triggered often.
113
113
  mode !== "build" && vitePluginAstroServer({ settings, logger, fs }),
114
114
  envVitePlugin({ settings }),
115
- astroEnv({ settings, mode, fs }),
115
+ astroEnv({ settings, mode, fs, sync }),
116
116
  markdownVitePlugin({ settings, logger }),
117
117
  htmlVitePlugin(),
118
118
  mdxVitePlugin(),
@@ -38,7 +38,7 @@ async function createContainer({
38
38
  include: rendererClientEntries
39
39
  }
40
40
  },
41
- { settings, logger, mode: "dev", command: "dev", fs }
41
+ { settings, logger, mode: "dev", command: "dev", fs, sync: false }
42
42
  );
43
43
  await runHookConfigDone({ settings, logger });
44
44
  const viteServer = await vite.createServer(viteConfig);
@@ -19,7 +19,7 @@ async function dev(inlineConfig) {
19
19
  await telemetry.record([]);
20
20
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
21
21
  const logger = restart.container.logger;
22
- const currentVersion = "4.11.1";
22
+ const currentVersion = "4.11.2";
23
23
  const isPrerelease = currentVersion.includes("-");
24
24
  if (!isPrerelease) {
25
25
  try {
@@ -37,7 +37,7 @@ function serverStart({
37
37
  host,
38
38
  base
39
39
  }) {
40
- const version = "4.11.1";
40
+ const version = "4.11.2";
41
41
  const localPrefix = `${dim("\u2503")} Local `;
42
42
  const networkPrefix = `${dim("\u2503")} Network `;
43
43
  const emptyPrefix = " ".repeat(11);
@@ -269,7 +269,7 @@ function printHelp({
269
269
  message.push(
270
270
  linebreak(),
271
271
  ` ${bgGreen(black(` ${commandName} `))} ${green(
272
- `v${"4.11.1"}`
272
+ `v${"4.11.2"}`
273
273
  )} ${headline}`
274
274
  );
275
275
  }
@@ -6,6 +6,7 @@ import { createServer } from "vite";
6
6
  import { getPackage } from "../../cli/install-package.js";
7
7
  import { createContentTypesGenerator } from "../../content/index.js";
8
8
  import { globalContentConfigObserver } from "../../content/utils.js";
9
+ import { syncAstroEnv } from "../../env/sync.js";
9
10
  import { telemetry } from "../../events/index.js";
10
11
  import { eventCliSession } from "../../events/session.js";
11
12
  import { runHookConfigSetup } from "../../integrations/hooks.js";
@@ -50,6 +51,7 @@ async function sync(inlineConfig, options) {
50
51
  await dbPackage?.typegen?.(astroConfig);
51
52
  const exitCode = await syncContentCollections(settings, { ...options, logger });
52
53
  if (exitCode !== 0) return exitCode;
54
+ syncAstroEnv(settings, options?.fs);
53
55
  logger.info(null, `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`);
54
56
  return 0;
55
57
  } catch (err) {
@@ -70,7 +72,7 @@ async function syncContentCollections(settings, { logger, fs }) {
70
72
  ssr: { external: [] },
71
73
  logLevel: "silent"
72
74
  },
73
- { settings, logger, mode: "build", command: "build", fs }
75
+ { settings, logger, mode: "build", command: "build", fs, sync: true }
74
76
  )
75
77
  );
76
78
  const hotSend = tempViteServer.hot.send;
@@ -0,0 +1,3 @@
1
+ import fsMod from 'node:fs';
2
+ import type { AstroSettings } from '../@types/astro.js';
3
+ export declare function syncAstroEnv(settings: AstroSettings, fs?: typeof fsMod): void;
@@ -0,0 +1,27 @@
1
+ import fsMod from "node:fs";
2
+ import { ENV_TYPES_FILE, TYPES_TEMPLATE_URL } from "./constants.js";
3
+ import { getEnvFieldType } from "./validators.js";
4
+ function syncAstroEnv(settings, fs = fsMod) {
5
+ if (!settings.config.experimental.env) {
6
+ return;
7
+ }
8
+ const schema = settings.config.experimental.env.schema ?? {};
9
+ let client = "";
10
+ let server = "";
11
+ for (const [key, options] of Object.entries(schema)) {
12
+ const str = `export const ${key}: ${getEnvFieldType(options)};
13
+ `;
14
+ if (options.context === "client") {
15
+ client += str;
16
+ } else {
17
+ server += str;
18
+ }
19
+ }
20
+ const template = fs.readFileSync(TYPES_TEMPLATE_URL, "utf-8");
21
+ const dts = template.replace("// @@CLIENT@@", client).replace("// @@SERVER@@", server);
22
+ fs.mkdirSync(settings.dotAstroDir, { recursive: true });
23
+ fs.writeFileSync(new URL(ENV_TYPES_FILE, settings.dotAstroDir), dts, "utf-8");
24
+ }
25
+ export {
26
+ syncAstroEnv
27
+ };
@@ -5,6 +5,7 @@ interface AstroEnvVirtualModPluginParams {
5
5
  settings: AstroSettings;
6
6
  mode: 'dev' | 'build' | string;
7
7
  fs: typeof fsMod;
8
+ sync: boolean;
8
9
  }
9
- export declare function astroEnv({ settings, mode, fs, }: AstroEnvVirtualModPluginParams): Plugin | undefined;
10
+ export declare function astroEnv({ settings, mode, fs, sync, }: AstroEnvVirtualModPluginParams): Plugin | undefined;
10
11
  export {};
@@ -2,19 +2,18 @@ import { fileURLToPath } from "node:url";
2
2
  import { loadEnv } from "vite";
3
3
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
4
4
  import {
5
- ENV_TYPES_FILE,
6
5
  MODULE_TEMPLATE_URL,
7
- TYPES_TEMPLATE_URL,
8
6
  VIRTUAL_MODULES_IDS,
9
7
  VIRTUAL_MODULES_IDS_VALUES
10
8
  } from "./constants.js";
11
- import { getEnvFieldType, validateEnvVariable } from "./validators.js";
9
+ import { validateEnvVariable } from "./validators.js";
12
10
  function astroEnv({
13
11
  settings,
14
12
  mode,
15
- fs
13
+ fs,
14
+ sync
16
15
  }) {
17
- if (!settings.config.experimental.env) {
16
+ if (!settings.config.experimental.env || sync) {
18
17
  return;
19
18
  }
20
19
  const schema = settings.config.experimental.env.schema ?? {};
@@ -34,22 +33,10 @@ function astroEnv({
34
33
  }
35
34
  }
36
35
  const validatedVariables = validatePublicVariables({ schema, loadedEnv });
37
- const clientTemplates = getClientTemplates({ validatedVariables });
38
- const serverTemplates = getServerTemplates({ validatedVariables, schema, fs });
39
36
  templates = {
40
- client: clientTemplates.module,
41
- server: serverTemplates.module,
37
+ ...getTemplates(schema, fs, validatedVariables),
42
38
  internal: `export const schema = ${JSON.stringify(schema)};`
43
39
  };
44
- generateDts({
45
- settings,
46
- fs,
47
- content: getDts({
48
- fs,
49
- client: clientTemplates.types,
50
- server: serverTemplates.types
51
- })
52
- });
53
40
  },
54
41
  buildEnd() {
55
42
  templates = null;
@@ -81,14 +68,6 @@ function astroEnv({
81
68
  function resolveVirtualModuleId(id) {
82
69
  return `\0${id}`;
83
70
  }
84
- function generateDts({
85
- content,
86
- settings,
87
- fs
88
- }) {
89
- fs.mkdirSync(settings.dotAstroDir, { recursive: true });
90
- fs.writeFileSync(new URL(ENV_TYPES_FILE, settings.dotAstroDir), content, "utf-8");
91
- }
92
71
  function validatePublicVariables({
93
72
  schema,
94
73
  loadedEnv
@@ -117,57 +96,31 @@ function validatePublicVariables({
117
96
  }
118
97
  return valid;
119
98
  }
120
- function getDts({
121
- client,
122
- server,
123
- fs
124
- }) {
125
- const template = fs.readFileSync(TYPES_TEMPLATE_URL, "utf-8");
126
- return template.replace("// @@CLIENT@@", client).replace("// @@SERVER@@", server);
127
- }
128
- function getClientTemplates({
129
- validatedVariables
130
- }) {
131
- let module = "";
132
- let types = "";
133
- for (const { key, type, value } of validatedVariables.filter((e) => e.context === "client")) {
134
- module += `export const ${key} = ${JSON.stringify(value)};`;
135
- types += `export const ${key}: ${type};
136
- `;
137
- }
138
- return {
139
- module,
140
- types
141
- };
142
- }
143
- function getServerTemplates({
144
- validatedVariables,
145
- schema,
146
- fs
147
- }) {
148
- let module = fs.readFileSync(MODULE_TEMPLATE_URL, "utf-8");
149
- let types = "";
99
+ function getTemplates(schema, fs, validatedVariables) {
100
+ let client = "";
101
+ let server = fs.readFileSync(MODULE_TEMPLATE_URL, "utf-8");
150
102
  let onSetGetEnv = "";
151
- for (const { key, type, value } of validatedVariables.filter((e) => e.context === "server")) {
152
- module += `export const ${key} = ${JSON.stringify(value)};`;
153
- types += `export const ${key}: ${type};
154
- `;
103
+ for (const { key, value, context } of validatedVariables) {
104
+ const str = `export const ${key} = ${JSON.stringify(value)};`;
105
+ if (context === "client") {
106
+ client += str;
107
+ } else {
108
+ server += str;
109
+ }
155
110
  }
156
111
  for (const [key, options] of Object.entries(schema)) {
157
112
  if (!(options.context === "server" && options.access === "secret")) {
158
113
  continue;
159
114
  }
160
- types += `export const ${key}: ${getEnvFieldType(options)};
161
- `;
162
- module += `export let ${key} = _internalGetSecret(${JSON.stringify(key)});
115
+ server += `export let ${key} = _internalGetSecret(${JSON.stringify(key)});
163
116
  `;
164
117
  onSetGetEnv += `${key} = reset ? undefined : _internalGetSecret(${JSON.stringify(key)});
165
118
  `;
166
119
  }
167
- module = module.replace("// @@ON_SET_GET_ENV@@", onSetGetEnv);
120
+ server = server.replace("// @@ON_SET_GET_ENV@@", onSetGetEnv);
168
121
  return {
169
- module,
170
- types
122
+ client,
123
+ server
171
124
  };
172
125
  }
173
126
  export {
@@ -33,7 +33,7 @@ class DevToolbarTooltip extends HTMLElement {
33
33
 
34
34
  svg {
35
35
  vertical-align: bottom;
36
- margin-right: 4px;
36
+ margin-inline-end: 4px;
37
37
  }
38
38
 
39
39
  hr {
@@ -9,9 +9,6 @@ function recordServerError(loader, config, { logger }, _err) {
9
9
  } catch {
10
10
  }
11
11
  const errorWithMetadata = collectErrorMetadata(err, config.root);
12
- if (errorWithMetadata.name !== AstroErrorData.UnhandledRejection.name) {
13
- telemetry.record(eventError({ cmd: "dev", err: errorWithMetadata, isFatal: false }));
14
- }
15
12
  logger.error(null, formatErrorMessage(errorWithMetadata, logger.level() === "debug"));
16
13
  return {
17
14
  error: err,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.11.1",
3
+ "version": "4.11.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",
@@ -155,7 +155,6 @@
155
155
  "preferred-pm": "^3.1.3",
156
156
  "prompts": "^2.4.2",
157
157
  "rehype": "^13.0.1",
158
- "resolve": "^1.22.8",
159
158
  "semver": "^7.6.2",
160
159
  "shiki": "^1.9.0",
161
160
  "string-width": "^7.1.0",
@@ -195,7 +194,6 @@
195
194
  "@types/js-yaml": "^4.0.9",
196
195
  "@types/probe-image-size": "^7.2.4",
197
196
  "@types/prompts": "^2.4.9",
198
- "@types/resolve": "^1.20.6",
199
197
  "@types/semver": "^7.5.8",
200
198
  "@types/send": "^0.17.4",
201
199
  "@types/unist": "^3.0.2",