pnpm patch <pkg>

Prepara un pacchetto per l'applicazione delle patch (ispirato a un comando simile in Yarn).

This command extracts the package to node_modules/.pnpm_patches/<pkg>, where <pkg> is the argument as given, such as foo or foo@1.0.0 (or the --edit-dir), a directory you can edit at will.

Once you're done with your changes, run pnpm patch-commit <path> (with <path> being the directory you received) to generate a patchfile and register it into your top-level manifest via the patchedDependencies field.

Utilizzo:

pnpm patch <pkg name>@<version>

note

To change a package's dependencies, don't use pnpm patch to modify its package.json! Use overrides or a package hook instead.

Opzioni#

--edit-dir <dir>#

Il pacchetto che deve essere corretto verrĂ  estratto in questa directory.

--ignore-existing#

Ignora i file di patch esistenti durante l'applicazione delle patch.

Configurazione#

patchedDependencies#

This field is added/updated automatically when you run pnpm patch-commit. It defines patches for dependencies using a dictionary where:

  • Keys: Package names with an exact version, a version range, or just the name.
  • Values: Relative paths to patch files.

Esempio:

pnpm-workspace.yaml
patchedDependencies:
  express@4.18.1: patches/express@4.18.1.patch

Dependencies can be patched by version range. The priority order is:

  1. Exact versions (highest priority)
  2. Version ranges
  3. Name-only patches (applies to all versions unless overridden)

Esempio:

pnpm-workspace.yaml
patchedDependencies:
  foo: patches/foo-1.patch
  foo@^2.0.0: patches/foo-2.patch
  foo@2.1.0: patches/foo-3.patch
  • patches/foo-3.patch is applied to foo@2.1.0.
  • patches/foo-2.patch applies to all foo versions matching ^2.0.0, except 2.1.0.
  • patches/foo-1.patch applies to all other foo versions.

Avoid overlapping version ranges. If you need to specialize a sub-range, explicitly exclude it from the broader range.

Esempio:

pnpm-workspace.yaml
patchedDependencies:
  # Specialized sub-range
  "foo@2.2.0-2.8.0": patches/foo.2.2.0-2.8.0.patch
  # General patch, excluding the sub-range above
  "foo@>=2.0.0 <2.2.0 || >2.8.0": patches/foo.gte2.patch

In most cases, defining an exact version is enough to override a broader range.

allowUnusedPatches#

Added in: v10.7.0 (Previously named allowNonAppliedPatches)

  • Default: false
  • Type: Boolean

When true, installation won't fail if some of the patches from the patchedDependencies field were not applied.

pnpm-workspace.yaml
patchedDependencies:
  express@4.18.1: patches/express@4.18.1.patch
allowUnusedPatches: true

note

In v11, patch application failures always throw an error. The ignorePatchFailures setting has been removed. When multiple patches in a group are applied, a failure in one does not prevent the rest from being attempted; all patch errors are reported together at the end.