fix(scripts): make vp pm work inside vp run scripts#127
Merged
Conversation
`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.
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.
🤔 本次变更属于 ...
🔗 相关 Issue
💡 背景与方案
问题:
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'])等各种形式)都解析到本地包装器而失败。dist/bin.js中pm仍为 0 次出现,pm是全局二进制独占命令。方案:新增
scripts/run-pm.mjs,通过vp run暴露的VP_CLI_BIN环境变量(指向完整 CLI 二进制)调用vp pm;VP_CLI_BIN未设置时回退到vp(兼容在vp run之外的直接调用,此时vp已解析到全局二进制)。将所有 pack/publish 脚本中的vp pm ...改为node scripts/run-pm.mjs ...,保留对vp pm的使用(符合 AGENTS.md「不要直接用 pnpm」的规范)。验证:
vp run内node 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 0node scripts/run-pm.mjs pack --filter @antdv-next/x→ 正常生成 tarball,exit 0vp fmt/vp lint对新文件:0 warnings, 0 errors📝 变更日志
pack:packages/publish:*scripts failing withCommand 'pm' not foundwhen invoked viavp run.pack:packages/publish:*等脚本经vp run运行时报Command 'pm' not found的问题。