@@ -8226,7 +8226,7 @@ class SemVer {
8226
8226
8227
8227
if (version instanceof SemVer) {
8228
8228
if (version.loose === !!options.loose &&
8229
- version.includePrerelease === !!options.includePrerelease) {
8229
+ version.includePrerelease === !!options.includePrerelease) {
8230
8230
return version
8231
8231
} else {
8232
8232
version = version.version
@@ -8392,6 +8392,19 @@ class SemVer {
8392
8392
// preminor will bump the version up to the next minor release, and immediately
8393
8393
// down to pre-release. premajor and prepatch work the same way.
8394
8394
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
+
8395
8408
switch (release) {
8396
8409
case 'premajor':
8397
8410
this.prerelease.length = 0
@@ -8422,6 +8435,12 @@ class SemVer {
8422
8435
}
8423
8436
this.inc('pre', identifier, identifierBase)
8424
8437
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
8425
8444
8426
8445
case 'major':
8427
8446
// If this is a pre-major version, bump up to the same major version.
@@ -8465,10 +8484,6 @@ class SemVer {
8465
8484
case 'pre': {
8466
8485
const base = Number(identifierBase) ? 1 : 0
8467
8486
8468
- if (!identifier && identifierBase === false) {
8469
- throw new Error('invalid increment argument: identifier is empty')
8470
- }
8471
-
8472
8487
if (this.prerelease.length === 0) {
8473
8488
this.prerelease = [base]
8474
8489
} else {
@@ -8727,20 +8742,13 @@ const diff = (version1, version2) => {
8727
8742
return 'major'
8728
8743
}
8729
8744
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
+ }
8734
8750
return 'patch'
8735
8751
}
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'
8744
8752
}
8745
8753
8746
8754
// add the `pre` prefix if we are going to a prerelease version
0 commit comments