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

recommend postinstall instead of prepare? #1309

Closed
trusktr opened this issue Oct 14, 2023 · 1 comment
Closed

recommend postinstall instead of prepare? #1309

trusktr opened this issue Oct 14, 2023 · 1 comment

Comments

@trusktr
Copy link

trusktr commented Oct 14, 2023

The prepare script runs any time that the package needs to be prepared (built). For example, prepare runs when the package will be packed. When installing a library from a git repo for example, the prepare hook will run, and it will have access to devDependencies in NPM's local checkout for the purposes of being able to run build tools, etc. This way, once the git pakage is packed up, it will work as expect the same as if it were published to the npmjs.com registry.

It seems like postinstall is a better package.json hook because it runs in less situations, while prepare runs in a lot more that don't make as much sense.

F.e. base on the docs, postinstall runs when:

  • npm ci in a project
  • npm install in a project
  • npm install --global <pkg name> in the installed project? Not sure about this one, I have never relied on it.
  • npm rebuild

On the other hand, prepare runs during all of the above, plus:

  • npm cache add
  • npm diff
  • npm pack
  • npm publish

and it seems like we don't really need to run git hook installation during cache, diff, pack, or publish.

@typicode
Copy link
Owner

You can find a detailed explanation here:
#884

But in short, postinstall will be executed when you run npm install some-package. While prepare will run in "development" only.

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

2 participants