fellow99/dsh-desktop-hos--plugins-harmony-plugin-market-runtime ↗★ 4

harmony-plugin-market-runtime

提供进程内纯JS的pnpm安装引擎 适合鸿蒙系统DSH,避免因派生子进程被系统杀掉而无法安装插件的问题。

包名
harmony-plugin-market-runtime
兼容性
待验证
Cordis 依赖范围
*
版本
0.1.0
许可证
MIT
最近更新
2026年10月21日

安装

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:fellow99/dsh-desktop-hos#ef585fdecc33723fa82370184c7b0b7a6ef3ce70&path:plugins/harmony-plugin-market-runtime

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:

ProblemWorker solution
Completion detectionthe worker exits when pnpm's pending work drains; worker.on('exit', code) is the signal
Exit codethe worker's exit code is pnpm's exit code
process.exitexits only the worker, never the Electron process
ESM module cacheevery new Worker(...) is a fresh module graph — no cache-busting
seccomp SIGSYSa 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 } per DesktopPnpmLike.

runPlugin runs pnpm --dir --reporter=append-only in a worker and streams output.

Requirements

  • The main process sets DSH_PNPM_ENGINE to the materialized pnpm CLI entry (/node_modules/dsh-market-pnpm/bin/pnpm.cjs), placed by scripts/collect-dsh.mjs's collectMarketPNPM(). The directory is distinct from node_modules/pnpm (which pnpm deploy populates with dsh's own pnpm dependency).
  • The engine is pnpm@10.34.6: pnpm@11's store v11 needs node:sqlite, which this Electron/Node runtime lacks (No such binding: sqlite on device); pnpm@10 does not.
  • The worker makes process.execPath writable (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.symlink to copy instead of symlink on EACCES/EPERM — pnpm creates a symlink in node_modules/.bin for every dependency binary, and HarmonyOS forbids symlinks. The bin lands as a real file.
  • The profile's pnpm-workspace.yaml sets nodeLinker: hoisted, packageImportMethod: copy, ignoreScripts: true, minimumReleaseAge: 0, and a sandbox-local storeDir.

Known limitations

  • ignoreScripts: true: plugins that need lifecycle build scripts cannot install.
  • No git: sources: the device has no git.
  • Cancel is best-effort: cancel() terminates the worker; pnpm is not preemptible mid-operation.
  • Native modules: only needed for packageImportMethod: clone (@reflink); the copy path loads none.

Files

FileRole
lib/index.jsplugin entry: provides desktopProfiles / desktopPnpm
lib/pnpm-inprocess.jsparent-side runner: worker lifecycle → { stdout, stderr, done, cancel }
lib/pnpm-worker.mjsworker entry: imports the pnpm CLI with a synthetic process.argv
cordis.patch.ymlbundle patch inserting the plugin row
tests/pnpm-inprocess.test.mjsunit tests (fake engine; no network)