@lark-apaas/coding-vite-preset 1.0.15-alpha.8 → 1.0.15-beta.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-overlay-plugin.d.ts","sourceRoot":"","sources":["../../src/vite-plugins/error-overlay-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAoC,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"error-overlay-plugin.d.ts","sourceRoot":"","sources":["../../src/vite-plugins/error-overlay-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAoC,MAAM,MAAM,CAAC;AAsErE,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAiDD;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAmHR;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -21,6 +21,69 @@ exports.errorOverlayPlugin = errorOverlayPlugin;
|
|
|
21
21
|
const fs_1 = __importDefault(require("fs"));
|
|
22
22
|
const path_1 = __importDefault(require("path"));
|
|
23
23
|
const OVERLAY_PATH = '/@error-overlay.js';
|
|
24
|
+
// 内联到 <script> 前必须转义 `<` `>` 和 line separator,避免 payload 里出现 `</script>` 破坏 script tag
|
|
25
|
+
function safeInlineJson(json) {
|
|
26
|
+
return json
|
|
27
|
+
.replace(/</g, '\\u003c')
|
|
28
|
+
.replace(/>/g, '\\u003e')
|
|
29
|
+
.replace(/\u2028/g, '\\u2028')
|
|
30
|
+
.replace(/\u2029/g, '\\u2029');
|
|
31
|
+
}
|
|
32
|
+
// 序列化 Vite 内部 err 对象为可 JSON 序列化的 payload,字段与 Vite prepareError 对齐
|
|
33
|
+
function serializeErrorPayload(err) {
|
|
34
|
+
const e = (err ?? {});
|
|
35
|
+
const stripAnsi = (s) => String(s ?? '').replace(/\x1b\[[0-9;]*m/g, '');
|
|
36
|
+
const payload = {
|
|
37
|
+
message: stripAnsi(e.message),
|
|
38
|
+
stack: stripAnsi(e.stack),
|
|
39
|
+
id: e.id ?? '',
|
|
40
|
+
frame: stripAnsi(e.frame ?? ''),
|
|
41
|
+
plugin: e.plugin ?? '',
|
|
42
|
+
pluginCode: e.pluginCode ? String(e.pluginCode) : '',
|
|
43
|
+
loc: e.loc ?? null,
|
|
44
|
+
};
|
|
45
|
+
return JSON.stringify(payload);
|
|
46
|
+
}
|
|
47
|
+
function buildCustomErrorHtml(errorPayloadJson, overlayPath) {
|
|
48
|
+
const escapedOverlayPath = JSON.stringify(overlayPath);
|
|
49
|
+
const safe = safeInlineJson(errorPayloadJson);
|
|
50
|
+
return `<!DOCTYPE html>
|
|
51
|
+
<html>
|
|
52
|
+
<head>
|
|
53
|
+
<meta charset="UTF-8">
|
|
54
|
+
<title>Compile Error</title>
|
|
55
|
+
<script type="module">
|
|
56
|
+
const error = ${safe};
|
|
57
|
+
try {
|
|
58
|
+
window.parent.postMessage({
|
|
59
|
+
type: 'SELECTED_LOG',
|
|
60
|
+
payload: JSON.stringify({
|
|
61
|
+
type: 'typedLogV2',
|
|
62
|
+
level: 'error',
|
|
63
|
+
id: 'compile-' + Date.now() + '-' + Math.random().toString(36).slice(2, 10),
|
|
64
|
+
args: ['Compile Error', error.message, error.plugin || '', error.id || '', error.frame || ''].filter(Boolean),
|
|
65
|
+
meta: { type: 'compile-error', noStacktrace: false, stacktrace: [] },
|
|
66
|
+
}),
|
|
67
|
+
}, '*');
|
|
68
|
+
window.parent.postMessage({ type: 'RenderError', data: 'compileError' }, '*');
|
|
69
|
+
} catch (e) { /* postMessage 失败可安全忽略,如 target origin 不匹配 */ }
|
|
70
|
+
try {
|
|
71
|
+
window.__COMPILE_ERROR__ = error;
|
|
72
|
+
const s = document.createElement('script');
|
|
73
|
+
s.type = 'module';
|
|
74
|
+
s.src = ${escapedOverlayPath};
|
|
75
|
+
document.head.appendChild(s);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
function escapeHtml(s) { return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); }
|
|
78
|
+
document.body.innerHTML =
|
|
79
|
+
'<h1 style="font-family:sans-serif;color:#e11d48">编译错误</h1>' +
|
|
80
|
+
'<pre style="font-family:monospace;white-space:pre-wrap">' + escapeHtml(error.message || '') + '</pre>';
|
|
81
|
+
}
|
|
82
|
+
</script>
|
|
83
|
+
</head>
|
|
84
|
+
<body></body>
|
|
85
|
+
</html>`;
|
|
86
|
+
}
|
|
24
87
|
/**
|
|
25
88
|
* 获取客户端脚本路径
|
|
26
89
|
*/
|
|
@@ -89,6 +152,7 @@ function errorOverlayPlugin(options = {}) {
|
|
|
89
152
|
configureServer(server) {
|
|
90
153
|
if (!enabled)
|
|
91
154
|
return;
|
|
155
|
+
// Serve /@error-overlay.js (URL-matched; safe to register early).
|
|
92
156
|
server.middlewares.use((req, res, next) => {
|
|
93
157
|
if (req.url !== overlayPath)
|
|
94
158
|
return next();
|
|
@@ -104,6 +168,46 @@ function errorOverlayPlugin(options = {}) {
|
|
|
104
168
|
res.end(`// Error: ${e}`);
|
|
105
169
|
}
|
|
106
170
|
});
|
|
171
|
+
// 拦截 Vite compile / transform 抛出的 err,替代 Vite 内置的 500 error HTML (`new ErrorOverlay(error)`)
|
|
172
|
+
// 为我们的 postMessage SELECTED_LOG + 加载自定义 overlay 响应。
|
|
173
|
+
// 关键:必须走 configureServer 返回的 post-hook,让本 middleware 位于 stack 中
|
|
174
|
+
// transformMiddleware/htmlFallbackMiddleware 之后、Vite 自身 errorMiddleware 之前;
|
|
175
|
+
// 这样 next(err) 才会先命中我们。
|
|
176
|
+
return () => {
|
|
177
|
+
// 4-arg error middleware (connect 的错误路径要求 4 参数签名)。
|
|
178
|
+
const compileErrorHandler = (err, _req, res, next) => {
|
|
179
|
+
try {
|
|
180
|
+
if (res.writableEnded || res.headersSent) {
|
|
181
|
+
return next(err);
|
|
182
|
+
}
|
|
183
|
+
const payloadJson = serializeErrorPayload(err);
|
|
184
|
+
const html = buildCustomErrorHtml(payloadJson, overlayPath);
|
|
185
|
+
const buf = Buffer.from(html, 'utf-8');
|
|
186
|
+
res.statusCode = 500;
|
|
187
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
188
|
+
res.setHeader('Content-Length', String(buf.length));
|
|
189
|
+
res.end(buf);
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
192
|
+
console.error('[error-overlay] error middleware failed:', e);
|
|
193
|
+
return next(err);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
// 关键:必须在 stack 里找到 Vite 内置的 viteErrorMiddleware 并 splice 到它之前。
|
|
197
|
+
// 单纯 `use()` append 只能位于 indexHtmlMiddleware 前,拿不到 HTML transform 失败;
|
|
198
|
+
// 而 Vite 的 errorMiddleware 是最后一个,我们必须紧挨着它前面才能截住所有 next(err)。
|
|
199
|
+
// 用 setImmediate 让本 splice 发生在 Vite 完成所有 `use()` 之后。
|
|
200
|
+
setImmediate(() => {
|
|
201
|
+
const mws = server.middlewares;
|
|
202
|
+
const idx = mws.stack.findIndex((m) => m.handle?.name === 'viteErrorMiddleware');
|
|
203
|
+
if (idx >= 0) {
|
|
204
|
+
mws.stack.splice(idx, 0, { route: '', handle: compileErrorHandler });
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
server.middlewares.use(compileErrorHandler);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
};
|
|
107
211
|
},
|
|
108
212
|
// HTML 注入 script
|
|
109
213
|
transformIndexHtml(html) {
|
|
@@ -116,9 +220,8 @@ function errorOverlayPlugin(options = {}) {
|
|
|
116
220
|
type: 'module',
|
|
117
221
|
src: overlayPath,
|
|
118
222
|
},
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
injectTo: 'head',
|
|
223
|
+
// 尽早加载,确保 window.__COMPILE_ERROR__ 消费时机
|
|
224
|
+
injectTo: 'head-prepend',
|
|
122
225
|
},
|
|
123
226
|
];
|
|
124
227
|
return { html, tags };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-overlay-plugin.js","sourceRoot":"","sources":["../../src/vite-plugins/error-overlay-plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;;
|
|
1
|
+
{"version":3,"file":"error-overlay-plugin.js","sourceRoot":"","sources":["../../src/vite-plugins/error-overlay-plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;;AAyIH,gDAqHC;AA5PD,4CAAoB;AACpB,gDAAwB;AAGxB,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAE1C,uFAAuF;AACvF,SAAS,cAAc,CAAC,IAAY;IAClC,OAAO,IAAI;SACR,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;SAC7B,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AACnC,CAAC;AAED,kEAAkE;AAClE,SAAS,qBAAqB,CAAC,GAAY;IACzC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAqE,CAAC;IAC1F,MAAM,SAAS,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACzF,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QAC7B,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;QACzB,EAAE,EAAE,CAAC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ACJ,CAAC;QAED,iBAAiB;QACjB,kBAAkB,CAAC,IAAY;YAC7B,IAAI,CAAC,OAAO;gBAAE,OAAO,IAAI,CAAC;YAE1B,MAAM,IAAI,GAAwB;gBAChC;oBACE,GAAG,EAAE,QAAQ;oBACb,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;wBACd,GAAG,EAAE,WAAW;qBACjB;oBACD,wCAAwC;oBACxC,QAAQ,EAAE,cAAc;iBACzB;aACF,CAAC;YAEF,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACxB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,kBAAe,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -502,14 +502,29 @@ if (!window.__VITE_ERROR_OVERLAY_INITIALIZED__) {
|
|
|
502
502
|
|
|
503
503
|
// ===== Global Error Listeners =====
|
|
504
504
|
function setupGlobalErrorListeners() {
|
|
505
|
+
// capture 阶段才能拿到资源 404(IMG/SCRIPT/LINK 的 error 不冒泡)
|
|
505
506
|
window.addEventListener('error', (event) => {
|
|
506
507
|
// 忽略编译错误模式下的运行时错误
|
|
507
508
|
if (currentMode === 'compileError') return;
|
|
508
509
|
|
|
509
510
|
if (event.error) {
|
|
510
511
|
handleRuntimeError(event.error);
|
|
512
|
+
return;
|
|
511
513
|
}
|
|
512
|
-
|
|
514
|
+
|
|
515
|
+
const target = event.target;
|
|
516
|
+
if (target && target !== window && target.tagName) {
|
|
517
|
+
const tag = target.tagName;
|
|
518
|
+
if (tag === 'IMG' || tag === 'SCRIPT' || tag === 'LINK') {
|
|
519
|
+
const url = target.src || target.href || '';
|
|
520
|
+
// 过滤已知常见噪声 (favicon / apple-touch-icon / manifest 等浏览器自动请求),
|
|
521
|
+
// 避免用户"页面日志"面板被这类无害 404 淹没
|
|
522
|
+
if (/\/favicon\.(ico|png|svg)|\/apple-touch-icon|\/manifest\.json|\/robots\.txt/.test(url)) return;
|
|
523
|
+
// 资源 404 只上报到页面日志,不 render overlay(避免整页遮盖用户预览)
|
|
524
|
+
logError(['Resource load failed', tag.toLowerCase(), url], 'runtimeError');
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}, true);
|
|
513
528
|
|
|
514
529
|
window.addEventListener('unhandledrejection', (event) => {
|
|
515
530
|
if (currentMode === 'compileError') return;
|
|
@@ -562,6 +577,19 @@ if (!window.__VITE_ERROR_OVERLAY_INITIALIZED__) {
|
|
|
562
577
|
};
|
|
563
578
|
|
|
564
579
|
// ===== Initialize =====
|
|
580
|
+
// 500 error HTML 场景兼容:宿主 HTML 塞 window.__COMPILE_ERROR__ 后加载本脚本,触发一次 render
|
|
581
|
+
if (window.__COMPILE_ERROR__) {
|
|
582
|
+
try {
|
|
583
|
+
const err = window.__COMPILE_ERROR__;
|
|
584
|
+
const msg = (err.message || '') + (err.frame ? '\n\n' + err.frame : '');
|
|
585
|
+
showCompileError(msg);
|
|
586
|
+
} catch (e) {
|
|
587
|
+
// showCompileError 失败可安全忽略 —— overlay 渲染降级不阻塞后续 setup;
|
|
588
|
+
// 且 SELECTED_LOG postMessage 已在服务端内联 script 里发过,页面日志不会丢
|
|
589
|
+
}
|
|
590
|
+
try { delete window.__COMPILE_ERROR__; } catch (e) { /* strict-mode / non-configurable delete 失败可安全忽略,不影响主流程 */ }
|
|
591
|
+
}
|
|
592
|
+
|
|
565
593
|
setupViteHMRListener();
|
|
566
594
|
setupGlobalErrorListeners();
|
|
567
595
|
}
|