Motivation ("The Why")
Sometimes it's necessary to patch a package. Maybe it's exposing internals that need to be hooked into, maybe it's getting a PR before it gets merged.
At the moment, one has to use a package like patch-package to do this. patch-package is unfortunately unmaintained though and has issues with install-strategy=linked and workspaces. This has made me very disgruntled.
Other package managers in the ecosystem (pnpm and yarn) have a built-in patch sub-command, so why not npm?
Example
Look at the myriad cases of patch-package. For example, there is a patch to add microsoft/TypeScript#63008.
How
I'm thinking the CLI could look like this:
npm patch apply [patches...] will apply patches. If no arguments are passed, all configured patches will be applied, otherwise only the specified patches will be applied
npm patch add <name> will create a patch for a package using changes in the working node_modules (similar to patch-package xxx)
Also, A feature I think would be really nice to have is patching in dependants, for example:
@ducks/quack patches typescript to add a feature PR
@ducks/mallard depends on @ducks/quack, npm i @ducks/quack results in the patch being applied
This could be accomplished through the use of a patches field in package.json, or something similar.
References
https://github.com/ds300/patch-package (unmaintained)
Motivation ("The Why")
Sometimes it's necessary to patch a package. Maybe it's exposing internals that need to be hooked into, maybe it's getting a PR before it gets merged.
At the moment, one has to use a package like
patch-packageto do this.patch-packageis unfortunately unmaintained though and has issues withinstall-strategy=linkedand workspaces. This has made me very disgruntled.Other package managers in the ecosystem (
pnpmandyarn) have a built-inpatchsub-command, so why not npm?Example
Look at the myriad cases of
patch-package. For example, there is a patch to add microsoft/TypeScript#63008.How
I'm thinking the CLI could look like this:
npm patch apply [patches...]will apply patches. If no arguments are passed, all configured patches will be applied, otherwise only the specified patches will be appliednpm patch add <name>will create a patch for a package using changes in the working node_modules (similar topatch-package xxx)Also, A feature I think would be really nice to have is patching in dependants, for example:
@ducks/quackpatchestypescriptto add a feature PR@ducks/mallarddepends on@ducks/quack,npm i @ducks/quackresults in the patch being appliedThis could be accomplished through the use of a
patchesfield inpackage.json, or something similar.References
https://github.com/ds300/patch-package (unmaintained)