Skip to content

Commit

Permalink
fix(version): allow v2 update if on latest v1
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine committed Oct 16, 2019
1 parent ec62fe7 commit 28a39b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lib/utils/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const utils = {
return parsed.version;
},

checkActiveVersion(activeVersion, latest, opts = {}) {
checkActiveVersion(activeVersion, versionToUse, latestV1, opts = {}) {
const activeMajor = semver.major(activeVersion);

if (opts.v1 && activeMajor > 1) {
Expand All @@ -96,19 +96,19 @@ const utils = {
});
}

if (semver.lte(latest, activeVersion) && !opts.force) {
if (semver.lte(versionToUse, activeVersion) && !opts.force) {
return null;
}

if (activeMajor === 1 && semver.diff(activeVersion, latest) === 'major') {
const latestMajor = semver.major(latest);
if (activeMajor === 1 && activeVersion !== latestV1 && semver.diff(activeVersion, versionToUse) === 'major') {
const majorToUse = semver.major(versionToUse);
throw new CliError({
message: `You are trying to update to Ghost v${latestMajor}, but your blog is not on the latest Ghost 1.0 version`,
message: `You are trying to update to Ghost v${majorToUse}, but your blog is not on the latest Ghost 1.0 version`,
help: 'Instead run "ghost update --v1".'
});
}

return latest;
return versionToUse;
},

async resolveVersion(customVersion = null, activeVersion = null, opts = {}) {
Expand All @@ -130,7 +130,7 @@ const utils = {
return latest;
}

return utils.checkActiveVersion(activeVersion, latest, opts);
return utils.checkActiveVersion(activeVersion, latest, versions.latestMajor.v1, opts);
},

async versionFromZip(zipPath, activeVersion = null, opts = {}) {
Expand Down
9 changes: 7 additions & 2 deletions test/unit/utils/version-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('Unit: Utils: version', function () {
describe('checkActiveVersion', function () {
it('throws if --v1 is passed and active version is >= 2.0', function () {
try {
checkActiveVersion('2.0.0', '2.1.0', {v1: true});
checkActiveVersion('2.0.0', '2.1.0', '1.0.0', {v1: true});
} catch (error) {
expect(error).to.be.an.instanceof(CliError);
expect(error.message).to.contain('v2 or greater');
Expand All @@ -157,8 +157,13 @@ describe('Unit: Utils: version', function () {
expect.fail('expected an error to be thrown');
});

it('allows upgrading from v1 if on latest v1', function () {
const result = checkActiveVersion('1.0.0', '2.0.0', '1.0.0');
expect(result).to.equal('2.0.0');
});

it('returns version if active === latest and --force is supplied', function () {
const result = checkActiveVersion('3.0.0', '3.0.0', {force: true});
const result = checkActiveVersion('3.0.0', '3.0.0', '1.0.0', {force: true});
expect(result).to.equal('3.0.0');
});

Expand Down

0 comments on commit 28a39b0

Please sign in to comment.