dsh-m 0.2.7 → 0.2.8
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/lib/core/dsh-cli.js +41 -1
- package/package.json +1 -1
package/lib/core/dsh-cli.js
CHANGED
|
@@ -287,6 +287,46 @@ export function rewritePnpmError(err) {
|
|
|
287
287
|
}
|
|
288
288
|
return err instanceof Error ? err : new Error(text);
|
|
289
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* 失败摘要:命令失败时从完整输出里提取可诊断的行,而不是盲取末尾。
|
|
292
|
+
* 2026-09-05 实证(dsh-better-sidebar 安装失败):pnpm ndjson 错误行 ~1.2KB,
|
|
293
|
+
* 错误码/信息/hint 在行首,尾截 800 只剩纯栈帧——`ERR_PNPM_IGNORED_BUILDS`
|
|
294
|
+
* 与 `node-pty` 关键字全部丢失,isPrepareBlocked 匹配不到,
|
|
295
|
+
* dangerouslyAllowAllBuilds 自愈重试从未触发,用户只看到一屏栈。
|
|
296
|
+
* 优先级:ndjson 错误行(code — message — hint)→ 含 ERR_ 码的行 + 尾部 → 纯尾部。
|
|
297
|
+
*/
|
|
298
|
+
export function errorDigest(out, maxChars = 800) {
|
|
299
|
+
const text = out.trim();
|
|
300
|
+
if (text === '')
|
|
301
|
+
return '';
|
|
302
|
+
if (text.length <= maxChars)
|
|
303
|
+
return text;
|
|
304
|
+
const lines = text.split('\n');
|
|
305
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
306
|
+
const line = lines[i].trim();
|
|
307
|
+
if (!line.startsWith('{') || !line.includes('"level":"error"'))
|
|
308
|
+
continue;
|
|
309
|
+
try {
|
|
310
|
+
const doc = JSON.parse(line);
|
|
311
|
+
const code = typeof doc.code === 'string' && doc.code !== '' ? doc.code
|
|
312
|
+
: typeof doc.err?.code === 'string' ? doc.err.code : null;
|
|
313
|
+
const message = typeof doc.err?.message === 'string' ? doc.err.message : null;
|
|
314
|
+
const hint = typeof doc.hint === 'string' ? doc.hint : null;
|
|
315
|
+
const parts = [code, message, hint].filter((p) => p !== null && p !== '');
|
|
316
|
+
if (parts.length > 0)
|
|
317
|
+
return parts.join(' — ');
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
/* 非 JSON 行,继续向前找 */
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const errCodeLines = lines.filter((l) => /ERR_[A-Z0-9_]+/.test(l)).slice(-5);
|
|
324
|
+
if (errCodeLines.length > 0) {
|
|
325
|
+
const digest = [...errCodeLines, text.slice(-maxChars)].join('\n').slice(-maxChars * 2);
|
|
326
|
+
return digest;
|
|
327
|
+
}
|
|
328
|
+
return text.slice(-maxChars);
|
|
329
|
+
}
|
|
290
330
|
export async function runCommand(command, args, options) {
|
|
291
331
|
return new Promise((resolvePromise, reject) => {
|
|
292
332
|
const child = spawn(command, args, {
|
|
@@ -350,7 +390,7 @@ export async function runCommand(command, args, options) {
|
|
|
350
390
|
if (code === 0)
|
|
351
391
|
finish();
|
|
352
392
|
else
|
|
353
|
-
finish(new Error(`命令失败 (exit ${code}): ${out
|
|
393
|
+
finish(new Error(`命令失败 (exit ${code}): ${errorDigest(out) || 'no output'}`));
|
|
354
394
|
});
|
|
355
395
|
});
|
|
356
396
|
}
|