Skip to content

Commit fc12d22

Browse files
vikaspotluri123acburdine
authored andcommitted
fix(version-resolver): allow v2 updates w/ multiple v2 releases
refs https://forum.ghost.org/t/error-when-attempting-update-to-ghost-2-x/2515
1 parent 4ae1f42 commit fc12d22

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

lib/utils/resolve-version.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,21 @@ module.exports = function resolveVersion(version, activeVersion, v1 = false, for
6666
// CASE: you haven't passed `--v1` and you are not about to install a fresh blog
6767
if (!v1 && activeVersion) {
6868
const majorVersionJump = semver.major(activeVersion) !== semver.major(versionToReturn);
69+
const v1Versions = versions.filter(version => semver.satisfies(version, `^${activeVersion}`));
6970

7071
// CASE 1: you want to force update and you are not on the latest v1 version
7172
// CASE 2: you don't use force and you are not on the latest v1 version
7273
if (majorVersionJump && force && versions.length > 1) {
74+
const latestV2 = versionToReturn;
7375
while (!semver.satisfies(versionToReturn, '^1.0.0')) {
7476
versionToReturn = versions.pop();
7577
}
76-
} else if (majorVersionJump && !force && versions.length) {
78+
79+
// super dirty hack @todo: fixme
80+
if (versionToReturn === activeVersion) {
81+
versionToReturn = latestV2;
82+
}
83+
} else if (majorVersionJump && !force && v1Versions.length) {
7784
return Promise.reject(new errors.CliError({
7885
message: 'You are about to migrate to Ghost 2.0. Your blog is not on the latest Ghost 1.0 version.',
7986
help: 'Please run "ghost update --v1".'

test/unit/utils/resolve-version-spec.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('Unit: resolveVersion', function () {
105105
});
106106

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

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

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

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

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

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

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

162162
return resolveVersion(null, '1.25.2', false)
163163
.then(function (version) {
164-
expect(version).to.eql('2.0.0');
164+
expect(version).to.eql('2.0.1');
165165
});
166166
});
167167

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

171171
return resolveVersion(null, '1.25.1', true)
172172
.then(function (version) {
173173
expect(version).to.eql('1.25.2');
174174
});
175175
});
176176

177+
it('updates to latest v2 with many v2 releases', function () {
178+
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0", "2.1.0", "2.2.0"]}');
179+
180+
return resolveVersion(null, '1.25.2', false, false)
181+
.then(function (version) {
182+
expect(version).to.eql('2.2.0');
183+
});
184+
});
185+
177186
it('force updating and you are on the latest v1', function () {
178-
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0"]}');
187+
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0", "2.0.1"]}');
179188

180189
return resolveVersion(null, '1.25.2', false, true)
181190
.then(function (version) {
182-
expect(version).to.eql('2.0.0');
191+
expect(version).to.eql('2.0.1');
183192
});
184193
});
185194

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

189198
return resolveVersion(null, '1.25.1', true, true)
190199
.then(function (version) {

0 commit comments

Comments
 (0)