Skip to content

Commit

Permalink
doc: document prepublish-on-install deprecation
Browse files Browse the repository at this point in the history
Now all we have to remember to do is come back to this when we put out
`npm@5`.

PR-URL: npm/npm#14290
Credit: @othiym23
Reviewed-By: @watilde
Reviewed-By: @iarna
Reviewed-By: @zkat
  • Loading branch information
othiym23 authored and zkat committed Oct 20, 2016
1 parent 52fdefd commit c12bbf8
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions doc/misc/npm-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ npm-scripts(7) -- How npm handles the "scripts" field
npm supports the "scripts" property of the package.json script, for the
following scripts:

* prepare:
Run both before the package is published, and on local `npm
install` without any arguments. (See below.)
* prepublish:
Run BEFORE the package is published. (Also run on local `npm
install` without any arguments.)
install` without any arguments. See below.)
* prepublishOnly:
Run BEFORE the package is published. (See below.)
* publish, postpublish:
Run AFTER the package is published.
* preinstall:
Expand Down Expand Up @@ -43,7 +48,30 @@ names will be run for those as well (e.g. `premyscript`, `myscript`,
`postmyscript`). Scripts from dependencies can be run with `npm explore
<pkg> -- npm run <stage>`.

## COMMON USES
## PREPUBLISH AND PREPARE

### DEPRECATION NOTE

Since `[email protected]`, the npm CLI has run the `prepublish` script for both `npm
publish` and `npm install`, because it's a convenient way to prepare a package
for use (some common use cases are described in the section below). It has
also turned out to be, in practice, [very
confusing](https://github.com/npm/npm/issues/10074). As of `[email protected]`, a new
event has been introduced, `prepare`, that preserves this existing behavior. A
_new_ event, `prepublishOnly` has been added as a transitional strategy to
allow users to avoid the confusing behavior of existing npm versions and only
run on `npm publish` (for instance, running the tests one last time to ensure
they're in good shape).

**IMPORTANT:** As of `npm@5`, `prepublish` will _only_ be run for `npm
publish`. This will make its behavior identical to `prepublishOnly`, so
`npm@6` or later may drop support for the use of `prepublishOnly`, and then
maybe we can all forget this embarrassing thing ever happened.

See <https://github.com/npm/npm/issues/10074> for a much lengthier
justification, with further reading, for this change.

### USE CASES

If you need to perform operations on your package before it is used, in a way
that is not dependent on the operating system or architecture of the
Expand Down

0 comments on commit c12bbf8

Please sign in to comment.