跳到主内容
版本:11 & 12

pnpm update

别名:upupgrade

pnpm update 基于指定的范围更新包到它们的最新版本。

在不带参数的情况下使用时,将更新所有依赖关系。

摘要:

命令含义
pnpm up更新所有依赖项,遵守 package.json 中指定的范围
pnpm up --latest将所有依赖项更新到最新版本
pnpm up foo@2foo 更新到 v2 上的最新版本
pnpm up "@babel/*"更新 @babel 范围内的所有依赖项

使用模式匹配选择依赖项

你可以使用模式来更新特定的依赖项。

更新所有 babel 包:

pnpm update "@babel/*"

更新所有依赖项,除了 webpack:

pnpm update "\!webpack"

模式也可以组合,因此下一个命令将更新所有 babel 包,除了 core

pnpm update "@babel/*" "\!@babel/core"

Updating GitHub Actions

Added in: v11.16.0

pnpm outdated can check the GitHub Actions referenced by the repository's workflow files for updates, and pnpm update can update them. This is opt-in for every command: pass --include-github-actions, or set update.githubActions to true in pnpm-workspace.yaml to enable it by default.

Updated actions are pinned to exact commit hashes, with their release tags preserved in comments:

- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

Checking for updates runs git ls-remote against every referenced repository. Actions whose refs cannot be read — for example, an action in a private repository — are skipped with a warning. If the actions are hosted on a different GitHub server (such as a GitHub Enterprise Server), set update.githubActionsServer (added in 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

仅更新在 dependenciesoptionalDependencies 中的依赖项。

--dev, -D

仅更新在 devDependencies 中的依赖项。

--no-optional

忽略在 optionalDependencies 中的依赖项。

--interactive, -i

显示过时的依赖项并选择要更新的依赖项。

--no-save

不更新 package.json 中的范围。

--changeset

Added in: 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

Added in: v11.16.0

Also update the GitHub Actions referenced by the repository's workflow files. See Updating GitHub Actions.

--filter <package_selector>

阅读更多有关过滤的内容。