Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(diff): fix prerelease to stable version diff logic #755

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions functions/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@ const diff = (version1, version2) => {
return 'major'
}

// Otherwise it can be determined by checking the high version

if (highVersion.patch) {
// anything higher than a patch bump would result in the wrong version
// If the main part has no difference
if (lowVersion.compareMain(highVersion) === 0) {
if (lowVersion.minor && !lowVersion.patch) {
return 'minor'
}
return 'patch'
}

if (highVersion.minor) {
// anything higher than a minor bump would result in the wrong version
return 'minor'
}

// bumping major/minor/patch all have same result
return 'major'
}

// add the `pre` prefix if we are going to a prerelease version
Expand Down
7 changes: 7 additions & 0 deletions test/functions/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ test('diff versions test', (t) => {
['1.0.0-1', '2.0.0-1', 'premajor'],
['1.0.0-1', '1.1.0-1', 'preminor'],
['1.0.0-1', '1.0.1-1', 'prepatch'],
['1.7.2-1', '1.8.1', 'minor'],
['1.1.1-pre', '2.1.1-pre', 'premajor'],
['1.1.1-pre', '2.1.1', 'major'],
['1.2.3-1', '1.2.3', 'patch'],
['1.4.0-1', '2.3.5', 'major'],
['1.6.1-5', '1.7.2', 'minor'],
['2.0.0-1', '2.1.1', 'major'],
].forEach((v) => {
const version1 = v[0]
const version2 = v[1]
Expand Down