@@ -11,14 +11,15 @@ Run this in a package directory to bump the version and write the new
1111data back to ` package.json ` and, if present, ` npm-shrinkwrap.json ` .
1212
1313The ` newversion ` argument should be a valid semver string, * or* a
14- valid second argument to semver.inc (one of " patch", " minor", " major" ,
15- " prepatch", " preminor", " premajor", " prerelease" ). In the second case,
14+ valid second argument to semver.inc (one of ` patch ` , ` minor ` , ` major ` ,
15+ ` prepatch ` , ` preminor ` , ` premajor ` , ` prerelease ` ). In the second case,
1616the existing version will be incremented by 1 in the specified field.
1717
18- If run in a git repo, it will also create a version commit and tag, and fail if
19- the repo is not clean. This behavior is controlled by ` git-tag-version ` (see
20- below), and can be disabled on the command line by running `npm
21- --no-git-tag-version version`
18+ If run in a git repo, it will also create a version commit and tag.
19+ This behavior is controlled by ` git-tag-version ` (see below), and can
20+ be disabled on the command line by running ` npm --no-git-tag-version version ` .
21+ It will fail if the working directory is not clean, unless the ` --force `
22+ flag is set.
2223
2324If supplied with ` --message ` (shorthand: ` -m ` ) config option, npm will
2425use it as a commit message when creating a version commit. If the
@@ -40,13 +41,35 @@ in your git config for this to work properly. For example:
4041
4142 Enter passphrase:
4243
43- If "preversion", "version", "postversion" in the "scripts" property of
44- the package.json, it will execute by running ` npm version ` . preversion
45- and version ware executed before bump the package version, postversion
46- was executed after bump the package version. For example to run ` npm version `
47- after passed all test:
48-
49- "scripts": { "preversion": "npm test" }
44+ If ` preversion ` , ` version ` , or ` postversion ` are in the ` scripts ` property of
45+ the package.json, they will be executed as part of running ` npm version ` .
46+
47+ The exact order of execution is as follows:
48+ 1 . Check to make sure the git working directory is clean before we get started.
49+ Your scripts may add files to the commit in future steps.
50+ This step is skipped if the ` --force ` flag is set.
51+ 2 . Run the ` preversion ` script. These scripts have access to the old ` version ` in package.json.
52+ A typical use would be running your full test suite before deploying.
53+ Any files you want added to the commit should be explicitly added using ` git add ` .
54+ 3 . Bump ` version ` in ` package.json ` as requested (` patch ` , ` minor ` , ` major ` , etc).
55+ 4 . Run the ` version ` script. These scripts have access to the new ` version ` in package.json
56+ (so they can incorporate it into file headers in generated files for example).
57+ Again, scripts should explicitly add generated files to the commit using ` git add ` .
58+ 5 . Commit and tag.
59+ 6 . Run the ` postversion ` script. Use it to clean up the file system or automatically push
60+ the commit and/or tag.
61+
62+ Take the following example:
63+
64+ "scripts": {
65+ "preversion": "npm test",
66+ "version": "npm run build && git add -A dist",
67+ "postversion": "git push && git push --tags && rm -rf build/temp"
68+ }
69+
70+ This runs all your tests, and proceeds only if they pass. Then runs your ` build ` script, and
71+ adds everything in the ` dist ` directory to the commit. After the commit, it pushes the new commit
72+ and tag up to the server, and deletes the ` build/temp ` directory.
5073
5174## CONFIGURATION
5275
0 commit comments