pnpm update
Aliases: up, upgrade
pnpm update updates packages to their latest version based on the specified
range.
Quando utilizado sem argumentos, atualiza todas as dependências.
Resumo#
| Comando | Resultado |
|---|---|
pnpm up |
Updates all dependencies, adhering to ranges specified in package.json |
pnpm up --latest |
Updates all dependencies to their latest versions |
pnpm up --tag next |
Updates all dependencies to the versions behind their next tags |
pnpm up foo@2 |
Updates foo to the latest version on v2 |
pnpm up "@babel/*" |
Updates all dependencies under the @babel scope |
What an update writes#
Besides moving pnpm-lock.yaml to the newly resolved versions, pnpm update writes the new range back to the place the dependency is declared:
- In
package.json, the range is moved onto the resolved version while the operator the dependency already declared is kept, so^1.1.0stays a caret range. - A dependency declared through the
catalog:protocol is not rewritten inpackage.json. The catalog entry it points at is updated instead, inpnpm-workspace.yaml. - A dependency declared through the
jsr:protocol keeps itsjsr:prefix, and its range moves like an npm range. - A dependency declared through a dist-tag, such as
"foo": "latest", keeps tracking the tag. The tag stays inpackage.jsonand only the lockfile moves to the version behind it, with--latestas well. - Since v12.12.0, a config dependency is updated too, and its new range is written to
pnpm-workspace.yaml. - A runtime (
node,deno,bundeclared indevEngines.runtime,engines.runtime, or through theruntime:/tool:protocol) and a package manager (pnpm,npm,yarn,bundeclared indevEngines.packageManagerorpackageManager) are updated too, and their new versions or ranges are written back topackage.json(andpnpm-lock.yamlwhen the pin is recorded there). Anengines.pnpmrange moves with the pnpm pin, the waypnpm self-updatemoves it. - When
cargo.enabledistrue, Cargo dependencies inCargo.tomlandCargo.lockare updated too. Passcrate:<name>(orcrate:<name>@<req>) to target specific crates. - When
python.enabledistrue, Python dependencies inpyproject.tomlandpylock.tomlare updated too. Passpypi:<name>(orpypi:<requirement>) to target specific Python distributions.
Recursive and filtered updates include standalone Python and Cargo workspace members. Python name patterns ignore case and treat runs of dots, underscores, and hyphens as one hyphen. Cargo selectors match both the dependency alias and the crate name.
- Since v12.6.0, a dependency whose specifier comes from a
packageExtensionsentry, areadPackagehook, or anoverrideis not written topackage.json. The lockfile keeps that specifier.pnpm updateandpnpm audit --fix=updatestill 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.
Pass --no-save to update the lockfile only and leave the declared ranges alone.
Since v12.0.0, --patches does something different
from all of this: it changes no version and no declared range, refreshing only
which registry artifact each locked version resolves to. That still rewrites
lockfile metadata (the integrity, the revision, and the package snapshot
around them), because artifact revisions may declare different dependencies. See
Registry revisions.
Updating to a specific version#
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.
Selecionando dependências com patterns#
É possível utilizar patterns para atualizar dependências específicas.
Update all babel packages:
pnpm update "@babel/*"
Update all dependencies, except webpack:
pnpm update "\!webpack"
Patterns may also be combined, so the next command will update all babel packages, except core:
pnpm update "@babel/*" "\!@babel/core"
Updating GitHub Actions#
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
Local actions are followed rather than looked up: a ./-relative reference, and
since v12.3.0 GitHub's self-repository spelling
(uses: $/.github/actions/setup), resolve inside the repository.
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.
Opções#
--recursive, -r#
Concurrently runs update in all subdirectories with a package.json (excluding
node_modules).
Exemplos de uso:
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
--depth <number>#
- Default: Infinity
- Type: Number
How deep in the dependency tree to update. 0 updates direct dependencies only.
--latest, -L#
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).
Since v12.6.0, --latest does not move a dependency past a specifier supplied by packageExtensions, a readPackage hook, or an override. The lockfile stays inside that specifier.
Since v12.23.0, pnpm update --latest <name> moves the override keyed by the bare name of a dependency it selects. The override keeps its range style, so 1.0.0 becomes the new exact version and ^1.0.0 becomes ^<new version>. The package.json entry stays as it is. pnpm update --interactive --latest does the same for the dependencies you select. pnpm prints a warning when it cannot move the override, for example an npm: alias, a $ reference, or a catalog: value. --latest without selectors leaves overrides alone.
A Cargo requirement keeps its operator when updated, so ~1.0 becomes ~1.1
and =1.0.0 stays exact. A requirement with only an upper bound, such as <2,
is kept while the new version matches it, and becomes a caret requirement, such
as ^2.0.0, when --latest moves past it. A requirement in the selector, as in
pnpm update crate:foo@^2, replaces it. savePrefix and saveExact apply only
to new Cargo dependencies. Saved Cargo requirements omit build metadata.
A Python requirement keeps its operator and precision too, so ~=1.0 becomes
~=2.0 and ==1.* becomes ==2.*. A requirement with only an upper bound,
such as <2, or with several clauses, such as >=1.0,<2, becomes >=2.0 when
--latest moves past it. A selected pre-release that the requirement does not
name, such as 1.4rc1 for ==1.*, adds a clause that names it, as in
==1.*,>=1.4rc1. savePrefix and saveExact do not apply to Python
requirements.
--tag <tag>#
Added in: v12.23.0
Update the dependencies to the version behind the given dist-tag, and write
that version to package.json with the range operator the dependency already
declares. The tag's version is used even when it is lower than the installed
version. pnpm up --tag next foo does the same as pnpm up foo@next.
A dependency that tracks a dist-tag, such as "foo": "latest", is switched to
the given tag. A dependency declared through the catalog:, workspace:, or
npm: protocol, through a named registry, or as a path or git URL, is not
rewritten. Config dependencies are not updated. A package that does not publish
the tag fails the update.
With --global, a package that does not publish the tag keeps its range, and
the other packages are updated. A global package also keeps its installed
version when the tag's version is lower.
The value must be a dist-tag name. A version or a range, such as 1.2.3 or
*, is rejected (ERR_PNPM_UPDATE_INVALID_TAG). --tag cannot be combined
with --latest, --workspace, --patches, or a selector that names a
version, such as foo@2 (ERR_PNPM_TAG_WITH_SPEC).
--patches#
Added in: v12.0.0
Refresh registry revisions without changing any
package version: for every locked registry package, pnpm resolves current
metadata for the same name@version, and adopts the artifact the registry
selects now if that changed. Versions and declared ranges are left alone, but the
lockfile entry is rewritten as a whole (integrity, revision, and the package
snapshot around them), since revisions may declare different dependencies.
Cannot be combined with package selectors, --latest, --tag, --interactive,
or --global (ERR_PNPM_PATCHES_WITH_SELECTOR).
--pnpr-server <url>#
Added in: v12.0.0
Offload the resolution of a --patches refresh to a pnpr server, the
way pnprServer does for an install.
--global, -g#
Atualiza os pacotes globais. 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#
Tenta vincular todos os pacotes do workspace. As versões são atualizadas para corresponder às versões dos pacotes dentro do workspace.
Se pacotes específicos forem atualizados, o comando falhará se alguma das dependências atualizadas não forem encontradas dentro do workspace. For instance, the following
command fails if express is not a workspace package:
pnpm up -r --workspace express
--prod, -P, --production#
Only update packages in dependencies and optionalDependencies.
--dev, -D#
Only update packages in devDependencies.
--no-optional#
Don't update packages in optionalDependencies.
--optional#
Only update packages in optionalDependencies.
--peer#
Also update packages in peerDependencies. It cannot be combined with --interactive (ERR_PNPM_INTERACTIVE_PEER_UNSUPPORTED).
--save-exact, -E#
With --latest or --tag, write the resolved version to package.json without a range operator. A dependency that already declares a ^, ~, or exact range keeps that operator.
--lockfile-only#
Update pnpm-lock.yaml without downloading dependencies or changing node_modules.
--lockfile-dir <dir>#
The directory in which pnpm-lock.yaml is created. It cannot be combined with --global.
--interactive, -i#
Exibe dependências desatualizadas e seleciona quais atualizar.
For a package from a registry declared with serverType: pnpr, the release notes between the installed and the offered version are shown below the list while the package is under the cursor.
With trustPolicy: no-downgrade, the list of dependencies offers only versions the trust policy accepts, and it has a Trust column. The --global list of package groups has no such column. The column names the strongest trust evidence of the offered version: staged publish, trusted publisher, provenance, or none. If a package in trustPolicyExclude is offered a version with weaker evidence than the installed one, the cell is yellow and also names the installed version's evidence.
Combined with --global, each isolated install group is presented as one selectable item: packages that share a global installation update together as a unit.
--long#
Show package homepage or repository URLs in the interactive update list:
pnpm update --interactive --long
The URL column is hidden by default. This option fetches full package metadata
and only affects --interactive. It cannot be combined with --global, which
selects package groups.
--no-save#
Don't update the ranges in package.json.
--changeset#
After the update completes, write a change intent (a changesets-compatible .changeset/*.md file) for affected workspace packages. Changes to dependencies or optionalDependencies get a patch bump, and changes to peerDependencies get a major bump. Packages that consume an updated catalog entry via the catalog: protocol are included. Private packages, packages without a name or a valid semver version, and packages listed in versioning.ignore or in the ignore array of .changeset/config.json are skipped. If neither the .changeset directory nor versioning in pnpm-workspace.yaml exists, a warning is printed and no changeset is generated.
Set update.changeset to true in pnpm-workspace.yaml to enable this behavior by default.
--no-changeset#
Don't write a change intent, even when update.changeset is true.
--include-github-actions#
Also update the GitHub Actions referenced by the repository's workflow files. See Updating GitHub Actions.
Supply-chain policy flags#
Added in: v12.3.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.
--minimum-release-age <minutes>, --minimum-release-age-exclude <package-spec>#
Added in: v12.23.0
Set minimumReleaseAge and minimumReleaseAgeExclude for this run, as they do for pnpm install.
--cpu, --os, --libc, --ignore-scripts, --ignore-pnpmfile#
These work as they do for pnpm install.