@xi-ix/dsh-multi-sync 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/client.js +11 -2
  2. package/index.js +48 -10
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -42,6 +42,8 @@ window.__ModuleLoader__.load({
42
42
  selectAll: '全选可安装',
43
43
  empty: '还没有扫描结果。',
44
44
  noRows: '清单里没有可安装的 npm 插件。',
45
+ nothingSelected: '没有选中任何插件(「已装」的行不会重复安装)。',
46
+ cliMissing: '找不到 dsh 命令行。试过:',
45
47
  from: '清单来源',
46
48
  generatedAt: '生成时间',
47
49
  mismatch: '清单来自另一台机器,DSH 版本不同,安装前请留意。',
@@ -94,6 +96,8 @@ window.__ModuleLoader__.load({
94
96
  selectAll: 'Select installable',
95
97
  empty: 'Nothing scanned yet.',
96
98
  noRows: 'The list has no installable npm plugin.',
99
+ nothingSelected: 'Nothing is selected ("installed" rows are not reinstalled).',
100
+ cliMissing: 'Cannot find the dsh CLI. Tried:',
97
101
  from: 'List from',
98
102
  generatedAt: 'Generated',
99
103
  mismatch: 'This list came from a machine running a different DSH version — check before installing.',
@@ -303,7 +307,10 @@ window.__ModuleLoader__.load({
303
307
 
304
308
  const install = useCallback(async () => {
305
309
  const items = (rows || []).filter((row) => selected[row.name]).map((row) => ({ name: row.name, version: row.version }))
306
- if (items.length === 0) return
310
+ if (items.length === 0) {
311
+ setMessage({ kind: 'err', text: L.nothingSelected })
312
+ return
313
+ }
307
314
  setBusy('install')
308
315
  setMessage(null)
309
316
  try {
@@ -315,7 +322,9 @@ window.__ModuleLoader__.load({
315
322
  const state = await api('/scan').catch(() => null)
316
323
  if (state) setList(state.list)
317
324
  } else {
318
- setMessage({ kind: 'err', text: body.result.stderr || body.result.message || 'install failed' })
325
+ const detail = body.result.stderr || body.result.message || 'install failed'
326
+ const tried = Array.isArray(body.result.tried) && body.result.tried.length > 0 ? `\n\n${L.cliMissing}\n${body.result.tried.join('\n')}` : ''
327
+ setMessage({ kind: 'err', text: detail + tried })
319
328
  }
320
329
  } catch (error) {
321
330
  setMessage({ kind: 'err', text: String(error.message || error) })
package/index.js CHANGED
@@ -363,23 +363,54 @@ function runOnce(command, argv, options) {
363
363
  /**
364
364
  * Run the DSH CLI, preferring the installation this process belongs to.
365
365
  *
366
- * The packaged CLI lives inside app.asar, which only the Electron runtime can
367
- * read; that attempt therefore goes through the running executable with
368
- * ELECTRON_RUN_AS_NODE. `dsh` on PATH is the fallback.
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
- async function runDsh(args) {
373
+ function cliAttempts(args) {
374
+ const attempts = []
371
375
  const nodeExecutable = process.env.DSH_NODE_EXECUTABLE
372
376
  const installDir = process.env.DSH_INSTALL_DIR
373
- const attempts = []
377
+ const asNode = { env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' } }
374
378
 
375
379
  if (nodeExecutable && installDir) {
376
380
  attempts.push({
377
381
  command: nodeExecutable,
378
382
  argv: [join(installDir, 'lib', 'bin.js'), ...args],
379
- options: { env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' } },
380
- label: `${nodeExecutable} lib/bin.js ${args.join(' ')}`,
383
+ options: asNode,
384
+ label: `${nodeExecutable} ${join(installDir, 'lib', 'bin.js')} ${args.join(' ')}`,
381
385
  })
382
386
  }
387
+
388
+ const resources = process.resourcesPath
389
+ if (resources) {
390
+ for (const relative of [
391
+ join('app.asar', 'dsh', 'node_modules', '@deepseek-ai', 'dsh', 'lib', 'bin.js'),
392
+ join('app', 'dsh', 'node_modules', '@deepseek-ai', 'dsh', 'lib', 'bin.js'),
393
+ ]) {
394
+ const entry = join(resources, relative)
395
+ if (!existsSync(entry)) continue
396
+ attempts.push({
397
+ command: process.execPath,
398
+ argv: [entry, ...args],
399
+ options: asNode,
400
+ label: `${process.execPath} ${entry} ${args.join(' ')}`,
401
+ })
402
+ }
403
+ const shim = join(resources, 'runtime', 'cli', 'bin', platform() === 'win32' ? 'dsh.cmd' : 'dsh')
404
+ if (existsSync(shim)) {
405
+ attempts.push({
406
+ command: shim,
407
+ argv: args,
408
+ options: { shell: platform() === 'win32' },
409
+ label: `${shim} ${args.join(' ')}`,
410
+ })
411
+ }
412
+ }
413
+
383
414
  attempts.push({
384
415
  command: 'dsh',
385
416
  argv: args,
@@ -387,14 +418,20 @@ async function runDsh(args) {
387
418
  label: `dsh ${args.join(' ')}`,
388
419
  })
389
420
 
421
+ return attempts
422
+ }
423
+
424
+ async function runDsh(args) {
390
425
  let last
391
- for (const attempt of attempts) {
426
+ const tried = []
427
+ for (const attempt of cliAttempts(args)) {
428
+ tried.push(attempt.label)
392
429
  last = await runOnce(attempt.command, attempt.argv, attempt.options)
393
430
  const missing = last.code === 'ENOENT' || /not found|不是内部或外部命令|cannot find/i.test(last.stderr)
394
431
  if (missing) continue
395
- return { ...last, command: attempt.label }
432
+ return { ...last, command: attempt.label, tried }
396
433
  }
397
- return { ...last, command: 'none', ok: false }
434
+ return { ...(last ?? { ok: false, stdout: '', stderr: '' }), command: 'none', ok: false, tried }
398
435
  }
399
436
 
400
437
  async function applyList(items) {
@@ -413,6 +450,7 @@ async function applyList(items) {
413
450
  ok: run.ok,
414
451
  specs,
415
452
  command: run.command,
453
+ tried: run.tried ?? [],
416
454
  exitCode: typeof run.code === 'number' ? run.code : null,
417
455
  stdout: tail(run.stdout),
418
456
  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.0",
3
+ "version": "0.1.1",
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",