fellow99/dsh-desktop-hos--plugins-harmony-plugin-market-runtime ↗★ 4
harmony-plugin-market-runtime
提供进程内纯JS的pnpm安装引擎 适合鸿蒙系统DSH,避免因派生子进程被系统杀掉而无法安装插件的问题。
安裝
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:fellow99/dsh-desktop-hos#ef585fdecc33723fa82370184c7b0b7a6ef3ce70&path:plugins/harmony-plugin-market-runtime說明文件
閱讀完整 README ↗harmony-plugin-market-runtime
HarmonyOS DSH plugin that provides the two services dsh-market feature-detects — desktopProfiles and desktopPnpm — so the market runs plugin installs in-process instead of spawning node/pnpm children (which HarmonyOS kills with SIGSYS).
This is the "Route 1" wiring of specs/012-pnpm-integration: it consumes the market's built-in cross-environment contract without modifying the market.
Why a plugin (not main-process code)
The market reads ctx.get('desktopProfiles') inside its inject(['webServer','loader']) callback. That callback fires during profile composition, before runProfile() returns to the Electron main process — so main-process code cannot provide the service in time. A host-plane plugin row, mounted during composition, can.
This plugin is therefore also a bundle (dsh.bundle.patch → cordis.patch.yml), listed in dsh.profile.bundles before dshmarket, so its row mounts first.
How it runs pnpm
pnpm's CLI (dist/pnpm.mjs) is a fire-and-forget bundle: importing it resolves long before the install finishes, and it never calls process.exit on success. So a direct in-process import cannot report completion.
This plugin runs the pnpm CLI in a worker_threads.Worker:
| Problem | Worker solution |
|---|---|
| Completion detection | the worker exits when pnpm's pending work drains; worker.on('exit', code) is the signal |
| Exit code | the worker's exit code is pnpm's exit code |
process.exit | exits only the worker, never the Electron process |
| ESM module cache | every new Worker(...) is a fresh module graph — no cache-busting |
| seccomp SIGSYS | a worker is a thread in the same process, not a forked child |
Services provided
desktopProfiles—{ current: { name, dir } }.desktopPnpm—{ runPlugin(args, invokingDir, signal) }returning{ stdout, stderr, done, cancel }perDesktopPnpmLike.
runPlugin runs pnpm --dir --reporter=append-only in a worker and streams output.
Requirements
- The main process sets
DSH_PNPM_ENGINEto the materialized pnpm CLI entry (/node_modules/dsh-market-pnpm/bin/pnpm.cjs), placed byscripts/collect-dsh.mjs'scollectMarketPNPM(). The directory is distinct fromnode_modules/pnpm(whichpnpm deploypopulates with dsh's ownpnpmdependency). - The engine is pnpm@10.34.6: pnpm@11's store v11 needs
node:sqlite, which this Electron/Node runtime lacks (No such binding: sqliteon device); pnpm@10 does not. - The worker makes
process.execPathwritable (no-op setter) before importing the engine — Electron's is read-only and pnpm assigns it (device:Cannot assign to read only property 'execPath'). - The worker patches
fs/fs.promises.symlinkto copy instead of symlink onEACCES/EPERM— pnpm creates a symlink innode_modules/.binfor every dependency binary, and HarmonyOS forbids symlinks. The bin lands as a real file. - The profile's
pnpm-workspace.yamlsetsnodeLinker: hoisted,packageImportMethod: copy,ignoreScripts: true,minimumReleaseAge: 0, and a sandbox-localstoreDir.
Known limitations
ignoreScripts: true: plugins that need lifecycle build scripts cannot install.- No
git:sources: the device has nogit. - Cancel is best-effort:
cancel()terminates the worker; pnpm is not preemptible mid-operation. - Native modules: only needed for
packageImportMethod: clone(@reflink); thecopypath loads none.
Files
| File | Role |
|---|---|
lib/index.js | plugin entry: provides desktopProfiles / desktopPnpm |
lib/pnpm-inprocess.js | parent-side runner: worker lifecycle → { stdout, stderr, done, cancel } |
lib/pnpm-worker.mjs | worker entry: imports the pnpm CLI with a synthetic process.argv |
cordis.patch.yml | bundle patch inserting the plugin row |
tests/pnpm-inprocess.test.mjs | unit tests (fake engine; no network) |