Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Allow customizing packages on install #94

Closed
begriffs opened this issue Jan 28, 2020 · 4 comments
Closed

[FEATURE] Allow customizing packages on install #94

begriffs opened this issue Jan 28, 2020 · 4 comments

Comments

@begriffs
Copy link

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
@isaacs
Copy link
Contributor

isaacs commented Jan 28, 2020

If this is really about donation request banners, they're being phased out in favor of the funding package.json stanza and npm fund command anyway. So I'd like to see another use case, at least, since that one won't matter soon enough.

What happens when the patch doesn't apply?

This feels like one hell of a footgun. I have deep misgivings about supporting it.

@begriffs
Copy link
Author

begriffs commented Jan 29, 2020 via email

@isaacs
Copy link
Contributor

isaacs commented Jan 29, 2020

Ok, then I'm gonna close this.

I know that there are registry-side tools that float patches like this, typically for security patches or bugfixes, but it seems like not an ideal fit for the cli.

Thanks for bringing it up, all the same :)

@isaacs isaacs closed this as completed Jan 29, 2020
@markcellus
Copy link

FWIW, patch-package would be great for this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants