pnpm self-update
将 pnpm 更新到最新版本或指定版本。
pnpm self-update [<version>]
用法示例:
pnpm self-update
pnpm self-update 10
pnpm self-update next-10
pnpm self-update 10.6.5
行为
pnpm self-update 的行为取决于项目上下文:
在一个固定 pnpm 的项目中
当项目的 package.json 文件中的 packageManager 字段设置为 pnpm(或者有 pnpm 的 devEngines.packageManager 条目)时,self-update 只会将 package.json 文件中的固定版本更新为已解析的版本。 它不会全局安装 pnpm。 下次运行 pnpm 命令时,pnpm 将自动下载并切换到指定的版本。
在项目之外(或当 pnpm pin 被忽略时)
如果项目没有固定 pnpm,或者通过 pmOnFail: ignore 忽略了固定,则 self-update 会将解析后的 pnpm 版本全局安装,并将其链接到 PNPM_HOME,使其成为系统上活动的 pnpm 二进制文件。
Project settings are ignored
Since v11.18.0, pnpm self-update takes no instruction from the project it is run in:
- pnpm is fetched through the same trusted registry and auth configuration used when switching pnpm versions, so a project's
.npmrcorpnpm-workspace.yamlcannot redirect the download or attach credentials to it, and the project's default.pnpmfile.(c|m)jsis not loaded. Pnpmfiles from trusted sources (thepnpmfilesetting, the global pnpmfile, config dependencies) still apply. - The project's
minimumReleaseAge,trustPolicy, andcisettings do not affectself-update. They still govern the project's own dependencies; forself-update, these values come from the built-in default, your global config, aPNPM_CONFIG_*environment variable, or a command-line flag. This stops a repository from either waiving the release-age cooldown or keeping you on an outdated pnpm by raising it, and from weakening the trust check that guards the pnpm download.
When self-update refuses a version that is younger than the minimumReleaseAge cutoff, an interactive run offers to update anyway; non-interactive runs still fail. CI never prompts, even on a runner that attaches a TTY.
安装 pnpm v12(Rust 重写版)
自 v11.10.0 版本起,pnpm self-update(以及 packageManager 版本切换功能)已支持安装并链接 Rust 重写版的 pnpm v12。 该版本在 next-12 发行标签下同时以 pnpm 和 @pnpm/exe 两个包名发布:
pnpm self-update next-12
v12 版本以 @pnpm/exe. - 包的形式发布原生二进制文件,pnpm 的内置安装程序会直接链接这些文件。 由于不再使用 Node.js 启动器,该命令无需承担 Node.js 启动开销。 从 v12 版本开始,安装过程将统一指向无作用域的 pnpm 包(即 Rust 可执行文件),即使是从单可执行文件格式的 @pnpm/exe 构建版本进行更新也是如此。