Skip to content

[FEATURE] Allow customizing packages on install #94

Description

@begriffs

What / Why

Currently running npm install fetches and installs a package as-is. However it would be more flexible to be able to specify a patch to apply at installation time to customize a package. One use case is to modify the package source to remove donation banners in install logs.

This is complementary to -- and more general than -- #80.

When

At install time, with the presence of a new flag.

How

Add a --patch /path/to/my.patch option to npm install. NPM would then fetch the source as usual, run patch -p0 < /path/to/my.patch to apply the customization, and continue with the normal installation process.

Example

Suppose you want to install core-js without its donation banner breaking your continuous integration. You can already use npm install --loglevel silent, but this will silence other potentially useful messages.

Instead, the user could create a patch file, e.g. nobanner.patch:

--- packages/core-js/postinstall.js
+++ packages/core-js/postinstall.js
@@ -52,5 +52,3 @@
   // eslint-disable-next-line no-console,no-control-regex
   console.log(COLOR ? BANNER : BANNER.replace(/\u001B\[\d+m/g, ''));
 }
-
-if (isBannerRequired()) showBanner();

Then, using the proposed feature, run:

npm install --patch nobanner.patch core-js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions