@markless/bundler 0.4.0 → 0.6.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.
@@ -0,0 +1,176 @@
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 MARKLESS_DEV_RELOADS_EVENT = "markless:dev-reloads";
7
+ const MARKLESS_DEV_RELOADS_ATTRIBUTE = "data-markless-dev-reloads";
8
+ const PLUGIN_CODE_KIND = "markless-dev-error";
9
+ const PLUGIN_CODE_VERSION = 1;
10
+ var MarklessCompileError = class extends Error {
11
+ payload;
12
+ id;
13
+ loc;
14
+ frame;
15
+ plugin = "markless";
16
+ pluginCode;
17
+ constructor(payload) {
18
+ super(payload.details);
19
+ this.name = "MarklessCompileError";
20
+ this.payload = payload.stack || !this.stack ? payload : {
21
+ ...payload,
22
+ stack: this.stack
23
+ };
24
+ this.id = this.payload.id;
25
+ const primary = this.payload.diagnostics[0];
26
+ this.loc = primary?.line !== void 0 && primary.column !== void 0 ? {
27
+ file: primary.filename,
28
+ line: primary.line,
29
+ column: primary.column
30
+ } : void 0;
31
+ this.frame = primary?.frame;
32
+ this.pluginCode = serializeMarklessDevError(this.payload);
33
+ }
34
+ };
35
+ function createCompileErrorPayload(input) {
36
+ return {
37
+ version: 1,
38
+ id: input.filename,
39
+ kind: "compile",
40
+ diagnostics: input.diagnostics.map((diagnostic) => compilerDiagnostic(input.source, diagnostic)),
41
+ details: input.details,
42
+ ...input.stack ? { stack: input.stack } : {}
43
+ };
44
+ }
45
+ function normalizeMarklessDevError(error, options = {}) {
46
+ if (error instanceof MarklessCompileError) return error.payload;
47
+ if (isObject(error) && isPayload(error.payload)) return error.payload;
48
+ if (isObject(error) && typeof error.pluginCode === "string") {
49
+ const payload = parseMarklessPluginCode(error.pluginCode);
50
+ if (payload) return payload;
51
+ }
52
+ const details = error instanceof Error ? error.message : String(error);
53
+ const code = isObject(error) && typeof error.code === "string" ? error.code : "MARKLESS_DEV_RUNTIME_ERROR";
54
+ return {
55
+ version: 1,
56
+ id: options.id ?? "navigation:unknown",
57
+ kind: "runtime",
58
+ diagnostics: [{
59
+ code,
60
+ message: details
61
+ }],
62
+ details,
63
+ ...error instanceof Error && error.stack ? { stack: error.stack } : {}
64
+ };
65
+ }
66
+ function serializeMarklessDevError(payload) {
67
+ return JSON.stringify({
68
+ kind: PLUGIN_CODE_KIND,
69
+ version: PLUGIN_CODE_VERSION,
70
+ payload
71
+ });
72
+ }
73
+ function formatMarklessSourceFrame(source, span) {
74
+ const lines = source.split("\n");
75
+ const start = sourcePosition(source, span.start);
76
+ const end = sourcePosition(source, Math.max(span.start, span.end));
77
+ const firstLine = Math.max(1, start.line - 2);
78
+ const lastLine = Math.min(lines.length, start.line + 2);
79
+ const width = String(lastLine).length;
80
+ const frame = [];
81
+ for (let line = firstLine; line <= lastLine; line += 1) {
82
+ const active = line === start.line;
83
+ const text = lines[line - 1] ?? "";
84
+ frame.push(`${active ? ">" : " "} ${String(line).padStart(width)} | ${text}`);
85
+ if (active) {
86
+ const firstLineEnd = start.line === end.line ? end.column : text.length + 1;
87
+ const caretLength = Math.max(1, firstLineEnd - start.column);
88
+ frame.push(` ${" ".repeat(width)} | ${" ".repeat(start.column - 1)}${"^".repeat(caretLength)}`);
89
+ }
90
+ }
91
+ return frame.join("\n");
92
+ }
93
+ function renderMarklessDevErrorDocument(payload, options = {}) {
94
+ const primary = payload.diagnostics[0] ?? {
95
+ code: "MARKLESS_DEV_RUNTIME_ERROR",
96
+ message: payload.details
97
+ };
98
+ const diagnostics = payload.diagnostics.slice(1).map((diagnostic) => {
99
+ return `<details><summary>${escapeHtml(`${diagnostic.code} — ${diagnostic.message}`)}</summary>${renderDiagnosticBody(diagnostic, options.base ?? "/")}</details>`;
100
+ });
101
+ const technical = [payload.details, payload.stack].filter(Boolean).join("\n\n");
102
+ const serialized = JSON.stringify(payload).replaceAll("<", "\\u003c");
103
+ return `<!doctype html>
104
+ <html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
105
+ <title>${escapeHtml(primary.code)} — Markless development error</title><style>${documentStyles}</style></head>
106
+ <body><main class="panel"><header><span class="badge">${escapeHtml(primary.code)}</span><h1>${escapeHtml(primary.message)}</h1></header>
107
+ ${renderDiagnosticBody(primary, options.base ?? "/")}
108
+ ${diagnostics.join("\n")}
109
+ <details><summary>Technical details</summary><pre>${escapeHtml(technical)}</pre></details>
110
+ <p class="recovery">Fix the error and reload to continue.</p></main>
111
+ <script>window.__MARKLESS_DEV_ERROR__ = ${serialized};<\/script></body></html>`;
112
+ }
113
+ function renderMarklessDevErrorPlainText(payload) {
114
+ return [payload.details, payload.stack].filter(Boolean).join("\n\n");
115
+ }
116
+ function compilerDiagnostic(source, diagnostic) {
117
+ const position = diagnostic.primarySpan ? sourcePosition(source, diagnostic.primarySpan.start) : void 0;
118
+ return {
119
+ code: diagnostic.code,
120
+ message: diagnostic.message,
121
+ ...diagnostic.primarySpan ? { filename: diagnostic.primarySpan.filename } : {},
122
+ ...position ? {
123
+ line: position.line,
124
+ column: position.column
125
+ } : {},
126
+ ...diagnostic.why ? { why: diagnostic.why } : {},
127
+ ...diagnostic.suggestions[0]?.message ? { suggestion: diagnostic.suggestions[0].message } : {},
128
+ ...diagnostic.docsUrl ? { docsUrl: diagnostic.docsUrl } : {},
129
+ ...diagnostic.primarySpan ? { frame: formatMarklessSourceFrame(source, diagnostic.primarySpan) } : {}
130
+ };
131
+ }
132
+ function sourcePosition(source, offset) {
133
+ const before = source.slice(0, Math.max(0, Math.min(offset, source.length)));
134
+ const lastLineBreak = before.lastIndexOf("\n");
135
+ return {
136
+ line: before.split("\n").length,
137
+ column: before.length - lastLineBreak
138
+ };
139
+ }
140
+ function parseMarklessPluginCode(value) {
141
+ try {
142
+ const envelope = JSON.parse(value);
143
+ if (isObject(envelope) && envelope.kind === PLUGIN_CODE_KIND && envelope.version === PLUGIN_CODE_VERSION && isPayload(envelope.payload)) return envelope.payload;
144
+ } catch {}
145
+ }
146
+ function isPayload(value) {
147
+ return isObject(value) && value.version === 1 && typeof value.id === "string" && (value.kind === "compile" || value.kind === "runtime") && Array.isArray(value.diagnostics) && typeof value.details === "string";
148
+ }
149
+ function isObject(value) {
150
+ return typeof value === "object" && value !== null;
151
+ }
152
+ function renderDiagnosticBody(diagnostic, base) {
153
+ const editorLocation = diagnostic.filename && diagnostic.line !== void 0 && diagnostic.column !== void 0 ? `${diagnostic.filename}:${diagnostic.line}:${diagnostic.column}` : void 0;
154
+ 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>` : ""}`;
155
+ }
156
+ function isHttpUrl(value) {
157
+ try {
158
+ const url = new URL(value);
159
+ return url.protocol === "http:" || url.protocol === "https:";
160
+ } catch {
161
+ return false;
162
+ }
163
+ }
164
+ function escapeHtml(value) {
165
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
166
+ }
167
+ function escapeAttribute(value) {
168
+ return escapeHtml(value);
169
+ }
170
+ const documentStyles = `
171
+ :root{color-scheme:light dark;font-family:system-ui,sans-serif;background:Canvas;color:CanvasText}
172
+ *{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%)}
173
+ .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}
174
+ 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}`;
175
+ //#endregion
176
+ export { MARKLESS_DEV_RELOADS_EVENT as a, formatMarklessSourceFrame as c, renderMarklessDevErrorPlainText as d, serializeMarklessDevError as f, MARKLESS_DEV_RELOADS_ATTRIBUTE as i, normalizeMarklessDevError as l, MARKLESS_DEV_ERROR_CLIENT_ID as n, MarklessCompileError as o, MARKLESS_DEV_ERROR_EVENT as r, createCompileErrorPayload as s, MARKLESS_DEV_ERROR_CLEAR_EVENT as t, renderMarklessDevErrorDocument as u };
@@ -1,10 +1,11 @@
1
1
  import { CompilerDiagnostic, SourceSpan } from "@markless/compiler";
