diff --git a/doc/cli/version.md b/doc/cli/version.md index 76d2e390c4d..480c90d3b4c 100644 --- a/doc/cli/version.md +++ b/doc/cli/version.md @@ -10,8 +10,13 @@ npm-version(1) -- Bump a package version Run this in a package directory to bump the version and write the new data back to the package.json file. +The `newversion` argument should be a valid semver string, *or* a valid +second argument to semver.inc (one of "patch", "minor", or "major"). In +the second case, the existing version will be incremented by that amount. + If run in a git repo, it will also create a version commit and tag, and fail if the repo is not clean. + If supplied with `--message` (shorthand: `-m`) command line option, npm will use it as a commit message when creating a version commit. diff --git a/lib/version.js b/lib/version.js index 2ebd02bc008..e626e474a35 100644 --- a/lib/version.js +++ b/lib/version.js @@ -21,10 +21,11 @@ version.usage = "npm version [--message commit-message]" function version (args, cb) { if (args.length !== 1) return cb(version.usage) - var newVer = semver.valid(args[0]) - if (!newVer) return cb(version.usage) readJson(path.join(process.cwd(), "package.json"), function (er, data) { if (er) return log.er(cb, "No package.json found")(er) + var newVer = semver.valid(args[0]) + if (!newVer) newVer = semver.inc(data.version, args[0]) + if (!newVer) return cb(version.usage) if (data.version === newVer) return cb(new Error("Version not changed")) data.version = newVer Object.keys(data).forEach(function (k) {