Feature Request: prepare script that does not run before publish

(Cameron Tacklind) #1

When developing npm packages, (projects with package.json at the root), it is common to specify extra setup steps needed to begin development. Specifically, it is common to see a readme like this:


Install dependencies and setup development environment

npm install

It would be awesome to have a “postinstall” script that only runs when npm install is run without arguments. Then the above could simply be:

npm install

Unfortunately, you can’t use postinstall (on published packages) because then the script is run when the package is included as a dependency.

Fortunately, this is exactly what the prepare script does if you can deal with the fact that it also runs before publishing. Regardless, I think a new script is warranted.

“postinstallOnly” might be an apt name…

(Daniel Stockman) #2

I don’t personally feel this is justified; if a contributor is unwilling to read the documentation, I personally would rather they didn’t contribute…

I suppose the larger question begging here is: why does the dev setup in this example involve steps that can’t be run during the npm publish lifecycles?

(Cameron Tacklind) #3

Anything that can be done to remove barriers for other developers to help is justified, imho. You may like to run your project another way. To each their own.

A sophisticated enough script could likely easily detect when it is not needed to be run. This would take care of the issue of the script also running before npm publish (when listed as a prepare script).

However, the same could be said for prepublish script and that one also running (weirdly imho) on npm install (with no args). Yet the community decided that a new script should be added prepublishOnly. In the same vein, I think postinstallOnly should be added.