astro 1.5.3 → 1.6.1

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 (52) hide show
  1. package/client-base.d.ts +98 -11
  2. package/dist/@types/astro.d.ts +8 -4
  3. package/dist/cli/index.js +4 -2
  4. package/dist/core/build/index.js +2 -2
  5. package/dist/core/build/static-build.js +2 -2
  6. package/dist/core/compile/compile.js +29 -9
  7. package/dist/core/config/config.js +3 -0
  8. package/dist/core/config/settings.js +2 -1
  9. package/dist/core/constants.d.ts +1 -0
  10. package/dist/core/constants.js +11 -2
  11. package/dist/core/create-vite.js +23 -85
  12. package/dist/core/dev/index.js +1 -1
  13. package/dist/core/errors/codes.d.ts +15 -0
  14. package/dist/core/errors/codes.js +19 -0
  15. package/dist/core/errors/dev/index.d.ts +2 -0
  16. package/dist/core/errors/dev/index.js +8 -0
  17. package/dist/core/errors/dev/utils.d.ts +10 -0
  18. package/dist/core/errors/dev/utils.js +69 -0
  19. package/dist/core/errors/dev/vite.d.ts +11 -0
  20. package/dist/core/errors/dev/vite.js +88 -0
  21. package/dist/core/errors/errors.d.ts +80 -0
  22. package/dist/core/errors/errors.js +94 -0
  23. package/dist/core/errors/index.d.ts +5 -0
  24. package/dist/core/errors/index.js +24 -0
  25. package/dist/core/errors/printer.d.ts +3 -0
  26. package/dist/core/errors/printer.js +34 -0
  27. package/dist/core/errors/utils.d.ts +13 -0
  28. package/dist/core/errors/utils.js +84 -0
  29. package/dist/core/messages.d.ts +1 -1
  30. package/dist/core/messages.js +9 -4
  31. package/dist/core/preview/index.js +3 -1
  32. package/dist/core/render/dev/index.js +11 -2
  33. package/dist/core/render/dev/vite.js +2 -1
  34. package/dist/core/routing/manifest/create.js +6 -1
  35. package/dist/core/util.d.ts +6 -6
  36. package/dist/core/util.js +17 -43
  37. package/dist/events/error.d.ts +1 -1
  38. package/dist/events/error.js +1 -1
  39. package/dist/runtime/server/render/astro.js +1 -1
  40. package/dist/runtime/server/render/component.js +7 -2
  41. package/dist/vite-plugin-astro/index.js +1 -1
  42. package/dist/vite-plugin-astro-postprocess/index.js +2 -1
  43. package/dist/vite-plugin-astro-server/index.js +3 -8
  44. package/dist/vite-plugin-jsx/index.js +2 -2
  45. package/dist/vite-plugin-markdown/index.js +23 -6
  46. package/dist/vite-plugin-markdown-legacy/index.js +25 -8
  47. package/dist/vite-plugin-utils/index.js +1 -1
  48. package/dist/vite-style-transform/style-transform.js +55 -7
  49. package/package.json +6 -3
  50. package/types.d.ts +14 -0
  51. package/dist/core/errors.d.ts +0 -36
  52. package/dist/core/errors.js +0 -158
package/client-base.d.ts CHANGED
@@ -1,19 +1,106 @@
1
1
  /// <reference path="./import-meta.d.ts" />
2
2
 
3
+ type MD = import('./dist/@types/astro').MarkdownInstance<Record<string, any>>;
4
+ interface ExportedMarkdownModuleEntities {
5
+ frontmatter: MD['frontmatter'];
6
+ file: MD['file'];
7
+ url: MD['url'];
8
+ getHeadings: MD['getHeadings'];
9
+ /** @deprecated Renamed to `getHeadings()` */
10
+ getHeaders: () => void;
11
+ Content: MD['Content'];
12
+ rawContent: MD['rawContent'];
13
+ compiledContent: MD['compiledContent'];
14
+ load: MD['default'];
15
+ }
16
+
3
17
  declare module '*.md' {
4
- type MD = import('./dist/@types/astro').MarkdownInstance<Record<string, any>>;
18
+ const { load }: ExportedMarkdownModuleEntities;
19
+ export const {
20
+ frontmatter,
21
+ file,
22
+ url,
23
+ getHeadings,
24
+ getHeaders,
25
+ Content,
26
+ rawContent,
27
+ compiledContent,
28
+ }: ExportedMarkdownModuleEntities;
29
+ export default load;
30
+ }
5
31
 
