@xi-ix/dsh-multi-sync 0.1.0 → 0.1.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/client.js +14 -2
- package/index.js +69 -11
- package/package.json +2 -1
package/client.js
CHANGED
|
@@ -42,6 +42,9 @@ window.__ModuleLoader__.load({
|
|
|
42
42
|
selectAll: '全选可安装',
|
|
43
43
|
empty: '还没有扫描结果。',
|
|
44
44
|
noRows: '清单里没有可安装的 npm 插件。',
|
|
45
|
+
nothingSelected: '没有选中任何插件(「已装」的行不会重复安装)。',
|
|
46
|
+
cliMissing: '找不到 dsh 命令行。试过:',
|
|
47
|
+
manualHint: '可以在终端里手动执行:',
|
|
45
48
|
from: '清单来源',
|
|
46
49
|
generatedAt: '生成时间',
|
|
47
50
|
mismatch: '清单来自另一台机器,DSH 版本不同,安装前请留意。',
|
|
@@ -94,6 +97,9 @@ window.__ModuleLoader__.load({
|
|
|
94
97
|
selectAll: 'Select installable',
|
|
95
98
|
empty: 'Nothing scanned yet.',
|
|
96
99
|
noRows: 'The list has no installable npm plugin.',
|
|
100
|
+
nothingSelected: 'Nothing is selected ("installed" rows are not reinstalled).',
|
|
101
|
+
cliMissing: 'Cannot find the dsh CLI. Tried:',
|
|
102
|
+
manualHint: 'You can run this in a terminal instead:',
|
|
97
103
|
from: 'List from',
|
|
98
104
|
generatedAt: 'Generated',
|
|
99
105
|
mismatch: 'This list came from a machine running a different DSH version — check before installing.',
|
|
@@ -303,7 +309,10 @@ window.__ModuleLoader__.load({
|
|
|
303
309
|
|
|
304
310
|
const install = useCallback(async () => {
|
|
305
311
|
const items = (rows || []).filter((row) => selected[row.name]).map((row) => ({ name: row.name, version: row.version }))
|
|
306
|
-
if (items.length === 0)
|
|
312
|
+
if (items.length === 0) {
|
|
313
|
+
setMessage({ kind: 'err', text: L.nothingSelected })
|
|
314
|
+
return
|
|
315
|
+
}
|
|
307
316
|
setBusy('install')
|
|
308
317
|
setMessage(null)
|
|
309
318
|
try {
|
|
@@ -315,7 +324,10 @@ window.__ModuleLoader__.load({
|
|
|
315
324
|
const state = await api('/scan').catch(() => null)
|
|
316
325
|
if (state) setList(state.list)
|
|
317
326
|
} else {
|
|
318
|
-
|
|
327
|
+
const detail = body.result.stderr || body.result.message || 'install failed'
|
|
328
|
+
const tried = Array.isArray(body.result.tried) && body.result.tried.length > 0 ? `\n\n${L.cliMissing}\n${body.result.tried.join('\n')}` : ''
|
|
329
|
+
const manual = body.result.manual ? `\n\n${L.manualHint}\n${body.result.manual}` : ''
|
|
330
|
+
setMessage({ kind: 'err', text: detail + tried + manual })
|
|
319
331
|
}
|
|
320
332
|
} catch (error) {
|
|
321
333
|
setMessage({ kind: 'err', text: String(error.message || error) })
|
package/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import { existsSync, readdirSync } from 'node:fs'
|
|
|
18
18
|
import { readFile, writeFile } from 'node:fs/promises'
|
|
19
19
|
import { execFile } from 'node:child_process'
|
|
20
20
|
import { homedir, platform } from 'node:os'
|
|
21
|
-
import { basename, join } from 'node:path'
|
|
21
|
+
import { basename, dirname, join } from 'node:path'
|
|
22
22
|
|
|
23
23
|
export const name = '@xi-ix/dsh-multi-sync'
|
|
24
24
|
export const inject = ['webServer']
|
|
@@ -363,23 +363,73 @@ function runOnce(command, argv, options) {
|
|
|
363
363
|
/**
|
|
364
364
|
* Run the DSH CLI, preferring the installation this process belongs to.
|
|
365
365
|
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
366
|
+
* A profile-launched host does not reliably inherit DSH_INSTALL_DIR, and the
|
|
367
|
+
* packaged CLI lives inside app.asar, which only the Electron runtime can read.
|
|
368
|
+
* The candidates therefore walk from the running executable outwards: the packaged
|
|
369
|
+
* asar CLI through this executable with ELECTRON_RUN_AS_NODE, the runtime shim, then
|
|
370
|
+
* whatever `dsh` the PATH offers. Each candidate is tried until one is not simply
|
|
371
|
+
* missing, so a machine without the CLI reports every location it looked at.
|
|
369
372
|
*/
|
|
370
|
-
|
|
373
|
+
/**
|
|
374
|
+
* The app's `Resources` directory.
|
|
375
|
+
*
|
|
376
|
+
* `process.resourcesPath` exists only in an Electron process; the host this plugin
|
|
377
|
+
* runs in may be a plain Node child of the desktop shell. Deriving it from the
|
|
378
|
+
* executable covers that: macOS keeps it at `Contents/Resources` beside
|
|
379
|
+
* `Contents/MacOS`, Windows at `resources` beside the executable.
|
|
380
|
+
*/
|
|
381
|
+
function resourcesRoot() {
|
|
382
|
+
if (process.resourcesPath) return process.resourcesPath
|
|
383
|
+
const executable = process.execPath
|
|
384
|
+
if (typeof executable !== 'string' || executable === '') return undefined
|
|
385
|
+
const candidates =
|
|
386
|
+
platform() === 'darwin'
|
|
387
|
+
? [join(dirname(executable), '..', 'Resources')]
|
|
388
|
+
: [join(dirname(executable), 'resources'), join(dirname(executable), '..', 'resources')]
|
|
389
|
+
for (const candidate of candidates) {
|
|
390
|
+
if (existsSync(candidate)) return candidate
|
|
391
|
+
}
|
|
392
|
+
return undefined
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function cliAttempts(args) {
|
|
396
|
+
const attempts = []
|
|
371
397
|
const nodeExecutable = process.env.DSH_NODE_EXECUTABLE
|
|
372
398
|
const installDir = process.env.DSH_INSTALL_DIR
|
|
373
|
-
const
|
|
399
|
+
const asNode = { env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' } }
|
|
374
400
|
|
|
375
401
|
if (nodeExecutable && installDir) {
|
|
376
402
|
attempts.push({
|
|
377
403
|
command: nodeExecutable,
|
|
378
404
|
argv: [join(installDir, 'lib', 'bin.js'), ...args],
|
|
379
|
-
options:
|
|
380
|
-
label: `${nodeExecutable} lib
|
|
405
|
+
options: asNode,
|
|
406
|
+
label: `${nodeExecutable} ${join(installDir, 'lib', 'bin.js')} ${args.join(' ')}`,
|
|
381
407
|
})
|
|
382
408
|
}
|
|
409
|
+
|
|
410
|
+
const resources = resourcesRoot()
|
|
411
|
+
if (resources) {
|
|
412
|
+
for (const relative of [
|
|
413
|
+
join('app.asar', 'dsh', 'node_modules', '@deepseek-ai', 'dsh', 'lib', 'bin.js'),
|
|
414
|
+
join('app', 'dsh', 'node_modules', '@deepseek-ai', 'dsh', 'lib', 'bin.js'),
|
|
415
|
+
join('app.asar.unpacked', 'dsh', 'node_modules', '@deepseek-ai', 'dsh', 'lib', 'bin.js'),
|
|
416
|
+
]) {
|
|
417
|
+
const entry = join(resources, relative)
|
|
418
|
+
if (!existsSync(entry)) continue
|
|
419
|
+
attempts.push({
|
|
420
|
+
command: process.execPath,
|
|
421
|
+
argv: [entry, ...args],
|
|
422
|
+
options: asNode,
|
|
423
|
+
label: `${process.execPath} ${entry} ${args.join(' ')}`,
|
|
424
|
+
})
|
|
425
|
+
}
|
|
426
|
+
for (const relative of [join('runtime', 'cli', 'bin'), join('cli', 'bin')]) {
|
|
427
|
+
const shim = join(resources, relative, platform() === 'win32' ? 'dsh.cmd' : 'dsh')
|
|
428
|
+
if (!existsSync(shim)) continue
|
|
429
|
+
attempts.push({ command: shim, argv: args, options: {}, label: `${shim} ${args.join(' ')}` })
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
383
433
|
attempts.push({
|
|
384
434
|
command: 'dsh',
|
|
385
435
|
argv: args,
|
|
@@ -387,14 +437,20 @@ async function runDsh(args) {
|
|
|
387
437
|
label: `dsh ${args.join(' ')}`,
|
|
388
438
|
})
|
|
389
439
|
|
|
440
|
+
return attempts
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async function runDsh(args) {
|
|
390
444
|
let last
|
|
391
|
-
|
|
445
|
+
const tried = []
|
|
446
|
+
for (const attempt of cliAttempts(args)) {
|
|
447
|
+
tried.push(attempt.label)
|
|
392
448
|
last = await runOnce(attempt.command, attempt.argv, attempt.options)
|
|
393
449
|
const missing = last.code === 'ENOENT' || /not found|不是内部或外部命令|cannot find/i.test(last.stderr)
|
|
394
450
|
if (missing) continue
|
|
395
|
-
return { ...last, command: attempt.label }
|
|
451
|
+
return { ...last, command: attempt.label, tried }
|
|
396
452
|
}
|
|
397
|
-
return { ...last, command: 'none', ok: false }
|
|
453
|
+
return { ...(last ?? { ok: false, stdout: '', stderr: '' }), command: 'none', ok: false, tried }
|
|
398
454
|
}
|
|
399
455
|
|
|
400
456
|
async function applyList(items) {
|
|
@@ -413,6 +469,8 @@ async function applyList(items) {
|
|
|
413
469
|
ok: run.ok,
|
|
414
470
|
specs,
|
|
415
471
|
command: run.command,
|
|
472
|
+
tried: run.tried ?? [],
|
|
473
|
+
manual: `dsh plugin --profile ${profile.name} add ${specs.join(' ')}`,
|
|
416
474
|
exitCode: typeof run.code === 'number' ? run.code : null,
|
|
417
475
|
stdout: tail(run.stdout),
|
|
418
476
|
stderr: tail(run.stderr),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xi-ix/dsh-multi-sync",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Copy one machine's installed DSH plugin list to another: scan the profile, export a pinned list, then install the selected entries on the other machine.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -49,3 +49,4 @@
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
|