Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/cli/npm-version.md')
-rw-r--r--doc/cli/npm-version.md39
1 files changed, 31 insertions, 8 deletions
diff --git a/doc/cli/npm-version.md b/doc/cli/npm-version.md
index 21295027f..0527a4d71 100644
--- a/doc/cli/npm-version.md
+++ b/doc/cli/npm-version.md
@@ -19,10 +19,11 @@ valid second argument to semver.inc (one of `patch`, `minor`, `major`,
`prepatch`, `preminor`, `premajor`, `prerelease`). In the second case,
the existing version will be incremented by 1 in the specified field.
-If run in a git repo, it will also create a version commit and tag, and fail if
-the repo is not clean. This behavior is controlled by `git-tag-version` (see
-below), and can be disabled on the command line by running `npm
---no-git-tag-version version`
+If run in a git repo, it will also create a version commit and tag.
+This behavior is controlled by `git-tag-version` (see below), and can
+be disabled on the command line by running `npm --no-git-tag-version version`.
+It will fail if the working directory is not clean, unless the `--force`
+flag is set.
If supplied with `--message` (shorthand: `-m`) config option, npm will
use it as a commit message when creating a version commit. If the
@@ -46,11 +47,33 @@ in your git config for this to work properly. For example:
If `preversion`, `version`, or `postversion` are in the `scripts` property of
the package.json, they will be executed as part of running `npm version`.
-`preversion` and `version` are executed before bumping the package version, and
-`postversion` is executed afterwards. For example, to run `npm version` only if
-all tests pass:
- "scripts": { "preversion": "npm test" }
+The exact order of execution is as follows:
+ 1. Check to make sure the git working directory is clean before we get started.
+ Your scripts may add files to the commit in future steps.
+ This step is skipped if the `--force` flag is set.
+ 2. Run the `preversion` script. These scripts have access to the old `version` in package.json.
+ A typical use would be running your full test suite before deploying.
+ Any files you want added to the commit should be explicitly added using `git add`.
+ 3. Bump `version` in `package.json` as requested (`patch`, `minor`, `major`, etc).
+ 4. Run the `version` script. These scripts have access to the new `version` in package.json
+ (so they can incorporate it into file headers in generated files for example).
+ Again, scripts should explicitly add generated files to the commit using `git add`.
+ 5. Commit and tag.
+ 6. Run the `postversion` script. Use it to clean up the file system or automatically push
+ the commit and/or tag.
+
+Take the following example:
+
+ "scripts": {
+ "preversion": "npm test",
+ "version": "npm run build && git add -A dist",
+ "postversion": "git push && git push --tags && rm -rf build/temp"
+ }
+
+This runs all your tests, and proceeds only if they pass. Then runs your `build` script, and
+adds everything in the `dist` directory to the commit. After the commit, it pushes the new commit
+and tag up to the server, and deletes the `build/temp` directory.
## CONFIGURATION