6
- export const frontmatter: MD['frontmatter'];
7
- export const file: MD['file'];
8
- export const url: MD['url'];
9
- export const getHeadings: MD['getHeadings'];
10
- /** @deprecated Renamed to `getHeadings()` */
11
- export const getHeaders: () => void;
12
- export const Content: MD['Content'];
13
- export const rawContent: MD['rawContent'];
14
- export const compiledContent: MD['compiledContent'];
32
+ declare module '*.markdown' {
33
+ const { load }: ExportedMarkdownModuleEntities;
34
+ export const {
35
+ frontmatter,
36
+ file,
37
+ url,
38
+ getHeadings,
39
+ getHeaders,
40
+ Content,
41
+ rawContent,
42
+ compiledContent,
43
+ }: ExportedMarkdownModuleEntities;
44
+ export default load;
45
+ }
46
+
47
+ declare module '*.mkdn' {
48
+ const { load }: ExportedMarkdownModuleEntities;
49
+ export const {
50
+ frontmatter,
51
+ file,
52
+ url,
53
+ getHeadings,
54
+ getHeaders,
55
+ Content,
56
+ rawContent,
57
+ compiledContent,
58
+ }: ExportedMarkdownModuleEntities;
59
+ export default load;
60
+ }
61
+
62
+ declare module '*.mkd' {
63
+ const { load }: ExportedMarkdownModuleEntities;
64
+ export const {
65
+ frontmatter,
66
+ file,
67
+ url,
68
+ getHeadings,
69
+ getHeaders,
70
+ Content,
71
+ rawContent,
72
+ compiledContent,
73
+ }: ExportedMarkdownModuleEntities;
74
+ export default load;
75
+ }
76
+
77
+ declare module '*.mdwn' {
78
+ const { load }: ExportedMarkdownModuleEntities;
79
+ export const {
80
+ frontmatter,
81
+ file,
82
+ url,
83
+ getHeadings,
84
+ getHeaders,
85
+ Content,
86
+ rawContent,
87
+ compiledContent,
88
+ }: ExportedMarkdownModuleEntities;
89
+ export default load;
90
+ }
15
91
 
16
- const load: MD['default'];
92
+ declare module '*.mdown' {
93
+ const { load }: ExportedMarkdownModuleEntities;
94
+ export const {
95
+ frontmatter,
96
+ file,
97
+ url,
98
+ getHeadings,
99
+ getHeaders,
100
+ Content,
101
+ rawContent,
102
+ compiledContent,
103
+ }: ExportedMarkdownModuleEntities;
17
104
  export default load;
18
105
  }
19
106
 
@@ -11,6 +11,7 @@ import type { PageBuildData } from '../core/build/types';
11
11
  import type { AstroConfigSchema } from '../core/config';
12
12
  import type { AstroCookies } from '../core/cookies';
13
13
  import type { AstroComponentFactory } from '../runtime/server';
14
+ import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
14
15
  export type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, ShikiConfig, } from '@astrojs/markdown-remark';
15
16
  export type { SSRManifest } from '../core/app/types';
