Failure to run `prepublishOnly` should always throw an error rather than just a warning

cli
help-wanted
priority:medium
triaged

(Pierre Vanduynslager) #1

What I Wanted to Do

Configure a build script to run before publishing, by calling it in prepublishOnly script.

What Happened Instead

When running npm publish, due to a permission error the prepublishOnly failed with the following error:

prepublishOnly: cannot run in wd @xxxxxt@xxxx npm run build (wd=xxxxxxx)

But instead of stopping there the publication continued and ended up publish a broken package as the built assets where not generated.

This problem happens only in the case of the cannot run in wd error. If the prepublishOnly scripts runs and fails, the error does stop the publication as expected.

Reproduction Steps

See issue https://github.com/semantic-release/semantic-release/issues/956 for more details.
The permission error is difficult to reproduce…It seems environment specific.

Details

The problem seems to come from here: https://github.com/npm/npm-lifecycle/blob/8fcaa21c580b09f5b9818920f6e29b63272e1975/index.js#L72

The code should log an error and call reject, at least when running the prepublishOnly or prepare lifecycle events. Not sure if there is cases where failing to run a script is not an error…