-
Notifications
You must be signed in to change notification settings - Fork 251
Description
Hi there, first of all, thanks for all of the hard work on npm and everything surrounding it! Really cool what you are doing.
Motivation ("The Why")
The behavior of npm to not run preinstall or postinstall scripts specified by the developer in the project on every npm install <pkg name> is confusing and leads to support requests such as npm/cli#1732
Would you consider starting to run these scripts once during installation of a package?
Example
npm install node-fetch # would also run the `postinstall` scriptHow
Current Behaviour
preinstall and postinstall scripts are not run during npm install <pkg>
Desired Behaviour
the scripts are run
References
- Originally a Discussion in
npm/feedback: Run preinstall / postinstall scripts on single package installation feedback#217, and @MylesBorins mentioned I should make an RFC here
My original use case was to be able to also install the corresponding @types/<pkg name> DefinitelyTyped dep (à la #328). See here for my original naïve approach (which ended up failing): https://github.com/jeffijoe/typesync/pull/65/files
Alternatives Considered
Hook Scripts
In the Open RFC Meeting on Feb 17, 2021 @darcyclarke and others mentioned Hook Scripts.
There are two downsides I've run into so far:
- they seem to be broken in npm v7 [BUG] Hook Scripts Not Run on
npm installcli#2692 - in npm v6, a
postinstallhook script, for example, runs once for every package that has been installed. So this means that with anode_modules/.hooks/postinstallscript, if you runnpm installwith yourpackage.jsoncontaining 20 dependencies, this script will run at least 20 times, and even more if those dependencies specify transitive dependencies...