astro 4.11.1 → 4.11.3

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 (41) hide show
  1. package/dist/@types/astro.d.ts +5 -2
  2. package/dist/actions/runtime/virtual/server.d.ts +1 -1
  3. package/dist/cli/install-package.d.ts +1 -1
  4. package/dist/cli/install-package.js +1 -29
  5. package/dist/config/index.js +1 -1
  6. package/dist/container/index.js +2 -2
  7. package/dist/container/pipeline.js +0 -3
  8. package/dist/content/vite-plugin-content-virtual-mod.d.ts +1 -1
  9. package/dist/content/vite-plugin-content-virtual-mod.js +2 -2
  10. package/dist/core/build/index.js +1 -1
  11. package/dist/core/build/plugins/plugin-content.js +3 -1
  12. package/dist/core/build/plugins/plugin-manifest.js +0 -1
  13. package/dist/core/compile/compile.js +1 -1
  14. package/dist/core/config/config.d.ts +1 -3
  15. package/dist/core/config/config.js +13 -19
  16. package/dist/core/config/validate.d.ts +3 -0
  17. package/dist/core/config/validate.js +8 -0
  18. package/dist/core/constants.js +1 -1
  19. package/dist/core/create-vite.d.ts +2 -1
  20. package/dist/core/create-vite.js +2 -2
  21. package/dist/core/dev/container.js +1 -1
  22. package/dist/core/dev/dev.js +1 -1
  23. package/dist/core/messages.js +2 -2
  24. package/dist/core/sync/index.js +3 -1
  25. package/dist/core/util.d.ts +0 -11
  26. package/dist/core/util.js +1 -44
  27. package/dist/core/viteUtils.d.ts +11 -0
  28. package/dist/core/viteUtils.js +49 -0
  29. package/dist/env/sync.d.ts +3 -0
  30. package/dist/env/sync.js +27 -0
  31. package/dist/env/vite-plugin-env.d.ts +2 -1
  32. package/dist/env/vite-plugin-env.js +19 -66
  33. package/dist/jsx/babel.js +1 -1
  34. package/dist/jsx/rehype.js +1 -1
  35. package/dist/runtime/client/dev-toolbar/ui-library/tooltip.js +1 -1
  36. package/dist/vite-plugin-astro-server/error.js +0 -3
  37. package/dist/vite-plugin-astro-server/pipeline.js +4 -6
  38. package/dist/vite-plugin-astro-server/resolve.js +1 -1
  39. package/dist/vite-plugin-astro-server/scripts.js +2 -1
  40. package/dist/vite-plugin-scanner/index.js +2 -1
  41. package/package.json +1 -3
@@ -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,11 @@ 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
10
  const require2 = createRequire(import.meta.url);
14
11
  async function getPackage(packageName, logger, options, otherDeps = []) {
15
12
  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());
13
+ require2.resolve(packageName, { paths: [options.cwd ?? process.cwd()] });
25
14
  const packageImport = await import(packageName);
26
15
  return packageImport;
27
16
  } catch (e) {
@@ -45,23 +34,6 @@ async function getPackage(packageName, logger, options, otherDeps = []) {
45
34
  }
46
35
  }
