Skip to content

Commit aed312c

Browse files
committed
feat(version): expand v1 update policy to cover all versions
no issue - previously, the supported version policy was you could update to any new major if you were on the latest v1 - now, we're expanding that to say you can upgrade to any new major only if you're on the latest version of the current major
1 parent 05c4a5d commit aed312c

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

lib/utils/version.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const utils = {
100100
return parsed.version;
101101
},
102102

103-
checkActiveVersion(activeVersion, versionToUse, latestV1, opts = {}) {
103+
checkActiveVersion(activeVersion, versionToUse, latestMajorVersions, opts = {}) {
104104
const activeMajor = semver.major(activeVersion);
105105

106106
if (opts.v1 && activeMajor > 1) {
@@ -115,11 +115,14 @@ const utils = {
115115
return null;
116116
}
117117

118-
if (activeMajor === 1 && activeVersion !== latestV1 && semver.diff(activeVersion, versionToUse) === 'major') {
118+
const latestMajor = latestMajorVersions[`v${activeMajor}`];
119+
120+
if (activeVersion !== latestMajor && semver.diff(activeVersion, versionToUse) === 'major') {
119121
const majorToUse = semver.major(versionToUse);
122+
120123
throw new CliError({
121-
message: `You are trying to update to Ghost v${majorToUse}, but your blog is not on the latest Ghost 1.0 version`,
122-
help: 'Instead run "ghost update v1".'
124+
message: `Unable to update Ghost directly to v${versionToUse}. You must be on the latest v${activeMajor}.x to update across major versions.`,
125+
help: `Run "ghost update v${activeMajor}" to get the latest v${activeMajor}.x version, then run "ghost update" to get to v${majorToUse}.`
123126
});
124127
}
125128

@@ -158,7 +161,7 @@ const utils = {
158161
return latest;
159162
}
160163

161-
return utils.checkActiveVersion(activeVersion, latest, versions.latestMajor.v1, opts);
164+
return utils.checkActiveVersion(activeVersion, latest, versions.latestMajor, opts);
162165
},
163166

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

test/unit/utils/version-spec.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,28 +189,45 @@ describe('Unit: Utils: version', function () {
189189

190190
it('throws if upgrading major versions from v1', function () {
191191
try {
192-
checkActiveVersion('1.0.0', '3.0.0');
192+
checkActiveVersion('1.0.0', '3.0.0', {v1: '1.5.0'});
193193
} catch (error) {
194194
expect(error).to.be.an.instanceof(CliError);
195-
expect(error.message).to.contain('not on the latest Ghost 1.0');
195+
expect(error.message).to.contain('You must be on the latest v1.x');
196+
return;
197+
}
198+
199+
expect.fail('expected an error to be thrown');
200+
});
201+
202+
it('throws if upgrading major versions from not latest v2', function () {
203+
try {
204+
checkActiveVersion('2.0.0', '3.0.0', {v2: '2.5.0'});
205+
} catch (error) {
206+
expect(error).to.be.an.instanceof(CliError);
207+
expect(error.message).to.contain('You must be on the latest v2.x');
196208
return;
197209
}
198210

199211
expect.fail('expected an error to be thrown');
200212
});
201213

202214
it('allows upgrading from v1 if on latest v1', function () {
203-
const result = checkActiveVersion('1.0.0', '2.0.0', '1.0.0');
215+
const result = checkActiveVersion('1.0.0', '2.0.0', {v1: '1.0.0'});
204216
expect(result).to.equal('2.0.0');
205217
});
206218

219+
it('allows upgrading from v2 if on latest v2', function () {
220+
const result = checkActiveVersion('2.0.0', '3.0.0', {v2: '2.0.0'});
221+
expect(result).to.equal('3.0.0');
222+
});
223+
207224
it('returns version if active === latest and --force is supplied', function () {
208-
const result = checkActiveVersion('3.0.0', '3.0.0', '1.0.0', {force: true});
225+
const result = checkActiveVersion('3.0.0', '3.0.0', {v3: '1.0.0'}, {force: true});
209226
expect(result).to.equal('3.0.0');
210227
});
211228

212229
it('returns latest if checks pass', function () {
213-
const result = checkActiveVersion('2.0.0', '3.0.0');
230+
const result = checkActiveVersion('2.0.0', '3.0.0', {v2: '2.0.0'});
214231
expect(result).to.equal('3.0.0');
215232
});
216233
});

0 commit comments

Comments
 (0)