pnpm update
别名:up、upgrade
pnpm update 基于指定的范围更新包到它们的最新版本。
在不带参数的情况下使用时,将更新所有依赖关系。
摘要:#
| 命令 | 含义 |
|---|---|
pnpm up |
更新所有依赖项,遵守 package.json 中指定的范围 |
pnpm up --latest |
将所有依赖项更新到最新版本 |
pnpm up foo@2 |
将 foo 更新到 v2 上的最新版本 |
pnpm up "@babel/*" |
更新 @babel 范围内的所有依赖项 |
Since v11.27.1, a dependency whose specifier comes from a packageExtensions entry, a readPackage hook, or an override is not written to package.json. The lockfile keeps that specifier. pnpm update and pnpm audit --fix=update still move it inside the range.
An exact pin from one of those sources is left as it is. When that pin is a vulnerable version, pnpm audit --fix=update warns and points at pnpm audit --fix, which writes an override. An override is applied after packageExtensions and readPackage, so it replaces a specifier those supply.
Updating to a specific version#
Since v11.23.0, pnpm update <name>@<version> fails with ERR_PNPM_UPDATE_VERSION_ON_INDIRECT_DEP when the package is not a direct dependency of any selected project. There is nowhere to record the version in that case; pin a transitive dependency through overrides instead. Ranges and tags are unaffected.
使用模式匹配选择依赖项#
你可以使用模式来更新特定的依赖项。
更新所有 babel 包:
pnpm update "@babel/*"
更新所有依赖项,除了 webpack:
pnpm update "\!webpack"
模式也可以组合,因此下一个命令将更新所有 babel 包,除了 core:
pnpm update "@babel/*" "\!@babel/core"
更新 GitHub Actions#
添加于:v11.16.0
pnpm outdated 可以检查仓库工作流文件所引用的 GitHub Actions 是否有更新,而 pnpm update 可以更新它们。每条命令都需要显式开启:传入 --include-github-actions,或在 pnpm-workspace.yaml 中把 update.githubActions 设为 true 以默认启用。
更新后的操作被锁定至具体的提交哈希,并且它们的发布标签保留在注释中:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
Local actions are followed rather than looked up: a ./-relative reference, and
since v11.26.0 GitHub's self-repository spelling
(uses: $/.github/actions/setup), resolve inside the repository.
检查更新会对每个被引用的仓库执行 git ls-remote。 Actions whose refs cannot be read (for example, an action in a private repository) are skipped with a warning. 如果这些 action 托管在另一个 GitHub 服务器上(例如 GitHub Enterprise Server),请设置 update.githubActionsServer(添加于 v11.17.0)。
配置项#
--recursive, -r#
同时在所有子目录中使用 package.json (不包括
node_modules) 运行更新。
用法示例:
pnpm --recursive update
# updates direct dependencies only
pnpm --recursive update --depth 0
# update typescript to the latest version in every package
pnpm --recursive update typescript@latest
--latest, -L#
将依赖项更新至由 latest 标签决定的最新稳定版本(有可能会跨越主版本号),只要 package.json 中指定的版本范围低于 latest 标签的版本号(即不会对预发布版本降级)。
Since v11.27.1, --latest does not move a dependency past a specifier supplied by packageExtensions, a readPackage hook, or an override. The lockfile stays inside that specifier.
--global, -g#
更新全局安装的依赖包。 Packages from the pnpm 10 global layout are migrated to the current layout. After a successful migration, pnpm removes the old installation and its symlinks, shims, and hard-linked executables from PNPM_HOME.
--workspace#
尝试从工作空间链接所有软件包。版本将更新至与工作空间内的包匹配的版本。
如果更新了特定的包,而在工作空间内也找不到任何可更新的依赖项,则命令将会失败。例如,如果 express 不是工作空间内的包,那么以下命令将失败:
pnpm up -r --workspace express
--prod, -P#
仅更新在 dependencies 和 optionalDependencies 中的依赖项。
--dev, -D#
仅更新在 devDependencies 中的依赖项。
--no-optional#
忽略在 optionalDependencies 中的依赖项。
--peer#
Added in: v11.28.0
Also update the ranges in peerDependencies. Without this flag, pnpm update leaves peerDependencies unchanged.
pnpm update --peer react
--interactive, -i#
显示过时的依赖项并选择要更新的依赖项。
自 v11.21.0 起,与 --global 结合使用时,每个隔离安装组会作为一个可选项呈现:共享同一次全局安装的包会作为一个整体一起更新。
--no-save#
不更新 package.json 中的范围。
--changeset#
添加于:v11.16.0
After the update completes, write a change intent (a changesets-compatible .changeset/*.md file) declaring a patch bump for every workspace package whose dependencies or optionalDependencies were changed by the update, and a major bump when its peerDependencies changed. 通过 catalog: 协议使用了已更新 catalog 条目的包也会被包含在内。私有包、未命名的包以及在 .changeset/config.json 的 ignore 数组中列出的包将被跳过。如果 .changeset/config.json 不存在,则会打印警告且不会生成变更集。
在 pnpm-workspace.yaml 中把 update.changeset 设为 true 可默认启用此行为,用 --no-changeset 可在单次更新中覆盖该设置。
--include-github-actions#
添加于:v11.16.0
同时更新被仓库中工作流文件引用的 GitHub Actions。参见更新 GitHub Actions。
Supply-chain policy flags#
Added in: v11.26.0
pnpm update accepts the same policy overrides as pnpm install and pnpm add: --trust-lockfile, --no-trust-lockfile, --trust-policy, --trust-policy-exclude, and --trust-policy-ignore-after, so a policy can be relaxed or tightened for a single run without editing pnpm-workspace.yaml.