astro 4.11.2 → 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.
@@ -7,9 +7,10 @@ import ora from "ora";
7
7
  import preferredPM from "preferred-pm";
8
8
  import prompts from "prompts";
9
9
  import whichPm from "which-pm";
10
+ const require2 = createRequire(import.meta.url);
10
11
  async function getPackage(packageName, logger, options, otherDeps = []) {
11
12
  try {
12
- createRequire(options.cwd ?? process.cwd()).resolve(packageName);
13
+ require2.resolve(packageName, { paths: [options.cwd ?? process.cwd()] });
13
14
  const packageImport = await import(packageName);
14
15
  return packageImport;
15
16
  } catch (e) {
@@ -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,
@@ -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.2";
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";
@@ -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.2";
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.2";
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.2"}`
272
+ `v${"4.11.3"}`
273
273
  )} ${headline}`
274
274
  );
275
275
  }
@@ -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
+ };
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) => {
@@ -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.2",
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",