Skip to content

fix pre* increments, add release increment #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 23 additions & 27 deletions classes/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,40 +173,37 @@ class SemVer {
} 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.
// preminor will bump the version up to the next minor release, and immediately down to prerelease. premajor and prepatch work the same way. If the version is already a prerelease for that release type, only the identifier is incremented instead.
inc (release, identifier, identifierBase) {
const inferredIdentifier = identifier || this.prerelease[0] || undefined
switch (release) {
case 'premajor':
case 'release':
if (this.prerelease.length === 0) {
throw new Error(`version ${this.raw} is not a prerelease`)
}
this.prerelease.length = 0
this.patch = 0
this.minor = 0
this.major++
this.inc('pre', identifier, identifierBase)
break
case 'premajor':
if (this.minor || this.patch || this.prerelease.length === 0) {
this.prerelease.length = 0
this.inc('major')
}
this.inc('pre', inferredIdentifier, identifierBase)
break
case 'preminor':
this.prerelease.length = 0
this.patch = 0
this.minor++
this.inc('pre', identifier, identifierBase)
if (this.patch || this.prerelease.length === 0) {
this.prerelease.length = 0
this.inc('minor')
}
this.inc('pre', inferredIdentifier, identifierBase)
break
case 'prepatch':
// If this is already a prerelease, it will bump to the next version
// drop any prereleases that might already exist, since they are not
// relevant at this point.
this.prerelease.length = 0
this.inc('patch', identifier, identifierBase)
this.inc('pre', identifier, identifierBase)
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', identifier, identifierBase)
this.inc('patch')
}
this.inc('pre', identifier, identifierBase)
this.inc('pre', inferredIdentifier, identifierBase)
break

case 'major':
// If this is a pre-major version, bump up to the same major version.
// Otherwise increment major.
Expand Down Expand Up @@ -235,17 +232,16 @@ class SemVer {
this.prerelease = []
break
case '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.
// If this is not a prerelease version, it will increment the patch.
// If it is a prerelease 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
// This probably shouldn't be used publicly.
// 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
// This does the "pre" part of "premajor" et al. If there is not already a prerelease this affects a decrease operation, not an increase. Because of that it probably shouldn't be used publicly.
case 'pre': {
const base = Number(identifierBase) ? 1 : 0

Expand Down
Loading