@markless/bundler 0.1.1 → 0.2.0
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/dev-error.d.ts +57 -0
- package/dist/dev-error.js +174 -0
- package/dist/preload.d.ts +1 -1
- package/dist/preload.js +1 -1
- package/dist/{rolldown-Czh1duwk.js → rolldown-CpG_S-ZJ.js} +795 -43
- package/dist/rolldown.d.ts +1 -1
- package/dist/rolldown.js +2 -2
- package/dist/{source-module-CSRzW4Ny.js → source-module-C8W2THUI.js} +111 -42
- package/dist/{types-D6KerlYq.d.ts → types-CzXV_ABj.d.ts} +9 -0
- package/dist/vite.d.ts +2 -1
- package/dist/vite.js +261 -17
- package/package.json +18 -9
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CompilerDiagnostic, SourceSpan } from "@markless/compiler";
|
|
2
|
+
|
|
3
|
+
//#region src/dev-error/index.d.ts
|
|
4
|
+
declare const MARKLESS_DEV_ERROR_EVENT = "markless:dev-error";
|
|
5
|
+
declare const MARKLESS_DEV_ERROR_CLEAR_EVENT = "markless:dev-error-clear";
|
|
6
|
+
declare const MARKLESS_DEV_ERROR_CLIENT_ID = "virtual:markless:dev-error-client";
|
|
7
|
+
interface MarklessDevDiagnostic {
|
|
8
|
+
readonly code: string;
|
|
9
|
+
readonly message: string;
|
|
10
|
+
readonly filename?: string;
|
|
11
|
+
readonly line?: number;
|
|
12
|
+
readonly column?: number;
|
|
13
|
+
readonly why?: string;
|
|
14
|
+
readonly suggestion?: string;
|
|
15
|
+
readonly docsUrl?: string;
|
|
16
|
+
readonly frame?: string;
|
|
17
|
+
}
|
|
18
|
+
interface MarklessDevErrorPayload {
|
|
19
|
+
readonly version: 1;
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly kind: 'compile' | 'runtime';
|
|
22
|
+
readonly diagnostics: readonly MarklessDevDiagnostic[];
|
|
23
|
+
readonly details: string;
|
|
24
|
+
readonly stack?: string;
|
|
25
|
+
}
|
|
26
|
+
interface MarklessErrorLocation {
|
|
27
|
+
readonly file?: string;
|
|
28
|
+
readonly line: number;
|
|
29
|
+
readonly column: number;
|
|
30
|
+
}
|
|
31
|
+
declare class MarklessCompileError extends Error {
|
|
32
|
+
readonly payload: MarklessDevErrorPayload;
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly loc?: MarklessErrorLocation;
|
|
35
|
+
readonly frame?: string;
|
|
36
|
+
readonly plugin = "markless";
|
|
37
|
+
readonly pluginCode: string;
|
|
38
|
+
constructor(payload: MarklessDevErrorPayload);
|
|
39
|
+
}
|
|
40
|
+
declare function createCompileErrorPayload(input: {
|
|
41
|
+
readonly filename: string;
|
|
42
|
+
readonly source: string;
|
|
43
|
+
readonly diagnostics: readonly CompilerDiagnostic[];
|
|
44
|
+
readonly details: string;
|
|
45
|
+
readonly stack?: string;
|
|
46
|
+
}): MarklessDevErrorPayload;
|
|
47
|
+
declare function normalizeMarklessDevError(error: unknown, options?: {
|
|
48
|
+
readonly id?: string;
|
|
49
|
+
}): MarklessDevErrorPayload;
|
|
50
|
+
declare function serializeMarklessDevError(payload: MarklessDevErrorPayload): string;
|
|
51
|
+
declare function formatMarklessSourceFrame(source: string, span: SourceSpan): string;
|
|
52
|
+
declare function renderMarklessDevErrorDocument(payload: MarklessDevErrorPayload, options?: {
|
|
53
|
+
readonly base?: string;
|
|
54
|
+
}): string;
|
|
55
|
+
declare function renderMarklessDevErrorPlainText(payload: MarklessDevErrorPayload): string;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { MARKLESS_DEV_ERROR_CLEAR_EVENT, MARKLESS_DEV_ERROR_CLIENT_ID, MARKLESS_DEV_ERROR_EVENT, MarklessCompileError, MarklessDevDiagnostic, MarklessDevErrorPayload, MarklessErrorLocation, createCompileErrorPayload, formatMarklessSourceFrame, normalizeMarklessDevError, renderMarklessDevErrorDocument, renderMarklessDevErrorPlainText, serializeMarklessDevError };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { joinURL } from "ufo";
|
|
2
|
+
//#region src/dev-error/index.ts
|
|
3
|
+
const MARKLESS_DEV_ERROR_EVENT = "markless:dev-error";
|
|
4
|
+
const MARKLESS_DEV_ERROR_CLEAR_EVENT = "markless:dev-error-clear";
|
|
5
|
+
const MARKLESS_DEV_ERROR_CLIENT_ID = "virtual:markless:dev-error-client";
|
|
6
|
+
const PLUGIN_CODE_KIND = "markless-dev-error";
|
|
7
|
+
const PLUGIN_CODE_VERSION = 1;
|
|
8
|
+
var MarklessCompileError = class extends Error {
|
|
9
|
+
payload;
|
|
10
|
+
id;
|
|
11
|
+
loc;
|
|
12
|
+
frame;
|
|
13
|
+
plugin = "markless";
|
|
14
|
+
pluginCode;
|
|
15
|
+
constructor(payload) {
|
|
16
|
+
super(payload.details);
|
|
17
|
+
this.name = "MarklessCompileError";
|
|
18
|
+
this.payload = payload.stack || !this.stack ? payload : {
|
|
19
|
+
...payload,
|
|
20
|
+
stack: this.stack
|
|
21
|
+
};
|
|
22
|
+
this.id = this.payload.id;
|
|
23
|
+
const primary = this.payload.diagnostics[0];
|
|
24
|
+
this.loc = primary?.line !== void 0 && primary.column !== void 0 ? {
|
|
25
|
+
file: primary.filename,
|
|
26
|
+
line: primary.line,
|
|
27
|
+
column: primary.column
|
|
28
|
+
} : void 0;
|
|
29
|
+
this.frame = primary?.frame;
|
|
30
|
+
this.pluginCode = serializeMarklessDevError(this.payload);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function createCompileErrorPayload(input) {
|
|
34
|
+
return {
|
|
35
|
+
version: 1,
|
|
36
|
+
id: input.filename,
|
|
37
|
+
kind: "compile",
|
|
38
|
+
diagnostics: input.diagnostics.map((diagnostic) => compilerDiagnostic(input.source, diagnostic)),
|
|
39
|
+
details: input.details,
|
|
40
|
+
...input.stack ? { stack: input.stack } : {}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function normalizeMarklessDevError(error, options = {}) {
|
|
44
|
+
if (error instanceof MarklessCompileError) return error.payload;
|
|
45
|
+
if (isObject(error) && isPayload(error.payload)) return error.payload;
|
|
46
|
+
if (isObject(error) && typeof error.pluginCode === "string") {
|
|
47
|
+
const payload = parseMarklessPluginCode(error.pluginCode);
|
|
48
|
+
if (payload) return payload;
|
|
49
|
+
}
|
|
50
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
51
|
+
const code = isObject(error) && typeof error.code === "string" ? error.code : "MARKLESS_DEV_RUNTIME_ERROR";
|
|
52
|
+
return {
|
|
53
|
+
version: 1,
|
|
54
|
+
id: options.id ?? "navigation:unknown",
|
|
55
|
+
kind: "runtime",
|
|
56
|
+
diagnostics: [{
|
|
57
|
+
code,
|
|
58
|
+
message: details
|
|
59
|
+
}],
|
|
60
|
+
details,
|
|
61
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function serializeMarklessDevError(payload) {
|
|
65
|
+
return JSON.stringify({
|
|
66
|
+
kind: PLUGIN_CODE_KIND,
|
|
67
|
+
version: PLUGIN_CODE_VERSION,
|
|
68
|
+
payload
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function formatMarklessSourceFrame(source, span) {
|
|
72
|
+
const lines = source.split("\n");
|
|
73
|
+
const start = sourcePosition(source, span.start);
|
|
74
|
+
const end = sourcePosition(source, Math.max(span.start, span.end));
|
|
75
|
+
const firstLine = Math.max(1, start.line - 2);
|
|
76
|
+
const lastLine = Math.min(lines.length, start.line + 2);
|
|
77
|
+
const width = String(lastLine).length;
|
|
78
|
+
const frame = [];
|
|
79
|
+
for (let line = firstLine; line <= lastLine; line += 1) {
|
|
80
|
+
const active = line === start.line;
|
|
81
|
+
const text = lines[line - 1] ?? "";
|
|
82
|
+
frame.push(`${active ? ">" : " "} ${String(line).padStart(width)} | ${text}`);
|
|
83
|
+
if (active) {
|
|
84
|
+
const firstLineEnd = start.line === end.line ? end.column : text.length + 1;
|
|
85
|
+
const caretLength = Math.max(1, firstLineEnd - start.column);
|
|
86
|
+
frame.push(` ${" ".repeat(width)} | ${" ".repeat(start.column - 1)}${"^".repeat(caretLength)}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return frame.join("\n");
|
|
90
|
+
}
|
|
91
|
+
function renderMarklessDevErrorDocument(payload, options = {}) {
|
|
92
|
+
const primary = payload.diagnostics[0] ?? {
|
|
93
|
+
code: "MARKLESS_DEV_RUNTIME_ERROR",
|
|
94
|
+
message: payload.details
|
|
95
|
+
};
|
|
96
|
+
const diagnostics = payload.diagnostics.slice(1).map((diagnostic) => {
|
|
97
|
+
return `<details><summary>${escapeHtml(`${diagnostic.code} — ${diagnostic.message}`)}</summary>${renderDiagnosticBody(diagnostic, options.base ?? "/")}</details>`;
|
|
98
|
+
});
|
|
99
|
+
const technical = [payload.details, payload.stack].filter(Boolean).join("\n\n");
|
|
100
|
+
const serialized = JSON.stringify(payload).replaceAll("<", "\\u003c");
|
|
101
|
+
return `<!doctype html>
|
|
102
|
+
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
103
|
+
<title>${escapeHtml(primary.code)} — Markless development error</title><style>${documentStyles}</style></head>
|
|
104
|
+
<body><main class="panel"><header><span class="badge">${escapeHtml(primary.code)}</span><h1>${escapeHtml(primary.message)}</h1></header>
|
|
105
|
+
${renderDiagnosticBody(primary, options.base ?? "/")}
|
|
106
|
+
${diagnostics.join("\n")}
|
|
107
|
+
<details><summary>Technical details</summary><pre>${escapeHtml(technical)}</pre></details>
|
|
108
|
+
<p class="recovery">Fix the error and reload to continue.</p></main>
|
|
109
|
+
<script>window.__MARKLESS_DEV_ERROR__ = ${serialized};<\/script></body></html>`;
|
|
110
|
+
}
|
|
111
|
+
function renderMarklessDevErrorPlainText(payload) {
|
|
112
|
+
return [payload.details, payload.stack].filter(Boolean).join("\n\n");
|
|
113
|
+
}
|
|
114
|
+
function compilerDiagnostic(source, diagnostic) {
|
|
115
|
+
const position = diagnostic.primarySpan ? sourcePosition(source, diagnostic.primarySpan.start) : void 0;
|
|
116
|
+
return {
|
|
117
|
+
code: diagnostic.code,
|
|
118
|
+
message: diagnostic.message,
|
|
119
|
+
...diagnostic.primarySpan ? { filename: diagnostic.primarySpan.filename } : {},
|
|
120
|
+
...position ? {
|
|
121
|
+
line: position.line,
|
|
122
|
+
column: position.column
|
|
123
|
+
} : {},
|
|
124
|
+
...diagnostic.why ? { why: diagnostic.why } : {},
|
|
125
|
+
...diagnostic.suggestions[0]?.message ? { suggestion: diagnostic.suggestions[0].message } : {},
|
|
126
|
+
...diagnostic.docsUrl ? { docsUrl: diagnostic.docsUrl } : {},
|
|
127
|
+
...diagnostic.primarySpan ? { frame: formatMarklessSourceFrame(source, diagnostic.primarySpan) } : {}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function sourcePosition(source, offset) {
|
|
131
|
+
const before = source.slice(0, Math.max(0, Math.min(offset, source.length)));
|
|
132
|
+
const lastLineBreak = before.lastIndexOf("\n");
|
|
133
|
+
return {
|
|
134
|
+
line: before.split("\n").length,
|
|
135
|
+
column: before.length - lastLineBreak
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function parseMarklessPluginCode(value) {
|
|
139
|
+
try {
|
|
140
|
+
const envelope = JSON.parse(value);
|
|
141
|
+
if (isObject(envelope) && envelope.kind === PLUGIN_CODE_KIND && envelope.version === PLUGIN_CODE_VERSION && isPayload(envelope.payload)) return envelope.payload;
|
|
142
|
+
} catch {}
|
|
143
|
+
}
|
|
144
|
+
function isPayload(value) {
|
|
145
|
+
return isObject(value) && value.version === 1 && typeof value.id === "string" && (value.kind === "compile" || value.kind === "runtime") && Array.isArray(value.diagnostics) && typeof value.details === "string";
|
|
146
|
+
}
|
|
147
|
+
function isObject(value) {
|
|
148
|
+
return typeof value === "object" && value !== null;
|
|
149
|
+
}
|
|
150
|
+
function renderDiagnosticBody(diagnostic, base) {
|
|
151
|
+
const editorLocation = diagnostic.filename && diagnostic.line !== void 0 && diagnostic.column !== void 0 ? `${diagnostic.filename}:${diagnostic.line}:${diagnostic.column}` : void 0;
|
|
152
|
+
return `${editorLocation ? `<a class="location" href="${escapeAttribute(joinURL(base, `/__open-in-editor?file=${encodeURIComponent(editorLocation)}`))}">${escapeHtml(editorLocation)}</a>` : ""}${diagnostic.why ? `<section><h2>Why</h2><p>${escapeHtml(diagnostic.why)}</p></section>` : ""}${diagnostic.suggestion ? `<section><h2>Suggested fix</h2><p>${escapeHtml(diagnostic.suggestion)}</p></section>` : ""}${diagnostic.frame ? `<pre class="frame">${escapeHtml(diagnostic.frame)}</pre>` : ""}${diagnostic.docsUrl && isHttpUrl(diagnostic.docsUrl) ? `<p><a href="${escapeAttribute(diagnostic.docsUrl)}">Read ${escapeHtml(diagnostic.code)} documentation</a></p>` : ""}`;
|
|
153
|
+
}
|
|
154
|
+
function isHttpUrl(value) {
|
|
155
|
+
try {
|
|
156
|
+
const url = new URL(value);
|
|
157
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
158
|
+
} catch {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function escapeHtml(value) {
|
|
163
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
164
|
+
}
|
|
165
|
+
function escapeAttribute(value) {
|
|
166
|
+
return escapeHtml(value);
|
|
167
|
+
}
|
|
168
|
+
const documentStyles = `
|
|
169
|
+
:root{color-scheme:light dark;font-family:system-ui,sans-serif;background:Canvas;color:CanvasText}
|
|
170
|
+
*{box-sizing:border-box}body{margin:0;min-height:100vh;display:grid;place-items:center;padding:clamp(1rem,4vw,3rem);background:color-mix(in srgb,Canvas 94%,#b42318 6%)}
|
|
171
|
+
.panel{width:min(60rem,100%);padding:clamp(1.25rem,3vw,2.5rem);border:1px solid color-mix(in srgb,CanvasText 20%,transparent);border-top:4px solid #c9362b;border-radius:.5rem;background:Canvas;box-shadow:0 1rem 3rem #0002}
|
|
172
|
+
header{display:flex;flex-direction:column;gap:.6rem;margin-bottom:1rem}.badge{align-self:flex-start;padding:.15rem .45rem;border-radius:.25rem;background:color-mix(in srgb,#c9362b 14%,Canvas);color:#c9362b;font:600 .75rem ui-monospace,monospace}h1{margin:0;font-size:clamp(1.4rem,3vw,2rem);line-height:1.2}h2{margin:1rem 0 .25rem;font-size:.8rem;text-transform:uppercase;letter-spacing:.06em;color:color-mix(in srgb,CanvasText 65%,transparent)}p{margin:.3rem 0 1rem;line-height:1.55}a{color:LinkText}.location{display:inline-block;margin-bottom:.5rem;font:500 .9rem ui-monospace,monospace}.frame,details pre{overflow:auto;padding:1rem;border-radius:.35rem;background:color-mix(in srgb,CanvasText 7%,Canvas);font: .85rem/1.55 ui-monospace,monospace;white-space:pre}details{margin-top:1rem;border-top:1px solid color-mix(in srgb,CanvasText 15%,transparent);padding-top:1rem}summary{cursor:pointer;font-weight:600}.recovery{margin:1.5rem 0 0;color:color-mix(in srgb,CanvasText 65%,transparent);font-size:.9rem}`;
|
|
173
|
+
//#endregion
|
|
174
|
+
export { MARKLESS_DEV_ERROR_CLEAR_EVENT, MARKLESS_DEV_ERROR_CLIENT_ID, MARKLESS_DEV_ERROR_EVENT, MarklessCompileError, createCompileErrorPayload, formatMarklessSourceFrame, normalizeMarklessDevError, renderMarklessDevErrorDocument, renderMarklessDevErrorPlainText, serializeMarklessDevError };
|
package/dist/preload.d.ts
CHANGED
package/dist/preload.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as planModulePreloads, S as planModulePreloadUrls, u as symbolVirtualModuleSourceFile } from "./source-module-C8W2THUI.js";
|
|
2
2
|
//#region src/build/module-preload-dom.ts
|
|
3
3
|
const PRIORITY_RANK = {
|
|
4
4
|
high: 2,
|