2
-
3
2
  //#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 {
3
+ export declare const MARKLESS_DEV_ERROR_EVENT = "markless:dev-error";
4
+ export declare const MARKLESS_DEV_ERROR_CLEAR_EVENT = "markless:dev-error-clear";
5
+ export declare const MARKLESS_DEV_ERROR_CLIENT_ID = "virtual:markless:dev-error-client";
6
+ export declare const MARKLESS_DEV_RELOADS_EVENT = "markless:dev-reloads";
7
+ export declare const MARKLESS_DEV_RELOADS_ATTRIBUTE = "data-markless-dev-reloads";
8
+ export interface MarklessDevDiagnostic {
8
9
  readonly code: string;
9
10
  readonly message: string;
10
11
  readonly filename?: string;
@@ -15,7 +16,7 @@ interface MarklessDevDiagnostic {
15
16
  readonly docsUrl?: string;
16
17
  readonly frame?: string;
17
18
  }
18
- interface MarklessDevErrorPayload {
19
+ export interface MarklessDevErrorPayload {
19
20
  readonly version: 1;
20
21
  readonly id: string;
21
22
  readonly kind: 'compile' | 'runtime';
@@ -23,12 +24,12 @@ interface MarklessDevErrorPayload {
23
24
  readonly details: string;
24
25
  readonly stack?: string;
25
26
  }
26
- interface MarklessErrorLocation {
27
+ export interface MarklessErrorLocation {
27
28
  readonly file?: string;
28
29
  readonly line: number;
29
30
  readonly column: number;
30
31
  }
31
- declare class MarklessCompileError extends Error {
32
+ export declare class MarklessCompileError extends Error {
32
33
  readonly payload: MarklessDevErrorPayload;
33
34
  readonly id: string;
34
35
  readonly loc?: MarklessErrorLocation;
@@ -37,21 +38,20 @@ declare class MarklessCompileError extends Error {
37
38
  readonly pluginCode: string;
38
39
  constructor(payload: MarklessDevErrorPayload);
39
40
  }
40
- declare function createCompileErrorPayload(input: {
41
+ export declare function createCompileErrorPayload(input: {
41
42
  readonly filename: string;
42
43
  readonly source: string;
43
44
  readonly diagnostics: readonly CompilerDiagnostic[];
44
45
  readonly details: string;
45
46
  readonly stack?: string;
46
47
  }): MarklessDevErrorPayload;
47
- declare function normalizeMarklessDevError(error: unknown, options?: {
48
+ export declare function normalizeMarklessDevError(error: unknown, options?: {
48
49
  readonly id?: string;
49
50
  }): MarklessDevErrorPayload;
50
- declare function serializeMarklessDevError(payload: MarklessDevErrorPayload): string;
51
- declare function formatMarklessSourceFrame(source: string, span: SourceSpan): string;
52
- declare function renderMarklessDevErrorDocument(payload: MarklessDevErrorPayload, options?: {
51
+ export declare function serializeMarklessDevError(payload: MarklessDevErrorPayload): string;
52
+ export declare function formatMarklessSourceFrame(source: string, span: SourceSpan): string;
53
+ export declare function renderMarklessDevErrorDocument(payload: MarklessDevErrorPayload, options?: {
53
54
  readonly base?: string;
54
55
  }): 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 };
56
+ export declare function renderMarklessDevErrorPlainText(payload: MarklessDevErrorPayload): string;
57
+ //#endregion
package/dist/dev-error.js CHANGED
@@ -1,174 +1,2 @@
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("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
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 };
1
+ import { a as MARKLESS_DEV_RELOADS_EVENT, c as formatMarklessSourceFrame, d as renderMarklessDevErrorPlainText, f as serializeMarklessDevError, i as MARKLESS_DEV_RELOADS_ATTRIBUTE, l as normalizeMarklessDevError, n as MARKLESS_DEV_ERROR_CLIENT_ID, o as MarklessCompileError, r as MARKLESS_DEV_ERROR_EVENT, s as createCompileErrorPayload, t as MARKLESS_DEV_ERROR_CLEAR_EVENT, u as renderMarklessDevErrorDocument } from "./dev-error-2hi-Icjn.js";
2
+ export { MARKLESS_DEV_ERROR_CLEAR_EVENT, MARKLESS_DEV_ERROR_CLIENT_ID, MARKLESS_DEV_ERROR_EVENT, MARKLESS_DEV_RELOADS_ATTRIBUTE, MARKLESS_DEV_RELOADS_EVENT, MarklessCompileError, createCompileErrorPayload, formatMarklessSourceFrame, normalizeMarklessDevError, renderMarklessDevErrorDocument, renderMarklessDevErrorPlainText, serializeMarklessDevError };
@@ -0,0 +1,17 @@
1
+ import "./types-iOUoceJ-.js";
2
+ import "@markless/serializer";
3
+ import "@markless/compiler";
4
+ import "@markless/web/inline/resumer";
5
+ //#region src/source-module.d.ts
6
+ declare const MARKLESS_VIRTUAL_PREFIX = "virtual:markless:";
7
+ declare function symbolVirtualModuleSourceFile(moduleId: string): string | null;
8
+ declare function resumeVirtualModuleId(filename: string): string;
9
+ declare function prerenderWakeVirtualModuleId(filename: string): string;
10
+ declare function prerenderWakeVirtualModuleSourceFile(moduleId: string): string | null;
11
+ //#endregion
12
+ //#region src/execution-log.d.ts
13
+ declare function isExecutionLogChunk(chunk: {
14
+ readonly moduleIds?: readonly string[];
15
+ }): boolean;
16
+ //#endregion
17
+ export { resumeVirtualModuleId as a, prerenderWakeVirtualModuleSourceFile as i, MARKLESS_VIRTUAL_PREFIX as n, symbolVirtualModuleSourceFile as o, prerenderWakeVirtualModuleId as r, isExecutionLogChunk as t };
@@ -0,0 +1,89 @@
1
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
2
+ import { dirname, isAbsolute, join, normalize, resolve } from "pathe";
3
+ //#region src/optimized-deps.ts
4
+ function optimizedDepsToInclude(specifiers, resolution) {
5
+ const root = resolve(resolution.root ?? "");
6
+ const preserveSymlinks = resolution.resolve?.preserveSymlinks === true;
7
+ const alias = resolution.resolve?.alias;
8
+ return specifiers.filter((specifier) => !servedFromSource(applyAlias(specifier, alias), root, preserveSymlinks));
9
+ }
10
+ function includeOptimizedDeps(config, specifiers) {
11
+ const bundled = optimizedDepsToInclude(specifiers, config);
12
+ if (bundled.length === 0) return;
13
+ const optimizeDeps = config.optimizeDeps ??= {};
14
+ const include = optimizeDeps.include ?? [];
15
+ optimizeDeps.include = [...include, ...bundled.filter((specifier) => !include.includes(specifier))];
16
+ }
17
+ function excludeSourceShippedDeps(config) {
18
+ const appManifest = nearestManifest(resolve(config.root ?? ""));
19
+ if (!appManifest) return;
20
+ const shipsSource = [];
21
+ const seen = /* @__PURE__ */ new Set();
22
+ const visit = (names, from) => {
23
+ for (const name of names) {
24
+ const directory = installedPackage(name, from);
25
+ if (directory === void 0 || seen.has(directory)) continue;
26
+ seen.add(directory);
27
+ const manifest = readManifest(join(directory, "package.json"));
28
+ if (manifest?.publishConfig?.marklessShipsSource !== true) continue;
29
+ if (!shipsSource.includes(name)) shipsSource.push(name);
30
+ visit(Object.keys(manifest.dependencies ?? {}), realpathOf(directory));
31
+ }
32
+ };
33
+ visit([...Object.keys(appManifest.manifest.dependencies ?? {}), ...Object.keys(appManifest.manifest.devDependencies ?? {})], appManifest.directory);
34
+ if (shipsSource.length === 0) return;
35
+ const optimizeDeps = config.optimizeDeps ??= {};
36
+ const exclude = optimizeDeps.exclude ?? [];
37
+ optimizeDeps.exclude = [...exclude, ...shipsSource.filter((name) => !exclude.includes(name))];
38
+ }
39
+ function readManifest(path) {
40
+ try {
41
+ return JSON.parse(readFileSync(path, "utf8"));
42
+ } catch {
43
+ return;
44
+ }
45
+ }
46
+ function nearestManifest(root) {
47
+ for (let directory = root;; directory = dirname(directory)) {
48
+ const manifest = existsSync(join(directory, "package.json")) ? readManifest(join(directory, "package.json")) : void 0;
49
+ if (manifest) return {
50
+ directory,
51
+ manifest
52
+ };
53
+ if (dirname(directory) === directory) return void 0;
54
+ }
55
+ }
56
+ function applyAlias(specifier, alias) {
57
+ if (!alias) return specifier;
58
+ const entries = Array.isArray(alias) ? alias : Object.entries(alias).map(([find, replacement]) => ({
59
+ find,
60
+ replacement
61
+ }));
62
+ for (const { find, replacement } of entries) if (typeof find === "string") {
63
+ if (specifier === find || specifier.startsWith(`${find}/`)) return replacement + specifier.slice(find.length);
64
+ } else if (find.test(specifier)) return specifier.replace(find, replacement);
65
+ return specifier;
66
+ }
67
+ function servedFromSource(id, root, preserveSymlinks) {
68
+ const path = isAbsolute(id) || id.startsWith(".") ? resolve(root, id) : installedPackage(id, root);
69
+ if (path === void 0) return false;
70
+ return !`${preserveSymlinks ? normalize(path) : realpathOf(path)}/`.includes("/node_modules/");
71
+ }
72
+ function installedPackage(specifier, root) {
73
+ const segments = specifier.split("/");
74
+ const name = specifier.startsWith("@") ? segments.slice(0, 2).join("/") : segments[0];
75
+ for (let directory = root;; directory = dirname(directory)) {
76
+ const entry = join(directory, "node_modules", name);
77
+ if (existsSync(entry)) return entry;
78
+ if (dirname(directory) === directory) return void 0;
79
+ }
80
+ }
81
+ function realpathOf(path) {
82
+ try {
83
+ return normalize(realpathSync(path));
84
+ } catch {
85
+ return normalize(path);
86
+ }
87
+ }
88
+ //#endregion
89
+ export { includeOptimizedDeps as n, optimizedDepsToInclude as r, excludeSourceShippedDeps as t };
package/dist/preload.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { o as MarklessBundleGraph } from "./types-BuooJg32.js";
2
- import { a as symbolVirtualModuleSourceFile, r as prerenderWakeVirtualModuleSourceFile } from "./source-module-XFgOFX1c.js";
3
-
1
+ import { o as MarklessBundleGraph } from "./types-iOUoceJ-.js";
2
+ import { i as prerenderWakeVirtualModuleSourceFile, o as symbolVirtualModuleSourceFile, t as isExecutionLogChunk } from "./execution-log-BL-7a77M.js";
3
+ import { UserConfig } from "vite";
4
4
  //#region src/build/preload-plan.d.ts
5
5
  type ModulePreloadPlanInput = {
6
6
  readonly bundleGraph: MarklessBundleGraph | undefined;
@@ -8,6 +8,7 @@ type ModulePreloadPlanInput = {
8
8
  readonly base?: string;
9
9
  readonly minProbability?: number;
10
10
  readonly maxPreloads?: number;
11
+ readonly lazyChunks?: ReadonlySet<string>;
11
12
  };
12
13
  type ModulePreloadRoot = string | {
13
14
  readonly name: string;
@@ -24,8 +25,14 @@ type ModulePreloadPlanEntry = {
24
25
  readonly fetchPriority?: ModulePreloadFetchPriority;
25
26
  readonly probability: number;
26
27
  };
27
- declare function planModulePreloadUrls(input: ModulePreloadPlanInput): string[];
28
- declare function planModulePreloads(input: ModulePreloadPlanInput): ModulePreloadPlanEntry[];
28
+ export declare function planModulePreloadUrls(input: ModulePreloadPlanInput): string[];
29
+ export declare function planModulePreloads(input: ModulePreloadPlanInput): ModulePreloadPlanEntry[];
30
+ //#endregion
31
+ //#region src/optimized-deps.d.ts
32
+ type DepResolution = Pick<UserConfig, 'root'> & {
33
+ readonly resolve?: Pick<NonNullable<UserConfig['resolve']>, 'alias' | 'preserveSymlinks'>;
34
+ };
35
+ export declare function optimizedDepsToInclude(specifiers: ReadonlyArray<string>, resolution: DepResolution): string[];
29
36
  //#endregion
30
37
  //#region src/build/module-preload-dom.d.ts
31
38
  type LazySymbolPreloadView = {
@@ -74,6 +81,36 @@ type ModulePreloadLink = ModulePreloadExistingLink & {
74
81
  crossOrigin: string;
75
82
  setAttribute?(name: string, value: string): void;
76
83
  };
77
- declare function preloadLazySymbolModules(input: PreloadLazySymbolModulesInput): AppendedModulePreloads;
84
+ export declare function preloadLazySymbolModules(input: PreloadLazySymbolModulesInput): AppendedModulePreloads;
85
+ //#endregion
86
+ //#region src/virtual-ids.d.ts
87
+ export declare function isSymbolOnlySourceRequest(id: string): boolean;
88
+ export declare function isResumeSourceRequest(id: string): boolean;
89
+ export declare function isRenderDataSourceRequest(id: string): boolean;
90
+ export declare function isRouteNavigationSourceRequest(id: string): boolean;
91
+ export declare function isClientPrimarySourceRequest(id: string): boolean;
92
+ export declare function resolverVirtualModuleSourceFile(id: string): string | null;
93
+ //#endregion
94
+ //#region src/build/planned-landing.d.ts
95
+ export declare function plannedLandingFiles(bundle: Readonly<Record<string, unknown>>): Map<string, ReadonlySet<string>> | undefined;
96
+ //#endregion
97
+ //#region src/build/warm-packs.d.ts
98
+ /** The packs a chunk evaluates a task after it runs, read from `warmPacksSuffix` before or after minifying. */
99
+ export declare function warmEvaluatedImports(code: string): string[];
100
+ //#endregion
101
+ //#region src/build/route-pack-groups.d.ts
102
+ export declare const MARKLESS_DEFERRED_PACK = "markless-deferred";
103
+ export declare const MARKLESS_NAVIGATION_PACK_PREFIX = "navigation:";
104
+ export declare function isMarklessDeferredPack(name: string | undefined): boolean;
105
+ /** Deferred packs plus the module-free facade chunks Rolldown emits in front of their entries. */
106
+ export declare function marklessDeferredChunkFileNames(chunks: Iterable<{
107
+ readonly fileName: string;
108
+ readonly name?: string;
109
+ readonly imports: readonly string[];
110
+ readonly moduleIds?: readonly string[];
111
+ }>): Set<string>;
112
+ export declare function isMarklessNavigationPack(name: string | undefined): boolean;
113
+ export declare function lazyStartupPackName(group: string): string;
114
+ export declare function startupPackOfLazy(name: string): string;
78
115
  //#endregion
79
- export { type AppendedModulePreloads, type LazySymbolPreloadView, type MarklessBundleGraph, type ModulePreloadFetchPriority, type ModulePreloadPlanEntry, type ModulePreloadPlanInput, type ModulePreloadPriority, type ModulePreloadRoot, type PreloadLazySymbolModulesInput, planModulePreloadUrls, planModulePreloads, preloadLazySymbolModules, prerenderWakeVirtualModuleSourceFile, symbolVirtualModuleSourceFile };
116
+ export { type AppendedModulePreloads, type LazySymbolPreloadView, type MarklessBundleGraph, type ModulePreloadFetchPriority, type ModulePreloadPlanEntry, type ModulePreloadPlanInput, type ModulePreloadPriority, type ModulePreloadRoot, type PreloadLazySymbolModulesInput, isExecutionLogChunk, prerenderWakeVirtualModuleSourceFile, symbolVirtualModuleSourceFile };
package/dist/preload.js CHANGED
@@ -1,4 +1,5 @@
1
- import { C as planModulePreloadUrls, c as prerenderWakeVirtualModuleSourceFile, m as symbolVirtualModuleSourceFile, w as planModulePreloads } from "./source-module-DI20i0ZG.js";
1
+ import { A as isSymbolOnlySourceRequest, D as isResumeSourceRequest, E as isRenderDataSourceRequest, I as resolverVirtualModuleSourceFile, It as planModulePreloadUrls, Lt as planModulePreloads, Nt as isExecutionLogChunk, O as isRouteNavigationSourceRequest, S as isClientPrimarySourceRequest, _t as prerenderWakeVirtualModuleSourceFile, i as isMarklessNavigationPack, l as startupPackOfLazy, n as MARKLESS_NAVIGATION_PACK_PREFIX, o as lazyStartupPackName, p as plannedLandingFiles, r as isMarklessDeferredPack, s as marklessDeferredChunkFileNames, t as MARKLESS_DEFERRED_PACK, u as warmEvaluatedImports, wt as symbolVirtualModuleSourceFile } from "./route-pack-groups-BXc755qH.js";
2
+ import { r as optimizedDepsToInclude } from "./optimized-deps-BfzxSm6C.js";
2
3
  //#region src/build/module-preload-dom.ts
3
4
  const PRIORITY_RANK = {
4
5
  high: 2,
@@ -72,4 +73,4 @@ function rememberHref(seen, href, baseURI) {
72
73
  if (baseURI) seen.add(new URL(href, baseURI).href);
73
74
  }
74
75
  //#endregion
75
- export { planModulePreloadUrls, planModulePreloads, preloadLazySymbolModules, prerenderWakeVirtualModuleSourceFile, symbolVirtualModuleSourceFile };
76
+ export { MARKLESS_DEFERRED_PACK, MARKLESS_NAVIGATION_PACK_PREFIX, isClientPrimarySourceRequest, isExecutionLogChunk, isMarklessDeferredPack, isMarklessNavigationPack, isRenderDataSourceRequest, isResumeSourceRequest, isRouteNavigationSourceRequest, isSymbolOnlySourceRequest, lazyStartupPackName, marklessDeferredChunkFileNames, optimizedDepsToInclude, planModulePreloadUrls, planModulePreloads, plannedLandingFiles, preloadLazySymbolModules, prerenderWakeVirtualModuleSourceFile, resolverVirtualModuleSourceFile, startupPackOfLazy, symbolVirtualModuleSourceFile, warmEvaluatedImports };