dsh-go-plugin-sync 0.4.1 → 0.4.2
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 +7 -0
- package/lib/client.js +17 -1
- package/lib/index.js +61 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.2 — 2026-12-04
|
|
4
|
+
|
|
5
|
+
### 修复
|
|
6
|
+
- 任务卡死可处理:任务状态里记录进程号,电脑端与 dsh-go 面板的进行中任务旁新增「取消任务」,会终止任务进程并把状态标记为已取消
|
|
7
|
+
- 单个安装命令超过 600 秒自动终止并记为失败(此前 pnpm 卡住时任务会一直显示运行中),POSIX 上使用 `timeout`,Windows 的 Node 任务器内置同样的超时
|
|
8
|
+
- 待处理列表把可安装项排在前面,不能安装的项在电脑端保持浅色弱化,dsh-go 面板同样按可安装优先排序
|
|
9
|
+
|
|
3
10
|
## 0.4.1 — 2026-12-04
|
|
4
11
|
|
|
5
12
|
### 改进
|
package/lib/client.js
CHANGED
|
@@ -120,6 +120,7 @@ window.__ModuleLoader__.load({
|
|
|
120
120
|
const toggle = (name, checked) => setPicked((previous) => ({ ...previous, [name]: checked }))
|
|
121
121
|
const installedRows = rows.filter((row) => row.status === 'same')
|
|
122
122
|
const pendingRows = rows.filter((row) => row.status !== 'same')
|
|
123
|
+
.slice().sort((a, b) => Number(Boolean(b.action)) - Number(Boolean(a.action)))
|
|
123
124
|
const all = (checked) => {
|
|
124
125
|
const next = {}
|
|
125
126
|
for (const row of pendingRows) next[row.name] = checked
|
|
@@ -193,6 +194,16 @@ window.__ModuleLoader__.load({
|
|
|
193
194
|
load()
|
|
194
195
|
}).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
|
|
195
196
|
}
|
|
197
|
+
const stopRun = () => {
|
|
198
|
+
if (!window.confirm(T('取消当前任务?已完成的项不会回滚。', 'Stop the running task? Finished items are not rolled back.'))) return
|
|
199
|
+
setBusy(true)
|
|
200
|
+
api('action', { action: 'stop' }).then((result) => {
|
|
201
|
+
setBusy(false)
|
|
202
|
+
if (result.error) { note(result.error, 'bad'); return }
|
|
203
|
+
note(T('已取消任务', 'Task cancelled'), 'good')
|
|
204
|
+
load()
|
|
205
|
+
}).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
|
|
206
|
+
}
|
|
196
207
|
const setPath = (path, value) => setConfig((previous) => {
|
|
197
208
|
const next = { ...previous }
|
|
198
209
|
const keys = path.split('.')
|
|
@@ -242,7 +253,12 @@ window.__ModuleLoader__.load({
|
|
|
242
253
|
running
|
|
243
254
|
? T(`${actionLabel(task.kind)}中${current ? `:${current.name}` : '(准备中)'}`, `${actionLabel(task.kind)}${current ? `: ${current.name}` : ' (preparing)'}`)
|
|
244
255
|
: T(`上次${actionLabel(task.kind)}结束`, `Last ${actionLabel(task.kind)} ended`),
|
|
245
|
-
running && h('
|
|
256
|
+
running && h('button', {
|
|
257
|
+
type: 'button',
|
|
258
|
+
style: { ...BUTTON, marginLeft: 'auto', padding: '1px 8px', fontSize: '12px' },
|
|
259
|
+
onClick: stopRun,
|
|
260
|
+
}, T('取消任务', 'Stop')),
|
|
261
|
+
running && h('span', { style: { fontSize: '12px', fontWeight: 400, opacity: 0.7 } }, `${elapsed}s`)),
|
|
246
262
|
running && h('div', { style: { height: '4px', borderRadius: '2px', background: 'rgba(128,128,128,.25)', overflow: 'hidden' } },
|
|
247
263
|
h('div', {
|
|
248
264
|
style: {
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { spawn } from 'node:child_process'
|
|
16
16
|
import { createHash } from 'node:crypto'
|
|
17
17
|
import {
|
|
18
|
-
accessSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync,
|
|
18
|
+
accessSync, appendFileSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync,
|
|
19
19
|
} from 'node:fs'
|
|
20
20
|
import { homedir } from 'node:os'
|
|
21
21
|
import { basename, dirname, extname, join, relative, resolve, sep } from 'node:path'
|
|
@@ -710,7 +710,7 @@ function readTaskStatus() {
|
|
|
710
710
|
try {
|
|
711
711
|
const parts = readFileSync(taskStatusPath(), 'utf8').trim().split(/\s+/)
|
|
712
712
|
const started = Number(parts[1]) || 0
|
|
713
|
-
if (parts[0] === 'running') return { running: true, startedAt: started * 1000, kind: parts[2] || '' }
|
|
713
|
+
if (parts[0] === 'running') return { running: true, startedAt: started * 1000, kind: parts[2] || '', pid: Number(parts[3]) || 0 }
|
|
714
714
|
if (parts[0] === 'done') {
|
|
715
715
|
const failed = Number(parts[2]) || 0
|
|
716
716
|
return { running: false, finishedAt: started * 1000, failed, kind: parts[3] || '', ok: failed === 0 }
|
|
@@ -798,6 +798,34 @@ function taskRunning() {
|
|
|
798
798
|
return Boolean(status?.running && Date.now() - status.startedAt < 15 * 60 * 1000)
|
|
799
799
|
}
|
|
800
800
|
|
|
801
|
+
/** Kill the running task (its status line carries the pid) and mark it cancelled. */
|
|
802
|
+
function stopTask() {
|
|
803
|
+
const status = readTaskStatus()
|
|
804
|
+
if (!status?.running) return { ok: false, error: '没有在运行的任务' }
|
|
805
|
+
const pid = Number(status.pid) || 0
|
|
806
|
+
if (pid > 0) {
|
|
807
|
+
try {
|
|
808
|
+
if (process.platform === 'win32') {
|
|
809
|
+
spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { stdio: 'ignore' })
|
|
810
|
+
} else {
|
|
811
|
+
try { process.kill(-pid, 'SIGTERM') } catch { try { process.kill(pid, 'SIGTERM') } catch {} }
|
|
812
|
+
}
|
|
813
|
+
} catch {}
|
|
814
|
+
}
|
|
815
|
+
const current = readTaskCurrent()
|
|
816
|
+
try {
|
|
817
|
+
let note = `@@ stop ${Math.floor(Date.now() / 1000)}\n`
|
|
818
|
+
if (current) note += `@@ ${current.action} ${current.name} fail\n`
|
|
819
|
+
note += '任务被用户取消\n'
|
|
820
|
+
appendFileSync(taskLogPath(), note)
|
|
821
|
+
} catch {}
|
|
822
|
+
const failed = readTaskResults().filter((result) => !result.ok).length
|
|
823
|
+
try {
|
|
824
|
+
writeFileSync(taskStatusPath(), `done ${Math.floor(Date.now() / 1000)} ${Math.max(1, failed)} ${status.kind || 'apply'}\n`)
|
|
825
|
+
} catch {}
|
|
826
|
+
return { ok: true, pid }
|
|
827
|
+
}
|
|
828
|
+
|
|
801
829
|
/** Start one background task; returns `{ ok }` or an explanation of why it did not start. */
|
|
802
830
|
function startTask(kind, lines, win) {
|
|
803
831
|
if (taskRunning()) return { ok: false, error: '已有任务在运行,等它结束再试' }
|
|
@@ -810,7 +838,9 @@ function startTask(kind, lines, win) {
|
|
|
810
838
|
`STATUS=${shQuote(taskStatusPath())}`,
|
|
811
839
|
`PROFILE=${shQuote(profileName())}`,
|
|
812
840
|
'DSH_BIN="${DSH_BIN:-$(command -v dsh || echo /usr/local/bin/dsh)}"',
|
|
841
|
+
'TIMEOUT=""; if command -v timeout >/dev/null 2>&1; then TIMEOUT="timeout 600"; fi',
|
|
813
842
|
': > "$LOG"',
|
|
843
|
+
`echo "running $(date +%s) ${kind} $$" > "$STATUS"`,
|
|
814
844
|
'failed=0',
|
|
815
845
|
'say() { echo "$@" >> "$LOG"; }',
|
|
816
846
|
...lines,
|
|
@@ -877,10 +907,15 @@ const spec = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'))
|
|
|
877
907
|
const log = fs.openSync(spec.log, 'w')
|
|
878
908
|
const say = (line) => fs.writeSync(log, line + '\\n')
|
|
879
909
|
const status = (line) => fs.writeFileSync(spec.status, line + '\\n')
|
|
880
|
-
status('running ' + Math.floor(Date.now() / 1000) + ' ' + spec.kind)
|
|
910
|
+
status('running ' + Math.floor(Date.now() / 1000) + ' ' + spec.kind + ' ' + process.pid)
|
|
881
911
|
function run(command, args) {
|
|
882
912
|
return new Promise((resolve) => {
|
|
883
913
|
let child
|
|
914
|
+
let timer = null
|
|
915
|
+
const finish = (code) => {
|
|
916
|
+
if (timer) { clearTimeout(timer); timer = null }
|
|
917
|
+
resolve(code)
|
|
918
|
+
}
|
|
884
919
|
try {
|
|
885
920
|
child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], env: process.env })
|
|
886
921
|
} catch (error) {
|
|
@@ -888,10 +923,15 @@ function run(command, args) {
|
|
|
888
923
|
resolve(1)
|
|
889
924
|
return
|
|
890
925
|
}
|
|
926
|
+
timer = setTimeout(() => {
|
|
927
|
+
say('超过 600 秒没有结束,终止:' + command + ' ' + args.join(' '))
|
|
928
|
+
try { child.kill() } catch {}
|
|
929
|
+
finish(1)
|
|
930
|
+
}, 600000)
|
|
891
931
|
child.stdout.on('data', (chunk) => fs.writeSync(log, chunk))
|
|
892
932
|
child.stderr.on('data', (chunk) => fs.writeSync(log, chunk))
|
|
893
|
-
child.on('error', (error) => { say(String(error && error.message ? error.message : error));
|
|
894
|
-
child.on('exit', (code) =>
|
|
933
|
+
child.on('error', (error) => { say(String(error && error.message ? error.message : error)); finish(1) })
|
|
934
|
+
child.on('exit', (code) => finish(code === 0 ? 0 : 1))
|
|
895
935
|
})
|
|
896
936
|
}
|
|
897
937
|
;(async () => {
|
|
@@ -916,7 +956,7 @@ function run(command, args) {
|
|
|
916
956
|
}
|
|
917
957
|
|
|
918
958
|
function localAddCommand(dir) {
|
|
919
|
-
return
|
|
959
|
+
return `\${TIMEOUT} "$DSH_BIN" plugin --profile "$PROFILE" add ${shQuote(dir)}`
|
|
920
960
|
}
|
|
921
961
|
|
|
922
962
|
/** The plugin manager reports a failed operation as `error` + `application:"failed"`, not `ok:false`. */
|
|
@@ -1435,7 +1475,7 @@ function buildView(scope, caps, ctx) {
|
|
|
1435
1475
|
en ? `elapsed ${elapsed}` : `已用 ${elapsed}`,
|
|
1436
1476
|
].filter(Boolean).join(' · ')
|
|
1437
1477
|
children.push({ type: 'callout', tone: stale ? 'warn' : 'info', text: stale
|
|
1438
|
-
? (en ? `${taskLabel(task.kind, true)} running too long (${progressText}); check the log.` : `${taskLabel(task.kind, false)}运行太久(${progressText}
|
|
1478
|
+
? (en ? `${taskLabel(task.kind, true)} running too long (${progressText}); check the log, or tap Stop task.` : `${taskLabel(task.kind, false)}运行太久(${progressText}),看下日志,或点「取消任务」。`)
|
|
1439
1479
|
: (en ? `${taskLabel(task.kind, true)} running: ${progressText}` : `${taskLabel(task.kind, false)}中:${progressText}`) })
|
|
1440
1480
|
} else if (task && task.ok === false) {
|
|
1441
1481
|
children.push({ type: 'callout', tone: 'bad', text: en
|
|
@@ -1493,7 +1533,8 @@ function buildView(scope, caps, ctx) {
|
|
|
1493
1533
|
|
|
1494
1534
|
const pending = rows.filter((row) => row.status !== 'same')
|
|
1495
1535
|
const installed = rows.filter((row) => row.status === 'same')
|
|
1496
|
-
const visible = state.showAll ? rows : pending
|
|
1536
|
+
const visible = (state.showAll ? rows : pending).slice()
|
|
1537
|
+
.sort((a, b) => Number(Boolean(b.action)) - Number(Boolean(a.action)))
|
|
1497
1538
|
if (rows.length === 0) {
|
|
1498
1539
|
children.push({ type: 'callout', tone: 'good', text: en ? 'The two hosts match.' : '两边完全一致。' })
|
|
1499
1540
|
} else {
|
|
@@ -1527,6 +1568,7 @@ function buildView(scope, caps, ctx) {
|
|
|
1527
1568
|
}
|
|
1528
1569
|
|
|
1529
1570
|
const primary = [
|
|
1571
|
+
...(task?.running ? [{ label: en ? 'Stop task' : '取消任务', action: 'stop-task' }] : []),
|
|
1530
1572
|
{ label: en ? 'Copy code' : '复制同步码', action: 'copy-code' },
|
|
1531
1573
|
{ label: en ? 'Select all' : '全选', action: 'select-all' },
|
|
1532
1574
|
{ label: en ? 'Clear' : '清空', action: 'clear' },
|
|
@@ -1823,6 +1865,12 @@ export function apply(ctx) {
|
|
|
1823
1865
|
actions: {
|
|
1824
1866
|
'copy-code': copyCode,
|
|
1825
1867
|
|
|
1868
|
+
'stop-task'() {
|
|
1869
|
+
const result = stopTask()
|
|
1870
|
+
if (!result.ok) return { toast: result.error || '没有在运行的任务' }
|
|
1871
|
+
return [{ toast: '已取消任务' }, { refresh: true }]
|
|
1872
|
+
},
|
|
1873
|
+
|
|
1826
1874
|
'import-code'(scope, event) {
|
|
1827
1875
|
const text = codeFromSubmit(event?.value)
|
|
1828
1876
|
if (text === '') return { toast: '先粘贴同步码' }
|
|
@@ -2033,6 +2081,11 @@ export function apply(ctx) {
|
|
|
2033
2081
|
webJson(res, 200, { ok: true })
|
|
2034
2082
|
return
|
|
2035
2083
|
}
|
|
2084
|
+
if (action === 'stop') {
|
|
2085
|
+
const result = stopTask()
|
|
2086
|
+
webJson(res, 200, result.ok ? { ok: true } : { error: result.error || '没有在运行的任务' })
|
|
2087
|
+
return
|
|
2088
|
+
}
|
|
2036
2089
|
if (action === 'relay-pull') {
|
|
2037
2090
|
if (!cfg.relay.repo) { webJson(res, 200, { error: '先配置中转仓' }); return }
|
|
2038
2091
|
state.relayLoadedAt = 0
|