Skip to main content
Version: 9.x

pnpm update

别名:upupgrade

¥Aliases: up, upgrade

pnpm update 根据指定范围将软件包更新到最新版本。

¥pnpm update updates packages to their latest version based on the specified range.

当不带参数使用时,更新所有依赖。

¥When used without arguments, updates all dependencies.

长话短说

¥TL;DR

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

选择具有模式的依赖

¥Selecting dependencies with patterns

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

¥You can use patterns to update specific dependencies.

更新所有 babel 软件包:

¥Update all babel packages:

pnpm update "@babel/*"

更新除 webpack 之外的所有依赖:

¥Update all dependencies, except webpack:

pnpm update "\!webpack"

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

¥Patterns may also be combined, so the next command will update all babel packages, except core:

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

选项

¥Options

--recursive, -r

同时在所有具有 package.json 的子目录中运行更新(不包括 node_modules)。

¥Concurrently runs update in all subdirectories with a package.json (excluding node_modules).

用法示例:

¥Usage examples:

pnpm --recursive update
# updates all packages up to 100 subdirectories in depth
pnpm --recursive update --depth 100
# update typescript to the latest version in every package
pnpm --recursive update typescript@latest

--latest, -L

只要 package.json 中指定的版本范围低于 latest 标签(即不会降级预发布),将依赖更新到由 latest 标签确定的最新稳定版本(可能跨主要版本升级软件包)。

¥Update the dependencies to their latest stable version as determined by their latest tags (potentially upgrading the packages across major versions) as long as the version range specified in package.json is lower than the latest tag (i.e. it will not downgrade prereleases).

--global, -g

更新全局包。

¥Update global packages.

--workspace

尝试链接工作区中的所有包。版本会更新以匹配工作区中包的版本。

¥Tries to link all packages from the workspace. Versions are updated to match the versions of packages inside the workspace.

如果更新了特定包,并且在工作区中未找到任何更新的依赖,则该命令将失败。例如,如果 express 不是工作区包,则以下命令将失败:

¥If specific packages are updated, the command will fail if any of the updated dependencies are not found inside the workspace. For instance, the following command fails if express is not a workspace package:

pnpm up -r --workspace express

--prod, -P

仅更新 dependenciesoptionalDependencies 中的软件包。

¥Only update packages in dependencies and optionalDependencies.

--dev, -D

仅更新 devDependencies 中的软件包。

¥Only update packages in devDependencies.

--no-optional

不要更新 optionalDependencies 中的软件包。

¥Don't update packages in optionalDependencies.

--interactive, -i

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

¥Show outdated dependencies and select which ones to update.

--filter <package_selector>

了解有关过滤的更多信息。

¥Read more about filtering.