From 1382369eb9508845bdf626c644d227465008c4dd Mon Sep 17 00:00:00 2001 From: Wodann Date: Mon, 16 Dec 2024 16:17:05 +0000 Subject: [PATCH] docs: add book entry about pnpm patch --- book/src/02_development/07_pnpm_patch.md | 34 ++++++++++++++++++++++++ book/src/SUMMARY.md | 1 + 2 files changed, 35 insertions(+) create mode 100644 book/src/02_development/07_pnpm_patch.md diff --git a/book/src/02_development/07_pnpm_patch.md b/book/src/02_development/07_pnpm_patch.md new file mode 100644 index 000000000..0c7fa1a3e --- /dev/null +++ b/book/src/02_development/07_pnpm_patch.md @@ -0,0 +1,34 @@ +# `pnpm patch` a dependency + +To modify/patch the code of a TypeScript dependency, you can use `pnpm patch`. E.g. to modify the `hardhat` dependency of the `hardhat-tests` folder, run: + +```bash +pnpm patch hardhat@2.22.15 +``` + +This will output something like: + +```bash +Patch: You can now edit the package at: + + /workspaces/edr/node_modules/.pnpm_patches/hardhat@2.22.15 + +To commit your changes, run: + + pnpm patch-commit '/workspaces/edr/node_modules/.pnpm_patches/hardhat@2.22.15' +``` + +When editing the package, make sure to overwite both the source files in `node_modules/.pnpm_patches/hardhat@2.22.15/src/` and the generated files in `node_modules/.pnpm_patches/hardhat@2.22.15/`. + +After you've edited the package at the listed directory and committed it using the `pnpm patch-commit` command, a `hardhat@2.22.15.patch` file will be created in the `patches/` directory. The top-level `package.json` file will also be updated with an entry looking something like this: + +```bash + "patchedDependencies": { + "@defi-wonderland/smock@2.4.0": "patches/@defi-wonderland__smock@2.4.0.patch", + "hardhat@2.22.15": "patches/hardhat@2.22.15.patch" + } +``` + +Each patched dependency has an entry. + +> BEWARE: sometimes the automated `pnpm patch-commit` tooling overwrites existing patched dependencies, so make sure that all entries are present. diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 1756f1f01..df26084a4 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -16,6 +16,7 @@ - [Update N-API targets](02_development/04_update_napi_targets.md) - [Using pnpm link](02_development/05_pnpm_link.md) - [Style Guide](02_development/06_style_guide.md) + - [`pnpm patch` a dependency](02_development/07_pnpm_patch.md) - [Release](./03_release.md)