@@ -13,6 +13,35 @@ const diff = (version1, version2) => {
1313 const highVersion = v1Higher ? v1 : v2
1414 const lowVersion = v1Higher ? v2 : v1
1515 const highHasPre = ! ! highVersion . prerelease . length
16+ const lowHasPre = ! ! lowVersion . prerelease . length
17+
18+ if ( lowHasPre && ! highHasPre ) {
19+ // Going from prerelease -> no prerelease requires some special casing
20+
21+ // If the low version has only a major, then it will always be a major
22+ // Some examples:
23+ // 1.0.0-1 -> 1.0.0
24+ // 1.0.0-1 -> 1.1.1
25+ // 1.0.0-1 -> 2.0.0
26+ if ( ! lowVersion . patch && ! lowVersion . minor ) {
27+ return 'major'
28+ }
29+
30+ // Otherwise it can be determined by checking the high version
31+
32+ if ( highVersion . patch ) {
33+ // anything higher than a patch bump would result in the wrong version
34+ return 'patch'
35+ }
36+
37+ if ( highVersion . minor ) {
38+ // anything higher than a minor bump would result in the wrong version
39+ return 'minor'
40+ }
41+
42+ // bumping major/minor/patch all have same result
43+ return 'major'
44+ }
1645
1746 // add the `pre` prefix if we are going to a prerelease version
1847 const prefix = highHasPre ? 'pre' : ''
@@ -29,26 +58,8 @@ const diff = (version1, version2) => {
2958 return prefix + 'patch'
3059 }
3160
32- // at this point we know stable versions match but overall versions are not equal,
33- // so either they are both prereleases, or the lower version is a prerelease
34-
35- if ( highHasPre ) {
36- // high and low are preleases
37- return 'prerelease'
38- }
39-
40- if ( lowVersion . patch ) {
41- // anything higher than a patch bump would result in the wrong version
42- return 'patch'
43- }
44-
45- if ( lowVersion . minor ) {
46- // anything higher than a minor bump would result in the wrong version
47- return 'minor'
48- }
49-
50- // bumping major/minor/patch all have same result
51- return 'major'
61+ // high and low are preleases
62+ return 'prerelease'
5263}
5364
5465module . exports = diff
0 commit comments