.pnpmfile.cjs
pnpm lets you hook directly into the installation process via special functions
(hooks). Hooks can be declared in a file called .pnpmfile.cjs
.
By default, .pnpmfile.cjs
should be located in the same directory as the
lockfile. For instance, in a workspace with a shared lockfile,
.pnpmfile.cjs
should be in the root of the monorepo.
Hooks
TL;DR
Hook Function | Process | Uses |
---|---|---|
hooks.readPackage(pkg, context): pkg | Called after pnpm parses the dependency's package manifest | Allows you to mutate a dependency's package.json |
hooks.afterAllResolved(lockfile, context): lockfile | Called after the dependencies have been resolved. | Allows you to mutate the lockfile. |
hooks.readPackage(pkg, context): pkg | Promise<pkg>
Allows you to mutate a dependency's package.json
after parsing and prior to
resolution. These mutations are not saved to the filesystem, however, they will
affect what gets resolved in the lockfile and therefore what gets installed.
Note that you will need to delete the pnpm-lock.yaml
if you have already
resolved the dependency you want to modify.
If you need changes to package.json
saved to the filesystem, you need to use the pnpm patch
command and patch the package.json
file.
This might be useful if you want to remove the bin
field of a dependency for instance.