16
17
  export interface AstroBuiltinProps {
@@ -54,6 +55,7 @@ export interface AstroComponentMetadata {
54
55
  export interface CLIFlags {
55
56
  root?: string;
56
57
  site?: string;
58
+ base?: string;
57
59
  host?: string | boolean;
58
60
  port?: number;
59
61
  config?: string;
@@ -219,6 +221,8 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
219
221
  render(slotName: string, args?: any[]): Promise<string>;
220
222
  };
221
223
  }
224
+ /** Union type of supported markdown file extensions */
225
+ declare type MarkdowFileExtension = typeof SUPPORTED_MARKDOWN_FILE_EXTENSIONS[number];
222
226
  export interface AstroGlobalPartial {
223
227
  /**
224
228
  * @deprecated since version 0.24. See the {@link https://astro.build/deprecated/resolve upgrade guide} for more details.
@@ -237,7 +241,7 @@ export interface AstroGlobalPartial {
237
241
  * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroglob)
238
242
  */
239
243
  glob(globStr: `${any}.astro`): Promise<AstroInstance[]>;
240
- glob<T extends Record<string, any>>(globStr: `${any}.md`): Promise<MarkdownInstance<T>[]>;
244
+ glob<T extends Record<string, any>>(globStr: `${any}${MarkdowFileExtension}`): Promise<MarkdownInstance<T>[]>;
241
245
  glob<T extends Record<string, any>>(globStr: `${any}.mdx`): Promise<MDXInstance<T>[]>;
242
246
  glob<T extends Record<string, any>>(globStr: string): Promise<T[]>;
243
247
  /**
@@ -675,7 +679,7 @@ export interface AstroUserConfig {
675
679
  * Pass [remark plugins](https://github.com/remarkjs/remark) to customize how your Markdown is built. You can import and apply the plugin function (recommended), or pass the plugin name as a string.
676
680
  *
677
681
  * :::caution
678
- * Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the `extendDefaultPlugins` flag.
682
+ * Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the [`extendDefaultPlugins`](#markdownextenddefaultplugins) flag.
679
683
  * :::
680
684
  *
681
685
  * ```js
@@ -696,7 +700,7 @@ export interface AstroUserConfig {
696
700
  * Pass [rehype plugins](https://github.com/remarkjs/remark-rehype) to customize how your Markdown's output HTML is processed. You can import and apply the plugin function (recommended), or pass the plugin name as a string.
697
701
  *
698
702
  * :::caution
699
- * Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the `extendDefaultPlugins` flag.
703
+ * Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the [`extendDefaultPlugins`](#markdownextenddefaultplugins) flag.
700
704
  * :::
701
705
  *
702
706
  * ```js
@@ -816,7 +820,7 @@ export interface AstroUserConfig {
816
820
  * @default `false`
817
821
  * @version 1.0.0-rc.1
818
822
  * @description
819
- * Enable Astro's pre-v1.0 support for components and JSX expressions in `.md` Markdown files.
823
+ * Enable Astro's pre-v1.0 support for components and JSX expressions in `.md` (and alternative extensions for markdown files like ".markdown") Markdown files.
820
824
  * In Astro `1.0.0-rc`, this original behavior was removed as the default, in favor of our new [MDX integration](/en/guides/integrations-guide/mdx/).
821
825
  *
822
826
  * To enable this behavior, set `legacy.astroFlavoredMarkdown` to `true` in your [`astro.config.mjs` configuration file](/en/guides/configuring-astro/#the-astro-config-file).
package/dist/cli/index.js CHANGED
@@ -14,13 +14,13 @@ import {
14
14
  } from "../core/config/index.js";
15
15
  import { ASTRO_VERSION } from "../core/constants.js";
16
16
  import devServer from "../core/dev/index.js";
17
- import { collectErrorMetadata } from "../core/errors.js";
17
+ import { collectErrorMetadata } from "../core/errors/dev/index.js";
18
+ import { createSafeError } from "../core/errors/index.js";
18
19
  import { debug, error, info } from "../core/logger/core.js";
19
20
  import { enableVerboseLogging, nodeLogDestination } from "../core/logger/node.js";
20
21
  import { formatConfigErrorMessage, formatErrorMessage, printHelp } from "../core/messages.js";
21
22
  import { appendForwardSlash } from "../core/path.js";
22
23
  import preview from "../core/preview/index.js";
23
- import { createSafeError } from "../core/util.js";
24
24
  import * as event from "../events/index.js";
25
25
  import { eventConfigError, eventError, telemetry } from "../events/index.js";
26
26
  import { check } from "./check/index.js";
@@ -44,6 +44,8 @@ function printAstroHelp() {
44
44
  "Global Flags": [
45
45
  ["--config <path>", "Specify your config file."],
46
46
  ["--root <path>", "Specify your project root folder."],
47
+ ["--site <url>", "Specify your project site."],
48
+ ["--base <pathname>", "Specify your project base."],
47
49
  ["--verbose", "Enable verbose logging."],
48
50
  ["--silent", "Disable all logging."],
49
51
  ["--version", "Show the version number and exit."],
@@ -8,7 +8,7 @@ import {
8
8
  runHookConfigSetup
9
9
  } from "../../integrations/index.js";
10
10
  import { createVite } from "../create-vite.js";
11
- import { fixViteErrorMessage } from "../errors.js";
11
+ import { enhanceViteSSRError } from "../errors/dev/index.js";
12
12
  import { debug, info, levels, timerMessage } from "../logger/core.js";
13
13
  import { apply as applyPolyfill } from "../polyfill.js";
14
14
  import { RouteCache } from "../render/route-cache.js";
@@ -127,7 +127,7 @@ class AstroBuilder {
127
127
  try {
128
128
  await this.build(setupData);
129
129
  } catch (_err) {
130
- throw fixViteErrorMessage(_err);
130
+ throw enhanceViteSSRError(_err);
131
131
  }
132
132
  }
133
133
  validateConfig() {
@@ -92,6 +92,7 @@ async function ssrBuild(opts, internals, input) {
92
92
  emptyOutDir: false,
93
93
  manifest: false,
94
94
  outDir: fileURLToPath(out),
95
+ copyPublicDir: !ssr,
95
96
  rollupOptions: {
96
97
  ...(_a = viteConfig.build) == null ? void 0 : _a.rollupOptions,
97
98
  input: [],
@@ -105,7 +106,7 @@ async function ssrBuild(opts, internals, input) {
105
106
  },
106
107
  ssr: true,
107
108
  minify: false,
108
- polyfillModulePreload: false,
109
+ modulePreload: { polyfill: false },
109
110
  reportCompressedSize: false
110
111
  },
111
112
  plugins: [
@@ -120,7 +121,6 @@ async function ssrBuild(opts, internals, input) {
120
121
  settings.config.output === "server" && vitePluginSSR(internals, settings.adapter),
121
122
  vitePluginAnalyzer(internals)
122
123
  ],
123
- publicDir: ssr ? false : viteConfig.publicDir,
124
124
  envPrefix: "PUBLIC_",
125
125
  base: settings.config.base
126
126
  };
@@ -1,7 +1,8 @@
1
1
  import { transform } from "@astrojs/compiler";
2
- import { AstroErrorCodes } from "../errors.js";
2
+ import { AstroErrorCodes } from "../errors/codes.js";
3
+ import { AggregateError, CompilerError } from "../errors/errors.js";
3
4
  import { prependForwardSlash } from "../path.js";
4
- import { AggregateError, resolvePath, viteID } from "../util.js";
5
+ import { resolvePath, viteID } from "../util.js";
5
6
  import { createStylePreprocessor } from "./style.js";
6
7
  const configCache = /* @__PURE__ */ new WeakMap();
7
8
  async function compile({
@@ -28,23 +29,42 @@ async function compile({
28
29
  return resolvePath(specifier, filename);
29
30
  }
30
31
  }).catch((err) => {
31
- err.code = err.code || AstroErrorCodes.UnknownCompilerError;
32
- throw err;
32
+ throw new CompilerError({
33
+ errorCode: AstroErrorCodes.UnknownCompilerError,
34
+ message: err.message ?? "Unknown compiler error",
35
+ stack: err.stack,
36
+ location: {
37
+ file: filename
38
+ }
39
+ });
33
40
  }).then((result) => {
41
+ const compilerError = result.diagnostics.find(
42
+ (diag) => diag.severity === 1 && diag.code < 2e3
43
+ );
44
+ if (compilerError) {
45
+ throw new CompilerError({
46
+ errorCode: compilerError.code,
47
+ message: compilerError.text,
48
+ location: {
49
+ line: compilerError.location.line,
50
+ column: compilerError.location.column,
51
+ file: compilerError.location.file
52
+ },
53
+ hint: compilerError.hint ? compilerError.hint : void 0
54
+ });
55
+ }
34
56
  switch (cssTransformErrors.length) {
35
57
  case 0:
36
58
  return result;
37
59
  case 1: {
38
60
  let error = cssTransformErrors[0];
39
- if (!error.code) {
40
- error.code = AstroErrorCodes.UnknownCompilerCSSError;
61
+ if (!error.errorCode) {
62
+ error.errorCode = AstroErrorCodes.UnknownCompilerCSSError;
41
63
  }
42
64
  throw cssTransformErrors[0];
43
65
  }
44
66
  default: {
45
- const aggregateError = new AggregateError(cssTransformErrors);
46
- aggregateError.code = AstroErrorCodes.UnknownCompilerCSSError;
47
- throw aggregateError;
67
+ throw new AggregateError({ ...cssTransformErrors[0], errors: cssTransformErrors });
48
68
  }
49
69
  }
50
70
  });
@@ -72,6 +72,7 @@ function resolveFlags(flags) {
72
72
  return {
73
73
  root: typeof flags.root === "string" ? flags.root : void 0,
74
74
  site: typeof flags.site === "string" ? flags.site : void 0,
75
+ base: typeof flags.base === "string" ? flags.base : void 0,
75
76
  port: typeof flags.port === "number" ? flags.port : void 0,
76
77
  config: typeof flags.config === "string" ? flags.config : void 0,
77
78
  host: typeof flags.host === "string" || typeof flags.host === "boolean" ? flags.host : void 0,
@@ -86,6 +87,8 @@ function mergeCLIFlags(astroConfig, flags, cmd) {
86
87
  astroConfig.markdown = astroConfig.markdown || {};
87
88
  if (typeof flags.site === "string")
88
89
  astroConfig.site = flags.site;
90
+ if (typeof flags.base === "string")
91
+ astroConfig.base = flags.base;
89
92
  if (typeof flags.drafts === "boolean")
90
93
  astroConfig.markdown.drafts = flags.drafts;
91
94
  if (typeof flags.port === "number") {
@@ -1,3 +1,4 @@
1
+ import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./../constants.js";
1
2
  import jsxRenderer from "../../jsx/renderer.js";
2
3
  import { loadTSConfig } from "./tsconfig.js";
3
4
  function createSettings(config, cwd) {
@@ -8,7 +9,7 @@ function createSettings(config, cwd) {
8
9
  tsConfigPath: tsconfig == null ? void 0 : tsconfig.path,
9
10
  adapter: void 0,
10
11
  injectedRoutes: [],
11
- pageExtensions: [".astro", ".md", ".html"],
12
+ pageExtensions: [".astro", ".html", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
12
13
  renderers: [jsxRenderer],
13
14
  scripts: [],
14
15
  watchFiles: (tsconfig == null ? void 0 : tsconfig.exists) ? [tsconfig.path, ...tsconfig.extendedPaths] : []
@@ -1 +1,2 @@
1
1
  export declare const ASTRO_VERSION: string;
2
+ export declare const SUPPORTED_MARKDOWN_FILE_EXTENSIONS: readonly [".markdown", ".mdown", ".mkdn", ".mkd", ".mdwn", ".md"];
@@ -1,4 +1,13 @@
1
- const ASTRO_VERSION = "1.5.3";
1
+ const ASTRO_VERSION = "1.6.1";
2
+ const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
+ ".markdown",
4
+ ".mdown",
5
+ ".mkdn",
6
+ ".mkd",
7
+ ".mdwn",
8
+ ".md"
9
+ ];
2
10
  export {
3
- ASTRO_VERSION
11
+ ASTRO_VERSION,
12
+ SUPPORTED_MARKDOWN_FILE_EXTENSIONS
4
13
  };
@@ -1,8 +1,6 @@
1
- import fs from "fs";
2
- import { createRequire } from "module";
3
- import path from "path";
4
1
  import { fileURLToPath } from "url";
5
2
  import * as vite from "vite";
3
+ import { crawlFrameworkPkgs } from "vitefu";
6
4
  import astroPostprocessVitePlugin from "../vite-plugin-astro-postprocess/index.js";
7
5
  import astroViteServerPlugin from "../vite-plugin-astro-server/index.js";
8
6
  import astroVitePlugin from "../vite-plugin-astro/index.js";
@@ -15,7 +13,7 @@ import legacyMarkdownVitePlugin from "../vite-plugin-markdown-legacy/index.js";
15
13
  import markdownVitePlugin from "../vite-plugin-markdown/index.js";
16
14
  import astroScriptsPlugin from "../vite-plugin-scripts/index.js";
17
15
  import astroScriptsPageSSRPlugin from "../vite-plugin-scripts/page-ssr.js";
18
- import { createCustomViteLogger } from "./errors.js";
16
+ import { createCustomViteLogger } from "./errors/dev/index.js";
19
17
  import { resolveDependency } from "./util.js";
20
18
  const ALWAYS_NOEXTERNAL = /* @__PURE__ */ new Set([
21
19
  "astro",
@@ -35,7 +33,22 @@ function getSsrNoExternalDeps(projectRoot) {
35
33
  return noExternalDeps;
36
34
  }
37
35
  async function createVite(commandConfig, { settings, logging, mode }) {
38
- const thirdPartyAstroPackages = await getAstroPackages(settings);
36
+ const astroPkgsConfig = await crawlFrameworkPkgs({
37
+ root: fileURLToPath(settings.config.root),
38
+ isBuild: mode === "build",
39
+ isFrameworkPkgByJson(pkgJson) {
40
+ var _a, _b, _c, _d;
41
+ return ((_a = pkgJson.peerDependencies) == null ? void 0 : _a.astro) || ((_b = pkgJson.dependencies) == null ? void 0 : _b.astro) || ((_c = pkgJson.keywords) == null ? void 0 : _c.includes("astro")) || ((_d = pkgJson.keywords) == null ? void 0 : _d.includes("astro-component")) || /^(@[^\/]+\/)?astro\-/.test(pkgJson.name);
42
+ },
43
+ isFrameworkPkgByName(pkgName) {
44
+ const isNotAstroPkg = isCommonNotAstro(pkgName);
45
+ if (isNotAstroPkg) {
46
+ return false;
47
+ } else {
48
+ return void 0;
49
+ }
50
+ }
51
+ });
39
52
  const commonConfig = {
40
53
  cacheDir: fileURLToPath(new URL("./node_modules/.vite/", settings.config.root)),
41
54
  clearScreen: false,
@@ -88,8 +101,11 @@ async function createVite(commandConfig, { settings, logging, mode }) {
88
101
  conditions: ["astro"]
89
102
  },
90
103
  ssr: {
91
- noExternal: [...getSsrNoExternalDeps(settings.config.root), ...thirdPartyAstroPackages],
92
- external: mode === "dev" ? ["shiki"] : []
104
+ noExternal: [
105
+ ...getSsrNoExternalDeps(settings.config.root),
106
+ ...astroPkgsConfig.ssr.noExternal
107
+ ],
108
+ external: [...mode === "dev" ? ["shiki"] : [], ...astroPkgsConfig.ssr.external]
93
109
  }
94
110
  };
95
111
  let result = commonConfig;
@@ -118,84 +134,6 @@ function sortPlugins(pluginOptions) {
118
134
  pluginOptions.splice(mdxPluginIndex, 1);
119
135
  pluginOptions.splice(jsxPluginIndex, 0, mdxPlugin);
120
136
  }
121
- async function getAstroPackages(settings) {
122
- const { astroPackages } = new DependencyWalker(settings.config.root);
123
- return astroPackages;
124
- }
125
- class DependencyWalker {
126
- constructor(root) {
127
- this.astroDeps = /* @__PURE__ */ new Set();
128
- this.nonAstroDeps = /* @__PURE__ */ new Set();
129
- const pkgUrl = new URL("./package.json", root);
130
- this.require = createRequire(pkgUrl);
131
- const pkgPath = fileURLToPath(pkgUrl);
132
- if (!fs.existsSync(pkgPath))
133
- return;
134
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
135
- const deps = [
136
- ...Object.keys(pkg.dependencies || {}),
137
- ...Object.keys(pkg.devDependencies || {})
138
- ];
139
- this.scanDependencies(deps);
140
- }
141
- get astroPackages() {
142
- return Array.from(this.astroDeps);
143
- }
144
- seen(dep) {
145
- return this.astroDeps.has(dep) || this.nonAstroDeps.has(dep);
146
- }
147
- readPkgJSON(dir) {
148
- try {
149
- const filePath = path.join(dir, "package.json");
150
- return JSON.parse(fs.readFileSync(filePath, "utf-8"));
151
- } catch (e) {
152
- }
153
- }
154
- resolvePkgJSON(dep) {
155
- try {
156
- const pkgJson = this.require(dep + "/package.json");
157
- return pkgJson;
158
- } catch (e) {
159
- try {
160
- let dir = path.dirname(this.require.resolve(dep));
161
- while (dir) {
162
- const pkgJSON = this.readPkgJSON(dir);
163
- if (pkgJSON && pkgJSON.name === dep)
164
- return pkgJSON;
165
- const parentDir = path.dirname(dir);
166
- if (parentDir === dir)
167
- break;
168
- dir = parentDir;
169
- }
170
- } catch {
171
- }
172
- }
173
- }
174
- scanDependencies(deps) {
175
- const newDeps = [];
176
- for (const dep of deps) {
177
- if (isCommonNotAstro(dep)) {
178
- this.nonAstroDeps.add(dep);
179
- continue;
180
- }
181
- const pkgJson = this.resolvePkgJSON(dep);
182
- if (!pkgJson) {
183
- this.nonAstroDeps.add(dep);
184
- continue;
185
- }
186
- const { dependencies = {}, peerDependencies = {}, keywords = [] } = pkgJson;
187
- if (peerDependencies.astro || dependencies.astro || keywords.includes("astro") || keywords.includes("astro-component") || /^(@[^\/]+\/)?astro\-/.test(dep)) {
188
- this.astroDeps.add(dep);
189
- const unknownDependencies = Object.keys(dependencies).filter((d) => !this.seen(d));
190
- newDeps.push(...unknownDependencies);
191
- } else {
192
- this.nonAstroDeps.add(dep);
193
- }
194
- }
195
- if (newDeps.length)
196
- this.scanDependencies(newDeps);
197
- }
198
- }
199
137
  const COMMON_DEPENDENCIES_NOT_ASTRO = [
200
138
  "autoprefixer",
201
139
  "react",
@@ -54,7 +54,7 @@ async function dev(settings, options) {
54
54
  isRestart
55
55
  })
56
56
  );
57
- const currentVersion = "1.5.3";
57
+ const currentVersion = "1.6.1";
58
58
  if (currentVersion.includes("-")) {
59
59
  warn(options.logging, null, msg.prerelease({ currentVersion }));
60
60
  }
@@ -0,0 +1,15 @@
1
+ export declare enum AstroErrorCodes {
2
+ StaticRedirectNotAllowed = 2005,
3
+ UnavailableInSSR = 2006,
4
+ GenericRuntimeError = 3000,
5
+ CssSyntaxError = 4000,
6
+ CssUnknownError = 4001,
7
+ FailedToLoadModuleSSR = 5000,
8
+ ConfigError = 6000,
9
+ GenericMarkdownError = 7000,
10
+ MarkdownFrontmatterParseError = 7001,
11
+ UnknownCompilerError = 9000,
12
+ UnknownCompilerCSSError = 9001,
13
+ UnknownViteSSRError = 9002,
14
+ UnknownError = 9999
15
+ }
@@ -0,0 +1,19 @@
1
+ var AstroErrorCodes = /* @__PURE__ */ ((AstroErrorCodes2) => {
2
+ AstroErrorCodes2[AstroErrorCodes2["StaticRedirectNotAllowed"] = 2005] = "StaticRedirectNotAllowed";
3
+ AstroErrorCodes2[AstroErrorCodes2["UnavailableInSSR"] = 2006] = "UnavailableInSSR";
4
+ AstroErrorCodes2[AstroErrorCodes2["GenericRuntimeError"] = 3e3] = "GenericRuntimeError";
5
+ AstroErrorCodes2[AstroErrorCodes2["CssSyntaxError"] = 4e3] = "CssSyntaxError";
6
+ AstroErrorCodes2[AstroErrorCodes2["CssUnknownError"] = 4001] = "CssUnknownError";
7
+ AstroErrorCodes2[AstroErrorCodes2["FailedToLoadModuleSSR"] = 5e3] = "FailedToLoadModuleSSR";
8
+ AstroErrorCodes2[AstroErrorCodes2["ConfigError"] = 6e3] = "ConfigError";
9
+ AstroErrorCodes2[AstroErrorCodes2["GenericMarkdownError"] = 7e3] = "GenericMarkdownError";
10
+ AstroErrorCodes2[AstroErrorCodes2["MarkdownFrontmatterParseError"] = 7001] = "MarkdownFrontmatterParseError";
11
+ AstroErrorCodes2[AstroErrorCodes2["UnknownCompilerError"] = 9e3] = "UnknownCompilerError";
12
+ AstroErrorCodes2[AstroErrorCodes2["UnknownCompilerCSSError"] = 9001] = "UnknownCompilerCSSError";
13
+ AstroErrorCodes2[AstroErrorCodes2["UnknownViteSSRError"] = 9002] = "UnknownViteSSRError";
14
+ AstroErrorCodes2[AstroErrorCodes2["UnknownError"] = 9999] = "UnknownError";
15
+ return AstroErrorCodes2;
16
+ })(AstroErrorCodes || {});
17
+ export {
18
+ AstroErrorCodes
19
+ };
@@ -0,0 +1,2 @@
1
+ export { collectErrorMetadata } from './utils.js';
2
+ export { createCustomViteLogger, enhanceViteSSRError, getViteErrorPayload } from './vite.js';
@@ -0,0 +1,8 @@
1
+ import { collectErrorMetadata } from "./utils.js";
2
+ import { createCustomViteLogger, enhanceViteSSRError, getViteErrorPayload } from "./vite.js";
3
+ export {
4
+ collectErrorMetadata,
5
+ createCustomViteLogger,
6
+ enhanceViteSSRError,
7
+ getViteErrorPayload
8
+ };
@@ -0,0 +1,10 @@
1
+ import { ErrorWithMetadata } from '../errors.js';
2
+ export declare const incompatiblePackages: {
3
+ 'react-spectrum': string;
4
+ };
5
+ export declare const incompatPackageExp: RegExp;
6
+ /**
7
+ * Takes any error-like object and returns a standardized Error + metadata object.
8
+ * Useful for consistent reporting regardless of where the error surfaced from.
9
+ */
10
+ export declare function collectErrorMetadata(e: any, filePath?: URL): ErrorWithMetadata;
@@ -0,0 +1,69 @@
1
+ import * as fs from "node:fs";
2
+ import { AggregateError } from "../errors.js";
3
+ import { codeFrame } from "../printer.js";
4
+ import { collectInfoFromStacktrace } from "../utils.js";
5
+ const incompatiblePackages = {
6
+ "react-spectrum": `@adobe/react-spectrum is not compatible with Vite's server-side rendering mode at the moment. You can still use React Spectrum from the client. Create an island React component and use the client:only directive. From there you can use React Spectrum.`
7
+ };
8
+ const incompatPackageExp = new RegExp(`(${Object.keys(incompatiblePackages).join("|")})`);
9
+ function collectErrorMetadata(e, filePath) {
10
+ const err = AggregateError.is(e) ? e.errors : [e];
11
+ err.forEach((error) => {
12
+ if (error.stack) {
13
+ error = collectInfoFromStacktrace(e);
14
+ }
15
+ if (!error.frame && error.loc) {
16
+ try {
17
+ const fileContents = fs.readFileSync(error.loc.file, "utf8");
18
+ const frame = codeFrame(fileContents, error.loc);
19
+ error.frame = frame;
20
+ } catch {
21
+ }
22
+ }
23
+ if (!error.hint) {
24
+ error.hint = generateHint(e, filePath);
25
+ }
26
+ });
27
+ if (!AggregateError.is(e) && Array.isArray(e.errors)) {
28
+ e.errors.forEach((buildError, i) => {
29
+ const { location, pluginName } = buildError;
30
+ if (location) {
31
+ err[i].loc = { file: location.file, line: location.line, column: location.column };
32
+ err[i].id = err[0].id || (location == null ? void 0 : location.file);
33
+ }
34
+ const possibleFilePath = err[i].pluginCode || err[i].id || (location == null ? void 0 : location.file);
35
+ if (possibleFilePath && !err[i].frame) {
36
+ try {
37
+ const fileContents = fs.readFileSync(possibleFilePath, "utf8");
38
+ err[i].frame = codeFrame(fileContents, { ...err[i].loc, file: possibleFilePath });
39
+ } catch {
40
+ }
41
+ }
42
+ if (pluginName) {
43
+ err[i].plugin = pluginName;
44
+ }
45
+ err[i].hint = generateHint(err[0], filePath);
46
+ });
47
+ }
48
+ return err[0];
49
+ }
50
+ function generateHint(err, filePath) {
51
+ var _a, _b;
52
+ if (/Unknown file extension \"\.(jsx|vue|svelte|astro|css)\" for /.test(err.message)) {
53
+ return "You likely need to add this package to `vite.ssr.noExternal` in your astro config file.";
54
+ } else if (err.toString().startsWith("ReferenceError") && ((_b = ((_a = err.loc) == null ? void 0 : _a.file) ?? (filePath == null ? void 0 : filePath.pathname)) == null ? void 0 : _b.endsWith(".astro"))) {
55
+ return "export statements in `.astro` files do not have access to local variable declarations, only imported values.";
56
+ } else {
57
+ const res = incompatPackageExp.exec(err.stack);
58
+ if (res) {
59
+ const key = res[0];
60
+ return incompatiblePackages[key];
61
+ }
62
+ }
63
+ return void 0;
64
+ }
65
+ export {
66
+ collectErrorMetadata,
67
+ incompatPackageExp,
68
+ incompatiblePackages
69
+ };
@@ -0,0 +1,11 @@
1
+ import { type ErrorPayload, type Logger, type LogLevel, type ViteDevServer } from 'vite';
2
+ import { AstroError, type ErrorWithMetadata } from '../errors.js';
3
+ /**
4
+ * Custom logger with better error reporting for incompatible packages
5
+ */
6
+ export declare function createCustomViteLogger(logLevel: LogLevel): Logger;
7
+ export declare function enhanceViteSSRError(error: Error, filePath?: URL, viteServer?: ViteDevServer): AstroError;
8
+ /**
9
+ * Generate a payload for Vite's error overlay
10
+ */
11
+ export declare function getViteErrorPayload(err: ErrorWithMetadata): ErrorPayload;