Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lifecycle of npm install

Tags:

node.js

npm

Npm install executes certain scripts like preinstall , postinstall and others.

I couldn't find explicit list and ordering of these scripts. It would be great to get some clarification and detailed overview of this process.

like image 486
husayt Avatar asked Feb 06 '17 20:02

husayt


1 Answers

It is described on the NPM page: npm-scripts. It is a bit cryptic, but the logic is straightforward.

E.g. running npm install will do preinstall install postinstall prepublish - this is rather exceptional case, prepublish only runs if there are no arguments, i.e. run locally. Also check which version of npm you are running, as prepublish with local install has been deprecated in 4.x in favour of another approach, described in issue 10074 and has a nice explanation in this blog. It comes down to the fact that npm install without arguments runs when you clone a package and it makes sense to prepare it. But people dislike this behaviour, so it was decided to split prepublish into two stages. prepare runs instead of prepublish during publishing and local npm install. prepublishOnly runs only with npm publish.

Hence npm publish will do prepublish publish postpublish or prepare prepublishOnly publish postpublish on 4.x

Finally, with version 6.x, npm install runs preinstall install postinstall prepare while npm publish runs prepare prepublish publish postpublish.

As far as I know, all other commands follow the logic of preX, X, postX.

like image 102
Alex Pakka Avatar answered Sep 24 '22 06:09

Alex Pakka