pnpm update
别名: up, upgrade
pnpm update 根据指定的范围更新软件包的最新版本。
在不带参数的情况下使用时,将更新所有依赖关系。
摘要:#
| 命令 | 含义 |
|---|---|
pnpm up | 遵循 package.json 指定的范围更新所有的依赖项 |
pnpm up --latest | 将所有依赖项更新到最新版本 |
pnpm up foo@2 | 将 foo 更新到 v2 上的最新版本 |
pnpm up "@babel/*" | 更新 @babel 范围内的所有依赖项 |
更新内容写入什么#
除了将 pnpm-lock.yaml 更新为新解析的版本外,pnpm update 还会将新的版本范围写回声明该依赖项的位置:
- 在
package.json中,版本范围被转移到了解析后的版本上,同时保留了该依赖项原先声明的运算符,因此^1.1.0依然保持为插入符号范围。 - 通过
catalog:协议声明的依赖项不会在package.json中被重写。它指向的目录条目会在pnpm-workspace.yaml中更新。 - 通过 dist-tag 声明的依赖项,例如
"foo": "latest",会保留对标签的追踪。标签会保留在package.json里,只有锁文件移动到标签所指向的版本——--latest也是如此。
传入 --no-save 以仅更新锁文件,而不改动声明的版本范围。
使用模式匹配选择依赖项#
你可以使用模式来更新特定的依赖项。
更新所有 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
检查更新会向每个引用的仓库运行 git ls-remote 命令。无法读取其引用的操作(例如位于私有仓库中的操作)会被跳过并伴随警告提示。如果操作托管在不同的 GitHub 服务器(例如一个 GitHub Enterprise Server),设置 update.githubActionsServer(添加于 v11.17.0)。
配置项#
--recursive, -r#
同时在所有子目录中使用 package.json (不包括 node_modules) 运行更新。
用法示例:
pnpm --recursive update
# 更新子目录深度为 100 以内的所有包
pnpm --recursive update --depth 100
# 将每个包中的 typescript 更新为最新版本
pnpm --recursive update typescript@latest
--latest, -L#
将依赖项更新至由 latest 标签决定的最新稳定版本(有可能会跨越主版本号),只要 package.json 中指定的版本范围低于 latest 标签的版本号(即不会对预发布版本降级)。
--global, -g#
更新全局安装的依赖包。
--workspace#
尝试从工作空间链接所有软件包。版本将更新至与工作空间内的包匹配的版本。
如果更新了特定的包,而在工作空间内也找不到任何可更新的依赖项,则命令将会失败。例如,如果 express 不是工作空间内的包,那么以下命令将失败:
pnpm up -r --workspace express
--prod, -P#
仅更新在 dependencies 和 optionalDependencies 中的依赖项。
--dev, -D#
仅更新在 devDependencies 中的依赖项。
--no-optional#
忽略在 optionalDependencies 中的依赖项。
--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. Packages that consume an updated catalog entry via the catalog: protocol are included. Private packages, packages without a name, and packages listed in the ignore array of .changeset/config.json are skipped. If .changeset/config.json does not exist, a warning is printed and no changeset is generated.
Set update.changeset to true in pnpm-workspace.yaml to enable this behavior by default, and use --no-changeset to override the setting for one update.
--include-github-actions#
添加于:v11.16.0
Also update the GitHub Actions referenced by the repository's workflow files. See Updating GitHub Actions.