47
36
  }
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
37
  function getInstallCommand(packages, packageManager) {
66
38
  switch (packageManager) {
67
39
  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);
@@ -1,6 +1,6 @@
1
1
  import { posix } from "node:path";
2
- import { validateConfig } from "../core/config/config.js";
3
2
  import { ASTRO_CONFIG_DEFAULTS } from "../core/config/schema.js";
3
+ import { validateConfig } from "../core/config/validate.js";
4
4
  import { Logger } from "../core/logger/core.js";
5
5
  import { nodeLogDestination } from "../core/logger/node.js";
6
6
  import { removeLeadingForwardSlash } from "../core/path.js";
@@ -73,7 +73,7 @@ class experimental_AstroContainer {
73
73
  async #containerResolve(specifier, astroConfig) {
74
74
  const found = this.#pipeline.manifest.entryModules[specifier];
75
75
  if (found) {
76
- return new URL(found, astroConfig.build.client).toString();
76
+ return new URL(found, astroConfig?.build.client).toString();
77
77
  }
78
78
  return found;
79
79
  }
@@ -1,11 +1,8 @@
1
1
  import { Pipeline } from "../core/base-pipeline.js";
2
- import { RouteNotFound } from "../core/errors/errors-data.js";
3
- import { AstroError } from "../core/errors/index.js";
4
2
  import {
5
3
  createModuleScriptElement,
6
4
  createStylesheetElementSet
7
5
  } from "../core/render/ssr-element.js";
8
- import { DEFAULT_404_ROUTE } from "../core/routing/astro-designed-error-pages.js";
9
6
  import { findRouteToRewrite } from "../core/routing/rewrite.js";
10
7
  class ContainerPipeline extends Pipeline {
11
8
  /**
@@ -1,5 +1,5 @@
1
1
  import nodeFs from 'node:fs';
2
- import { type Plugin } from 'vite';
2
+ import type { Plugin } from 'vite';
3
3
  import type { AstroSettings } from '../@types/astro.js';
4
4
  import { type ContentLookupMap } from './utils.js';
5
5
  interface AstroContentVirtualModPluginParams {
@@ -3,11 +3,11 @@ import { extname } from "node:path";
3
3
  import { fileURLToPath, pathToFileURL } from "node:url";
4
4
  import glob from "fast-glob";
5
5
  import pLimit from "p-limit";
6
- import {} from "vite";
7
6
  import { encodeName } from "../core/build/util.js";
8
7
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
9
8
  import { appendForwardSlash, removeFileExtension } from "../core/path.js";
10
- import { isServerLikeOutput, rootRelativePath } from "../core/util.js";
9
+ import { isServerLikeOutput } from "../core/util.js";
10
+ import { rootRelativePath } from "../core/viteUtils.js";
11
11
  import {
12
12
  CONTENT_FLAG,
13
13
  CONTENT_RENDER_FLAG,
@@ -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,6 +1,5 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  import glob from "fast-glob";
3
- import {} from "vite";
4
3
  import { getAssetsPrefix } from "../../../assets/utils/getAssetsPrefix.js";
5
4
  import { normalizeTheLocale } from "../../../i18n/index.js";
6
5
  import { toRoutingStrategy } from "../../../i18n/utils.js";
@@ -3,7 +3,7 @@ import { transform } from "@astrojs/compiler";
3
3
  import { normalizePath } from "vite";
4
4
  import { AggregateError, CompilerError } from "../errors/errors.js";
5
5
  import { AstroErrorData } from "../errors/index.js";
6
- import { resolvePath } from "../util.js";
6
+ import { resolvePath } from "../viteUtils.js";
7
7
  import { createStylePreprocessor } from "./style.js";
8
8
  async function compile({
9
9
  astroConfig,
@@ -1,8 +1,6 @@
1
+ import fs from 'node:fs';
1
2
  import type { Arguments as Flags } from 'yargs-parser';
2
3
  import type { AstroConfig, AstroInlineConfig, AstroUserConfig, CLIFlags } from '../../@types/astro.js';
3
- import fs from 'node:fs';
4
- /** Turn raw config values into normalized values */
5
- export declare function validateConfig(userConfig: any, root: string, cmd: string): Promise<AstroConfig>;
6
4
  /** Convert the generic "yargs" flag object into our own, custom TypeScript object. */
7
5
  export declare function resolveFlags(flags: Partial<Flags>): CLIFlags;
8
6
  export declare function resolveRoot(cwd?: string | URL): string;
@@ -8,23 +8,8 @@ import { trackAstroConfigZodError } from "../errors/errors.js";
8
8
  import { AstroError, AstroErrorData } from "../errors/index.js";
9
9
  import { formatConfigErrorMessage } from "../messages.js";
10
10
  import { mergeConfig } from "./merge.js";
11
- import { createRelativeSchema } from "./schema.js";
11
+ import { validateConfig } from "./validate.js";
12
12
  import { loadConfigWithVite } from "./vite-load.js";
13
- async function validateConfig(userConfig, root, cmd) {
14
- const AstroConfigRelativeSchema = createRelativeSchema(cmd, root);
15
- let result;
16
- try {
17
- result = await AstroConfigRelativeSchema.parseAsync(userConfig);
18
- } catch (e) {
19
- if (e instanceof ZodError) {
20
- trackAstroConfigZodError(e);
21
- console.error(formatConfigErrorMessage(e) + "\n");
22
- telemetry.record(eventConfigError({ cmd, err: e, isFatal: true }));
23
- }
24
- throw e;
25
- }
26
- return result;
27
- }
28
13
  function resolveFlags(flags) {
29
14
  return {
30
15
  root: typeof flags.root === "string" ? flags.root : void 0,
@@ -113,7 +98,17 @@ async function resolveConfig(inlineConfig, command, fsMod = fs) {
113
98
  }
114
99
  const userConfig = await loadConfig(root, inlineOnlyConfig.configFile, fsMod);
115
100
  const mergedConfig = mergeConfig(userConfig, inlineUserConfig);
116
- const astroConfig = await validateConfig(mergedConfig, root, command);
101
+ let astroConfig;
102
+ try {
103
+ astroConfig = await validateConfig(mergedConfig, root, command);
104
+ } catch (e) {
105
+ if (e instanceof ZodError) {
106
+ trackAstroConfigZodError(e);
107
+ console.error(formatConfigErrorMessage(e) + "\n");
108
+ telemetry.record(eventConfigError({ cmd: command, err: e, isFatal: true }));
109
+ }
110
+ throw e;
111
+ }
117
112
  return { userConfig: mergedConfig, astroConfig };
118
113
  }
119
114
  export {
@@ -121,6 +116,5 @@ export {
121
116
  resolveConfig,
122
117
  resolveConfigPath,
123
118
  resolveFlags,
124
- resolveRoot,
125
- validateConfig
119
+ resolveRoot
126
120
  };
@@ -0,0 +1,3 @@
1
+ import type { AstroConfig } from '../../@types/astro.js';
2
+ /** Turn raw config values into normalized values */
3
+ export declare function validateConfig(userConfig: any, root: string, cmd: string): Promise<AstroConfig>;
@@ -0,0 +1,8 @@
1
+ import { createRelativeSchema } from "./schema.js";
2
+ async function validateConfig(userConfig, root, cmd) {
3
+ const AstroConfigRelativeSchema = createRelativeSchema(cmd, root);
4
+ return await AstroConfigRelativeSchema.parseAsync(userConfig);
5
+ }
6
+ export {
7
+ validateConfig
8
+ };
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.11.1";
1
+ const ASTRO_VERSION = "4.11.3";
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.3";
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.3";
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.3"}`
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;
@@ -1,5 +1,4 @@
1
1
  import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro.js';
2
- import type { ModuleLoader } from './module-loader/index.js';
3
2
  /** Returns true if argument is an object of any prototype/class (but not null). */
4
3
  export declare function isObject(value: unknown): value is Record<string, any>;
5
4
  /** Cross-realm compatible URL */
@@ -40,18 +39,8 @@ export declare function isServerLikeOutput(config: AstroConfig): boolean;
40
39
  export declare function isModeServerWithNoAdapter(settings: AstroSettings): boolean;
41
40
  export declare function isContentCollectionsCacheEnabled(config: AstroConfig): boolean;
42
41
  export declare function relativeToSrcDir(config: AstroConfig, idOrUrl: URL | string): string;
43
- export declare function rootRelativePath(root: URL, idOrUrl: URL | string, shouldPrependForwardSlash?: boolean): string;
44
42
  export declare function emoji(char: string, fallback: string): string;
45
- /**
46
- * Simulate Vite's resolve and import analysis so we can import the id as an URL
47
- * through a script tag or a dynamic import as-is.
48
- */
49
- export declare function resolveIdToUrl(loader: ModuleLoader, id: string, root?: URL): Promise<string>;
50
43
  export declare function resolveJsToTs(filePath: string): string;
51
- /**
52
- * Resolve the hydration paths so that it can be imported in the client
53
- */
54
- export declare function resolvePath(specifier: string, importer: string): string;
55
44
  /**
56
45
  * Set a default NODE_ENV so Vite doesn't set an incorrect default when loading the Astro config
57
46
  */
package/dist/core/util.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
- import { normalizePath } from "vite";
5
4
  import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./constants.js";
6
- import { prependForwardSlash, removeTrailingForwardSlash, slash } from "./path.js";
5
+ import { removeTrailingForwardSlash, slash } from "./path.js";
7
6
  function isObject(value) {
8
7
  return typeof value === "object" && value != null;
9
8
  }
@@ -123,40 +122,9 @@ function relativeToSrcDir(config, idOrUrl) {
123
122
  }
124
123
  return id.slice(slash(fileURLToPath(config.srcDir)).length);
125
124
  }
126
- function rootRelativePath(root, idOrUrl, shouldPrependForwardSlash = true) {
127
- let id;
128
- if (typeof idOrUrl !== "string") {
129
- id = unwrapId(viteID(idOrUrl));
130
- } else {
131
- id = idOrUrl;
132
- }
133
- const normalizedRoot = normalizePath(fileURLToPath(root));
134
- if (id.startsWith(normalizedRoot)) {
135
- id = id.slice(normalizedRoot.length);
136
- }
137
- return shouldPrependForwardSlash ? prependForwardSlash(id) : id;
138
- }
139
125
  function emoji(char, fallback) {
140
126
  return process.platform !== "win32" ? char : fallback;
141
127
  }
142
- async function resolveIdToUrl(loader, id, root) {
143
- let resultId = await loader.resolveId(id, void 0);
144
- if (!resultId && id.endsWith(".jsx")) {
145
- resultId = await loader.resolveId(id.slice(0, -4), void 0);
146
- }
147
- if (!resultId) {
148
- return VALID_ID_PREFIX + id;
149
- }
150
- if (path.isAbsolute(resultId)) {
151
- const normalizedRoot = root && normalizePath(fileURLToPath(root));
152
- if (normalizedRoot && resultId.startsWith(normalizedRoot)) {
153
- return resultId.slice(normalizedRoot.length - 1);
154
- } else {
155
- return "/@fs" + prependForwardSlash(resultId);
156
- }
157
- }
158
- return VALID_ID_PREFIX + resultId;
159
- }
160
128
  function resolveJsToTs(filePath) {
161
129
  if (filePath.endsWith(".jsx") && !fs.existsSync(filePath)) {
162
130
  const tryPath = filePath.slice(0, -4) + ".tsx";
@@ -166,14 +134,6 @@ function resolveJsToTs(filePath) {
166
134
  }
167
135
  return filePath;
168
136
  }
169
- function resolvePath(specifier, importer) {
170
- if (specifier.startsWith(".")) {
171
- const absoluteSpecifier = path.resolve(path.dirname(importer), specifier);
172
- return resolveJsToTs(normalizePath(absoluteSpecifier));
173
- } else {
174
- return specifier;
175
- }
176
- }
177
137
  function ensureProcessNodeEnv(defaultNodeEnv) {
178
138
  if (!process.env.NODE_ENV) {
179
139
  process.env.NODE_ENV = defaultNodeEnv;
@@ -197,11 +157,8 @@ export {
197
157
  padMultilineString,
198
158
  parseNpmName,
199
159
  relativeToSrcDir,
200
- resolveIdToUrl,
201
160
  resolveJsToTs,
202
161
  resolvePages,
203
- resolvePath,
204
- rootRelativePath,
205
162
  unwrapId,
206
163
  viteID
207
164
  };
@@ -0,0 +1,11 @@
1
+ import type { ModuleLoader } from './module-loader/index.js';
2
+ /**
3
+ * Resolve the hydration paths so that it can be imported in the client
4
+ */
5
+ export declare function resolvePath(specifier: string, importer: string): string;
6
+ export declare function rootRelativePath(root: URL, idOrUrl: URL | string, shouldPrependForwardSlash?: boolean): string;
7
+ /**
8
+ * Simulate Vite's resolve and import analysis so we can import the id as an URL
9
+ * through a script tag or a dynamic import as-is.
10
+ */
11
+ export declare function resolveIdToUrl(loader: ModuleLoader, id: string, root?: URL): Promise<string>;
@@ -0,0 +1,49 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import { normalizePath } from "vite";
4
+ import { prependForwardSlash } from "../core/path.js";
5
+ import { VALID_ID_PREFIX, resolveJsToTs, unwrapId, viteID } from "./util.js";
6
+ function resolvePath(specifier, importer) {
7
+ if (specifier.startsWith(".")) {
8
+ const absoluteSpecifier = path.resolve(path.dirname(importer), specifier);
9
+ return resolveJsToTs(normalizePath(absoluteSpecifier));
10
+ } else {
11
+ return specifier;
12
+ }
13
+ }
14
+ function rootRelativePath(root, idOrUrl, shouldPrependForwardSlash = true) {
15
+ let id;
16
+ if (typeof idOrUrl !== "string") {
17
+ id = unwrapId(viteID(idOrUrl));
18
+ } else {
19
+ id = idOrUrl;
20
+ }
21
+ const normalizedRoot = normalizePath(fileURLToPath(root));
22
+ if (id.startsWith(normalizedRoot)) {
23
+ id = id.slice(normalizedRoot.length);
24
+ }
25
+ return shouldPrependForwardSlash ? prependForwardSlash(id) : id;
26
+ }
27
+ async function resolveIdToUrl(loader, id, root) {
28
+ let resultId = await loader.resolveId(id, void 0);
29
+ if (!resultId && id.endsWith(".jsx")) {
30
+ resultId = await loader.resolveId(id.slice(0, -4), void 0);
31
+ }
32
+ if (!resultId) {
33
+ return VALID_ID_PREFIX + id;
34
+ }
35
+ if (path.isAbsolute(resultId)) {
36
+ const normalizedRoot = root && normalizePath(fileURLToPath(root));
37
+ if (normalizedRoot && resultId.startsWith(normalizedRoot)) {
38
+ return resultId.slice(normalizedRoot.length - 1);
39
+ } else {
40
+ return "/@fs" + prependForwardSlash(resultId);
41
+ }
42
+ }
43
+ return VALID_ID_PREFIX + resultId;
44
+ }
45
+ export {
46
+ resolveIdToUrl,
47
+ resolvePath,
48
+ rootRelativePath
49
+ };
@@ -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 {
package/dist/jsx/babel.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as t from "@babel/types";
2
2
  import { AstroError } from "../core/errors/errors.js";
3
3
  import { AstroErrorData } from "../core/errors/index.js";
4
- import { resolvePath } from "../core/util.js";
4
+ import { resolvePath } from "../core/viteUtils.js";
5
5
  const ClientOnlyPlaceholder = "astro-client-only";
6
6
  function isComponent(tagName) {
7
7
  return tagName[0] && tagName[0].toLowerCase() !== tagName[0] || tagName.includes(".") || /[^a-zA-Z]/.test(tagName[0]);
@@ -1,7 +1,7 @@
1
1
  import { visit } from "unist-util-visit";
2
2
  import { AstroError } from "../core/errors/errors.js";
3
3
  import { AstroErrorData } from "../core/errors/index.js";
4
- import { resolvePath } from "../core/util.js";
4
+ import { resolvePath } from "../core/viteUtils.js";
5
5
  const ClientOnlyPlaceholder = "astro-client-only";
6
6
  const rehypeAnalyzeAstroMetadata = () => {
7
7
  return (tree, file) => {
@@ -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,
@@ -1,16 +1,14 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  import { getInfoOutput } from "../cli/info/index.js";
3
3
  import {} from "../core/base-pipeline.js";
4
- import { shouldAppendForwardSlash } from "../core/build/util.js";
5
4
  import { ASTRO_VERSION, DEFAULT_404_COMPONENT } from "../core/constants.js";
6
5
  import { enhanceViteSSRError } from "../core/errors/dev/index.js";
7
- import { RewriteEncounteredAnError } from "../core/errors/errors-data.js";
8
- import { AggregateError, AstroError, CSSError, MarkdownError } from "../core/errors/index.js";
9
- import { prependForwardSlash, removeTrailingForwardSlash } from "../core/path.js";
6
+ import { AggregateError, CSSError, MarkdownError } from "../core/errors/index.js";
10
7
  import { Pipeline, loadRenderer } from "../core/render/index.js";
11
- import { DEFAULT_404_ROUTE, default404Page } from "../core/routing/astro-designed-error-pages.js";
8
+ import { default404Page } from "../core/routing/astro-designed-error-pages.js";
12
9
  import { findRouteToRewrite } from "../core/routing/rewrite.js";
13
- import { isPage, isServerLikeOutput, resolveIdToUrl, viteID } from "../core/util.js";
10
+ import { isPage, isServerLikeOutput, viteID } from "../core/util.js";
11
+ import { resolveIdToUrl } from "../core/viteUtils.js";
14
12
  import { PAGE_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
15
13
  import { getStylesForURL } from "./css.js";
16
14
  import { getComponentMetadata } from "./metadata.js";
@@ -1,4 +1,4 @@
1
- import { resolveIdToUrl } from "../core/util.js";
1
+ import { resolveIdToUrl } from "../core/viteUtils.js";
2
2
  function createResolve(loader, root) {
3
3
  return async function(s) {
4
4
  return await resolveIdToUrl(loader, s, root);
@@ -1,5 +1,6 @@
1
1
  import { createModuleScriptElementWithSrc } from "../core/render/ssr-element.js";
2
- import { rootRelativePath, viteID } from "../core/util.js";
2
+ import { viteID } from "../core/util.js";
3
+ import { rootRelativePath } from "../core/viteUtils.js";
3
4
  import { crawlGraph } from "./vite.js";
4
5
  async function getScriptsForURL(filePath, root, loader) {
5
6
  const elements = /* @__PURE__ */ new Set();
@@ -2,7 +2,8 @@ import { extname } from "node:path";
2
2
  import { bold } from "kleur/colors";
3
3
  import { normalizePath } from "vite";
4
4
  import {} from "../core/logger/core.js";
5
- import { isEndpoint, isPage, isServerLikeOutput, rootRelativePath } from "../core/util.js";
5
+ import { isEndpoint, isPage, isServerLikeOutput } from "../core/util.js";
6
+ import { rootRelativePath } from "../core/viteUtils.js";
6
7
  import { getPrerenderDefault } from "../prerender/utils.js";
7
8
  import { scan } from "./scan.js";
8
9
  const KNOWN_FILE_EXTENSIONS = [".astro", ".js", ".ts"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.11.1",
3
+ "version": "4.11.3",
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",