dsh-plugin-yanyan-toolkit 1.2.0 → 1.4.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/CHANGELOG.md +67 -0
- package/README.en.md +82 -0
- package/README.i18n.yaml +7 -6
- package/README.md +53 -37
- package/README.zh.md +24 -8
- package/cordis.patch.yml +10 -2
- package/icon.svg +5 -8
- package/lib/client.js +179 -4
- package/lib/index.js +120 -15
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +5 -2
- package/packages/dsh-plugin-yanyan-icon/README.md +33 -0
- package/packages/dsh-plugin-yanyan-icon/README.zh.md +33 -0
- package/packages/dsh-plugin-yanyan-icon/cordis.patch.yml +7 -0
- package/packages/dsh-plugin-yanyan-icon/icon.svg +7 -0
- package/packages/dsh-plugin-yanyan-icon/lib/client.js +388 -0
- package/packages/dsh-plugin-yanyan-icon/lib/index.js +239 -0
- package/packages/dsh-plugin-yanyan-icon/locale/en.json +6 -0
- package/packages/dsh-plugin-yanyan-icon/locale/zh.json +6 -0
- package/packages/dsh-plugin-yanyan-icon/package.json +32 -0
- package/packages/dsh-plugin-yanyan-subagent/README.md +3 -2
- package/packages/dsh-plugin-yanyan-subagent/README.zh.md +3 -2
- package/packages/dsh-plugin-yanyan-subagent/lib/client.js +157 -33
- package/packages/dsh-plugin-yanyan-subagent/lib/index.js +45 -4
- package/packages/dsh-plugin-yanyan-subagent/lib/legacy-hidden-ids.json +29 -9
- package/packages/dsh-plugin-yanyan-subagent/lib/log-rewrite.js +29 -0
- package/packages/dsh-plugin-yanyan-subagent/locale/en.json +1 -1
- package/packages/dsh-plugin-yanyan-subagent/locale/zh.json +1 -1
- package/packages/dsh-plugin-yanyan-subagent/package.json +2 -2
- package/packages/dsh-plugin-yanyan-update/README.md +1 -0
- package/packages/dsh-plugin-yanyan-update/README.zh.md +1 -0
- package/packages/dsh-plugin-yanyan-update/lib/index.js +86 -2
- package/packages/dsh-plugin-yanyan-update/package.json +1 -1
|
@@ -16,7 +16,7 @@ import path from 'node:path';
|
|
|
16
16
|
import { execFileSync } from 'node:child_process';
|
|
17
17
|
|
|
18
18
|
export const name = 'dsh-plugin-yanyan-update';
|
|
19
|
-
export const VERSION = '1.
|
|
19
|
+
export const VERSION = '1.2.1';
|
|
20
20
|
export const inject = ['webServer', 'connection'];
|
|
21
21
|
export const ROUTE_BASE = '/__dsh-plugin-yanyan-update';
|
|
22
22
|
|
|
@@ -548,6 +548,77 @@ async function updateLocal(id, cls, profileDir, cfg) {
|
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
550
|
|
|
551
|
+
// ───────────── 更新后启用态恢复(修复「更新完默认关闭」) ─────────────
|
|
552
|
+
// 根因(已查证官方实现):updateBundle 在 HMR 下先 removeBundle 再 installBundle。
|
|
553
|
+
// removeBundle 内部 selectBundle(name, false),installBundle 仅把 bundle 选择态放回
|
|
554
|
+
// (options?.enabled !== false 时 selectBundle(name, true)),并不保证「已安装插件」页
|
|
555
|
+
// 开关所依据的 entry 级 enablement:cordis.patch.yml 的 loader 行 override(见
|
|
556
|
+
// dsh-web-0.4.16/packages/dsh-plugin-manager/src/host/state.ts:145)。实测面板显示
|
|
557
|
+
// 「更新完成,已即时生效。」后,插件行开关落为关闭,插件不会自动启动。
|
|
558
|
+
// 修复借鉴官方 gateway.ts:1631 restoreBundleSelection:更新前容错捕获启用态,
|
|
559
|
+
// 更新成功后显式放回;所有方法可选、异常吞掉、绝不改动 ok/updated/message。
|
|
560
|
+
|
|
561
|
+
// 容错读取更新前的启用态。listPlugins 条目含 entryId / moduleName / enabled
|
|
562
|
+
// (entry 级,即开关本体,且 entryId 是 setPluginEnabled 要求的身份);listBundles
|
|
563
|
+
// 条目含 name / enabled(bundle 选择态,官方 updateBundle 读取的同一来源)。
|
|
564
|
+
// 读不到或抛错一律按「开启」处理:可更新插件绝大多数正在使用,且官方 restoreBundleSelection
|
|
565
|
+
// 也是无条件 setBundleEnabled(name, true)。只有明确读到 enabled === false(用户主动关闭)
|
|
566
|
+
// 才标记 wasDisabled,避免把用户故意关掉的插件强行打开。
|
|
567
|
+
export async function readEnablement(manager, id) {
|
|
568
|
+
const out = { wasDisabled: false, entryId: null };
|
|
569
|
+
const asList = (res) => {
|
|
570
|
+
if (Array.isArray(res)) return res;
|
|
571
|
+
if (res && typeof res === 'object' && Array.isArray(res.value)) return res.value;
|
|
572
|
+
return [];
|
|
573
|
+
};
|
|
574
|
+
const matches = (row) => row && typeof row === 'object' &&
|
|
575
|
+
(row.entryId === id || row.moduleName === id || row.name === id);
|
|
576
|
+
try {
|
|
577
|
+
if (manager && typeof manager.listPlugins === 'function') {
|
|
578
|
+
const row = asList(await manager.listPlugins()).find(matches);
|
|
579
|
+
if (row) {
|
|
580
|
+
if (typeof row.entryId === 'string' && row.entryId) out.entryId = row.entryId;
|
|
581
|
+
out.wasDisabled = row.enabled === false;
|
|
582
|
+
return out;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
} catch (error) {
|
|
586
|
+
// 读不到即按开启处理
|
|
587
|
+
}
|
|
588
|
+
try {
|
|
589
|
+
if (manager && typeof manager.listBundles === 'function') {
|
|
590
|
+
const row = asList(await manager.listBundles()).find((b) => b && b.name === id);
|
|
591
|
+
if (row) out.wasDisabled = row.enabled === false;
|
|
592
|
+
}
|
|
593
|
+
} catch (error) {
|
|
594
|
+
// 读不到即按开启处理
|
|
595
|
+
}
|
|
596
|
+
return out;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// 更新成功后 best-effort 恢复启用态。优先 setPluginEnabled(entry 级,直接持久化
|
|
600
|
+
// patch 行 override,对应「已安装插件」页开关);该方法缺失或抛错时回退官方
|
|
601
|
+
// restoreBundleSelection 同款 setBundleEnabled(bundle 选择态)。二者均幂等置 true。
|
|
602
|
+
export async function restoreEnablement(manager, id, enablement) {
|
|
603
|
+
if (!manager || (enablement && enablement.wasDisabled)) return; // 尊重用户主动关闭
|
|
604
|
+
const target = (enablement && enablement.entryId) || id;
|
|
605
|
+
try {
|
|
606
|
+
if (typeof manager.setPluginEnabled === 'function') {
|
|
607
|
+
await manager.setPluginEnabled(target, true);
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
} catch (error) {
|
|
611
|
+
// setPluginEnabled 要求 entryId;传包名可能抛 unknown-plugin,回退 bundle 级
|
|
612
|
+
}
|
|
613
|
+
try {
|
|
614
|
+
if (typeof manager.setBundleEnabled === 'function') {
|
|
615
|
+
await manager.setBundleEnabled(id, true);
|
|
616
|
+
}
|
|
617
|
+
} catch (error) {
|
|
618
|
+
// best-effort,绝不改变更新结论
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
551
622
|
// io 为可选注入点,仅供单测替换 IO(network / fs / manager 来源),生产调用省略。
|
|
552
623
|
// 单测据此完全不触碰真实 pluginManager、npm registry 与 profile 文件。
|
|
553
624
|
export async function updateRegistry(ctx, id, cfg, deps, io) {
|
|
@@ -595,6 +666,9 @@ export async function updateRegistry(ctx, id, cfg, deps, io) {
|
|
|
595
666
|
const targetSpec = id + '@' + latest;
|
|
596
667
|
const requestId = 'yanyan-update-' + id + '-' + Date.now() + '-' +
|
|
597
668
|
Math.random().toString(36).slice(2, 8);
|
|
669
|
+
// 更新前先捕获启用态:官方 updateBundle 只恢复 bundle 选择态,entry 级开关
|
|
670
|
+
// (「已安装插件」页开关本体)在 remove→install 后会丢失。readEnablement 全容错。
|
|
671
|
+
const enablement = await readEnablement(manager, id);
|
|
598
672
|
|
|
599
673
|
// 首选:直接复用官方 updateBundle。HMR 下安装失败/取消时官方自动把移除的版本
|
|
600
674
|
// 重新装回(写入 restore 字段);非 HMR 直接覆盖安装,根本不先卸载。
|
|
@@ -613,7 +687,13 @@ export async function updateRegistry(ctx, id, cfg, deps, io) {
|
|
|
613
687
|
detail: String((error && error.message) || error),
|
|
614
688
|
});
|
|
615
689
|
}
|
|
616
|
-
|
|
690
|
+
const parsed = parseUpdateResult(outcome);
|
|
691
|
+
// 更新成功后把启用态放回:修复官方 updateBundle 只恢复 bundle 选择态、
|
|
692
|
+
// 导致「已安装插件」页开关变灰、插件不自动启动的问题。失败时不触碰启用态。
|
|
693
|
+
if (parsed.ok && parsed.updated) {
|
|
694
|
+
await restoreEnablement(manager, id, enablement);
|
|
695
|
+
}
|
|
696
|
+
return Object.assign({}, base, parsed, {
|
|
617
697
|
id,
|
|
618
698
|
spec: targetSpec,
|
|
619
699
|
});
|
|
@@ -669,6 +749,8 @@ export async function updateRegistry(ctx, id, cfg, deps, io) {
|
|
|
669
749
|
(first.error.diagnostic || first.error.code)) || '覆盖安装被拒绝'),
|
|
670
750
|
});
|
|
671
751
|
}
|
|
752
|
+
// 覆盖安装成功也放回启用态(与首选分支一致,幂等、best-effort)。
|
|
753
|
+
await restoreEnablement(manager, id, enablement);
|
|
672
754
|
return { ok: true, updated: true, restartRequired: true, id, spec: targetSpec,
|
|
673
755
|
message: '更新完成,重启 DSH 服务后生效。' };
|
|
674
756
|
}
|
|
@@ -683,6 +765,8 @@ export async function updateRegistry(ctx, id, cfg, deps, io) {
|
|
|
683
765
|
const restored = await ensureRestore();
|
|
684
766
|
return failResult(new Error('installBundle 被拒绝:' + JSON.stringify(r2)), restored);
|
|
685
767
|
}
|
|
768
|
+
// 两阶段 remove→install 成功同样放回启用态。
|
|
769
|
+
await restoreEnablement(manager, id, enablement);
|
|
686
770
|
return { ok: true, updated: true, restartRequired: true, id, spec: targetSpec,
|
|
687
771
|
message: '更新完成,重启 DSH 服务后生效。' };
|
|
688
772
|
} catch (error) {
|