@@ -8226,7 +8226,7 @@ class SemVer {
82268226
82278227 if (version instanceof SemVer) {
82288228 if (version.loose === !!options.loose &&
8229- version.includePrerelease === !!options.includePrerelease) {
8229+ version.includePrerelease === !!options.includePrerelease) {
82308230 return version
82318231 } else {
82328232 version = version.version
@@ -8392,6 +8392,19 @@ class SemVer {
83928392 // preminor will bump the version up to the next minor release, and immediately
83938393 // down to pre-release. premajor and prepatch work the same way.
83948394 inc (release, identifier, identifierBase) {
8395+ if (release.startsWith('pre')) {
8396+ if (!identifier && identifierBase === false) {
8397+ throw new Error('invalid increment argument: identifier is empty')
8398+ }
8399+ // Avoid an invalid semver results
8400+ if (identifier) {
8401+ const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE])
8402+ if (!match || match[1] !== identifier) {
8403+ throw new Error(`invalid identifier: ${identifier}`)
8404+ }
8405+ }
8406+ }
8407+
83958408 switch (release) {
83968409 case 'premajor':
83978410 this.prerelease.length = 0
@@ -8422,6 +8435,12 @@ class SemVer {
84228435 }
84238436 this.inc('pre', identifier, identifierBase)
84248437 break
8438+ case 'release':
8439+ if (this.prerelease.length === 0) {
8440+ throw new Error(`version ${this.raw} is not a prerelease`)
8441+ }
8442+ this.prerelease.length = 0
8443+ break
84258444
84268445 case 'major':
84278446 // If this is a pre-major version, bump up to the same major version.
@@ -8465,10 +8484,6 @@ class SemVer {
84658484 case 'pre': {
84668485 const base = Number(identifierBase) ? 1 : 0
84678486
8468- if (!identifier && identifierBase === false) {
8469- throw new Error('invalid increment argument: identifier is empty')
8470- }
8471-
84728487 if (this.prerelease.length === 0) {
84738488 this.prerelease = [base]
84748489 } else {
@@ -8727,20 +8742,13 @@ const diff = (version1, version2) => {
87278742 return 'major'
87288743 }
87298744
8730- // Otherwise it can be determined by checking the high version
8731-
8732- if (highVersion.patch) {
8733- // anything higher than a patch bump would result in the wrong version
8745+ // If the main part has no difference
8746+ if (lowVersion.compareMain(highVersion) === 0) {
8747+ if (lowVersion.minor && !lowVersion.patch) {
8748+ return 'minor'
8749+ }
87348750 return 'patch'
87358751 }
8736-
8737- if (highVersion.minor) {
8738- // anything higher than a minor bump would result in the wrong version
8739- return 'minor'
8740- }
8741-
8742- // bumping major/minor/patch all have same result
8743- return 'major'
87448752 }
87458753
87468754 // add the `pre` prefix if we are going to a prerelease version
0 commit comments