Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: semver.diff prerelease to release recognition #334

Closed
wants to merge 2 commits into from
Closed
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
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
14 changes: 9 additions & 5 deletions test/functions/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ 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],

['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