Sometimes, when working with open source packages, you may find a bug that has not yet been fixed, or it has been fixed but the PR hasn't been merged yet. Or you need an extra feature, but it is very specific and adding it to the library would not benefit that many users compared to the cost of maintainance. So what are your options... Fork the package? Depend on a git commit and build manually? There's a simpler solution: patch-package to the rescue!
This post is a follow-up to one of my older posts, with a more recent approach to the same problem.
pacth-package is a neat tool that will allow you to change the code in your node_modules so that you can fix a temporary bug, or adapt a package to your specific needs!
yarn add patch-package
yarn patch-package left-pad
yarn patch-packageto your
You're all set!
You will notice a new folder
patches at the root of your project. It will contain all the patches for all the modules you patched.
When you upgrade a module, patch-package will warn you that the patch may be outdated. You will need to run
yarn patch-package left-pad again. If there is no conflict, the patch will be upgraded as well, and nothing will be left to do. if the package has been modified at the same places as your patch did, then you will need to delete your patch, and follow the previous steps from the start.
When the fix you have been waiting for has finally been released, or you deleted the package, you don't need the patch anymore! You can safely delete it in the