diff options
Diffstat (limited to 'deps/npm/doc/cli/npm-version.md')
-rw-r--r-- | deps/npm/doc/cli/npm-version.md | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/deps/npm/doc/cli/npm-version.md b/deps/npm/doc/cli/npm-version.md index 63a5e9512..0a00e78cd 100644 --- a/deps/npm/doc/cli/npm-version.md +++ b/deps/npm/doc/cli/npm-version.md @@ -11,14 +11,15 @@ Run this in a package directory to bump the version and write the new data back to `package.json` and, if present, `npm-shrinkwrap.json`. The `newversion` argument should be a valid semver string, *or* a -valid second argument to semver.inc (one of "patch", "minor", "major", -"prepatch", "preminor", "premajor", "prerelease"). In the second case, +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 @@ -40,13 +41,35 @@ in your git config for this to work properly. For example: Enter passphrase: -If "preversion", "version", "postversion" in the "scripts" property of -the package.json, it will execute by running `npm version`. preversion -and version ware executed before bump the package version, postversion -was executed after bump the package version. For example to run `npm version` -after passed all test: - - "scripts": { "preversion": "npm test" } +If `preversion`, `version`, or `postversion` are in the `scripts` property of +the package.json, they will be executed as part of running `npm version`. + +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 |