Skip to content

Commit

Permalink
fix(version-resolver): allow v2 updates w/ multiple v2 releases
Browse files Browse the repository at this point in the history
  • Loading branch information
vikaspotluri123 authored and acburdine committed Aug 20, 2018
1 parent 4ae1f42 commit fc12d22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
9 changes: 8 additions & 1 deletion lib/utils/resolve-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,21 @@ module.exports = function resolveVersion(version, activeVersion, v1 = false, for
// CASE: you haven't passed `--v1` and you are not about to install a fresh blog
if (!v1 && activeVersion) {
const majorVersionJump = semver.major(activeVersion) !== semver.major(versionToReturn);
const v1Versions = versions.filter(version => semver.satisfies(version, `^${activeVersion}`));

// CASE 1: you want to force update and you are not on the latest v1 version
// CASE 2: you don't use force and you are not on the latest v1 version
if (majorVersionJump && force && versions.length > 1) {
const latestV2 = versionToReturn;
while (!semver.satisfies(versionToReturn, '^1.0.0')) {
versionToReturn = versions.pop();
}
} else if (majorVersionJump && !force && versions.length) {

// super dirty hack @todo: fixme
if (versionToReturn === activeVersion) {
versionToReturn = latestV2;
}
} else if (majorVersionJump && !force && v1Versions.length) {
return Promise.reject(new errors.CliError({
message: 'You are about to migrate to Ghost 2.0. Your blog is not on the latest Ghost 1.0 version.',
help: 'Please run "ghost update --v1".'
Expand Down
27 changes: 18 additions & 9 deletions test/unit/utils/resolve-version-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Unit: resolveVersion', function () {
});

it('filters out 2.0 version if v1 param is specified', function () {
stubYarn('{"data": ["1.0.0", "1.0.1", "1.52.37", "2.0.0"]}');
stubYarn('{"data": ["1.0.0", "1.0.1", "1.52.37", "2.0.0", "2.0.1"]}');

return resolveVersion(null, null, true).then(function (version) {
expect(version).to.equal('1.52.37');
Expand All @@ -126,7 +126,7 @@ describe('Unit: resolveVersion', function () {
});

it('filters out 2.0 version if v1 param is specified', function () {
stubYarn('{"data": ["1.0.0", "1.0.1", "1.52.37", "2.0.0"]}');
stubYarn('{"data": ["1.0.0", "1.0.1", "1.52.37", "2.0.0", "2.0.1"]}');

return resolveVersion(null, '1.52.37', true).then(function () {
throw new Error('Version finder should not have resolved');
Expand All @@ -146,7 +146,7 @@ describe('Unit: resolveVersion', function () {

describe('jump to next major', function () {
it('throws error if you aren\'t on the latest v1', function () {
stubYarn('{"data": ["1.23.0", "1.24.0", "1.25.0", "2.0.0"]}');
stubYarn('{"data": ["1.23.0", "1.24.0", "1.25.0", "2.0.0", "2.0.1"]}');

return resolveVersion(null, '1.24.0', false).then(function () {
throw new Error('Version finder should not have resolved');
Expand All @@ -157,34 +157,43 @@ describe('Unit: resolveVersion', function () {
});

it('resolves if you are on the latest v1', function () {
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0"]}');
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0", "2.0.1"]}');

return resolveVersion(null, '1.25.2', false)
.then(function (version) {
expect(version).to.eql('2.0.0');
expect(version).to.eql('2.0.1');
});
});

it('resolves using `--v1` and you are\'t on the latest v1', function () {
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0"]}');
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0", "2.0.1"]}');

return resolveVersion(null, '1.25.1', true)
.then(function (version) {
expect(version).to.eql('1.25.2');
});
});

it('updates to latest v2 with many v2 releases', function () {
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0", "2.1.0", "2.2.0"]}');

return resolveVersion(null, '1.25.2', false, false)
.then(function (version) {
expect(version).to.eql('2.2.0');
});
});

it('force updating and you are on the latest v1', function () {
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0"]}');
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0", "2.0.1"]}');

return resolveVersion(null, '1.25.2', false, true)
.then(function (version) {
expect(version).to.eql('2.0.0');
expect(version).to.eql('2.0.1');
});
});

it('force updating with `--v1`', function () {
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0"]}');
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0", "2.0.1"]}');

return resolveVersion(null, '1.25.1', true, true)
.then(function (version) {
Expand Down

0 comments on commit fc12d22

Please sign in to comment.