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.
- package/dist/cli/index.js +2 -2
- package/dist/core/build/index.js +2 -2
- package/dist/core/build/static-build.js +2 -2
- package/dist/core/compile/compile.js +29 -9
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +1 -1
- package/dist/core/dev/index.js +1 -1
- package/dist/core/errors/codes.d.ts +15 -0
- package/dist/core/errors/codes.js +19 -0
- package/dist/core/errors/dev/index.d.ts +2 -0
- package/dist/core/errors/dev/index.js +8 -0
- package/dist/core/errors/dev/utils.d.ts +10 -0
- package/dist/core/errors/dev/utils.js +69 -0
- package/dist/core/errors/dev/vite.d.ts +11 -0
- package/dist/core/errors/dev/vite.js +88 -0
- package/dist/core/errors/errors.d.ts +80 -0
- package/dist/core/errors/errors.js +94 -0
- package/dist/core/errors/index.d.ts +5 -0
- package/dist/core/errors/index.js +24 -0
- package/dist/core/errors/printer.d.ts +3 -0
- package/dist/core/errors/printer.js +34 -0
- package/dist/core/errors/utils.d.ts +13 -0
- package/dist/core/errors/utils.js +84 -0
- package/dist/core/messages.d.ts +1 -1
- package/dist/core/messages.js +9 -4
- package/dist/core/render/dev/index.js +11 -2
- package/dist/core/util.d.ts +1 -6
- package/dist/core/util.js +0 -43
- package/dist/events/error.d.ts +1 -1
- package/dist/events/error.js +1 -1
- package/dist/runtime/server/render/astro.js +1 -1
- package/dist/runtime/server/render/component.js +7 -2
- package/dist/vite-plugin-astro/index.js +1 -1
- package/dist/vite-plugin-astro-server/index.js +3 -8
- package/dist/vite-plugin-markdown/index.js +20 -4
- package/dist/vite-plugin-markdown-legacy/index.js +20 -4
- package/dist/vite-plugin-utils/index.js +1 -1
- package/dist/vite-style-transform/style-transform.js +55 -7
- package/package.json +7 -6
- package/types.d.ts +14 -0
- package/dist/core/errors.d.ts +0 -36
- package/dist/core/errors.js +0 -158
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";
|
package/dist/core/build/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
runHookConfigSetup
|
|
9
9
|
} from "../../integrations/index.js";
|
|
10
10
|
import { createVite } from "../create-vite.js";
|
|
11
|
-
import {
|
|
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
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
32
|
-
|
|
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.
|
|
40
|
-
error.
|
|
61
|
+
if (!error.errorCode) {
|
|
62
|
+
error.errorCode = AstroErrorCodes.UnknownCompilerCSSError;
|
|
41
63
|
}
|
|
42
64
|
throw cssTransformErrors[0];
|
|
43
65
|
}
|
|
44
66
|
default: {
|
|
45
|
-
|
|
46
|
-
aggregateError.code = AstroErrorCodes.UnknownCompilerCSSError;
|
|
47
|
-
throw aggregateError;
|
|
67
|
+
throw new AggregateError({ ...cssTransformErrors[0], errors: cssTransformErrors });
|
|
48
68
|
}
|
|
49
69
|
}
|
|
50
70
|
});
|
package/dist/core/constants.js
CHANGED
package/dist/core/create-vite.js
CHANGED
|
@@ -13,7 +13,7 @@ import legacyMarkdownVitePlugin from "../vite-plugin-markdown-legacy/index.js";
|
|
|
13
13
|
import markdownVitePlugin from "../vite-plugin-markdown/index.js";
|
|
14
14
|
import astroScriptsPlugin from "../vite-plugin-scripts/index.js";
|
|
15
15
|
import astroScriptsPageSSRPlugin from "../vite-plugin-scripts/page-ssr.js";
|
|
16
|
-
import { createCustomViteLogger } from "./errors.js";
|
|
16
|
+
import { createCustomViteLogger } from "./errors/dev/index.js";
|
|
17
17
|
import { resolveDependency } from "./util.js";
|
|
18
18
|
const ALWAYS_NOEXTERNAL = /* @__PURE__ */ new Set([
|
|
19
19
|
"astro",
|
package/dist/core/dev/index.js
CHANGED
|
@@ -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,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;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import {
|
|
4
|
+
createLogger
|
|
5
|
+
} from "vite";
|
|
6
|
+
import { AstroErrorCodes } from "../codes.js";
|
|
7
|
+
import { AstroError } from "../errors.js";
|
|
8
|
+
import { incompatPackageExp } from "./utils.js";
|
|
9
|
+
function createCustomViteLogger(logLevel) {
|
|
10
|
+
const viteLogger = createLogger(logLevel);
|
|
11
|
+
const logger = {
|
|
12
|
+
...viteLogger,
|
|
13
|
+
error(msg, options) {
|
|
14
|
+
if (incompatPackageExp.test(msg))
|
|
15
|
+
return;
|
|
16
|
+
return viteLogger.error(msg, options);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
return logger;
|
|
20
|
+
}
|
|
21
|
+
function enhanceViteSSRError(error, filePath, viteServer) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
if (viteServer) {
|
|
24
|
+
try {
|
|
25
|
+
viteServer.ssrFixStacktrace(error);
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const newError = new AstroError({
|
|
30
|
+
name: error.name,
|
|
31
|
+
message: error.message,
|
|
32
|
+
location: error.loc,
|
|
33
|
+
stack: error.stack,
|
|
34
|
+
errorCode: error.errorCode ? error.errorCode : AstroErrorCodes.UnknownViteSSRError
|
|
35
|
+
});
|
|
36
|
+
if (filePath && /failed to load module for ssr:/.test(error.message)) {
|
|
37
|
+
const importName = (_a = error.message.split("for ssr:").at(1)) == null ? void 0 : _a.trim();
|
|
38
|
+
if (importName) {
|
|
39
|
+
newError.setMessage(`Could not import "${importName}"`);
|
|
40
|
+
newError.setHint("Make sure the file exists");
|
|
41
|
+
newError.setErrorCode(AstroErrorCodes.FailedToLoadModuleSSR);
|
|
42
|
+
const path = fileURLToPath(filePath);
|
|
43
|
+
const content = fs.readFileSync(path).toString();
|
|
44
|
+
const lns = content.split("\n");
|
|
45
|
+
const line = lns.findIndex((ln) => ln.includes(importName));
|
|
46
|
+
if (line !== -1) {
|
|
47
|
+
const column = (_b = lns[line]) == null ? void 0 : _b.indexOf(importName);
|
|
48
|
+
newError.setLocation({
|
|
49
|
+
file: path,
|
|
50
|
+
line: line + 1,
|
|
51
|
+
column
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return newError;
|
|
57
|
+
}
|
|
58
|
+
function getViteErrorPayload(err) {
|
|
59
|
+
var _a, _b, _c, _d;
|
|
60
|
+
let plugin = err.plugin;
|
|
61
|
+
if (!plugin && err.hint) {
|
|
62
|
+
plugin = "astro";
|
|
63
|
+
}
|
|
64
|
+
const message = `${err.message}
|
|
65
|
+
|
|
66
|
+
${err.hint ?? ""}`;
|
|
67
|
+
const frame = (_a = err.frame) == null ? void 0 : _a.replace(/\t/g, " ");
|
|
68
|
+
return {
|
|
69
|
+
type: "error",
|
|
70
|
+
err: {
|
|
71
|
+
...err,
|
|
72
|
+
frame,
|
|
73
|
+
loc: {
|
|
74
|
+
file: (_b = err.loc) == null ? void 0 : _b.file,
|
|
75
|
+
line: ((_c = err.loc) == null ? void 0 : _c.line) ?? 0,
|
|
76
|
+
column: ((_d = err.loc) == null ? void 0 : _d.column) ?? 0
|
|
77
|
+
},
|
|
78
|
+
plugin,
|
|
79
|
+
message: message.trim(),
|
|
80
|
+
stack: err.stack
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
createCustomViteLogger,
|
|
86
|
+
enhanceViteSSRError,
|
|
87
|
+
getViteErrorPayload
|
|
88
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { DiagnosticCode } from '@astrojs/compiler/shared/diagnostics.js';
|
|
2
|
+
import { AstroErrorCodes } from './codes.js';
|
|
3
|
+
interface ErrorProperties {
|
|
4
|
+
errorCode: AstroErrorCodes | DiagnosticCode;
|
|
5
|
+
name?: string;
|
|
6
|
+
message?: string;
|
|
7
|
+
location?: ErrorLocation;
|
|
8
|
+
hint?: string;
|
|
9
|
+
stack?: string;
|
|
10
|
+
frame?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ErrorLocation {
|
|
13
|
+
file?: string;
|
|
14
|
+
line?: number;
|
|
15
|
+
column?: number;
|
|
16
|
+
}
|
|
17
|
+
declare type ErrorTypes = 'CSSError' | 'CompilerError' | 'RuntimeError' | 'MarkdownError' | 'AstroAggregateError';
|
|
18
|
+
export declare class AstroError extends Error {
|
|
19
|
+
errorCode: AstroErrorCodes | DiagnosticCode;
|
|
20
|
+
loc: ErrorLocation | undefined;
|
|
21
|
+
hint: string | undefined;
|
|
22
|
+
frame: string | undefined;
|
|
23
|
+
type: ErrorTypes | undefined;
|
|
24
|
+
constructor(props: ErrorProperties, ...params: any);
|
|
25
|
+
setErrorCode(errorCode: AstroErrorCodes | DiagnosticCode): void;
|
|
26
|
+
setLocation(location: ErrorLocation): void;
|
|
27
|
+
setName(name: string): void;
|
|
28
|
+
setMessage(message: string): void;
|
|
29
|
+
setHint(hint: string): void;
|
|
30
|
+
setFrame(source: string, location: ErrorLocation): void;
|
|
31
|
+
}
|
|
32
|
+
export declare class CSSError extends AstroError {
|
|
33
|
+
type: ErrorTypes;
|
|
34
|
+
static is(err: Error | unknown): boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare class CompilerError extends AstroError {
|
|
37
|
+
type: ErrorTypes;
|
|
38
|
+
constructor(props: ErrorProperties & {
|
|
39
|
+
errorCode: DiagnosticCode | AstroErrorCodes.UnknownCompilerError;
|
|
40
|
+
}, ...params: any);
|
|
41
|
+
static is(err: Error | unknown): boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare class RuntimeError extends AstroError {
|
|
44
|
+
type: ErrorTypes;
|
|
45
|
+
static is(err: Error | unknown): boolean;
|
|
46
|
+
}
|
|
47
|
+
export declare class MarkdownError extends AstroError {
|
|
48
|
+
type: ErrorTypes;
|
|
49
|
+
static is(err: Error | unknown): boolean;
|
|
50
|
+
}
|
|
51
|
+
export declare class AggregateError extends AstroError {
|
|
52
|
+
type: ErrorTypes;
|
|
53
|
+
errors: AstroError[];
|
|
54
|
+
constructor(props: ErrorProperties & {
|
|
55
|
+
errors: AstroError[];
|
|
56
|
+
}, ...params: any);
|
|
57
|
+
static is(err: Error | unknown): boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generic object representing an error with all possible data
|
|
61
|
+
* Compatible with both Astro's and Vite's errors
|
|
62
|
+
*/
|
|
63
|
+
export interface ErrorWithMetadata {
|
|
64
|
+
[name: string]: any;
|
|
65
|
+
type?: ErrorTypes;
|
|
66
|
+
message: string;
|
|
67
|
+
stack: string;
|
|
68
|
+
code?: number;
|
|
69
|
+
hint?: string;
|
|
70
|
+
id?: string;
|
|
71
|
+
frame?: string;
|
|
72
|
+
plugin?: string;
|
|
73
|
+
pluginCode?: string;
|
|
74
|
+
loc?: {
|
|
75
|
+
file?: string;
|
|
76
|
+
line?: number;
|
|
77
|
+
column?: number;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { AstroErrorCodes } from "./codes.js";
|
|
2
|
+
import { codeFrame } from "./printer.js";
|
|
3
|
+
class AstroError extends Error {
|
|
4
|
+
constructor(props, ...params) {
|
|
5
|
+
super(...params);
|
|
6
|
+
const { errorCode, name, message, stack, location, hint, frame } = props;
|
|
7
|
+
this.errorCode = errorCode;
|
|
8
|
+
if (name) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
} else {
|
|
11
|
+
this.name = AstroErrorCodes[errorCode];
|
|
12
|
+
}
|
|
13
|
+
if (message)
|
|
14
|
+
this.message = message;
|
|
15
|
+
this.stack = stack ? stack : this.stack;
|
|
16
|
+
this.loc = location;
|
|
17
|
+
this.hint = hint;
|
|
18
|
+
this.frame = frame;
|
|
19
|
+
}
|
|
20
|
+
setErrorCode(errorCode) {
|
|
21
|
+
this.errorCode = errorCode;
|
|
22
|
+
this.name = AstroErrorCodes[errorCode];
|
|
23
|
+
}
|
|
24
|
+
setLocation(location) {
|
|
25
|
+
this.loc = location;
|
|
26
|
+
}
|
|
27
|
+
setName(name) {
|
|
28
|
+
this.name = name;
|
|
29
|
+
}
|
|
30
|
+
setMessage(message) {
|
|
31
|
+
this.message = message;
|
|
32
|
+
}
|
|
33
|
+
setHint(hint) {
|
|
34
|
+
this.hint = hint;
|
|
35
|
+
}
|
|
36
|
+
setFrame(source, location) {
|
|
37
|
+
this.frame = codeFrame(source, location);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class CSSError extends AstroError {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
this.type = "CSSError";
|
|
44
|
+
}
|
|
45
|
+
static is(err) {
|
|
46
|
+
return err.type === "CSSError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class CompilerError extends AstroError {
|
|
50
|
+
constructor(props, ...params) {
|
|
51
|
+
super(props, ...params);
|
|
52
|
+
this.type = "CompilerError";
|
|
53
|
+
this.name = "CompilerError";
|
|
54
|
+
}
|
|
55
|
+
static is(err) {
|
|
56
|
+
return err.type === "CompilerError";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class RuntimeError extends AstroError {
|
|
60
|
+
constructor() {
|
|
61
|
+
super(...arguments);
|
|
62
|
+
this.type = "RuntimeError";
|
|
63
|
+
}
|
|
64
|
+
static is(err) {
|
|
65
|
+
return err.type === "RuntimeError";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class MarkdownError extends AstroError {
|
|
69
|
+
constructor() {
|
|
70
|
+
super(...arguments);
|
|
71
|
+
this.type = "MarkdownError";
|
|
72
|
+
}
|
|
73
|
+
static is(err) {
|
|
74
|
+
return err.type === "MarkdownError";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
class AggregateError extends AstroError {
|
|
78
|
+
constructor(props, ...params) {
|
|
79
|
+
super(props, ...params);
|
|
80
|
+
this.type = "AstroAggregateError";
|
|
81
|
+
this.errors = props.errors;
|
|
82
|
+
}
|
|
83
|
+
static is(err) {
|
|
84
|
+
return err.type === "AstroAggregateError";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
AggregateError,
|
|
89
|
+
AstroError,
|
|
90
|
+
CSSError,
|
|
91
|
+
CompilerError,
|
|
92
|
+
MarkdownError,
|
|
93
|
+
RuntimeError
|
|
94
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { AstroErrorCodes } from './codes.js';
|
|
2
|
+
export type { ErrorLocation, ErrorWithMetadata } from './errors';
|
|
3
|
+
export { AggregateError, AstroError, CompilerError, CSSError, MarkdownError, RuntimeError, } from './errors.js';
|
|
4
|
+
export { codeFrame } from './printer.js';
|
|
5
|
+
export { collectInfoFromStacktrace, createSafeError, positionAt } from './utils.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AstroErrorCodes } from "./codes.js";
|
|
2
|
+
import {
|
|
3
|
+
AggregateError,
|
|
4
|
+
AstroError,
|
|
5
|
+
CompilerError,
|
|
6
|
+
CSSError,
|
|
7
|
+
MarkdownError,
|
|
8
|
+
RuntimeError
|
|
9
|
+
} from "./errors.js";
|
|
10
|
+
import { codeFrame } from "./printer.js";
|
|
11
|
+
import { collectInfoFromStacktrace, createSafeError, positionAt } from "./utils.js";
|
|
12
|
+
export {
|
|
13
|
+
AggregateError,
|
|
14
|
+
AstroError,
|
|
15
|
+
AstroErrorCodes,
|
|
16
|
+
CSSError,
|
|
17
|
+
CompilerError,
|
|
18
|
+
MarkdownError,
|
|
19
|
+
RuntimeError,
|
|
20
|
+
codeFrame,
|
|
21
|
+
collectInfoFromStacktrace,
|
|
22
|
+
createSafeError,
|
|
23
|
+
positionAt
|
|
24
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import eol from "eol";
|
|
2
|
+
function codeFrame(src, loc) {
|
|
3
|
+
if (!loc || loc.line === void 0 || loc.column === void 0) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
const lines = eol.lf(src).split("\n").map((ln) => ln.replace(/\t/g, " "));
|
|
7
|
+
const visibleLines = [];
|
|
8
|
+
for (let n = -2; n <= 2; n++) {
|
|
9
|
+
if (lines[loc.line + n])
|
|
10
|
+
visibleLines.push(loc.line + n);
|
|
11
|
+
}
|
|
12
|
+
let gutterWidth = 0;
|
|
13
|
+
for (const lineNo of visibleLines) {
|
|
14
|
+
let w = `> ${lineNo}`;
|
|
15
|
+
if (w.length > gutterWidth)
|
|
16
|
+
gutterWidth = w.length;
|
|
17
|
+
}
|
|
18
|
+
let output = "";
|
|
19
|
+
for (const lineNo of visibleLines) {
|
|
20
|
+
const isFocusedLine = lineNo === loc.line - 1;
|
|
21
|
+
output += isFocusedLine ? "> " : " ";
|
|
22
|
+
output += `${lineNo + 1} | ${lines[lineNo]}
|
|
23
|
+
`;
|
|
24
|
+
if (isFocusedLine)
|
|
25
|
+
output += `${Array.from({ length: gutterWidth }).join(" ")} | ${Array.from({
|
|
26
|
+
length: loc.column
|
|
27
|
+
}).join(" ")}^
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
codeFrame
|
|
34
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SSRError } from '../../@types/astro.js';
|
|
2
|
+
export declare function collectInfoFromStacktrace(error: SSRError): SSRError;
|
|
3
|
+
/**
|
|
4
|
+
* Get the line and character based on the offset
|
|
5
|
+
* @param offset The index of the position
|
|
6
|
+
* @param text The text for which the position should be retrived
|
|
7
|
+
*/
|
|
8
|
+
export declare function positionAt(offset: number, text: string): {
|
|
9
|
+
line: number;
|
|
10
|
+
column: number;
|
|
11
|
+
};
|
|
12
|
+
/** Coalesce any throw variable to an Error instance. */
|
|
13
|
+
export declare function createSafeError(err: any): Error;
|