@@ -8980,7 +8980,7 @@ class SemVer {
8980
8980
8981
8981
if ( version instanceof SemVer ) {
8982
8982
if ( version . loose === ! ! options . loose &&
8983
- version . includePrerelease === ! ! options . includePrerelease ) {
8983
+ version . includePrerelease === ! ! options . includePrerelease ) {
8984
8984
return version
8985
8985
} else {
8986
8986
version = version . version
@@ -9146,6 +9146,19 @@ class SemVer {
9146
9146
// preminor will bump the version up to the next minor release, and immediately
9147
9147
// down to pre-release. premajor and prepatch work the same way.
9148
9148
inc ( release , identifier , identifierBase ) {
9149
+ if ( release . startsWith ( 'pre' ) ) {
9150
+ if ( ! identifier && identifierBase === false ) {
9151
+ throw new Error ( 'invalid increment argument: identifier is empty' )
9152
+ }
9153
+ // Avoid an invalid semver results
9154
+ if ( identifier ) {
9155
+ const match = `-${ identifier } ` . match ( this . options . loose ? re [ t . PRERELEASELOOSE ] : re [ t . PRERELEASE ] )
9156
+ if ( ! match || match [ 1 ] !== identifier ) {
9157
+ throw new Error ( `invalid identifier: ${ identifier } ` )
9158
+ }
9159
+ }
9160
+ }
9161
+
9149
9162
switch ( release ) {
9150
9163
case 'premajor' :
9151
9164
this . prerelease . length = 0
@@ -9176,6 +9189,12 @@ class SemVer {
9176
9189
}
9177
9190
this . inc ( 'pre' , identifier , identifierBase )
9178
9191
break
9192
+ case 'release' :
9193
+ if ( this . prerelease . length === 0 ) {
9194
+ throw new Error ( `version ${ this . raw } is not a prerelease` )
9195
+ }
9196
+ this . prerelease . length = 0
9197
+ break
9179
9198
9180
9199
case 'major' :
9181
9200
// If this is a pre-major version, bump up to the same major version.
@@ -9219,10 +9238,6 @@ class SemVer {
9219
9238
case 'pre' : {
9220
9239
const base = Number ( identifierBase ) ? 1 : 0
9221
9240
9222
- if ( ! identifier && identifierBase === false ) {
9223
- throw new Error ( 'invalid increment argument: identifier is empty' )
9224
- }
9225
-
9226
9241
if ( this . prerelease . length === 0 ) {
9227
9242
this . prerelease = [ base ]
9228
9243
} else {
@@ -9481,20 +9496,13 @@ const diff = (version1, version2) => {
9481
9496
return 'major'
9482
9497
}
9483
9498
9484
- // Otherwise it can be determined by checking the high version
9485
-
9486
- if ( highVersion . patch ) {
9487
- // anything higher than a patch bump would result in the wrong version
9499
+ // If the main part has no difference
9500
+ if ( lowVersion . compareMain ( highVersion ) === 0 ) {
9501
+ if ( lowVersion . minor && ! lowVersion . patch ) {
9502
+ return 'minor'
9503
+ }
9488
9504
return 'patch'
9489
9505
}
9490
-
9491
- if ( highVersion . minor ) {
9492
- // anything higher than a minor bump would result in the wrong version
9493
- return 'minor'
9494
- }
9495
-
9496
- // bumping major/minor/patch all have same result
9497
- return 'major'
9498
9506
}
9499
9507
9500
9508
// add the `pre` prefix if we are going to a prerelease version
0 commit comments