Sometimes it's necessary to patch a package. Maybe it 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?
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)
npm patch add-pr <name> <pr> will create a patch for a package from a PR on the package's repoistory (pulled from package.json)
--repo-path points to a git clone which can be used instead of a fresh clone
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.
Sometimes it's necessary to patch a package. Maybe it 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?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)npm patch add-pr <name> <pr>will create a patch for a package from a PR on the package'srepoistory(pulled from package.json)--repo-pathpoints to a git clone which can be used instead of a fresh cloneAlso, 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.