dsh-selfupdater 0.4.13 → 0.4.15
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/index.js +26 -2
- package/lib/plugin-update-task.mjs +26 -9
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -296,10 +296,34 @@ export function apply(ctx) {
|
|
|
296
296
|
* 返回数据与 DSH 小节同款三行模板:当前版本 / 最新版本 / 上次检查。
|
|
297
297
|
*/
|
|
298
298
|
const pluginBusy = () => existsSync(pluginLockFile);
|
|
299
|
-
/**
|
|
299
|
+
/**
|
|
300
|
+
* 读插件状态并合并"服务端视角"的忙闲标记。
|
|
301
|
+
*
|
|
302
|
+
* 【为何要归位 done_pending_restart】更新成功后 setState 把
|
|
303
|
+
* done_pending_restart 写进磁盘,但"是否已经重启"只有通过比较
|
|
304
|
+
* 真实落盘版本才能判定:重启后 resolveInstalledVersion 读到的新版本
|
|
305
|
+
* 已经等于 targetVersion(更新已生效),此时再把"请重启生效"的徽章
|
|
306
|
+
* 继续挂在界面上就是误导(用户实测"重启后还一直显示请重启")。
|
|
307
|
+
* 这里在读取时归一化:若状态是 done_pending_restart 且当前真实
|
|
308
|
+
* 运行版本已 >= targetVersion,说明更新已生效,把 state 归位为 idle,
|
|
309
|
+
* 并顺手覆写磁盘,避免每次读都重复判定。
|
|
310
|
+
*/
|
|
300
311
|
const pluginStatusView = () => {
|
|
301
312
|
const status = readPluginStatus(dshStateDir);
|
|
302
|
-
|
|
313
|
+
const state = status.state ?? (pluginBusy() ? 'running' : 'idle');
|
|
314
|
+
// 仅处理"待重启"终态:targetVersion 存在才可能有归位判定。
|
|
315
|
+
if (state === 'done_pending_restart' && typeof status.targetVersion === 'string' && status.targetVersion !== '') {
|
|
316
|
+
const installedNow = selfInstalled();
|
|
317
|
+
// 重启后真实版本已到目标版本 => 更新已生效,徽章不再有意义。
|
|
318
|
+
// 用 isNewer(target, installed) 判"目标是否还新于已装":返回 false
|
|
319
|
+
// 即目标不再领先,说明已装版本已追平/超过目标(更新已生效)。
|
|
320
|
+
if (installedNow !== null && isNewer(status.targetVersion, installedNow) === false) {
|
|
321
|
+
const settled = { ...status, state: 'idle', message: null };
|
|
322
|
+
writePluginStatus(dshStateDir, settled);
|
|
323
|
+
return settled;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return { ...status, state };
|
|
303
327
|
};
|
|
304
328
|
|
|
305
329
|
registerRoute('GET', '/dsh-selfupdater/plugins', (_req, res) => {
|
|
@@ -104,17 +104,31 @@ async function fetchVersionDoc(base, pkg) {
|
|
|
104
104
|
return { version: doc.version, tarball: doc?.dist?.tarball ?? null };
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* 查询最新版本与下载地址(检查更新与更新任务共用,保证两边结论一致)。
|
|
109
|
+
*
|
|
110
|
+
* 0.4.14 修复:旧实现"第一个成功的 registry 就采用"。腾讯镜像 /latest 端点
|
|
111
|
+
* CDN 缓存陈旧时仍返回旧版本文档,导致"检查更新拿到 npmjs 的新版本、
|
|
112
|
+
* 点更新后任务却被镜像的旧版本骗过"而误判"无需更新"(NAS 0.4.12→0.4.13
|
|
113
|
+
* 实测踩坑)。改为并行查询全部 registry、取 semver 最大的结果:
|
|
114
|
+
* 任何一个镜像拿到新版即生效,单镜像陈旧缓存不再能压制判定。
|
|
115
|
+
*
|
|
116
|
+
* @returns {{version: string, tarball: string|null}} 全部失败时抛聚合错误。
|
|
117
|
+
*/
|
|
108
118
|
async function fetchLatestRelease(pkg) {
|
|
119
|
+
const candidates = registryCandidates();
|
|
120
|
+
const results = await Promise.allSettled(candidates.map((base) => fetchVersionDoc(base, pkg)));
|
|
121
|
+
let best = null;
|
|
109
122
|
const errors = [];
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
errors.push(`${
|
|
123
|
+
results.forEach((r, i) => {
|
|
124
|
+
if (r.status === 'fulfilled') {
|
|
125
|
+
if (best === null || isNewer(r.value.version, best.version)) best = r.value;
|
|
126
|
+
} else {
|
|
127
|
+
errors.push(`${candidates[i]}: ${r.reason.message}`);
|
|
115
128
|
}
|
|
116
|
-
}
|
|
117
|
-
throw new Error(errors.join(';'));
|
|
129
|
+
});
|
|
130
|
+
if (best === null) throw new Error(errors.join(';'));
|
|
131
|
+
return best;
|
|
118
132
|
}
|
|
119
133
|
|
|
120
134
|
/** 只取最新版本号(检查更新路由使用)。 */
|
|
@@ -375,7 +389,10 @@ export async function runPluginUpdateTask({ appDir, workspace, logger }) {
|
|
|
375
389
|
const release = await fetchLatestRelease(SELF_NAME);
|
|
376
390
|
if (!isNewer(release.version, installed)) {
|
|
377
391
|
log(`已是最新版本 ${installed},无需更新`);
|
|
378
|
-
|
|
392
|
+
// 状态必须是 idle:无需更新不是"待重启",若错用 done_pending_restart
|
|
393
|
+
// 前端会同时渲染"已是最新"消息与"重启生效"徽章,自相矛盾
|
|
394
|
+
//(NAS 0.4.12→0.4.13 实测踩坑)。消息照常显示,12 秒后自动隐藏。
|
|
395
|
+
setState('idle', `当前已是最新(${installed}),无需更新`);
|
|
379
396
|
return;
|
|
380
397
|
}
|
|
381
398
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-selfupdater",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.15",
|
|
4
4
|
"description": "Self-update plugin for DeepSeek Harness: DSH core upgrades via detached swap script; plugin self-update installs in-place without killing the host and prompts for restart. DSH 主程序与已装插件的一站式在线更新插件。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|