
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
patch-package
Advanced tools
The patch-package npm package allows users to keep track of modifications to node_modules. It is useful when a user needs to make a quick fix to a node module and wants to persist this change across installs without waiting for the upstream fix. It lets you keep your workarounds in version control.
Creating Patches
This command is used to create a patch file for the npm package 'some-package'. After making changes to the node module, running this command will generate a patch file in a directory that can be committed to version control.
npx patch-package some-package
Applying Patches
This command applies all patches from the patches directory. It is typically used in the postinstall script in package.json to ensure that patches are applied after every npm install.
npx patch-package
Applying Specific Patch
This command applies a patch to a specific package. It is useful when you want to apply a patch to 'some-package' without applying all available patches.
npx patch-package some-package
Shrinkwrap is a tool for locking down the versions of npm packages installed. It is similar to patch-package in that it helps maintain consistency in dependencies, but it does not allow for modifications to the package code itself.
patch-package lets you easily make small necessary changes to packages in your
node_modules
folder, without the headache of forking them.
# fix a bug in one of your deps
vim node_modules/some-package/brokenFile.js
# run patch-package to generate a .patch file for that package in ./patches
patch-package some-package
# commit the patch file
git add -A
git commit -m "fix brokenFile.js in some-package"
Patches created by patch-package
are automatically and gracefully applied
any time the contents of node_modules is changed by npm/yarn. You get warnings
if the versions of patched dependencies change, and errors when the patch can
no longer be applied.
yarn add -D patch-package
In package.json
"scripts": {
"prepare": "patch-package"
}
First make changes to the files of a particular package in your node_modules folder, then run
patch-package package-name
where package-name
matches the name of the package you made changes to.
If this is the first time you've used patch-package
, it will create a folder called patches
in
the root dir of your app. Inside will be a file called package-name:0.44.0.patch
or something,
which is a diff between normal old package-name
and your fixed version. Commit this and you and your team will enjoy the same changes from here on out.
Use exactly the same process as for making patches in the first place, i.e. make more changes, run patch-package, commit the changes to the patch file.
Run patch-package without arguments to apply all patches in your project.
patch-package cannot apply individual packages just yet, but you can use the unix patch
command, of course.
patch --forward -p1 -i patches/package-name:0.44.2.patch
Nawh. It's not like monkey patching or anything. You're just fixing your dependencies.
patch-package <package-name>
again and the warning goes away.MIT
1.2.1
FAQs
Fix broken node modules with no fuss
The npm package patch-package receives a total of 2,844,589 weekly downloads. As such, patch-package popularity was classified as popular.
We found that patch-package demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.