Skip to content

[tech] 🐛 fix(cli): 修复 Windows 下 update 的 Core 范围查询 + 发布 cli@3.6.6 - #64

Merged
liguochuan00 merged 2 commits into
mainfrom
chore/release-cli-3.6.6
Sep 30, 2026
Merged

liguochuan00 merged 2 commits into
mainfrom
chore/release-cli-3.6.6

Conversation

@liguochuan00

Copy link
Copy Markdown
Collaborator

问题

Windows 上 flow2spec update 永远认为 Core 已是最新(update --core 实际是 no-op):

CLI:      3.6.5 -> 3.6.5
Core:     3.8.2 -> 3.8.2
Template: 3.8.1 -> 3.8.1

根因

queryLatestCoreMetadata() 用 npm view <core>@^3.8.2 … 查兼容范围内最新 Core。Windows 下 runCommandSync 必须 shell: true(否则找不到 npm.cmd),而参数只拼接、不转义,cmd.exe 把 ^ 当转义符吃掉,查询退化成精确版本 @3.8.2,目标永远等于当前基线。

本机实测(同一条命令,唯一差别是 shell):shell: true → 只返回 3.8.2/3.8.1;bash(^ 不特殊)→ 返回含 3.8.3 的完整列表。Linux/macOS 与 CI 一直正常,所以此前未暴露。

改法

  • 先 npm view <core> versions --json 列全部版本,在 JS 里按 caret 范围过滤取最大
  • 再对选中的精确版本查 templateVersion(老版本缺该字段时回落到 Core 版本本身)
  • 全程不向 argv 传特殊字符;新增 satisfiesCoreRange()

验证

  • Windows 真实 registry 实测:update --check 现在正确报告 Core: 3.8.3 -> 3.8.3
  • Windows 等价回放(复刻 test-cli-update 的 mock):^3.8.2 → 3.9.0、^0.2.3 → 0.2.4、--core 生效校验通过、任何调用都不含 ^
  • npm test 全链、version:check、pack:check 通过(test-cli-update 在 win32 只跑 help 冒烟,CI 会跑完整 mock)

版本

CLI 3.6.5 → 3.6.6;Core 保持 3.8.3、Template 3.8.2,兼容范围仍 ^3.8.2。

flow2spec update 用 `npm view <core>@^x.y.z` 查兼容范围内最新 Core;Windows 上
参数经 cmd.exe 执行(shell:true 才能找到 npm.cmd)且只拼接不转义,`^` 被当转义符
吃掉后查询退化为精确版本,目标永远等于当前基线:update --check 永远显示已最新、
update --core 实际 no-op(Linux/macOS 不受影响,CI 在 Linux 故未暴露)。

改为 `npm view <core> versions --json` 列全部版本,在 JS 里按 caret 范围过滤取最大,
再对选中的精确版本查 templateVersion;全程不向 argv 传特殊字符。
test-cli-update 的 mock 与断言同步,并新增「任何调用都不得传 ^」回归断言。
Core 保持 3.8.3、Template 3.8.2,CLI 兼容范围仍为 ^3.8.2。
本轮已跑 version:check / npm test / pack:check 全部通过。
@liguochuan00
liguochuan00 merged commit 30238e5 into main Sep 30, 2026
4 checks passed
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