Skip to content

fix(scripts): make vp pm work inside vp run scripts#127

Merged
cc-hearts merged 1 commit into
mainfrom
fix/publish-vp-pm-in-vp-run
Jul 6, 2026
Merged

fix(scripts): make vp pm work inside vp run scripts#127
cc-hearts merged 1 commit into
mainfrom
fix/publish-vp-pm-in-vp-run

Conversation

@cc-hearts

Copy link
Copy Markdown
Member

🤔 本次变更属于 ...

  • 🆕 新功能
  • 🐞 Bug 修复
  • 📝 站点 / 文档改进
  • 📽️ Demo 改进
  • 💄 组件样式改进
  • 🤖 TypeScript 类型定义改进
  • 📦 包体积优化
  • ⚡️ 性能优化
  • ⭐️ 功能增强
  • 🌐 国际化
  • 🛠 重构
  • 🎨 代码风格优化
  • ✅ 测试用例
  • 🔀 分支合并
  • ⏩ 工作流
  • ⌨️ 无障碍改进
  • ❓ 其他(请说明)

🔗 相关 Issue

无对应 issue。现象:vp run publish:x / publish:packages / pack:packages 等命令报 error: Command 'pm' not found

💡 背景与方案

问题vp run publish:x 等脚本里的 vp pm ... 会失败,报 error: Command 'pm' not found,导致发布/打包脚本无法运行。

根因

  • vp pm 只在完整的 Vite+ CLI 二进制(~/.vite-plus/bin/vp,Rust,v0.2.x)中实现;本地 node_modules/.bin/vp(vite-plus JS 包装器)只覆盖核心命令(dev/build/run/exec/install/...),不含 pm
  • vp run <script> 执行脚本时会把 node_modules/.bin 加到 PATH 最前,导致脚本里的 vp pm(以及 sh -c 'vp pm'、变量间接、node 子进程 spawnSync('vp', ['pm']) 等各种形式)都解析到本地包装器而失败。
  • 已确认升级 vite-plus 也无法解决:npm 上 v0.2.2 的 JS 包装器 dist/bin.jspm 仍为 0 次出现,pm 是全局二进制独占命令。

方案:新增 scripts/run-pm.mjs,通过 vp run 暴露的 VP_CLI_BIN 环境变量(指向完整 CLI 二进制)调用 vp pmVP_CLI_BIN 未设置时回退到 vp(兼容在 vp run 之外的直接调用,此时 vp 已解析到全局二进制)。将所有 pack/publish 脚本中的 vp pm ... 改为 node scripts/run-pm.mjs ...,保留对 vp pm 的使用(符合 AGENTS.md「不要直接用 pnpm」的规范)。

验证

  • vp runnode scripts/run-pm.mjs whoami → 真实输出(不再报 Command 'pm' not found
  • vp run publish:x(1.1.2 已发布)→ build 成功 + no new packages,exit 0(原为 exit 2)
  • 临时改为未发布版本后 publish --dry-run → 完整 tarball 输出 + + @antdv-next/x@x.x.x,exit 0
  • node scripts/run-pm.mjs pack --filter @antdv-next/x → 正常生成 tarball,exit 0
  • vp fmt / vp lint 对新文件:0 warnings, 0 errors

📝 变更日志

语言 变更日志
🇺🇸 英文 Fix pack:packages / publish:* scripts failing with Command 'pm' not found when invoked via vp run.
🇨🇳 中文 修复 pack:packages / publish:* 等脚本经 vp run 运行时报 Command 'pm' not found 的问题。

`vp pm` is only implemented by the full Vite+ CLI binary, not by the local
`node_modules/.bin/vp` JS wrapper (which only covers core commands like
dev/build/run/exec/install). `vp run` prepends `node_modules/.bin` to PATH,
so any `vp pm ...` in the pack/publish scripts resolved to the local wrapper
and failed with `error: Command 'pm' not found`.

Add scripts/run-pm.mjs that forwards to `vp pm` via the `VP_CLI_BIN` env var
(exposed by `vp run`, pointing at the full CLI binary), with a `vp` fallback
for use outside `vp run`. Switch all pack/publish scripts to use it.
@cc-hearts cc-hearts merged commit d7c841d into main Jul 6, 2026
1 check 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