Skip to content

Commit

Permalink
fix: semver.diff prerelease to release recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
dominique-blockchain authored and wraithgar committed Apr 5, 2023
1 parent da08e01 commit 960a0f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 11 additions & 0 deletions functions/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ const diff = (version1, version2) => {
}
}
}
if (v1['major'] === v2['major'] &&
v1['minor'] === v2['minor'] &&
v1['patch'] === v2['patch'] && !(v1.prerelease.length && v2.prerelease.length)) {
const releaseTypes = []
for (const key in v1) {
if (key === 'major' || key === 'minor' || key === 'patch') {
if (v1[key]) releaseTypes.push(key);
}
}
return releaseTypes.pop();
}
return defaultResult // may be undefined
}
}
Expand Down
16 changes: 11 additions & 5 deletions test/functions/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ const diff = require('../../functions/diff')
test('diff versions test', (t) => {
// [version1, version2, result]
// diff(version1, version2) -> result
[['1.2.3', '0.2.3', 'major'],
[ ['1.2.3', '0.2.3', 'major'],
['0.2.3', '1.2.3', 'major'],
['1.4.5', '0.2.3', 'major'],
['1.2.3', '2.0.0-pre', 'premajor'],
['2.0.0-pre', '1.2.3', 'premajor'],
['1.2.3', '1.3.3', 'minor'],
['1.0.1', '1.1.0-pre', 'preminor'],
['1.2.3', '1.2.4', 'patch'],
['1.2.3', '1.2.4-pre', 'prepatch'],
['0.0.1', '0.0.1-pre', 'prerelease'],
['0.0.1', '0.0.1-pre-2', 'prerelease'],
['1.1.0', '1.1.0-pre', 'prerelease'],
['0.0.1', '0.0.1-pre', 'patch'],
['0.0.1', '0.0.1-pre-2', 'patch'],
['1.1.0', '1.1.0-pre', 'minor'],
['1.1.0-pre-1', '1.1.0-pre-2', 'prerelease'],
['1.0.0', '1.0.0', null],

['1.0.0', '1.0.0', null]
['1.0.0', '1.0.0', null],
['0.0.2-1', '0.0.2', 'patch'],
['0.1.0-1', '0.1.0', 'minor'],
['1.0.0-1', '1.0.0', 'major']
].forEach((v) => {
const version1 = v[0]
const version2 = v[1]
Expand Down

0 comments on commit 960a0f0

Please sign in to comment.