dsh-plugin-update-center 1.0.0 → 1.0.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/README.md +8 -4
- package/client.js +83 -16
- package/lib/engine.js +168 -60
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,10 @@ removeBundle(name)
|
|
|
39
39
|
installBundle(`${name}@${latest}`, { enabled: 原状态, saveExact: true, registry, requestId })
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
-
|
|
42
|
+
- 失败处理按插件进行:失败插件自动装回旧版本(包括 remove 阶段失败,旧版本可能已被删掉),**已成功的插件保持新版本**。
|
|
43
|
+
- `EPERM`(Windows 文件锁)、`EBUSY`、`ECONNRESET` 等瞬态错误会短退避重试 3 次;仍失败才回滚。
|
|
44
|
+
- 失败插件回滚并校验通过后,继续更新其余独立插件;依赖失败插件的项标记为「跳过」,不强行更新。
|
|
45
|
+
- 只有回滚也失败、或 `package.json` / patch 元数据损坏时才停止批次;此时提示恢复快照,不自动刷新。
|
|
43
46
|
- 更新前再次核对版本与 integrity,防止检查后发布变化。
|
|
44
47
|
- 保留插件原来的启用/停用状态。
|
|
45
48
|
- 有任务正在运行或已有更新任务时不会直接更新;可以选择「任务完成后自动更新」进入队列。
|
|
@@ -53,7 +56,8 @@ installBundle(`${name}@${latest}`, { enabled: 原状态, saveExact: true, regist
|
|
|
53
56
|
- 队列等待所有任务空闲,再静默 10 秒,然后 5 秒倒计时开始;倒计时内来新任务会退回等待。
|
|
54
57
|
- 每个插件开始前再查一次任务;运行中来新 conversation,当前插件安装完后暂停,任务结束再恢复。
|
|
55
58
|
- 队列在页面刷新/关闭后保留(Host 内存);Host 重启后不自动续跑。
|
|
56
|
-
-
|
|
59
|
+
- 全部完成后聚合:任意失败项 → 不自动刷新,显示失败状态和「重试失败项」;否则任意 `restart-required` → 只提示重启;否则任意成功插件带 `dsh.client` → 自动刷新页面(3 秒倒计时可取消);都没有 → 不提示。
|
|
60
|
+
- 失败插件保持旧版本,仍是「可更新」状态;可以立即重试,或重启 DSH 后在更新列表里重新检查/更新。
|
|
57
61
|
- 启动层客户端插件更新按「需要重启」处理,避免只刷新后启动层失败。
|
|
58
62
|
|
|
59
63
|
## DSH 本体更新
|
|
@@ -143,8 +147,8 @@ npm test
|
|
|
143
147
|
|
|
144
148
|
- 账号行没有官方 list 插槽,chip 依赖两个稳定锚点:账号按钮的 `data-signed-out` 与 `SettingsRoot` 的 `*_triggerRow` class 后缀。DSH 大版本改这两处 DOM 时 chip 会暂时不显示,需要同步调整 `useAccountRowHost`。
|
|
145
149
|
- 新装插件或更新插件后,Web 页面需要刷新一次才能加载新的 Client 模块;Host 半会由 HMR 重载。
|
|
146
|
-
-
|
|
150
|
+
- 更新是「先卸后装」:失败时按插件回滚,已成功项不回滚;`package.json` 被占用(EPERM)会先重试,重启 DSH 通常能释放锁。
|
|
147
151
|
- 只处理顶层 profile 依赖;Suite 类组合包的子插件需要按组合包本身的更新方式处理。
|
|
148
152
|
- 队列只存在 Host 内存:页面刷新/关闭不影响,Host 重启后队列丢失,不会自动续跑。
|
|
149
153
|
- DSH 本体更新门控依赖桌面 preload 的 `dshDesktop.updates`;浏览器模式无法感知,只能按运行版本重查。
|
|
150
|
-
-
|
|
154
|
+
- 残留清理删除悬空的 bundle 选择与 `cordis.patch.yml` 失效引用;同名数据目录只报告、不自动删除。
|
package/client.js
CHANGED
|
@@ -48,6 +48,15 @@ window.__ModuleLoader__.load({
|
|
|
48
48
|
'status.done': '已更新',
|
|
49
49
|
'status.restart': '待重启',
|
|
50
50
|
'status.failed': '失败',
|
|
51
|
+
'status.failedRolledBack': '失败,已回滚',
|
|
52
|
+
'status.failedUnreconciled': '失败,待处理',
|
|
53
|
+
'status.skipped': '跳过(依赖失败项)',
|
|
54
|
+
'done.partial': '已更新 {updated} 个,{failed} 个失败已回滚。',
|
|
55
|
+
'done.retryHint': '失败项保持旧版本;可立即重试,或重启 DSH 后重新检查。',
|
|
56
|
+
'done.retryFailed': '重试失败项',
|
|
57
|
+
'done.retryBusy': '正在重试…',
|
|
58
|
+
'done.unreconciled': '更新未完成,请勿重启;请先重试失败项或恢复快照。',
|
|
59
|
+
'done.skipped': '{count} 个依赖项已跳过。',
|
|
51
60
|
'done.restart': '新版本已安装,重启 DSH 后生效。',
|
|
52
61
|
'done.refresh': '更新已安装;如界面仍是旧版本,请刷新页面或重启 DSH。',
|
|
53
62
|
'done.snapshot': '更新前快照:{path}',
|
|
@@ -131,6 +140,15 @@ window.__ModuleLoader__.load({
|
|
|
131
140
|
'status.done': 'Updated',
|
|
132
141
|
'status.restart': 'Restart needed',
|
|
133
142
|
'status.failed': 'Failed',
|
|
143
|
+
'status.failedRolledBack': 'Failed, rolled back',
|
|
144
|
+
'status.failedUnreconciled': 'Failed, needs attention',
|
|
145
|
+
'status.skipped': 'Skipped (dependency failed)',
|
|
146
|
+
'done.partial': '{updated} updated, {failed} failed and rolled back.',
|
|
147
|
+
'done.retryHint': 'Failed plugins stay on their old version. Retry now or restart DSH and retry from the update list.',
|
|
148
|
+
'done.retryFailed': 'Retry failed',
|
|
149
|
+
'done.retryBusy': 'Retrying…',
|
|
150
|
+
'done.unreconciled': 'The update did not finish. Do not restart yet; retry the failed plugins or restore the snapshot.',
|
|
151
|
+
'done.skipped': '{count} dependent plugins skipped.',
|
|
134
152
|
'done.restart': 'New versions are installed. Restart DSH to load them.',
|
|
135
153
|
'done.refresh': 'Updates are installed. Refresh the page or restart DSH if the UI still shows the old version.',
|
|
136
154
|
'done.snapshot': 'Pre-update snapshot: {path}',
|
|
@@ -215,6 +233,7 @@ window.__ModuleLoader__.load({
|
|
|
215
233
|
'.dshpu-status{flex:none;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary,#8a94a6);white-space:nowrap;padding-top:1px}',
|
|
216
234
|
'.dshpu-status[data-tone="success"]{color:var(--dsw-alias-state-success-primary,#1a8a4a)}',
|
|
217
235
|
'.dshpu-status[data-tone="error"]{color:var(--dsw-alias-state-error-primary,#d93025)}',
|
|
236
|
+
'.dshpu-status[data-tone="warn"]{color:var(--dsw-alias-state-warn-primary,#b26a00)}',
|
|
218
237
|
'.dshpu-status[data-tone="busy"]{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}',
|
|
219
238
|
'.dshpu-progress{display:flex;flex-direction:column;gap:8px}',
|
|
220
239
|
'.dshpu-progressHead{display:flex;align-items:baseline;justify-content:space-between;gap:12px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#657080)}',
|
|
@@ -503,12 +522,17 @@ window.__ModuleLoader__.load({
|
|
|
503
522
|
)
|
|
504
523
|
}
|
|
505
524
|
|
|
506
|
-
function ProgressView({ job, refresh }) {
|
|
525
|
+
function ProgressView({ job, refresh, retryFailed, retryBusy }) {
|
|
507
526
|
const [, setTick] = useState(0)
|
|
508
527
|
const waiting = job.state === 'queued' || job.state === 'starting'
|
|
509
528
|
const needsReload = refresh?.needsReload === true
|
|
510
529
|
const refreshCancelled = refresh?.cancelled === true
|
|
511
530
|
const refreshSeconds = refresh?.seconds ?? 0
|
|
531
|
+
const results = job.results ?? []
|
|
532
|
+
const successes = results.filter((entry) => entry.ok === true)
|
|
533
|
+
const failures = results.filter((entry) => entry.ok !== true && entry.skipped !== true)
|
|
534
|
+
const skipped = results.filter((entry) => entry.skipped === true)
|
|
535
|
+
const unreconciled = failures.find((entry) => entry.reconciled !== true)
|
|
512
536
|
|
|
513
537
|
useEffect(() => {
|
|
514
538
|
if (job.state !== 'starting') return
|
|
@@ -530,16 +554,25 @@ window.__ModuleLoader__.load({
|
|
|
530
554
|
? t('progress.waiting')
|
|
531
555
|
: t('progress.current', { name: current.name, done: job.done, total: job.total })
|
|
532
556
|
: job.state === 'done'
|
|
533
|
-
?
|
|
557
|
+
? failures.length > 0
|
|
558
|
+
? t('done.partial', { updated: successes.length, failed: failures.length })
|
|
559
|
+
: t('done.summary', { count: job.done })
|
|
534
560
|
: t('done.stopped', { name: current?.name ?? '' })
|
|
535
561
|
const percent = percentOf(job)
|
|
536
|
-
const
|
|
537
|
-
const failureText = failed === undefined
|
|
562
|
+
const failureText = unreconciled === undefined
|
|
538
563
|
? null
|
|
539
|
-
: t('done.stopped', { name:
|
|
540
|
-
const rollbackText =
|
|
564
|
+
: t('done.stopped', { name: unreconciled.name }) + ':' + message(unreconciled.error ?? 'operation-failed')
|
|
565
|
+
const rollbackText = unreconciled?.rollback == null
|
|
541
566
|
? ''
|
|
542
|
-
: ' ' + (
|
|
567
|
+
: ' ' + (unreconciled.rollback.ok === true ? t('done.rollbackOk') : t('done.rollbackFailed'))
|
|
568
|
+
const retryButton = failures.length > 0
|
|
569
|
+
? h('button', {
|
|
570
|
+
type: 'button',
|
|
571
|
+
className: 'dshpu-link',
|
|
572
|
+
disabled: retryBusy === true,
|
|
573
|
+
onClick: () => { void retryFailed?.() },
|
|
574
|
+
}, retryBusy === true ? t('done.retryBusy') : t('done.retryFailed'))
|
|
575
|
+
: null
|
|
543
576
|
|
|
544
577
|
return h(React.Fragment, null,
|
|
545
578
|
waiting
|
|
@@ -567,17 +600,21 @@ window.__ModuleLoader__.load({
|
|
|
567
600
|
: null,
|
|
568
601
|
h('ul', { className: 'dshpu-list' },
|
|
569
602
|
(job.items ?? []).map((item) => {
|
|
570
|
-
const result =
|
|
603
|
+
const result = results.find((entry) => entry.name === item.name)
|
|
571
604
|
const isCurrent = job.state === 'running' && current?.name === item.name
|
|
572
605
|
const status = result !== undefined
|
|
573
606
|
? result.ok === true
|
|
574
607
|
? result.restartRequired === true ? t('status.restart') : t('status.done')
|
|
575
|
-
:
|
|
608
|
+
: result.skipped === true
|
|
609
|
+
? t('status.skipped')
|
|
610
|
+
: result.reconciled === true
|
|
611
|
+
? t('status.failedRolledBack')
|
|
612
|
+
: t('status.failedUnreconciled')
|
|
576
613
|
: isCurrent
|
|
577
614
|
? phaseLabel(current.phase)
|
|
578
615
|
: t('status.waiting')
|
|
579
616
|
const tone = result !== undefined
|
|
580
|
-
? result.ok === true ? 'success' : 'error'
|
|
617
|
+
? result.ok === true ? 'success' : result.skipped === true ? 'idle' : result.reconciled === true ? 'warn' : 'error'
|
|
581
618
|
: isCurrent ? 'busy' : 'idle'
|
|
582
619
|
return h(UpdateRow, {
|
|
583
620
|
key: item.name,
|
|
@@ -593,14 +630,24 @@ window.__ModuleLoader__.load({
|
|
|
593
630
|
),
|
|
594
631
|
job.state === 'failed' && failureText !== null
|
|
595
632
|
? h(StatusNote, { tone: 'error', icon: h(UI.IconWarningOutlineMedium, { size: 16 }) },
|
|
596
|
-
failureText + rollbackText)
|
|
633
|
+
failureText + rollbackText + ' ' + t('done.unreconciled'),
|
|
634
|
+
retryButton)
|
|
597
635
|
: null,
|
|
598
|
-
job.state === 'done'
|
|
636
|
+
job.state === 'done' && failures.length === 0
|
|
599
637
|
? h(StatusNote, { tone: 'success', icon: h(UI.IconCheckCircleOutlineRegular, { size: 16 }) },
|
|
600
638
|
t('done.summary', { count: job.done }))
|
|
601
639
|
: null,
|
|
640
|
+
job.state === 'done' && failures.length > 0
|
|
641
|
+
? h(StatusNote, { tone: 'warn', icon: h(UI.IconWarningOutlineMedium, { size: 16 }) },
|
|
642
|
+
t('done.partial', { updated: successes.length, failed: failures.length }) + ' ' + t('done.retryHint'),
|
|
643
|
+
retryButton)
|
|
644
|
+
: null,
|
|
645
|
+
skipped.length > 0
|
|
646
|
+
? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) },
|
|
647
|
+
t('done.skipped', { count: skipped.length }))
|
|
648
|
+
: null,
|
|
602
649
|
// Restart wins over reload: a full restart reloads the page too.
|
|
603
|
-
job.state === 'done' && job.restartRequired === true
|
|
650
|
+
job.state === 'done' && failures.length === 0 && job.restartRequired === true
|
|
604
651
|
? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) }, t('done.restart'))
|
|
605
652
|
: null,
|
|
606
653
|
job.state === 'done' && refresh?.reloaded === true
|
|
@@ -718,7 +765,7 @@ window.__ModuleLoader__.load({
|
|
|
718
765
|
)
|
|
719
766
|
}
|
|
720
767
|
|
|
721
|
-
function UpdatePanel({ open, onClose, refresh }) {
|
|
768
|
+
function UpdatePanel({ open, onClose, refresh, retryFailed, retryBusy }) {
|
|
722
769
|
const state = useStoreValue()
|
|
723
770
|
const snapshot = state.snapshot
|
|
724
771
|
const job = snapshot?.job ?? null
|
|
@@ -789,7 +836,7 @@ window.__ModuleLoader__.load({
|
|
|
789
836
|
|
|
790
837
|
const loading = snapshot === null || snapshot === undefined || (checking && updates.length === 0)
|
|
791
838
|
let body
|
|
792
|
-
if (showJob) body = h(ProgressView, { job, refresh })
|
|
839
|
+
if (showJob) body = h(ProgressView, { job, refresh, retryFailed, retryBusy })
|
|
793
840
|
else if (loading) body = h(EmptyOrLoading, { state })
|
|
794
841
|
else body = h(ListView, { state, updates, selected, toggle, busy, queueOffer, desktopBlocked, desktopPhase })
|
|
795
842
|
|
|
@@ -1012,6 +1059,26 @@ window.__ModuleLoader__.load({
|
|
|
1012
1059
|
// guard the same completed job would trigger another reload forever.
|
|
1013
1060
|
const alreadyReloaded = reloadPending && hasReloadMarker(job.id)
|
|
1014
1061
|
const needsReload = reloadPending && alreadyReloaded !== true
|
|
1062
|
+
const [retryBusy, setRetryBusy] = useState(false)
|
|
1063
|
+
|
|
1064
|
+
const retryFailed = async () => {
|
|
1065
|
+
if (retryBusy === true || job === null) return
|
|
1066
|
+
const names = (job.results ?? [])
|
|
1067
|
+
.filter((entry) => entry.ok !== true && entry.skipped !== true)
|
|
1068
|
+
.map((entry) => entry.name)
|
|
1069
|
+
if (names.length === 0) return
|
|
1070
|
+
setRetryBusy(true)
|
|
1071
|
+
try {
|
|
1072
|
+
const snapshot = await api({ action: 'check', force: true })
|
|
1073
|
+
publish({ snapshot })
|
|
1074
|
+
await startUpdates(names, true)
|
|
1075
|
+
} catch (error) {
|
|
1076
|
+
publish({ error: errorCodeOf(error) })
|
|
1077
|
+
} finally {
|
|
1078
|
+
setRetryBusy(false)
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1015
1082
|
const [refreshCancelled, setRefreshCancelled] = useState(false)
|
|
1016
1083
|
const [refreshSeconds, setRefreshSeconds] = useState(3)
|
|
1017
1084
|
|
|
@@ -1117,7 +1184,7 @@ window.__ModuleLoader__.load({
|
|
|
1117
1184
|
return h(React.Fragment, null,
|
|
1118
1185
|
h('style', null, STYLE),
|
|
1119
1186
|
chips,
|
|
1120
|
-
h(UpdatePanel, { open, onClose: () => setOpen(false), refresh }),
|
|
1187
|
+
h(UpdatePanel, { open, onClose: () => setOpen(false), refresh, retryFailed, retryBusy }),
|
|
1121
1188
|
h(ResiduePanel, { open: openResidue, onClose: () => setOpenResidue(false) }),
|
|
1122
1189
|
)
|
|
1123
1190
|
}
|
package/lib/engine.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* the npm registry for their latest compatible stable release, and updating the
|
|
6
6
|
* selected plugins through the official DSH plugin manager. The official
|
|
7
7
|
* manager has no `updateBundle` in the current runtime, so one update is
|
|
8
|
-
* `removeBundle` followed by an exact `installBundle`; a failed
|
|
9
|
-
*
|
|
8
|
+
* `removeBundle` followed by an exact `installBundle`; a failed plugin is put
|
|
9
|
+
* back on its previous exact version while already-updated plugins are kept.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { randomUUID } from 'node:crypto'
|
|
@@ -242,11 +242,11 @@ export function createEngine({
|
|
|
242
242
|
return { manifests, dependents }
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
async function verifyOnce(row) {
|
|
245
|
+
async function verifyOnce(row, version = row.latest) {
|
|
246
246
|
const bundles = await manager.listBundles()
|
|
247
247
|
const bundle = Array.isArray(bundles) ? bundles.find((entry) => entry?.name === row.name) : undefined
|
|
248
248
|
if (!bundle || bundle.installed !== true) return { ok: false, reason: 'bundle-missing' }
|
|
249
|
-
if (bundle.version !==
|
|
249
|
+
if (bundle.version !== version) return { ok: false, reason: 'version-mismatch' }
|
|
250
250
|
if (bundle.enabled !== row.enabled) return { ok: false, reason: 'enabled-mismatch' }
|
|
251
251
|
if (bundle.error !== undefined) return { ok: false, reason: bundle.error?.code ?? 'bundle-error' }
|
|
252
252
|
if (row.enabled === true && typeof manager.listPlugins === 'function') {
|
|
@@ -264,7 +264,7 @@ export function createEngine({
|
|
|
264
264
|
const dir = join(profileDir, 'node_modules', row.name)
|
|
265
265
|
const manifest = await readJson(join(dir, 'package.json'))
|
|
266
266
|
if (manifest === null) return { ok: false, reason: 'manifest-unreadable' }
|
|
267
|
-
if (manifest.version !==
|
|
267
|
+
if (manifest.version !== version) return { ok: false, reason: 'manifest-version-mismatch' }
|
|
268
268
|
const entry = entryFileOf(manifest)
|
|
269
269
|
if (entry !== null && !existsSync(join(dir, entry))) return { ok: false, reason: 'entry-missing' }
|
|
270
270
|
const patch = manifest.dsh?.bundle?.patch
|
|
@@ -273,10 +273,10 @@ export function createEngine({
|
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
/** Give the fresh rows a short moment to settle before judging activation. */
|
|
276
|
-
async function verifyInstall(row) {
|
|
276
|
+
async function verifyInstall(row, version = row.latest) {
|
|
277
277
|
let result = { ok: false, reason: 'unknown' }
|
|
278
278
|
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
279
|
-
result = await verifyOnce(row)
|
|
279
|
+
result = await verifyOnce(row, version)
|
|
280
280
|
if (result.ok) return result
|
|
281
281
|
if (attempt < 3) await new Promise((resolve) => setTimeout(resolve, 400))
|
|
282
282
|
}
|
|
@@ -395,18 +395,80 @@ export function createEngine({
|
|
|
395
395
|
return checkPromise
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
-
|
|
398
|
+
const TRANSIENT_CODES = new Set([
|
|
399
|
+
'operation-error',
|
|
400
|
+
'operation-failed',
|
|
401
|
+
'EPERM',
|
|
402
|
+
'EBUSY',
|
|
403
|
+
'ENOTEMPTY',
|
|
404
|
+
'ECONNRESET',
|
|
405
|
+
'ETIMEDOUT',
|
|
406
|
+
'EAI_AGAIN',
|
|
407
|
+
])
|
|
408
|
+
|
|
409
|
+
function isTransientCode(code) {
|
|
410
|
+
return typeof code === 'string' && TRANSIENT_CODES.has(code)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* File locks (EPERM on Windows) and transient registry errors can clear after
|
|
415
|
+
* a short pause. Retrying the exact same manager operation is safe: the
|
|
416
|
+
* manager's package write is atomic, and a failed attempt leaves either the
|
|
417
|
+
* old or the new state, both of which the caller reconciles afterwards.
|
|
418
|
+
*/
|
|
419
|
+
async function retryResult(operation, attempts = 3) {
|
|
420
|
+
let result
|
|
421
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
422
|
+
try {
|
|
423
|
+
result = await operation()
|
|
424
|
+
} catch (error) {
|
|
425
|
+
if (!isTransientCode(errorCode(error)) || attempt === attempts) throw error
|
|
426
|
+
await sleep(400 * attempt)
|
|
427
|
+
continue
|
|
428
|
+
}
|
|
429
|
+
if (!isTransientCode(result?.error?.code) || attempt === attempts) return result
|
|
430
|
+
await sleep(400 * attempt)
|
|
431
|
+
}
|
|
432
|
+
return result
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Put the failed plugin back on its previous exact version without touching
|
|
437
|
+
* any plugin that already updated. A remove-stage failure is the important
|
|
438
|
+
* case: `removeBundle` may have deleted files before the package.json write
|
|
439
|
+
* failed, so the old version is verified and reinstalled when needed.
|
|
440
|
+
*/
|
|
441
|
+
async function reconcileRow(row) {
|
|
442
|
+
const bundles = await manager.listBundles().catch(() => null)
|
|
443
|
+
const bundle = Array.isArray(bundles) ? bundles.find((entry) => entry?.name === row.name) : undefined
|
|
444
|
+
if (
|
|
445
|
+
bundle
|
|
446
|
+
&& bundle.installed === true
|
|
447
|
+
&& bundle.version === row.version
|
|
448
|
+
&& bundle.enabled === row.enabled
|
|
449
|
+
&& bundle.error === undefined
|
|
450
|
+
) {
|
|
451
|
+
const verification = await verifyInstall(row, row.version).catch(() => ({ ok: false, reason: 'verify-failed' }))
|
|
452
|
+
if (verification.ok === true) return { ok: true, action: 'intact', verification }
|
|
453
|
+
}
|
|
399
454
|
try {
|
|
400
|
-
const result = await manager.installBundle(`${row.name}@${row.version}`, {
|
|
455
|
+
const result = await retryResult(() => manager.installBundle(`${row.name}@${row.version}`, {
|
|
401
456
|
enabled: row.enabled,
|
|
402
457
|
saveExact: true,
|
|
403
458
|
...row.registry === null || row.registry === undefined ? {} : { registry: row.registry },
|
|
404
|
-
|
|
405
|
-
|
|
459
|
+
requestId: `rollback:${row.name}`,
|
|
460
|
+
}))
|
|
461
|
+
if (!successful(result)) {
|
|
462
|
+
return { ok: false, action: 'reinstalled', error: result?.error?.code ?? 'rollback-failed' }
|
|
463
|
+
}
|
|
406
464
|
} catch (error) {
|
|
407
465
|
log('warn', 'rollback failed for %s:', row.name, errorCode(error))
|
|
408
|
-
return { ok: false, error: errorCode(error) }
|
|
466
|
+
return { ok: false, action: 'reinstalled', error: errorCode(error) }
|
|
409
467
|
}
|
|
468
|
+
const verification = await verifyInstall(row, row.version).catch(() => ({ ok: false, reason: 'verify-failed' }))
|
|
469
|
+
return verification.ok === true
|
|
470
|
+
? { ok: true, action: 'reinstalled', verification }
|
|
471
|
+
: { ok: false, action: 'reinstalled', error: 'rollback-verification-failed', verification }
|
|
410
472
|
}
|
|
411
473
|
|
|
412
474
|
async function record(job, entry) {
|
|
@@ -420,7 +482,7 @@ export function createEngine({
|
|
|
420
482
|
|
|
421
483
|
async function updateOne(job, row) {
|
|
422
484
|
job.current = { name: row.name, from: row.version, to: row.latest, phase: 'verifying' }
|
|
423
|
-
let
|
|
485
|
+
let failure = null
|
|
424
486
|
try {
|
|
425
487
|
const fresh = await registry.release(row.name, abort.signal, { version: row.latest })
|
|
426
488
|
if (fresh.version !== row.latest || fresh.manifest?.dist?.integrity !== row.integrity) throw coded('release-changed')
|
|
@@ -431,27 +493,20 @@ export function createEngine({
|
|
|
431
493
|
if (previous === null || previous.manifest?.dsh?.bundle === undefined) throw coded('rollback-unavailable')
|
|
432
494
|
}
|
|
433
495
|
job.current = { ...job.current, phase: 'removing' }
|
|
434
|
-
const removal = await manager.removeBundle(row.name)
|
|
435
|
-
if (removal?.error)
|
|
436
|
-
|
|
496
|
+
const removal = await retryResult(() => manager.removeBundle(row.name))
|
|
497
|
+
if (removal?.error) {
|
|
498
|
+
failure = { error: removal.error.code ?? 'remove-failed', application: removal.application ?? null }
|
|
499
|
+
throw coded(failure.error)
|
|
500
|
+
}
|
|
437
501
|
job.current = { ...job.current, phase: 'installing' }
|
|
438
|
-
const result = await manager.installBundle(`${row.name}@${row.latest}`, {
|
|
502
|
+
const result = await retryResult(() => manager.installBundle(`${row.name}@${row.latest}`, {
|
|
439
503
|
enabled: row.enabled,
|
|
440
504
|
saveExact: true,
|
|
441
505
|
...row.registry === null || row.registry === undefined ? {} : { registry: row.registry },
|
|
442
506
|
requestId: `${job.id}:${row.name}`,
|
|
443
|
-
})
|
|
507
|
+
}))
|
|
444
508
|
if (!successful(result)) {
|
|
445
|
-
|
|
446
|
-
await record(job, {
|
|
447
|
-
name: row.name,
|
|
448
|
-
from: row.version,
|
|
449
|
-
to: row.latest,
|
|
450
|
-
ok: false,
|
|
451
|
-
error: result?.error?.code ?? 'install-failed',
|
|
452
|
-
application: result?.application ?? null,
|
|
453
|
-
rollback: rollbackResult,
|
|
454
|
-
})
|
|
509
|
+
failure = { error: result?.error?.code ?? 'install-failed', application: result?.application ?? null }
|
|
455
510
|
throw coded('install-failed')
|
|
456
511
|
}
|
|
457
512
|
// A package can install "successfully" yet leave a broken row, a
|
|
@@ -460,16 +515,7 @@ export function createEngine({
|
|
|
460
515
|
job.current = { ...job.current, phase: 'verifying-install' }
|
|
461
516
|
const verification = await verifyInstall(row)
|
|
462
517
|
if (verification.ok !== true) {
|
|
463
|
-
|
|
464
|
-
await record(job, {
|
|
465
|
-
name: row.name,
|
|
466
|
-
from: row.version,
|
|
467
|
-
to: row.latest,
|
|
468
|
-
ok: false,
|
|
469
|
-
error: 'verification-failed',
|
|
470
|
-
verification,
|
|
471
|
-
rollback: rollbackResult,
|
|
472
|
-
})
|
|
518
|
+
failure = { error: 'verification-failed', verification }
|
|
473
519
|
throw coded('verification-failed')
|
|
474
520
|
}
|
|
475
521
|
const restartRequired = result.application === 'restart-required'
|
|
@@ -487,18 +533,27 @@ export function createEngine({
|
|
|
487
533
|
})
|
|
488
534
|
row.available = false
|
|
489
535
|
} catch (error) {
|
|
490
|
-
if (
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
536
|
+
if (failure === null) failure = { error: errorCode(error), application: null }
|
|
537
|
+
const reconciliation = await reconcileRow(row)
|
|
538
|
+
await record(job, {
|
|
539
|
+
name: row.name,
|
|
540
|
+
from: row.version,
|
|
541
|
+
to: row.latest,
|
|
542
|
+
ok: false,
|
|
543
|
+
error: failure.error,
|
|
544
|
+
application: failure.application ?? null,
|
|
545
|
+
...failure.verification === undefined ? {} : { verification: failure.verification },
|
|
546
|
+
rollback: reconciliation.ok === true
|
|
547
|
+
? {
|
|
548
|
+
ok: true,
|
|
549
|
+
action: reconciliation.action,
|
|
550
|
+
...reconciliation.verification === undefined ? {} : { verification: reconciliation.verification },
|
|
551
|
+
}
|
|
552
|
+
: { ok: false, action: reconciliation.action ?? 'reinstalled', error: reconciliation.error ?? 'rollback-failed' },
|
|
553
|
+
reconciled: reconciliation.ok === true,
|
|
554
|
+
})
|
|
555
|
+
error.reconciliation = reconciliation
|
|
556
|
+
error.updateFailure = failure
|
|
502
557
|
throw error
|
|
503
558
|
}
|
|
504
559
|
}
|
|
@@ -524,6 +579,9 @@ export function createEngine({
|
|
|
524
579
|
failure: null,
|
|
525
580
|
restartRequired: false,
|
|
526
581
|
reloadRequired: false,
|
|
582
|
+
failures: 0,
|
|
583
|
+
skipped: 0,
|
|
584
|
+
unreconciled: false,
|
|
527
585
|
snapshotDir: null,
|
|
528
586
|
waitingFor: null,
|
|
529
587
|
countdownEndsAt: null,
|
|
@@ -555,27 +613,77 @@ export function createEngine({
|
|
|
555
613
|
*/
|
|
556
614
|
function summarize(job) {
|
|
557
615
|
const successes = job.results.filter((entry) => entry.ok === true)
|
|
616
|
+
const failures = job.results.filter((entry) => entry.ok !== true && entry.skipped !== true)
|
|
617
|
+
const skipped = job.results.filter((entry) => entry.skipped === true)
|
|
618
|
+
job.failures = failures.length
|
|
619
|
+
job.skipped = skipped.length
|
|
620
|
+
job.unreconciled = job.unreconciled === true || failures.some((entry) => entry.reconciled !== true)
|
|
558
621
|
const bootClient = successes.some((entry) => entry.bootCritical === true && entry.hasClient === true)
|
|
559
622
|
job.restartRequired = job.restartRequired === true || bootClient
|
|
560
|
-
|
|
623
|
+
// A failed item leaves the profile usable, but an automatic reload would
|
|
624
|
+
// make a half-finished batch look complete. Require an explicit retry or a
|
|
625
|
+
// restart instead of the three-second refresh.
|
|
626
|
+
job.reloadRequired = job.unreconciled !== true
|
|
627
|
+
&& failures.length === 0
|
|
628
|
+
&& job.restartRequired !== true
|
|
629
|
+
&& successes.some((entry) => entry.hasClient === true)
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function orderByDependencies(selected) {
|
|
633
|
+
const remaining = [...selected]
|
|
634
|
+
const ordered = []
|
|
635
|
+
while (remaining.length > 0) {
|
|
636
|
+
let index = remaining.findIndex((row) => !remaining.some((other) => other !== row && Array.isArray(other.dependents) && other.dependents.includes(row.name)))
|
|
637
|
+
if (index < 0) index = 0
|
|
638
|
+
ordered.push(remaining.splice(index, 1)[0])
|
|
639
|
+
}
|
|
640
|
+
return ordered
|
|
561
641
|
}
|
|
562
642
|
|
|
563
643
|
async function runJob(job, selected) {
|
|
644
|
+
const ordered = orderByDependencies(selected)
|
|
645
|
+
const skipped = new Set()
|
|
564
646
|
try {
|
|
565
|
-
for (const row of
|
|
566
|
-
|
|
567
|
-
|
|
647
|
+
for (const row of ordered) {
|
|
648
|
+
if (job.cancelled === true) {
|
|
649
|
+
job.state = 'cancelled'
|
|
650
|
+
break
|
|
651
|
+
}
|
|
652
|
+
if (skipped.has(row.name)) {
|
|
653
|
+
await record(job, {
|
|
654
|
+
name: row.name,
|
|
655
|
+
from: row.version,
|
|
656
|
+
to: row.latest,
|
|
657
|
+
ok: false,
|
|
658
|
+
skipped: true,
|
|
659
|
+
error: 'skipped-dependency',
|
|
660
|
+
rollback: null,
|
|
661
|
+
})
|
|
662
|
+
job.done += 1
|
|
663
|
+
continue
|
|
664
|
+
}
|
|
665
|
+
try {
|
|
666
|
+
await updateOne(job, row)
|
|
667
|
+
job.done += 1
|
|
668
|
+
} catch (error) {
|
|
669
|
+
const reconciliation = error.reconciliation
|
|
670
|
+
if (reconciliation?.ok !== true) {
|
|
671
|
+
job.state = 'failed'
|
|
672
|
+
job.failure = error.updateFailure?.error ?? errorCode(error)
|
|
673
|
+
job.unreconciled = true
|
|
674
|
+
break
|
|
675
|
+
}
|
|
676
|
+
job.done += 1
|
|
677
|
+
for (const dependent of row.dependents ?? []) skipped.add(dependent)
|
|
678
|
+
}
|
|
568
679
|
}
|
|
569
|
-
job.state = 'done'
|
|
570
|
-
} catch (error) {
|
|
571
|
-
job.state = 'failed'
|
|
572
|
-
job.failure = errorCode(error)
|
|
573
|
-
log('warn', 'plugin update stopped:', job.failure)
|
|
680
|
+
if (job.state !== 'failed' && job.state !== 'cancelled') job.state = 'done'
|
|
574
681
|
} finally {
|
|
575
682
|
job.finishedAt = now()
|
|
576
683
|
if (job.current !== null) job.current = { ...job.current, phase: 'finished' }
|
|
577
684
|
summarize(job)
|
|
578
|
-
// The next open re-checks so the list reflects the new versions
|
|
685
|
+
// The next open re-checks so the list reflects the new versions and the
|
|
686
|
+
// failed rows stay available for a retry.
|
|
579
687
|
state.checkedAt = 0
|
|
580
688
|
}
|
|
581
689
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-update-center",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "尊重 DSH 原始风格的插件更新插件:在侧边栏检查、排队更新已安装插件,支持快照回滚、安装后校验、卸载残留清理与离线恢复。 A DSH-native plugin update center for the sidebar with snapshots, rollback, queued updates and leftover cleanup.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|