astro 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/cli/index.js +2 -2
  2. package/dist/core/build/index.js +2 -2
  3. package/dist/core/build/static-build.js +2 -2
  4. package/dist/core/compile/compile.js +29 -9
  5. package/dist/core/constants.js +1 -1
  6. package/dist/core/create-vite.js +1 -1
  7. package/dist/core/dev/index.js +1 -1
  8. package/dist/core/errors/codes.d.ts +15 -0
  9. package/dist/core/errors/codes.js +19 -0
  10. package/dist/core/errors/dev/index.d.ts +2 -0
  11. package/dist/core/errors/dev/index.js +8 -0
  12. package/dist/core/errors/dev/utils.d.ts +10 -0
  13. package/dist/core/errors/dev/utils.js +69 -0
  14. package/dist/core/errors/dev/vite.d.ts +11 -0
  15. package/dist/core/errors/dev/vite.js +88 -0
  16. package/dist/core/errors/errors.d.ts +80 -0
  17. package/dist/core/errors/errors.js +94 -0
  18. package/dist/core/errors/index.d.ts +5 -0
  19. package/dist/core/errors/index.js +24 -0
  20. package/dist/core/errors/printer.d.ts +3 -0
  21. package/dist/core/errors/printer.js +34 -0
  22. package/dist/core/errors/utils.d.ts +13 -0
  23. package/dist/core/errors/utils.js +84 -0
  24. package/dist/core/messages.d.ts +1 -1
  25. package/dist/core/messages.js +9 -4
  26. package/dist/core/render/dev/index.js +11 -2
  27. package/dist/core/util.d.ts +1 -6
  28. package/dist/core/util.js +0 -43
  29. package/dist/events/error.d.ts +1 -1
  30. package/dist/events/error.js +1 -1
  31. package/dist/runtime/server/render/astro.js +1 -1
  32. package/dist/runtime/server/render/component.js +7 -2
  33. package/dist/vite-plugin-astro/index.js +1 -1
  34. package/dist/vite-plugin-astro-server/index.js +3 -8
  35. package/dist/vite-plugin-markdown/index.js +20 -4
  36. package/dist/vite-plugin-markdown-legacy/index.js +20 -4
  37. package/dist/vite-plugin-utils/index.js +1 -1
  38. package/dist/vite-style-transform/style-transform.js +55 -7
  39. package/package.json +7 -6
  40. package/types.d.ts +14 -0
  41. package/dist/core/errors.d.ts +0 -36
  42. package/dist/core/errors.js +0 -158
