Tool for patching buggy NPM packages instead of forking them
npm install custompatchjsdiff published on the NPM registry but it is a bogus one)
bash
npm install custompatch -g
`
Setup
It operates in exactly the same way as patch-package so you can use the same setup if you have it already.
Add the following to your package.json
`json
"scripts":
{
"prepare": "custompatch"
}
`
Usage
$3
Open your IDE and make the required changes for the bugfix inside your dependency in node_modules. After that run
`bash
custompatch "name-of-the-buggy-package"
`
This will create a folder called patches inside your project and a file called name-of-the-buggy-package#version.patch in this folder.
This file will be a unified diff between your fixed version of the dependency and its original code.
You can specify more than 1 package on the command-line - but no command-line options are accepted.
$3
The process is exactly the same as for creating a patch for the first time.
$3
Run custompatch without arguments inside your project folder - it will apply all the patches from patches folder.
If you want to target specific patches you can use the --patch (-p) flag like so:
`bash
custompatch --patch [name-of-the-buggy-package]
`
$3
To reverse all patches you can use the --reverse (-r) flag like so:
`bash
custompatch --reverse
`
To reverse specific patches you can use the --reverse (-r) flag like so:
`bash
custompatch --reverse [name-of-the-buggy-package]
`
Benefits of patching over forking
- Forks often require extra build steps - and even more often you do not need this overhead
- CustomPatch warns you when a patch was not applied cleanly - so that you can check that your fix is still valid for the new version of dependency
- Keep your patches colocated with the code that depends on them
- Patches can be reviewed as part of your normal review process, forks probably can't
Patch filenames format
The filename of a patch will be composed as packageName, followed by the # symbol, followed by packageSemVer (and the extension is .patch)
If the packageName contains a symbol which collides with the directory separator of the current filesystem - these symbols will be replaced with +`