@lark-apaas/devtool-kits 1.2.0 → 1.2.1
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/error.html +23 -194
- package/dist/index.cjs +5 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/error.html
CHANGED
|
@@ -12,22 +12,22 @@
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
body {
|
|
15
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
|
15
|
+
font-family: "PingFang SC", -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
|
16
16
|
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
|
17
17
|
sans-serif;
|
|
18
18
|
-webkit-font-smoothing: antialiased;
|
|
19
19
|
-moz-osx-font-smoothing: grayscale;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
.container {
|
|
22
|
+
.overlay-container {
|
|
23
23
|
min-height: 100vh;
|
|
24
24
|
display: flex;
|
|
25
25
|
align-items: center;
|
|
26
26
|
justify-content: center;
|
|
27
|
-
background-color: #
|
|
27
|
+
background-color: #fff;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
.content {
|
|
30
|
+
.overlay-content {
|
|
31
31
|
display: flex;
|
|
32
32
|
flex-direction: column;
|
|
33
33
|
justify-content: center;
|
|
@@ -35,104 +35,37 @@
|
|
|
35
35
|
text-align: center;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
.error-image {
|
|
39
|
-
margin-bottom:
|
|
40
|
-
width:
|
|
38
|
+
.overlay-error-image {
|
|
39
|
+
margin-bottom: 12px; /* mb-3 */
|
|
40
|
+
width: 100px; /* w-[100px] */
|
|
41
41
|
height: auto;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
.title {
|
|
45
|
-
font-size: 18px; /* text-l (推测为 text-lg) */
|
|
46
|
-
line-height: 22px;
|
|
44
|
+
.overlay-title {
|
|
47
45
|
color: #1F2329;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
font-size: 14px; /* text-sm */
|
|
54
|
-
line-height: 22px;
|
|
55
|
-
color: #646A73;
|
|
56
|
-
font-weight: 400; /* font-normal */
|
|
57
|
-
margin-bottom: 8px; /* mb-2 */
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.button-group {
|
|
61
|
-
display: flex;
|
|
62
|
-
gap: 16px; /* space-x-4 */
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.button {
|
|
66
|
-
height: 32px; /* h-[32px] */
|
|
67
|
-
padding: 0 16px;
|
|
68
|
-
border-radius: 6px; /* rounded-[6px] */
|
|
69
|
-
font-size: 14px; /* text-sm */
|
|
70
|
-
font-weight: 400; /* font-[400] */
|
|
71
|
-
cursor: pointer;
|
|
72
|
-
transition: all 0.2s;
|
|
73
|
-
outline: none; /* focus:outline-hidden */
|
|
74
|
-
border: 1px solid;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.button-copy {
|
|
78
|
-
background-color: white; /* bg-white */
|
|
79
|
-
color: #4B5563; /* text-gray-600 */
|
|
80
|
-
border-color: #D0D3D6; /* border-[#D0D3D6] */
|
|
81
|
-
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); /* shadow-xs */
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.button-copy:hover {
|
|
85
|
-
background-color: #F3F4F6; /* hover:bg-gray-100 */
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.button-copy:active {
|
|
89
|
-
background-color: #E5E7EB; /* active:bg-gray-200 */
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.button-repair {
|
|
93
|
-
background-color: #2563EB; /* bg-blue-600 */
|
|
94
|
-
color: white; /* text-white */
|
|
95
|
-
border-color: transparent; /* border-transparent */
|
|
96
|
-
font-weight: 500; /* font-medium */
|
|
97
|
-
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); /* shadow-xs */
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
.button-repair:hover {
|
|
101
|
-
background-color: #2563EB; /* hover:bg-blue-600 (保持不变) */
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
.button-repair:active {
|
|
105
|
-
background-color: #1E40AF; /* active:bg-blue-700 */
|
|
46
|
+
text-align: center;
|
|
47
|
+
font-size: 14px;
|
|
48
|
+
font-style: normal;
|
|
49
|
+
font-weight: 500;
|
|
50
|
+
line-height: 22px;
|
|
106
51
|
}
|
|
107
52
|
</style>
|
|
108
53
|
|
|
109
54
|
<script>
|
|
110
55
|
// 全局错误对象
|
|
111
56
|
let clientBasePath = '{{.clientBasePath}}';
|
|
112
|
-
let errorData = {
|
|
113
|
-
message: `{{.errorData.message}}`,
|
|
114
|
-
};
|
|
115
|
-
|
|
116
57
|
// 探针配置
|
|
117
58
|
const PROBE_INTERVAL = 2000; // 探测间隔 2 秒
|
|
118
|
-
const PROBE_TIMEOUT =
|
|
59
|
+
const PROBE_TIMEOUT = 3000; // 单次请求超时 5 秒
|
|
119
60
|
let probeTimer = null;
|
|
120
61
|
|
|
121
62
|
// 初始化页面
|
|
122
63
|
function init() {
|
|
123
64
|
// 通知前端,渲染错误页面已准备就绪
|
|
124
65
|
sendPostMessage({
|
|
125
|
-
type: '
|
|
66
|
+
type: 'ServiceStartupFail'
|
|
126
67
|
});
|
|
127
68
|
|
|
128
|
-
// 如果有错误对象,发送 postMessage
|
|
129
|
-
if (errorData) {
|
|
130
|
-
sendPostMessage({
|
|
131
|
-
type: 'RenderError',
|
|
132
|
-
data: errorData,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
69
|
// 启动服务恢复探针
|
|
137
70
|
startServiceProbe();
|
|
138
71
|
}
|
|
@@ -228,52 +161,6 @@
|
|
|
228
161
|
}
|
|
229
162
|
}
|
|
230
163
|
|
|
231
|
-
// 复制错误信息到剪贴板
|
|
232
|
-
async function handleCopy() {
|
|
233
|
-
if (!errorData) {
|
|
234
|
-
console.error('没有错误信息可复制');
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const { message, logs } = errorData;
|
|
239
|
-
let result = '';
|
|
240
|
-
|
|
241
|
-
if (message) {
|
|
242
|
-
result += message + '\n\n';
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (logs) {
|
|
246
|
-
result += '错误日志:\n' + logs;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (!result) {
|
|
250
|
-
result = '未找到错误信息';
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const success = await copyToClipboard(result);
|
|
254
|
-
if (success) {
|
|
255
|
-
console.log('错误信息已复制到剪贴板');
|
|
256
|
-
// 可选:显示复制成功提示
|
|
257
|
-
const btn = document.getElementById('copyBtn');
|
|
258
|
-
const originalText = btn.textContent;
|
|
259
|
-
btn.textContent = '已复制!';
|
|
260
|
-
setTimeout(() => {
|
|
261
|
-
btn.textContent = originalText;
|
|
262
|
-
}, 2000);
|
|
263
|
-
} else {
|
|
264
|
-
console.error('复制失败');
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// 告诉妙搭修复
|
|
269
|
-
function handleRepair() {
|
|
270
|
-
console.log('[Render Error Repair] 告诉妙搭修复错误:', errorData);
|
|
271
|
-
sendPostMessage({
|
|
272
|
-
type: 'RenderErrorRepair',
|
|
273
|
-
data: errorData,
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
|
|
277
164
|
// 发送 postMessage
|
|
278
165
|
function sendPostMessage(message, targetOrigin) {
|
|
279
166
|
const origin = targetOrigin || getPreviewParentOrigin();
|
|
@@ -296,57 +183,6 @@
|
|
|
296
183
|
return 'https://miaoda.feishu-boe.cn';
|
|
297
184
|
}
|
|
298
185
|
|
|
299
|
-
// 复制到剪贴板
|
|
300
|
-
async function copyToClipboard(text) {
|
|
301
|
-
// 优先使用现代的 Clipboard API
|
|
302
|
-
if (navigator.clipboard && window.isSecureContext) {
|
|
303
|
-
try {
|
|
304
|
-
await navigator.clipboard.writeText(text);
|
|
305
|
-
return true;
|
|
306
|
-
} catch (error) {
|
|
307
|
-
// 权限被拒绝或其他错误,降级到 execCommand
|
|
308
|
-
console.warn('Clipboard API 失败,降级到 execCommand:', error);
|
|
309
|
-
return fallbackCopyToClipboard(text);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// 降级方案:使用传统的 execCommand 方法
|
|
314
|
-
return fallbackCopyToClipboard(text);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// 降级复制方案(兼容旧浏览器)
|
|
318
|
-
function fallbackCopyToClipboard(text) {
|
|
319
|
-
try {
|
|
320
|
-
// 创建临时的 textarea 元素
|
|
321
|
-
const textArea = document.createElement('textarea');
|
|
322
|
-
textArea.value = text;
|
|
323
|
-
|
|
324
|
-
// 设置样式,使其不可见
|
|
325
|
-
textArea.style.position = 'fixed';
|
|
326
|
-
textArea.style.left = '-999999px';
|
|
327
|
-
textArea.style.top = '-999999px';
|
|
328
|
-
textArea.setAttribute('readonly', '');
|
|
329
|
-
|
|
330
|
-
// 添加到 DOM
|
|
331
|
-
document.body.appendChild(textArea);
|
|
332
|
-
|
|
333
|
-
// 选中文本
|
|
334
|
-
textArea.focus();
|
|
335
|
-
textArea.select();
|
|
336
|
-
|
|
337
|
-
// 执行复制命令
|
|
338
|
-
const successful = document.execCommand('copy');
|
|
339
|
-
|
|
340
|
-
// 清理:移除临时元素
|
|
341
|
-
document.body.removeChild(textArea);
|
|
342
|
-
|
|
343
|
-
return successful;
|
|
344
|
-
} catch (error) {
|
|
345
|
-
console.error('降级复制方案失败:', error);
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
186
|
// 页面加载完成后初始化
|
|
351
187
|
if (document.readyState === 'loading') {
|
|
352
188
|
document.addEventListener('DOMContentLoaded', init);
|
|
@@ -356,23 +192,16 @@
|
|
|
356
192
|
</script>
|
|
357
193
|
</head>
|
|
358
194
|
<body>
|
|
359
|
-
<div class="container">
|
|
360
|
-
<div class="content">
|
|
195
|
+
<div class="overlay-container">
|
|
196
|
+
<div class="overlay-content">
|
|
361
197
|
<img
|
|
362
|
-
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylcylz_fsph_ryhs/ljhwZthlaukjlkulzlp/feisuda/template/
|
|
363
|
-
alt="
|
|
364
|
-
class="error-image"
|
|
198
|
+
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylcylz_fsph_ryhs/ljhwZthlaukjlkulzlp/feisuda/template/illustration_empty_negative_error.svg"
|
|
199
|
+
alt="Error"
|
|
200
|
+
class="overlay-error-image"
|
|
201
|
+
width="100"
|
|
202
|
+
height="100"
|
|
365
203
|
/>
|
|
366
|
-
<p class="title"
|
|
367
|
-
<p class="description">可复制错误信息,或告诉妙搭进行修复。</p>
|
|
368
|
-
<div class="button-group">
|
|
369
|
-
<button class="button button-copy" id="copyBtn" onclick="handleCopy()">
|
|
370
|
-
复制错误信息
|
|
371
|
-
</button>
|
|
372
|
-
<button class="button button-repair" id="repairBtn" onclick="handleRepair()">
|
|
373
|
-
告诉妙搭修复
|
|
374
|
-
</button>
|
|
375
|
-
</div>
|
|
204
|
+
<p class="overlay-title">服务不可用</p>
|
|
376
205
|
</div>
|
|
377
206
|
</div>
|
|
378
207
|
</body>
|
package/dist/index.cjs
CHANGED
|
@@ -1397,17 +1397,10 @@ function checkForErrors(logs) {
|
|
|
1397
1397
|
return false;
|
|
1398
1398
|
}
|
|
1399
1399
|
__name(checkForErrors, "checkForErrors");
|
|
1400
|
-
function
|
|
1401
|
-
|
|
1402
|
-
if (errorLogs.length > 0) {
|
|
1403
|
-
logsText = errorLogs.join("\n");
|
|
1404
|
-
} else {
|
|
1405
|
-
logsText = "\u672A\u627E\u5230\u76F8\u5173\u9519\u8BEF\u65E5\u5FD7";
|
|
1406
|
-
}
|
|
1407
|
-
return template.replace("{{.errorData.message}}", `\u670D\u52A1\u542F\u52A8\u5F02\u5E38\uFF0C\u8BF7\u6839\u636E\u65E5\u5FD7\u4FEE\u590D\u76F8\u5173\u95EE\u9898
|
|
1408
|
-
${JSON.stringify(logsText)}`).replace("{{.clientBasePath}}", clientBasePath);
|
|
1400
|
+
function injectTemplateData(template, clientBasePath) {
|
|
1401
|
+
return template.replace("{{.clientBasePath}}", clientBasePath);
|
|
1409
1402
|
}
|
|
1410
|
-
__name(
|
|
1403
|
+
__name(injectTemplateData, "injectTemplateData");
|
|
1411
1404
|
function handleDevProxyError(err, req, res, options) {
|
|
1412
1405
|
const { logDir = import_node_path3.default.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target = `http://localhost:${process.env.SERVER_PORT || 3e3}`, clientBasePath = process.env.CLIENT_BASE_PATH || "/" } = options || {};
|
|
1413
1406
|
const clientBasePathWithoutSlash = normalizeBasePath(clientBasePath);
|
|
@@ -1419,7 +1412,7 @@ function handleDevProxyError(err, req, res, options) {
|
|
|
1419
1412
|
(async () => {
|
|
1420
1413
|
try {
|
|
1421
1414
|
const isConnError = isConnectionError(err);
|
|
1422
|
-
const {
|
|
1415
|
+
const { hasCompileError } = await readRecentErrorLogs(logDir, maxErrorLogs, logFileName);
|
|
1423
1416
|
if (isConnError && !hasCompileError) {
|
|
1424
1417
|
console.log("[Proxy Error]: Connection error without compile errors, possibly server restarting...");
|
|
1425
1418
|
try {
|
|
@@ -1443,7 +1436,7 @@ function handleDevProxyError(err, req, res, options) {
|
|
|
1443
1436
|
console.log("[Proxy Error]: Compile error or non-connection error, showing error page");
|
|
1444
1437
|
}
|
|
1445
1438
|
const template = getErrorHtmlTemplate();
|
|
1446
|
-
const html =
|
|
1439
|
+
const html = injectTemplateData(template, clientBasePathWithoutSlash);
|
|
1447
1440
|
res.writeHead(200, {
|
|
1448
1441
|
"Content-Type": "text/html; charset=utf-8",
|
|
1449
1442
|
"Cache-Control": "no-cache, no-store, must-revalidate",
|