Skip to content

fix(installer): 修复 PowerShell 远程入口 BOM 解析与 pnpm 版本校验 - #47

Open
Cora093 wants to merge 1 commit into
omdsh-dev:mainfrom
Cora093:codex/fix-install-ps1-entry
Open

fix(installer): 修复 PowerShell 远程入口 BOM 解析与 pnpm 版本校验#47
Cora093 wants to merge 1 commit into
omdsh-dev:mainfrom
Cora093:codex/fix-install-ps1-entry

Conversation

@Cora093

@Cora093 Cora093 commented Aug 14, 2026

Copy link
Copy Markdown

问题

Windows PowerShell 安装入口存在两类问题:

  1. scripts/install.ps1 为兼容 Windows PowerShell 5.1 的 -File 模式带有 UTF-8 BOM,但 README 和脚本注释中的远程执行命令直接把下载结果交给 iexScriptBlock.Create。BOM 会被解析成 # 命令,并导致 param(...) 不再位于脚本起点,出现命令报错或 -Version-DryRun 等参数失效。
  2. README 声明需要 pnpm >= 10,但脚本此前只检查 pnpm 是否存在。使用 pnpm 8 时,会在安装阶段才出现 ERR_PNPM_ADDING_TO_ROOT,且脚本已经开始处理 profile 配置。

修复

  • PowerShell 远程入口统一调整为:
    1. 使用 irm 下载脚本文本;
    2. 调用 .TrimStart([char]0xFEFF) 移除 BOM;
    3. 通过 ScriptBlock.Create 执行。
  • 保留脚本的 UTF-8 BOM,继续兼容 Windows PowerShell 5.1 的 -File 入口。
  • 默认安装与指定版本示例均可独立复制执行。
  • 在版本解析、profile 写入和安装前检查 pnpm --version
    • 未安装、版本读取失败或无法解析时给出明确错误;
    • 主版本低于 10 时提示升级并以退出码 1 结束。
  • 同步更新中英文 README。
  • 新增 PowerShell 安装入口回归测试。

验证

  • pnpm vitest run tests/install-powershell.spec.ts:7/7 通过
    • UTF-8 BOM 保留
    • Windows PowerShell 5.1 -File 执行
    • Windows PowerShell 5.1 内存执行及参数绑定
    • 安装了 pwsh 时额外验证 pwsh 内存执行
    • pnpm 8 在修改 profile 前被拒绝
    • 文档入口均执行 BOM 清理
    • 指定版本示例保持自包含
  • pnpm typecheck:通过
  • git diff --check:通过
  • 原问题 Windows 机器实测:
    • 正确识别 dsh-better-sidebar@0.11.0
    • -DryRun 正常执行
    • 退出码为 0

关联

Related to #44

@Cora093
Cora093 marked this pull request as ready for review August 14, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant