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

[BUG] postinstall not exec when run npm install xxx, but npm install do #1732

Closed
zitup opened this issue Aug 27, 2020 · 3 comments
Closed

[BUG] postinstall not exec when run npm install xxx, but npm install do #1732

zitup opened this issue Aug 27, 2020 · 3 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 6.x work is associated with a specific npm 6 release

Comments

@zitup
Copy link

zitup commented Aug 27, 2020

Current Behavior:

postinstall don't exec when run npm install xxx, but just run npm install trigger execution
AND, script in node_modules/.hooks/postinstall will exec both in npm install xxx and npm install

Expected Behavior:

postinstall exec too when run npm install xxx

Steps To Reproduce:

package.json

 "scripts": {
    "postinstall": "node script.js"
  },

script

#!/usr/bin/env node

console.log("postinstall...");

console.log("    " + process.env.npm_package_name);

console.log("    " + process.env.PWD);

Environment:

  • OS: macOS 10.15.5
  • Node: 12.15.0
  • npm: 6.13.4
@zitup zitup added Bug thing that needs fixing Needs Triage needs review for next steps Release 6.x work is associated with a specific npm 6 release labels Aug 27, 2020
@zitup
Copy link
Author

zitup commented Sep 7, 2020

Nobody answered, closed.

@zitup zitup closed this as completed Sep 7, 2020
@karlhorky
Copy link
Contributor

I think this is known behavior for the npm CLI: https://npm.community/t/preinstall-npm-hook-doesnt-execute-when-installing-a-specific-package/2505

Yarn does run the postinstall after every install (which seems like the better option).

@zitup
Copy link
Author

zitup commented Feb 20, 2021

YES, yarn does well, I would love to see npm upgrade :)

And FYI @karlhorky , I discovered this problem when i was developing a module like typesync, but npm's problems stuck me

I mentioned above is one of these, another one is when you install two package use npm install xxx1 xxx2, script in ./hooks/postinstall will only process one, so strange...

In addition, i use exec('npm install @types/xxx') to install types package, but don't know why it executes very slowly, maybe add @types/xxx to package.json and exec npm install is a good idea.

And,

in npm v6, a postinstall hook script, for example, runs once for every package that has been installed. So this means that with a node_modules/.hooks/postinstall script, if you run npm install with your package.json containing 20 dependencies, this script will run at least 20 times, and even more if those dependencies specify transitive dependencies...

It's true...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 6.x work is associated with a specific npm 6 release
Projects
None yet
Development

No branches or pull requests

2 participants