Skip to content

Commit 95266f2

Browse files
committed
fix(version): add premajor to update version diff check
no issue - if one of the versions in a comparison is a prerelease (i.e. comparing v3.0.0 and v4.0.0-alpha.1), semver.diff returns 'premajor' instead of 'major', so we need to handle both cases.
1 parent ee8f9e1 commit 95266f2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/utils/version.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const utils = {
117117

118118
const latestMajor = latestMajorVersions[`v${activeMajor}`];
119119

120-
if (activeVersion !== latestMajor && semver.diff(activeVersion, versionToUse) === 'major') {
120+
if (activeVersion !== latestMajor && ['major', 'premajor'].includes(semver.diff(activeVersion, versionToUse))) {
121121
const majorToUse = semver.major(versionToUse);
122122

123123
throw new CliError({

test/unit/utils/version-spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ describe('Unit: Utils: version', function () {
211211
expect.fail('expected an error to be thrown');
212212
});
213213

214+
it('throws if upgrading premajor versions from not latest v2', function () {
215+
try {
216+
checkActiveVersion('2.0.0', '4.0.0-alpha.3', {v2: '2.5.0'});
217+
} catch (error) {
218+
expect(error).to.be.an.instanceof(CliError);
219+
expect(error.message).to.contain('You must be on the latest v2.x');
220+
return;
221+
}
222+
223+
expect.fail('expected an error to be thrown');
224+
});
225+
214226
it('allows upgrading from v1 if on latest v1', function () {
215227
const result = checkActiveVersion('1.0.0', '2.0.0', {v1: '1.0.0'});
216228
expect(result).to.equal('2.0.0');

0 commit comments

Comments
 (0)