Skip to content

Commit d588e37

Browse files
eminberkaydberkay.daglar
and
berkay.daglar
authored
fix(diff): fix prerelease to stable version diff logic (#755)
Refactored version diff logic to handle transitions from prerelease versions to stable versions correctly for major/minor/patch version bumps. Closes #606 --------- Co-authored-by: berkay.daglar <berkay.daglar@v-count.com>
1 parent 753e02b commit d588e37

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

functions/diff.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,13 @@ const diff = (version1, version2) => {
2727
return 'major'
2828
}
2929

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
30+
// If the main part has no difference
31+
if (lowVersion.compareMain(highVersion) === 0) {
32+
if (lowVersion.minor && !lowVersion.patch) {
33+
return 'minor'
34+
}
3435
return 'patch'
3536
}
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'
4437
}
4538

4639
// add the `pre` prefix if we are going to a prerelease version

test/functions/diff.js

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ test('diff versions test', (t) => {
3434
['1.0.0-1', '2.0.0-1', 'premajor'],
3535
['1.0.0-1', '1.1.0-1', 'preminor'],
3636
['1.0.0-1', '1.0.1-1', 'prepatch'],
37+
['1.7.2-1', '1.8.1', 'minor'],
38+
['1.1.1-pre', '2.1.1-pre', 'premajor'],
39+
['1.1.1-pre', '2.1.1', 'major'],
40+
['1.2.3-1', '1.2.3', 'patch'],
41+
['1.4.0-1', '2.3.5', 'major'],
42+
['1.6.1-5', '1.7.2', 'minor'],
43+
['2.0.0-1', '2.1.1', 'major'],
3744
].forEach((v) => {
3845
const version1 = v[0]
3946
const version2 = v[1]

0 commit comments

Comments
 (0)