Skip to content

Built-in patch utility? #9341

@james-pre

Description

@james-pre

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.

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