Skip to content

Commit 28a39b0

Browse files
committed
fix(version): allow v2 update if on latest v1
1 parent ec62fe7 commit 28a39b0

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

lib/utils/version.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const utils = {
8585
return parsed.version;
8686
},
8787

88-
checkActiveVersion(activeVersion, latest, opts = {}) {
88+
checkActiveVersion(activeVersion, versionToUse, latestV1, opts = {}) {
8989
const activeMajor = semver.major(activeVersion);
9090

9191
if (opts.v1 && activeMajor > 1) {
@@ -96,19 +96,19 @@ const utils = {
9696
});
9797
}
9898

99-
if (semver.lte(latest, activeVersion) && !opts.force) {
99+
if (semver.lte(versionToUse, activeVersion) && !opts.force) {
100100
return null;
101101
}
102102

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

111-
return latest;
111+
return versionToUse;
112112
},
113113

114114
async resolveVersion(customVersion = null, activeVersion = null, opts = {}) {
@@ -130,7 +130,7 @@ const utils = {
130130
return latest;
131131
}
132132

133-
return utils.checkActiveVersion(activeVersion, latest, opts);
133+
return utils.checkActiveVersion(activeVersion, latest, versions.latestMajor.v1, opts);
134134
},
135135

136136
async versionFromZip(zipPath, activeVersion = null, opts = {}) {

test/unit/utils/version-spec.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('Unit: Utils: version', function () {
130130
describe('checkActiveVersion', function () {
131131
it('throws if --v1 is passed and active version is >= 2.0', function () {
132132
try {
133-
checkActiveVersion('2.0.0', '2.1.0', {v1: true});
133+
checkActiveVersion('2.0.0', '2.1.0', '1.0.0', {v1: true});
134134
} catch (error) {
135135
expect(error).to.be.an.instanceof(CliError);
136136
expect(error.message).to.contain('v2 or greater');
@@ -157,8 +157,13 @@ describe('Unit: Utils: version', function () {
157157
expect.fail('expected an error to be thrown');
158158
});
159159

160+
it('allows upgrading from v1 if on latest v1', function () {
161+
const result = checkActiveVersion('1.0.0', '2.0.0', '1.0.0');
162+
expect(result).to.equal('2.0.0');
163+
});
164+
160165
it('returns version if active === latest and --force is supplied', function () {
161-
const result = checkActiveVersion('3.0.0', '3.0.0', {force: true});
166+
const result = checkActiveVersion('3.0.0', '3.0.0', '1.0.0', {force: true});
162167
expect(result).to.equal('3.0.0');
163168
});
164169

0 commit comments

Comments
 (0)