@xi-ix/dsh-multi-sync 0.1.1 → 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.
Files changed (3) hide show
  1. package/client.js +4 -1
  2. package/index.js +30 -10
  3. package/package.json +2 -1
package/client.js CHANGED
@@ -44,6 +44,7 @@ window.__ModuleLoader__.load({
44
44
  noRows: '清单里没有可安装的 npm 插件。',
45
45
  nothingSelected: '没有选中任何插件(「已装」的行不会重复安装)。',
46
46
  cliMissing: '找不到 dsh 命令行。试过:',
47
+ manualHint: '可以在终端里手动执行:',
47
48
  from: '清单来源',
48
49
  generatedAt: '生成时间',
49
50
  mismatch: '清单来自另一台机器,DSH 版本不同,安装前请留意。',
@@ -98,6 +99,7 @@ window.__ModuleLoader__.load({
98
99
  noRows: 'The list has no installable npm plugin.',
99
100
  nothingSelected: 'Nothing is selected ("installed" rows are not reinstalled).',
100
101
  cliMissing: 'Cannot find the dsh CLI. Tried:',
102
+ manualHint: 'You can run this in a terminal instead:',
101
103
  from: 'List from',
102
104
  generatedAt: 'Generated',
103
105
  mismatch: 'This list came from a machine running a different DSH version — check before installing.',
@@ -324,7 +326,8 @@ window.__ModuleLoader__.load({
324
326
  } else {
325
327
  const detail = body.result.stderr || body.result.message || 'install failed'
326
328
  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 })
329
+ const manual = body.result.manual ? `\n\n${L.manualHint}\n${body.result.manual}` : ''
330
+ setMessage({ kind: 'err', text: detail + tried + manual })
328
331
  }
329
332
  } catch (error) {
330
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']
@@ -370,6 +370,28 @@ function runOnce(command, argv, options) {
370
370
  * whatever `dsh` the PATH offers. Each candidate is tried until one is not simply
371
371
  * missing, so a machine without the CLI reports every location it looked at.
372
372
  */
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
+
373
395
  function cliAttempts(args) {
374
396
  const attempts = []
375
397
  const nodeExecutable = process.env.DSH_NODE_EXECUTABLE
@@ -385,11 +407,12 @@ function cliAttempts(args) {
385
407
  })
386
408
  }
387
409
 
388
- const resources = process.resourcesPath
410
+ const resources = resourcesRoot()
389
411
  if (resources) {
390
412
  for (const relative of [
391
413
  join('app.asar', 'dsh', 'node_modules', '@deepseek-ai', 'dsh', 'lib', 'bin.js'),
392
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'),
393
416
  ]) {
394
417
  const entry = join(resources, relative)
395
418
  if (!existsSync(entry)) continue
@@ -400,14 +423,10 @@ function cliAttempts(args) {
400
423
  label: `${process.execPath} ${entry} ${args.join(' ')}`,
401
424
  })
402
425
  }
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
- })
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(' ')}` })
411
430
  }
412
431
  }
413
432
 
@@ -451,6 +470,7 @@ async function applyList(items) {
451
470
  specs,
452
471
  command: run.command,
453
472
  tried: run.tried ?? [],
473
+ manual: `dsh plugin --profile ${profile.name} add ${specs.join(' ')}`,
454
474
  exitCode: typeof run.code === 'number' ? run.code : null,
455
475
  stdout: tail(run.stdout),
456
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.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
+