[RRFC] Run preinstall / postinstall scripts on single package installation
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 777
- Forks
- 267
- PR merge metrics
- No merged PRs in 30d
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 https://github.com/npm/cli/issues/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` script
How
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: https://github.com/npm/feedback/discussions/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 https://github.com/npm/cli/issues/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...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Current Behaviour and Desired Behaviour sections, then read the linked npm/feedback discussion and related references including issues #1732, #2692, and RFC #326. Done means the proposal resolves how npm should run the project’s preinstall and postinstall scripts during single-package installation without relying on the alternatives described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100