diff options
author | isaacs <i@izs.me> | 2014-05-07 05:17:22 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-05-07 05:18:04 +0400 |
commit | e1160eba7ac481a0c0523774cdfc53e1dd054104 (patch) | |
tree | fc3223e98c14c3b41eb2f300a69f3f9a65593dbd /node_modules/semver/semver.js | |
parent | 79a102f922c5c53576773a9d212a513a7d6a5894 (diff) |
semver@2.3.0
This adds the "prerelease", "prepatch", "preminor", "premajor" options
for `npm version`.
Diffstat (limited to 'node_modules/semver/semver.js')
-rw-r--r-- | node_modules/semver/semver.js | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/node_modules/semver/semver.js b/node_modules/semver/semver.js index 9e9470d86..a7385b41c 100644 --- a/node_modules/semver/semver.js +++ b/node_modules/semver/semver.js @@ -258,6 +258,8 @@ function SemVer(version, loose) { return version; else version = version.version; + } else if (typeof version !== 'string') { + throw new TypeError('Invalid Version: ' + version); } if (!(this instanceof SemVer)) @@ -330,7 +332,7 @@ SemVer.prototype.comparePre = function(other) { return -1; else if (!this.prerelease.length && other.prerelease.length) return 1; - else if (!this.prerelease.lenth && !other.prerelease.length) + else if (!this.prerelease.length && !other.prerelease.length) return 0; var i = 0; @@ -351,19 +353,49 @@ SemVer.prototype.comparePre = function(other) { } while (++i); }; +// preminor will bump the version up to the next minor release, and immediately +// down to pre-release. premajor and prepatch work the same way. SemVer.prototype.inc = function(release) { switch (release) { + case 'premajor': + this.inc('major'); + this.inc('pre'); + break; + case 'preminor': + this.inc('minor'); + this.inc('pre'); + break; + case 'prepatch': + this.inc('patch'); + this.inc('pre'); + break; + // If the input is a non-prerelease version, this acts the same as + // prepatch. + case 'prerelease': + if (this.prerelease.length === 0) + this.inc('patch'); + this.inc('pre'); + break; case 'major': this.major++; this.minor = -1; case 'minor': this.minor++; - this.patch = -1; + this.patch = 0; + this.prerelease = []; + break; case 'patch': - this.patch++; + // If this is not a pre-release version, it will increment the patch. + // If it is a pre-release it will bump up to the same patch version. + // 1.2.0-5 patches to 1.2.0 + // 1.2.0 patches to 1.2.1 + if (this.prerelease.length === 0) + this.patch++; this.prerelease = []; break; - case 'prerelease': + // This probably shouldn't be used publically. + // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction. + case 'pre': if (this.prerelease.length === 0) this.prerelease = [0]; else { |