Skip to content

[RRFC] Built-in npm patch? #865

@james-pre

Description

@james-pre

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions