fix(console): Windows 下解析 DSH 家目录与 npm/pnpm spawn 失败 - #8
Open
MiloMMIN wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
该 PR 修复薄控制台在 Windows 上的两类兼容性问题:DSH 家目录解析错误导致 profile/版本读取失败,以及 spawnSync 直接调用 npm/pnpm 在 Windows 下 ENOENT 导致安装/更新/移除与版本检查不可用,从而恢复「插件」面板的正确展示与操作能力。
Changes:
resolveDshHome()回退逻辑改用os.homedir(),避免 Windows 下HOME缺失导致落到错误目录。- 新增
cmdShim(),在 win32 下为npm/pnpm追加.cmd后缀,并应用到runPnpm()/npmViewLatest()调用点。 - 重新构建
lib/index.mjs以同步产物变更。
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/plugin/console/src/index.ts | 修复 Windows 下 DSH 家目录回退与 npm/pnpm spawn 失败问题(引入 homedir() 与 cmdShim() 并接入调用点)。 |
| packages/plugin/console/lib/index.mjs | 同步构建产物,反映上述 Windows 兼容性修复。 |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @@ -11,14 +11,15 @@ | |||
| import { readFileSync, writeFileSync, existsSync } from 'node:fs' | |||
| import { execFile, spawnSync } from 'node:child_process' | |||
两个 Windows 兼容问题导致面板把全部插件误标「本地」且读写配置失败:
1. resolveDshHome 回退用 HOME ?? '/tmp'——Windows 无 HOME 环境变量时落到
C:\\tmp\\.dsh,读不到 profile 的 cordis.patch.yml(ENOENT)、读不到已装
版本(版本行显示 ?),面板版本检查全 null → 误标「本地」。
改为 os.homedir() 回退,与官方 dsh-home-paths 的 defaultDshHome 一致。
2. spawnSync('npm'/'pnpm') 在 Windows 上跑不起来:裸名因无 .exe 而
ENOENT;带 .cmd 后缀则 libuv 批处理包装在本机 CreateProcessW 直接
EINVAL(受限沙箱与普通 web 进程均复现,用户面板「检查更新」实测
全部失败)。win32 下改由 node 直接执行各 CLI 的 JS 入口——npm 随
node 发行(<node>\\node_modules\\npm\\bin\\npm-cli.js),pnpm 全局装
在 %APPDATA%\\npm\\node_modules\\pnpm\\bin\\pnpm.mjs;入口缺失时回退
.cmd 垫片。实测本机两种入口均返回正确结果(npm view → 0.1.6 等)。
lib/ 由 tsdown 重新构建(仅 index.mjs 变化,client 产物零变化)。
MiloMMIN
force-pushed
the
fix/windows-home-and-cmd-shim
branch
from
August 14, 2026 13:05
fb19770 to
4ccd83a
Compare
|
在 Windows + dsh 0.1.0-rc.6 上复现了同样的问题(插件面板与 plugin_status 读 profile 报 ENOENT,路径落到 D:\tmp.dsh\profiles\web\cordis.patch.yml),本地用同样的 homedir() 修复验证通过,与本 PR 根因一致。 补充一点:plugin_status 还有另一个缺口——它只列 cordis.patch.yml 的 insert 行,从不读 dsh.profile.bundles,导致所有 bundle 插件在 plugin_status 里不可见(与工具描述不符)。已在 #9 提交修复,与本 PR 互补、无文件重叠。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Windows 上「插件」面板把全部用户插件显示为 ? · 本地,「检查更新」永远查不到版本;面板的 install / update / remove 与启停持久化也全部失败。
根因(两个 Windows 兼容问题)
esolveDshHome() 回退用 process.env.HOME ?? '/tmp'。Windows 没有 HOME 环境变量 → 落到 C:\tmp.dsh,而真实 home 在 C:\Users<user>.dsh。实测读写 profile 配置报 ENOENT: open 'C:\tmp.dsh\profiles\web\cordis.patch.yml';已装版本也读不到(版本行显示 ?)。
修改(最小 diff:src 3 处 + 重建 lib)
esolveDshHome() 回退改为 os.homedir(),与官方 dsh-home-paths 的 defaultDshHome() 一致;
ode 直接执行各 CLI 的 JS 入口——npm 随 node 发行(\node_modules\npm\bin\npm-cli.js),pnpm 全局装在 %APPDATA%\npm\node_modules\pnpm\bin\pnpm.mjs;入口缺失时回退 .cmd 垫片。
unPnpm 与
pmViewLatest 两处调用点使用(避免 shell:true 的注入面,参数仍走 argv 数组);
验证
ode npm-cli.js view @anionex/dsh-vision-toolkit version →