pnpm patch <pkg>
Préparez un paquet pour les correctifs (inspiré par une commande similaire dans Yarn).
Cette commande va provoquer l'extraction d'un package dans un répertoire temporaire destiné à être éditable à volonté.
Once you're done with your changes, run pnpm patch-commit <path> (with <path> being the temporary directory you received) to generate a patchfile and register it into your top-level manifest via the patchedDependencies field.
Utilisation :
pnpm patch <pkg name>@<version>
If you want to change the dependencies of a package, don't use patching to modify the package.json file of the package. For overriding dependencies, use overrides or a package hook.
Options
--edit-dir <dir>
Le paquet qui doit être corrigé sera extrait dans ce répertoire.
--ignore-existing
Ignorez les fichiers de correctifs existants lors de la correction.
Configuration
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.
Exemple:
patchedDependencies:
express@4.18.1: patches/express@4.18.1.patch
Dependencies can be patched by version range. The priority order is:
- Exact versions (highest priority)
- Version ranges
- Name-only patches (applies to all versions unless overridden)
A special case: the version range * behaves like a name-only patch but does not ignore patch failures.
Exemple:
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.patchis applied tofoo@2.1.0.patches/foo-2.patchapplies to all foo versions matching^2.0.0, except2.1.0.patches/foo-1.patchapplies to all other foo versions.
Avoid overlapping version ranges. If you need to specialize a sub-range, explicitly exclude it from the broader range.
Exemple:
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)
- Par défaut: false
- Type: Boolean
When true, installation won't fail if some of the patches from the patchedDependencies field were not applied.
patchedDependencies:
express@4.18.1: patches/express@4.18.1.patch
allowUnusedPatches: true
ignorePatchFailures
Added in: v10.7.0
- Default: undefined
- Type: Boolean, undefined
Controls how patch failures are handled.
Behaviour:
- undefined (default):
- Errors out when a patch with an exact version or version range fails.
- Ignores failures from name-only patches.
- false: Errors out for any patch failure.
- true: Prints a warning instead of failing when any patch cannot be applied.