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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import eol from "eol";
|
|
2
|
+
import stripAnsi from "strip-ansi";
|
|
3
|
+
function collectInfoFromStacktrace(error) {
|
|
4
|
+
var _a, _b, _c;
|
|
5
|
+
if (!error.stack)
|
|
6
|
+
return error;
|
|
7
|
+
error.stack = eol.lf(error.stack);
|
|
8
|
+
const stackText = stripAnsi(error.stack);
|
|
9
|
+
if (!error.loc || !error.loc.column && !error.loc.line) {
|
|
10
|
+
const possibleFilePath = ((_a = error.loc) == null ? void 0 : _a.file) || error.pluginCode || error.id || stackText.split("\n").find((ln) => ln.includes("src") || ln.includes("node_modules"));
|
|
11
|
+
const source = possibleFilePath == null ? void 0 : possibleFilePath.replace(/^[^(]+\(([^)]+).*$/, "$1").replace(/^\s+at\s+/, "");
|
|
12
|
+
const [file, line, column] = (source == null ? void 0 : source.split(":")) ?? [];
|
|
13
|
+
if (line && column) {
|
|
14
|
+
error.loc = {
|
|
15
|
+
file,
|
|
16
|
+
line: Number.parseInt(line),
|
|
17
|
+
column: Number.parseInt(column)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!error.plugin) {
|
|
22
|
+
error.plugin = ((_b = /withastro\/astro\/packages\/integrations\/([\w-]+)/gim.exec(stackText)) == null ? void 0 : _b.at(1)) || ((_c = /(@astrojs\/[\w-]+)\/(server|client|index)/gim.exec(stackText)) == null ? void 0 : _c.at(1)) || void 0;
|
|
23
|
+
}
|
|
24
|
+
error.stack = cleanErrorStack(error.stack);
|
|
25
|
+
return error;
|
|
26
|
+
}
|
|
27
|
+
function cleanErrorStack(stack) {
|
|
28
|
+
return stack.split(/\n/g).map((l) => l.replace(/\/@fs\//g, "/")).join("\n");
|
|
29
|
+
}
|
|
30
|
+
function positionAt(offset, text) {
|
|
31
|
+
const lineOffsets = getLineOffsets(text);
|
|
32
|
+
offset = Math.max(0, Math.min(text.length, offset));
|
|
33
|
+
let low = 0;
|
|
34
|
+
let high = lineOffsets.length;
|
|
35
|
+
if (high === 0) {
|
|
36
|
+
return {
|
|
37
|
+
line: 0,
|
|
38
|
+
column: offset
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
while (low <= high) {
|
|
42
|
+
const mid = Math.floor((low + high) / 2);
|
|
43
|
+
const lineOffset = lineOffsets[mid];
|
|
44
|
+
if (lineOffset === offset) {
|
|
45
|
+
return {
|
|
46
|
+
line: mid,
|
|
47
|
+
column: 0
|
|
48
|
+
};
|
|
49
|
+
} else if (offset > lineOffset) {
|
|
50
|
+
low = mid + 1;
|
|
51
|
+
} else {
|
|
52
|
+
high = mid - 1;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const line = low - 1;
|
|
56
|
+
return { line, column: offset - lineOffsets[line] };
|
|
57
|
+
}
|
|
58
|
+
function getLineOffsets(text) {
|
|
59
|
+
const lineOffsets = [];
|
|
60
|
+
let isLineStart = true;
|
|
61
|
+
for (let i = 0; i < text.length; i++) {
|
|
62
|
+
if (isLineStart) {
|
|
63
|
+
lineOffsets.push(i);
|
|
64
|
+
isLineStart = false;
|
|
65
|
+
}
|
|
66
|
+
const ch = text.charAt(i);
|
|
67
|
+
isLineStart = ch === "\r" || ch === "\n";
|
|
68
|
+
if (ch === "\r" && i + 1 < text.length && text.charAt(i + 1) === "\n") {
|
|
69
|
+
i++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (isLineStart && text.length > 0) {
|
|
73
|
+
lineOffsets.push(text.length);
|
|
74
|
+
}
|
|
75
|
+
return lineOffsets;
|
|
76
|
+
}
|
|
77
|
+
function createSafeError(err) {
|
|
78
|
+
return err instanceof Error || err && err.name && err.message ? err : new Error(JSON.stringify(err));
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
collectInfoFromStacktrace,
|
|
82
|
+
createSafeError,
|
|
83
|
+
positionAt
|
|
84
|
+
};
|
package/dist/core/messages.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { AddressInfo } from 'net';
|
|
3
3
|
import { ResolvedServerUrls } from 'vite';
|
|
4
4
|
import { ZodError } from 'zod';
|
|
5
|
-
import { ErrorWithMetadata } from './errors.js';
|
|
5
|
+
import { ErrorWithMetadata } from './errors/index.js';
|
|
6
6
|
/** Display */
|
|
7
7
|
export declare function req({ url, statusCode, reqTime, }: {
|
|
8
8
|
url: string;
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.6.
|
|
50
|
+
const version = "1.6.2";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -200,14 +200,19 @@ ${errorList.join(
|
|
|
200
200
|
)}`;
|
|
201
201
|
}
|
|
202
202
|
function formatErrorMessage(err, args = []) {
|
|
203
|
+
var _a, _b, _c;
|
|
203
204
|
args.push(`${bgRed(black(` error `))}${red(bold(padMultilineString(err.message)))}`);
|
|
204
205
|
if (err.hint) {
|
|
205
206
|
args.push(` ${bold("Hint:")}`);
|
|
206
207
|
args.push(yellow(padMultilineString(err.hint, 4)));
|
|
207
208
|
}
|
|
208
|
-
if (err.id) {
|
|
209
|
+
if (err.id || ((_a = err.loc) == null ? void 0 : _a.file)) {
|
|
209
210
|
args.push(` ${bold("File:")}`);
|
|
210
|
-
args.push(
|
|
211
|
+
args.push(
|
|
212
|
+
red(
|
|
213
|
+
` ${err.id ?? ((_b = err.loc) == null ? void 0 : _b.file)}${((_c = err.loc) == null ? void 0 : _c.line) && err.loc.column ? `:${err.loc.line}:${err.loc.column}` : ""}`
|
|
214
|
+
)
|
|
215
|
+
);
|
|
211
216
|
}
|
|
212
217
|
if (err.frame) {
|
|
213
218
|
args.push(` ${bold("Code:")}`);
|
|
@@ -250,7 +255,7 @@ function printHelp({
|
|
|
250
255
|
message.push(
|
|
251
256
|
linebreak(),
|
|
252
257
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
253
|
-
`v${"1.6.
|
|
258
|
+
`v${"1.6.2"}`
|
|
254
259
|
)} ${headline}`
|
|
255
260
|
);
|
|
256
261
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath } from "url";
|
|
2
2
|
import { PAGE_SCRIPT_ID } from "../../../vite-plugin-scripts/index.js";
|
|
3
|
+
import { enhanceViteSSRError } from "../../errors/dev/index.js";
|
|
4
|
+
import { AggregateError, CSSError, MarkdownError } from "../../errors/index.js";
|
|
3
5
|
import { isPage, resolveIdToUrl } from "../../util.js";
|
|
4
6
|
import { createRenderContext, renderPage as coreRenderPage } from "../index.js";
|
|
5
7
|
import { filterFoundRenderers, loadRenderer } from "../renderer.js";
|
|
@@ -16,8 +18,15 @@ async function preload({
|
|
|
16
18
|
filePath
|
|
17
19
|
}) {
|
|
18
20
|
const renderers = await loadRenderers(env.viteServer, env.settings);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
try {
|
|
22
|
+
const mod = await env.viteServer.ssrLoadModule(fileURLToPath(filePath));
|
|
23
|
+
return [renderers, mod];
|
|
24
|
+
} catch (err) {
|
|
25
|
+
if (MarkdownError.is(err) || CSSError.is(err) || AggregateError.is(err)) {
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
throw enhanceViteSSRError(err, filePath, env.viteServer);
|
|
29
|
+
}
|
|
21
30
|
}
|
|
22
31
|
async function getScriptsAndStyles({ env, filePath }) {
|
|
23
32
|
const scripts = await getScriptsForURL(filePath, env.viteServer);
|
package/dist/core/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ViteDevServer } from 'vite';
|
|
2
2
|
import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro';
|
|
3
3
|
/** Returns true if argument is an object of any prototype/class (but not null). */
|
|
4
4
|
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
@@ -24,10 +24,6 @@ export declare function parseNpmName(spec: string): {
|
|
|
24
24
|
name: string;
|
|
25
25
|
subpath?: string;
|
|
26
26
|
} | undefined;
|
|
27
|
-
/** Coalesce any throw variable to an Error instance. */
|
|
28
|
-
export declare function createSafeError(err: any): Error;
|
|
29
|
-
/** generate code frame from esbuild error */
|
|
30
|
-
export declare function codeFrame(src: string, loc: ErrorPayload['err']['loc']): string;
|
|
31
27
|
export declare function resolveDependency(dep: string, projectRoot: URL): string;
|
|
32
28
|
/**
|
|
33
29
|
* Convert file URL to ID for viteServer.moduleGraph.idToModuleMap.get(:viteID)
|
|
@@ -54,4 +50,3 @@ export declare function resolveJsToTs(filePath: string): string;
|
|
|
54
50
|
* Resolve the hydration paths so that it can be imported in the client
|
|
55
51
|
*/
|
|
56
52
|
export declare function resolvePath(specifier: string, importer: string): string;
|
|
57
|
-
export declare const AggregateError: any;
|
package/dist/core/util.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import eol from "eol";
|
|
2
1
|
import fs from "fs";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import resolve from "resolve";
|
|
@@ -67,38 +66,6 @@ function parseNpmName(spec) {
|
|
|
67
66
|
subpath
|
|
68
67
|
};
|
|
69
68
|
}
|
|
70
|
-
function createSafeError(err) {
|
|
71
|
-
return err instanceof Error || err && err.name && err.message ? err : new Error(JSON.stringify(err));
|
|
72
|
-
}
|
|
73
|
-
function codeFrame(src, loc) {
|
|
74
|
-
if (!loc)
|
|
75
|
-
return "";
|
|
76
|
-
const lines = eol.lf(src).split("\n").map((ln) => ln.replace(/\t/g, " "));
|
|
77
|
-
const visibleLines = [];
|
|
78
|
-
for (let n = -2; n <= 2; n++) {
|
|
79
|
-
if (lines[loc.line + n])
|
|
80
|
-
visibleLines.push(loc.line + n);
|
|
81
|
-
}
|
|
82
|
-
let gutterWidth = 0;
|
|
83
|
-
for (const lineNo of visibleLines) {
|
|
84
|
-
let w = `> ${lineNo}`;
|
|
85
|
-
if (w.length > gutterWidth)
|
|
86
|
-
gutterWidth = w.length;
|
|
87
|
-
}
|
|
88
|
-
let output = "";
|
|
89
|
-
for (const lineNo of visibleLines) {
|
|
90
|
-
const isFocusedLine = lineNo === loc.line - 1;
|
|
91
|
-
output += isFocusedLine ? "> " : " ";
|
|
92
|
-
output += `${lineNo + 1} | ${lines[lineNo]}
|
|
93
|
-
`;
|
|
94
|
-
if (isFocusedLine)
|
|
95
|
-
output += `${Array.from({ length: gutterWidth }).join(" ")} | ${Array.from({
|
|
96
|
-
length: loc.column
|
|
97
|
-
}).join(" ")}^
|
|
98
|
-
`;
|
|
99
|
-
}
|
|
100
|
-
return output;
|
|
101
|
-
}
|
|
102
69
|
function resolveDependency(dep, projectRoot) {
|
|
103
70
|
const resolved = resolve.sync(dep, {
|
|
104
71
|
basedir: fileURLToPath(projectRoot)
|
|
@@ -194,19 +161,9 @@ function resolvePath(specifier, importer) {
|
|
|
194
161
|
return specifier;
|
|
195
162
|
}
|
|
196
163
|
}
|
|
197
|
-
const AggregateError = typeof globalThis.AggregateError !== "undefined" ? globalThis.AggregateError : class extends Error {
|
|
198
|
-
constructor(errors, message) {
|
|
199
|
-
super(message);
|
|
200
|
-
this.errors = [];
|
|
201
|
-
this.errors = Array.from(errors);
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
164
|
export {
|
|
205
|
-
AggregateError,
|
|
206
165
|
VALID_ID_PREFIX,
|
|
207
166
|
arraify,
|
|
208
|
-
codeFrame,
|
|
209
|
-
createSafeError,
|
|
210
167
|
emoji,
|
|
211
168
|
getLocalAddress,
|
|
212
169
|
getOutputFilename,
|
package/dist/events/error.d.ts
CHANGED
package/dist/events/error.js
CHANGED
|
@@ -36,7 +36,7 @@ function isAstroComponent(obj) {
|
|
|
36
36
|
return typeof obj === "object" && Object.prototype.toString.call(obj) === "[object AstroComponent]";
|
|
37
37
|
}
|
|
38
38
|
function isAstroComponentFactory(obj) {
|
|
39
|
-
return obj == null ? false :
|
|
39
|
+
return obj == null ? false : obj.isAstroComponentFactory === true;
|
|
40
40
|
}
|
|
41
41
|
async function* renderAstroComponent(component) {
|
|
42
42
|
for await (const value of component) {
|
|
@@ -41,7 +41,7 @@ function getComponentType(Component) {
|
|
|
41
41
|
}
|
|
42
42
|
async function renderComponent(result, displayName, Component, _props, slots = {}) {
|
|
43
43
|
var _a;
|
|
44
|
-
Component = await Component;
|
|
44
|
+
Component = await Component ?? Component;
|
|
45
45
|
switch (getComponentType(Component)) {
|
|
46
46
|
case "fragment": {
|
|
47
47
|
const children2 = await renderSlot(result, slots == null ? void 0 : slots.default);
|
|
@@ -92,7 +92,12 @@ Did you mean to add ${formatList(probableRendererNames.map((r) => "`" + r + "`")
|
|
|
92
92
|
const { children, slotInstructions } = await renderSlots(result, slots);
|
|
93
93
|
let renderer;
|
|
94
94
|
if (metadata.hydrate !== "only") {
|
|
95
|
-
|
|
95
|
+
let isTagged = false;
|
|
96
|
+
try {
|
|
97
|
+
isTagged = Component && Component[Renderer];
|
|
98
|
+
} catch {
|
|
99
|
+
}
|
|
100
|
+
if (isTagged) {
|
|
96
101
|
const rendererName = Component[Renderer];
|
|
97
102
|
renderer = renderers.find(({ name }) => name === rendererName);
|
|
98
103
|
}
|
|
@@ -249,7 +249,7 @@ if (import.meta.hot) { import.meta.hot.decline() }`;
|
|
|
249
249
|
throw frontmatterErr;
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
-
if (err.stack.includes("wasm-function")) {
|
|
252
|
+
if (err.stack && err.stack.includes("wasm-function")) {
|
|
253
253
|
const search = new URLSearchParams({
|
|
254
254
|
labels: "compiler",
|
|
255
255
|
title: "\u{1F41B} BUG: `@astrojs/compiler` panic",
|
|
@@ -2,11 +2,8 @@ import mime from "mime";
|
|
|
2
2
|
import { Readable } from "stream";
|
|
3
3
|
import { attachToResponse, getSetCookiesFromResponse } from "../core/cookies/index.js";
|
|
4
4
|
import { call as callEndpoint } from "../core/endpoint/dev/index.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
fixViteErrorMessage,
|
|
8
|
-
getViteErrorPayload
|
|
9
|
-
} from "../core/errors.js";
|
|
5
|
+
import { collectErrorMetadata, getViteErrorPayload } from "../core/errors/dev/index.js";
|
|
6
|
+
import { createSafeError } from "../core/errors/index.js";
|
|
10
7
|
import { error, info, warn } from "../core/logger/core.js";
|
|
11
8
|
import * as msg from "../core/messages.js";
|
|
12
9
|
import { appendForwardSlash } from "../core/path.js";
|
|
@@ -200,13 +197,11 @@ async function handleRequest(env, manifest, req, res) {
|
|
|
200
197
|
});
|
|
201
198
|
body = Buffer.concat(bytes);
|
|
202
199
|
}
|
|
203
|
-
let filePath;
|
|
204
200
|
try {
|
|
205
201
|
const matchedRoute = await matchRoute(pathname, env, manifest);
|
|
206
|
-
filePath = matchedRoute == null ? void 0 : matchedRoute.filePath;
|
|
207
202
|
return await handleRoute(matchedRoute, url, pathname, body, origin, env, manifest, req, res);
|
|
208
203
|
} catch (_err) {
|
|
209
|
-
const err =
|
|
204
|
+
const err = createSafeError(_err);
|
|
210
205
|
const errorWithMetadata = collectErrorMetadata(err);
|
|
211
206
|
error(env.logging, null, msg.formatErrorMessage(errorWithMetadata));
|
|
212
207
|
handle500Response(viteServer, origin, req, res, errorWithMetadata);
|
|
@@ -3,16 +3,32 @@ import fs from "fs";
|
|
|
3
3
|
import matter from "gray-matter";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { normalizePath } from "vite";
|
|
6
|
-
import {
|
|
6
|
+
import { AstroErrorCodes, MarkdownError } from "../core/errors/index.js";
|
|
7
7
|
import { warn } from "../core/logger/core.js";
|
|
8
8
|
import { isMarkdownFile } from "../core/util.js";
|
|
9
9
|
import { getFileInfo, safelyGetAstroData } from "../vite-plugin-utils/index.js";
|
|
10
10
|
function safeMatter(source, id) {
|
|
11
11
|
try {
|
|
12
12
|
return matter(source);
|
|
13
|
-
} catch (
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
} catch (err) {
|
|
14
|
+
const markdownError = new MarkdownError({
|
|
15
|
+
errorCode: AstroErrorCodes.GenericMarkdownError,
|
|
16
|
+
message: err.message,
|
|
17
|
+
stack: err.stack,
|
|
18
|
+
location: {
|
|
19
|
+
file: id
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
if (err.name === "YAMLException") {
|
|
23
|
+
markdownError.setErrorCode(AstroErrorCodes.MarkdownFrontmatterParseError);
|
|
24
|
+
markdownError.setLocation({
|
|
25
|
+
file: id,
|
|
26
|
+
line: err.mark.line,
|
|
27
|
+
column: err.mark.column
|
|
28
|
+
});
|
|
29
|
+
markdownError.setMessage(err.reason);
|
|
30
|
+
}
|
|
31
|
+
throw markdownError;
|
|
16
32
|
}
|
|
17
33
|
}
|
|
18
34
|
const astroJsxRuntimeModulePath = normalizePath(
|
|
@@ -6,7 +6,7 @@ import matter from "gray-matter";
|
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
import { pagesVirtualModuleId } from "../core/app/index.js";
|
|
8
8
|
import { cachedCompilation } from "../core/compile/index.js";
|
|
9
|
-
import {
|
|
9
|
+
import { AstroErrorCodes, MarkdownError } from "../core/errors/index.js";
|
|
10
10
|
import { isMarkdownFile } from "../core/util.js";
|
|
11
11
|
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
|
12
12
|
import {
|
|
@@ -18,9 +18,25 @@ const MARKDOWN_CONTENT_FLAG = "?content";
|
|
|
18
18
|
function safeMatter(source, id) {
|
|
19
19
|
try {
|
|
20
20
|
return matter(source);
|
|
21
|
-
} catch (
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
} catch (err) {
|
|
22
|
+
const markdownError = new MarkdownError({
|
|
23
|
+
errorCode: AstroErrorCodes.GenericMarkdownError,
|
|
24
|
+
message: err.message,
|
|
25
|
+
stack: err.stack,
|
|
26
|
+
location: {
|
|
27
|
+
file: id
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
if (err.name === "YAMLException") {
|
|
31
|
+
markdownError.setErrorCode(AstroErrorCodes.MarkdownFrontmatterParseError);
|
|
32
|
+
markdownError.setLocation({
|
|
33
|
+
file: id,
|
|
34
|
+
line: err.mark.line,
|
|
35
|
+
column: err.mark.column
|
|
36
|
+
});
|
|
37
|
+
markdownError.setMessage(err.reason);
|
|
38
|
+
}
|
|
39
|
+
throw markdownError;
|
|
24
40
|
}
|
|
25
41
|
}
|
|
26
42
|
function markdown({ settings }) {
|
|
@@ -4,7 +4,7 @@ function getFileInfo(id, config) {
|
|
|
4
4
|
config.site ? new URL(config.base, config.site).pathname : config.base
|
|
5
5
|
);
|
|
6
6
|
const fileId = id.split("?")[0];
|
|
7
|
-
let fileUrl = fileId.includes("/pages/") ? fileId.replace(/^.*?\/pages\//, sitePathname).replace(/(\/index)?\.(md|astro)$/, "") : void 0;
|
|
7
|
+
let fileUrl = fileId.includes("/pages/") ? fileId.replace(/^.*?\/pages\//, sitePathname).replace(/(\/index)?\.(md|markdown|mdown|mkdn|mkd|mdwn|md|astro)$/, "") : void 0;
|
|
8
8
|
if (fileUrl && config.trailingSlash === "always") {
|
|
9
9
|
fileUrl = appendForwardSlash(fileUrl);
|
|
10
10
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { fileURLToPath } from "url";
|
|
2
2
|
import { createTransformStyleWithViteFn } from "./transform-with-vite.js";
|
|
3
|
+
import { readFileSync } from "fs";
|
|
4
|
+
import { AstroErrorCodes } from "../core/errors/codes.js";
|
|
5
|
+
import { CSSError } from "../core/errors/errors.js";
|
|
6
|
+
import { positionAt } from "../core/errors/index.js";
|
|
3
7
|
function createViteStyleTransformer(viteConfig) {
|
|
4
8
|
return {
|
|
5
9
|
transformStyleWithVite: createTransformStyleWithViteFn(viteConfig)
|
|
@@ -16,13 +20,57 @@ function getNormalizedIDForPostCSS(filename) {
|
|
|
16
20
|
function createTransformStyles(viteStyleTransformer, filename, ssr, pluginContext) {
|
|
17
21
|
const normalizedID = getNormalizedIDForPostCSS(filename);
|
|
18
22
|
return async function(styleSource, lang) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
var _a;
|
|
24
|
+
let result;
|
|
25
|
+
try {
|
|
26
|
+
result = await viteStyleTransformer.transformStyleWithVite.call(pluginContext, {
|
|
27
|
+
id: normalizedID,
|
|
28
|
+
source: styleSource,
|
|
29
|
+
lang,
|
|
30
|
+
ssr,
|
|
31
|
+
viteDevServer: viteStyleTransformer.viteDevServer
|
|
32
|
+
});
|
|
33
|
+
} catch (err) {
|
|
34
|
+
const fileContent = readFileSync(filename).toString();
|
|
35
|
+
const styleTagBeginning = fileContent.indexOf(((_a = err.input) == null ? void 0 : _a.source) ?? err.code);
|
|
36
|
+
if (err.name === "CssSyntaxError") {
|
|
37
|
+
const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);
|
|
38
|
+
throw new CSSError({
|
|
39
|
+
errorCode: AstroErrorCodes.CssSyntaxError,
|
|
40
|
+
message: err.reason,
|
|
41
|
+
location: {
|
|
42
|
+
file: filename,
|
|
43
|
+
line: errorLine,
|
|
44
|
+
column: err.column
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (err.line && err.column) {
|
|
49
|
+
const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);
|
|
50
|
+
throw new CSSError({
|
|
51
|
+
errorCode: AstroErrorCodes.CssUnknownError,
|
|
52
|
+
message: err.message,
|
|
53
|
+
location: {
|
|
54
|
+
file: filename,
|
|
55
|
+
line: errorLine,
|
|
56
|
+
column: err.column
|
|
57
|
+
},
|
|
58
|
+
frame: err.frame
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const errorPosition = positionAt(styleTagBeginning, fileContent);
|
|
62
|
+
errorPosition.line += 1;
|
|
63
|
+
throw new CSSError({
|
|
64
|
+
errorCode: AstroErrorCodes.CssUnknownError,
|
|
65
|
+
message: err.message,
|
|
66
|
+
location: {
|
|
67
|
+
file: filename,
|
|
68
|
+
line: errorPosition.line,
|
|
69
|
+
column: 0
|
|
70
|
+
},
|
|
71
|
+
frame: err.frame
|
|
72
|
+
});
|
|
73
|
+
}
|
|
26
74
|
return result;
|
|
27
75
|
};
|
|
28
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
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",
|
|
@@ -82,15 +82,16 @@
|
|
|
82
82
|
"client-base.d.ts",
|
|
83
83
|
"import-meta.d.ts",
|
|
84
84
|
"astro-jsx.d.ts",
|
|
85
|
+
"types.d.ts",
|
|
85
86
|
"README.md",
|
|
86
87
|
"vendor"
|
|
87
88
|
],
|
|
88
89
|
"dependencies": {
|
|
89
|
-
"@astrojs/compiler": "^0.
|
|
90
|
+
"@astrojs/compiler": "^0.29.5",
|
|
90
91
|
"@astrojs/language-server": "^0.26.2",
|
|
91
92
|
"@astrojs/markdown-remark": "^1.1.3",
|
|
92
93
|
"@astrojs/telemetry": "^1.0.1",
|
|
93
|
-
"@astrojs/webapi": "^1.1.
|
|
94
|
+
"@astrojs/webapi": "^1.1.1",
|
|
94
95
|
"@babel/core": "^7.18.2",
|
|
95
96
|
"@babel/generator": "^7.18.2",
|
|
96
97
|
"@babel/parser": "^7.18.4",
|
|
@@ -132,7 +133,7 @@
|
|
|
132
133
|
"recast": "^0.20.5",
|
|
133
134
|
"rehype": "^12.0.1",
|
|
134
135
|
"resolve": "^1.22.0",
|
|
135
|
-
"rollup": "
|
|
136
|
+
"rollup": "^2.79.1",
|
|
136
137
|
"semver": "^7.3.7",
|
|
137
138
|
"shiki": "^0.11.1",
|
|
138
139
|
"sirv": "^2.0.2",
|
|
@@ -144,7 +145,7 @@
|
|
|
144
145
|
"typescript": "*",
|
|
145
146
|
"unist-util-visit": "^4.1.0",
|
|
146
147
|
"vfile": "^5.3.2",
|
|
147
|
-
"vite": "~3.1
|
|
148
|
+
"vite": "~3.2.1",
|
|
148
149
|
"vitefu": "^0.1.0",
|
|
149
150
|
"yargs-parser": "^21.0.1",
|
|
150
151
|
"zod": "^3.17.3"
|
|
@@ -172,7 +173,7 @@
|
|
|
172
173
|
"@types/send": "^0.17.1",
|
|
173
174
|
"@types/unist": "^2.0.6",
|
|
174
175
|
"ast-types": "^0.14.2",
|
|
175
|
-
"astro-scripts": "0.0.
|
|
176
|
+
"astro-scripts": "0.0.9",
|
|
176
177
|
"chai": "^4.3.6",
|
|
177
178
|
"cheerio": "^1.0.0-rc.11",
|
|
178
179
|
"mocha": "^9.2.2",
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import './astro-jsx';
|
|
2
|
+
import { AstroBuiltinAttributes } from './dist/@types/astro';
|
|
3
|
+
|
|
4
|
+
/** Any supported HTML or SVG element name, as defined by the HTML specification */
|
|
5
|
+
export type HTMLTag = keyof astroHTML.JSX.DefinedIntrinsicElements;
|
|
6
|
+
/** The built-in attributes for any known HTML or SVG element name */
|
|
7
|
+
export type HTMLAttributes<Tag extends HTMLTag> = Omit<
|
|
8
|
+
astroHTML.JSX.IntrinsicElements[Tag],
|
|
9
|
+
keyof AstroBuiltinAttributes
|
|
10
|
+
>;
|
|
11
|
+
|
|
12
|
+
// TODO: Enable generic/polymorphic types once compiler output stabilizes in the Language Server
|
|
13
|
+
// type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<(P & HTMLAttributes<P['as']>), 'as'> & { as?: P['as'] };
|
|
14
|
+
// export type Polymorphic<P extends { as: HTMLTag }> = PolymorphicAttributes<Omit<P, 'as'> & { as: NonNullable<P['as']>}>;
|
package/dist/core/errors.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { ErrorPayload, Logger, LogLevel, ViteDevServer } from 'vite';
|
|
2
|
-
export declare enum AstroErrorCodes {
|
|
3
|
-
UnknownError = 1000,
|
|
4
|
-
ConfigError = 1001,
|
|
5
|
-
UnknownCompilerError = 2000,
|
|
6
|
-
UnknownCompilerCSSError = 2001
|
|
7
|
-
}
|
|
8
|
-
export interface ErrorWithMetadata {
|
|
9
|
-
[name: string]: any;
|
|
10
|
-
message: string;
|
|
11
|
-
stack: string;
|
|
12
|
-
code?: number;
|
|
13
|
-
hint?: string;
|
|
14
|
-
id?: string;
|
|
15
|
-
frame?: string;
|
|
16
|
-
plugin?: string;
|
|
17
|
-
pluginCode?: string;
|
|
18
|
-
loc?: {
|
|
19
|
-
file?: string;
|
|
20
|
-
line: number;
|
|
21
|
-
column: number;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export declare function cleanErrorStack(stack: string): string;
|
|
25
|
-
/**
|
|
26
|
-
* Update the error message to correct any vite-isms that we don't want to expose to the user.
|
|
27
|
-
* The `server` is required if the error may come from `server.ssrLoadModule()`.
|
|
28
|
-
*/
|
|
29
|
-
export declare function fixViteErrorMessage(_err: unknown, server?: ViteDevServer, filePath?: URL): Error;
|
|
30
|
-
export declare function createCustomViteLogger(logLevel: LogLevel): Logger;
|
|
31
|
-
/**
|
|
32
|
-
* Takes any error-like object and returns a standardized Error + metadata object.
|
|
33
|
-
* Useful for consistent reporting regardless of where the error surfaced from.
|
|
34
|
-
*/
|
|
35
|
-
export declare function collectErrorMetadata(e: any, filePath?: URL): ErrorWithMetadata;
|
|
36
|
-
export declare function getViteErrorPayload(err: ErrorWithMetadata): ErrorPayload;
|