@@ -1,158 +0,0 @@
1
- import eol from "eol";
2
- import fs from "fs";
3
- import { fileURLToPath } from "node:url";
4
- import stripAnsi from "strip-ansi";
5
- import { createLogger } from "vite";
6
- import { codeFrame, createSafeError } from "./util.js";
7
- var AstroErrorCodes = /* @__PURE__ */ ((AstroErrorCodes2) => {
8
- AstroErrorCodes2[AstroErrorCodes2["UnknownError"] = 1e3] = "UnknownError";
9
- AstroErrorCodes2[AstroErrorCodes2["ConfigError"] = 1001] = "ConfigError";
10
- AstroErrorCodes2[AstroErrorCodes2["UnknownCompilerError"] = 2e3] = "UnknownCompilerError";
11
- AstroErrorCodes2[AstroErrorCodes2["UnknownCompilerCSSError"] = 2001] = "UnknownCompilerCSSError";
12
- return AstroErrorCodes2;
13
- })(AstroErrorCodes || {});
14
- function cleanErrorStack(stack) {
15
- return stack.split(/\n/g).map((l) => l.replace(/\/@fs\//g, "/")).join("\n");
16
- }
17
- function fixViteErrorMessage(_err, server, filePath) {
18
- var _a, _b;
19
- const err = createSafeError(_err);
20
- try {
21
- server == null ? void 0 : server.ssrFixStacktrace(err);
22
- } catch {
23
- }
24
- if (err.message === "import.meta.glob() can only accept string literals.") {
25
- err.message = "Astro.glob() and import.meta.glob() can only accept string literals.";
26
- }
27
- if (filePath && /failed to load module for ssr:/.test(err.message)) {
28
- const importName = (_a = err.message.split("for ssr:").at(1)) == null ? void 0 : _a.trim();
29
- if (importName) {
30
- try {
31
- const content = fs.readFileSync(fileURLToPath(filePath)).toString();
32
- const lns = content.split("\n");
33
- const line = lns.findIndex((ln) => ln.includes(importName));
34
- if (line == -1)
35
- return err;
36
- const column = (_b = lns[line]) == null ? void 0 : _b.indexOf(importName);
37
- if (!err.id) {
38
- err.id = `${fileURLToPath(filePath)}:${line + 1}:${column + 1}`;
39
- }
40
- } catch {
41
- }
42
- }
43
- }
44
- return err;
45
- }
46
- const incompatiblePackages = {
47
- "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.`
48
- };
49
- const incompatPackageExp = new RegExp(`(${Object.keys(incompatiblePackages).join("|")})`);
50
- function createCustomViteLogger(logLevel) {
51
- const viteLogger = createLogger(logLevel);
52
- const logger = {
53
- ...viteLogger,
54
- error(msg, options) {
55
- if (incompatPackageExp.test(msg))
56
- return;
57
- return viteLogger.error(msg, options);
58
- }
59
- };
60
- return logger;
61
- }
62
- function generateHint(err, filePath) {
63
- var _a, _b;
64
- if (/Unknown file extension \"\.(jsx|vue|svelte|astro|css)\" for /.test(err.message)) {
65
- return "You likely need to add this package to `vite.ssr.noExternal` in your astro config file.";
66
- } 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"))) {
67
- return "export statements in `.astro` files do not have access to local variable declarations, only imported values.";
68
- } else {
69
- const res = incompatPackageExp.exec(err.stack);
70
- if (res) {
71
- const key = res[0];
72
- return incompatiblePackages[key];
73
- }
74
- }
75
- return void 0;
76
- }
77
- function collectErrorMetadata(e, filePath) {
78
- var _a, _b;
79
- const err = e;
80
- if (e.stack) {
81
- e.stack = eol.lf(e.stack);
82
- const stackText = stripAnsi(e.stack);
83
- const possibleFilePath = err.pluginCode || err.id || stackText.split("\n").find((ln) => ln.includes("src") || ln.includes("node_modules"));
84
- const source = possibleFilePath == null ? void 0 : possibleFilePath.replace(/^[^(]+\(([^)]+).*$/, "$1").replace(/^\s+at\s+/, "");
85
- const [file, line, column] = (source == null ? void 0 : source.split(":")) ?? [];
86
- if (!err.loc && line && column) {
87
- err.loc = {
88
- file,
89
- line: Number.parseInt(line),
90
- column: Number.parseInt(column)
91
- };
92
- }
93
- if (!err.plugin) {
94
- err.plugin = ((_a = /withastro\/astro\/packages\/integrations\/([\w-]+)/gim.exec(stackText)) == null ? void 0 : _a.at(1)) || ((_b = /(@astrojs\/[\w-]+)\/(server|client|index)/gim.exec(stackText)) == null ? void 0 : _b.at(1)) || void 0;
95
- }
96
- err.stack = cleanErrorStack(e.stack);
97
- }
98
- if (e.name === "YAMLException") {
99
- err.loc = { file: e.id, line: e.mark.line, column: e.mark.column };
100
- err.message = e.reason;
101
- }
102
- if (!err.frame && err.loc) {
103
- try {
104
- const fileContents = fs.readFileSync(err.loc.file, "utf8");
105
- const frame = codeFrame(fileContents, err.loc);
106
- err.frame = frame;
107
- } catch {
108
- }
109
- }
110
- if (Array.isArray(e.errors)) {
111
- const { location, pluginName, text } = e.errors[0];
112
- if (location) {
113
- err.loc = { file: location.file, line: location.line, column: location.column };
114
- err.id = err.id || (location == null ? void 0 : location.file);
115
- }
116
- const possibleFilePath = err.pluginCode || err.id || (location == null ? void 0 : location.file);
117
- if (possibleFilePath && !err.frame) {
118
- try {
119
- const fileContents = fs.readFileSync(possibleFilePath, "utf8");
120
- err.frame = codeFrame(fileContents, err.loc);
121
- } catch {
122
- }
123
- }
124
- if (pluginName) {
125
- err.plugin = pluginName;
126
- }
127
- err.hint = generateHint(err, filePath);
128
- return err;
129
- }
130
- err.hint = generateHint(e, filePath);
131
- return err;
132
- }
133
- function getViteErrorPayload(err) {
134
- let plugin = err.plugin;
135
- if (!plugin && err.hint) {
136
- plugin = "astro";
137
- }
138
- const message = `${err.message}
139
-
140
- ${err.hint ?? ""}`;
141
- return {
142
- type: "error",
143
- err: {
144
- ...err,
145
- plugin,
146
- message: message.trim(),
147
- stack: err.stack
148
- }
149
- };
150
- }
151
- export {
152
- AstroErrorCodes,
153
- cleanErrorStack,
154
- collectErrorMetadata,
155
- createCustomViteLogger,
156
- fixViteErrorMessage,
157
- getViteErrorPayload
158
- };