@xi-ix/dsh-multi-sync 0.1.5 → 0.1.6
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/index.js +72 -4
- package/package.json +2 -1
package/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import { readFile, writeFile } from 'node:fs/promises'
|
|
|
19
19
|
import { execFile } from 'node:child_process'
|
|
20
20
|
import { homedir, platform } from 'node:os'
|
|
21
21
|
import { basename, dirname, join } from 'node:path'
|
|
22
|
+
import { pathToFileURL } from 'node:url'
|
|
22
23
|
|
|
23
24
|
export const name = '@xi-ix/dsh-multi-sync'
|
|
24
25
|
export const inject = ['webServer']
|
|
@@ -518,6 +519,72 @@ async function runDsh(args) {
|
|
|
518
519
|
return { ...(last ?? { ok: false, stdout: '', stderr: '' }), command: 'none', ok: false, tried }
|
|
519
520
|
}
|
|
520
521
|
|
|
522
|
+
/**
|
|
523
|
+
* Install through the plugin manager's own operations, inside this process.
|
|
524
|
+
*
|
|
525
|
+
* The CLI refuses `--profile desktop` by design — `manageDesktopProfile` is reserved
|
|
526
|
+
* for the installed carrier — so spawning it can never work against the desktop app.
|
|
527
|
+
* The plugin manager is mounted in this very process, so its operations module is the
|
|
528
|
+
* sanctioned entry point: the same code the CLI and the plugin_manager tool call.
|
|
529
|
+
*/
|
|
530
|
+
async function installInProcess(profile, specs) {
|
|
531
|
+
const resources = resourcesRoot()
|
|
532
|
+
if (!resources) return undefined
|
|
533
|
+
const dshRoot = join(resources, 'app.asar', 'dsh', 'node_modules', '@deepseek-ai')
|
|
534
|
+
const operations = join(dshRoot, 'dsh-plugin-manager', 'lib', 'operations.js')
|
|
535
|
+
if (!existsSync(operations)) return undefined
|
|
536
|
+
|
|
537
|
+
let module
|
|
538
|
+
try {
|
|
539
|
+
module = await import(pathToFileURL(operations).href)
|
|
540
|
+
} catch (error) {
|
|
541
|
+
return undefined
|
|
542
|
+
}
|
|
543
|
+
if (typeof module.runProfilePnpm !== 'function') return undefined
|
|
544
|
+
|
|
545
|
+
const output = []
|
|
546
|
+
const tail = (text) => text.trim().split(/\r?\n/).slice(-40).join('\n')
|
|
547
|
+
try {
|
|
548
|
+
const result = await module.runProfilePnpm(
|
|
549
|
+
{
|
|
550
|
+
profile: profile.name,
|
|
551
|
+
dir: profile.dir,
|
|
552
|
+
installAnchor: join(dshRoot, 'dsh', 'package.json'),
|
|
553
|
+
cwd: process.cwd(),
|
|
554
|
+
},
|
|
555
|
+
['add', ...specs],
|
|
556
|
+
{
|
|
557
|
+
execution: 'cli',
|
|
558
|
+
outputBytes: 64 * 1024,
|
|
559
|
+
lockWaitMs: 120_000,
|
|
560
|
+
lookupTimeoutMs: 120_000,
|
|
561
|
+
onOutput: (text) => output.push(String(text)),
|
|
562
|
+
},
|
|
563
|
+
)
|
|
564
|
+
const exitCode = typeof result?.exitCode === 'number' ? result.exitCode : null
|
|
565
|
+
const text = output.join('')
|
|
566
|
+
return {
|
|
567
|
+
ok: exitCode === 0,
|
|
568
|
+
command: 'in-process plugin manager',
|
|
569
|
+
tried: [operations],
|
|
570
|
+
exitCode,
|
|
571
|
+
stdout: tail(text),
|
|
572
|
+
stderr: exitCode === 0 ? '' : tail(text),
|
|
573
|
+
message: exitCode === 0 ? null : 'plugin manager refused the install',
|
|
574
|
+
}
|
|
575
|
+
} catch (error) {
|
|
576
|
+
return {
|
|
577
|
+
ok: false,
|
|
578
|
+
command: 'in-process plugin manager',
|
|
579
|
+
tried: [operations],
|
|
580
|
+
exitCode: null,
|
|
581
|
+
stdout: '',
|
|
582
|
+
stderr: String(error?.message ?? error),
|
|
583
|
+
message: 'plugin manager threw',
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
521
588
|
async function applyList(items) {
|
|
522
589
|
const profile = resolveProfile()
|
|
523
590
|
const specs = []
|
|
@@ -528,17 +595,18 @@ async function applyList(items) {
|
|
|
528
595
|
}
|
|
529
596
|
if (specs.length === 0) throw new Error('nothing to install: need name@version entries')
|
|
530
597
|
|
|
531
|
-
const run = await runDsh(['plugin', '--profile', profile.name, 'add', ...specs])
|
|
532
598
|
const tail = (text) => text.trim().split(/\r?\n/).slice(-40).join('\n')
|
|
599
|
+
const inProcess = await installInProcess(profile, specs)
|
|
600
|
+
const run = inProcess ?? (await runDsh(['plugin', '--profile', profile.name, 'add', ...specs]))
|
|
533
601
|
return {
|
|
534
602
|
ok: run.ok,
|
|
535
603
|
specs,
|
|
536
604
|
command: run.command,
|
|
537
605
|
tried: run.tried ?? [],
|
|
538
606
|
manual: `dsh plugin --profile ${profile.name} add ${specs.join(' ')}`,
|
|
539
|
-
exitCode: typeof run.code === 'number' ? run.code : null,
|
|
540
|
-
stdout: tail(run.stdout),
|
|
541
|
-
stderr: tail(run.stderr),
|
|
607
|
+
exitCode: typeof run.exitCode === 'number' ? run.exitCode : typeof run.code === 'number' ? run.code : null,
|
|
608
|
+
stdout: tail(run.stdout ?? ''),
|
|
609
|
+
stderr: tail(run.stderr ?? ''),
|
|
542
610
|
message: run.ok ? null : run.message ?? 'dsh plugin add failed',
|
|
543
611
|
}
|
|
544
612
|
}
|
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.6",
|
|
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",
|
|
@@ -53,3 +53,4 @@
|
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
|
|
56
|
+
|