Skip to content

Commit d243bed

Browse files
kirrg001acburdine
authored andcommitted
fix(v2): changed major version comparison
refs #759 - `semver.satisfies(version, '^2.0.0')` doesn't work with release candidates - switch to compare the major version with `semver.major`
1 parent e9ed36b commit d243bed

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

lib/commands/setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class SetupCommand extends Command {
180180
task: migrator.migrate,
181181
// CASE: We are about to install Ghost 2.0. We moved the execution of knex-migrator into Ghost.
182182
enabled: () => {
183-
if (semver.satisfies(instance.cliConfig.get('active-version'), '^2.0.0')) {
183+
if (semver.major(instance.cliConfig.get('active-version')) === 2) {
184184
return false;
185185
}
186186

lib/commands/update.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class UpdateCommand extends Command {
7272
task: majorUpdate,
7373
// CASE: Skip if you are already on ^2 or you update from v1 to v1.
7474
enabled: () => {
75-
if (semver.satisfies(instance.cliConfig.get('active-version'), '^2.0.0') ||
76-
!semver.satisfies(context.version, '^2.0.0')) {
75+
if (semver.major(instance.cliConfig.get('active-version')) === 2 ||
76+
semver.major(context.version) === 1) {
7777
return false;
7878
}
7979

@@ -96,9 +96,10 @@ class UpdateCommand extends Command {
9696
task: migrator.migrate,
9797
// CASE: We have moved the execution of knex-migrator into Ghost 2.0.0.
9898
// If you are already on v2 or you update from v1 to v2, then skip the task.
99+
// We compare the major versions, otherwise pre-releases won't match.
99100
enabled: () => {
100-
if (semver.satisfies(instance.cliConfig.get('active-version'), '^2.0.0') ||
101-
semver.satisfies(context.version, '^2.0.0')) {
101+
if (semver.major(instance.cliConfig.get('active-version')) === 2 ||
102+
semver.major(context.version) === 2) {
102103
return false;
103104
}
104105

lib/process-manager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ProcessManager {
7676
stopOnError: true,
7777
port: this.instance.config.get('server.port'),
7878
host: this.instance.config.get('server.host', 'localhost'),
79-
useNetServer: semver.satisfies(this.instance.cliConfig.get('active-version'), '^2.0.0')
79+
useNetServer: semver.major(this.instance.cliConfig.get('active-version')) === 2
8080
}, options || {});
8181

8282
return portPolling(options).catch((err) => {

lib/tasks/migrator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module.exports.rollback = function runRollback(context) {
8585

8686
// Ghost 2.0.0 uses the new knex-migrator version. We have to ensure you can still use CLI 1.9 with an older blog, because
8787
// we haven't restricted a CLI version range in Ghost (we only used cli: > X.X.X)
88-
if (semver.satisfies(context.instance.cliConfig.get('active-version'), '^2.0.0')) {
88+
if (semver.major(context.instance.cliConfig.get('active-version')) === 2) {
8989
args = ['--force', '--v', context.instance.cliConfig.get('previous-version'), '--mgpath', currentDir];
9090
} else {
9191
args = ['--force', '--mgpath', currentDir];

test/unit/tasks/migrator-spec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,15 @@ describe('Unit: Tasks > Migrator', function () {
158158
});
159159

160160
describe('rollback', function () {
161+
let cliConfig;
162+
163+
beforeEach(function () {
164+
cliConfig = configStub();
165+
cliConfig.get.withArgs('active-version').returns('1.25.3');
166+
});
167+
161168
it('runs direct command if useGhostUser returns false', function () {
162169
const config = configStub();
163-
const cliConfig = configStub();
164170
const execaStub = sinon.stub().resolves();
165171
const useGhostUserStub = sinon.stub().returns(false);
166172

@@ -181,7 +187,7 @@ describe('Unit: Tasks > Migrator', function () {
181187
});
182188
});
183189

184-
it('forward version option to knex-migrator if blog is on v1', function () {
190+
it('forward version option to knex-migrator if blog jumps from v1 to v2', function () {
185191
const config = configStub();
186192
const cliConfig = configStub();
187193
const execaStub = sinon.stub().resolves();
@@ -209,7 +215,6 @@ describe('Unit: Tasks > Migrator', function () {
209215

210216
it('runs sudo command if useGhostUser returns true', function () {
211217
const config = configStub();
212-
const cliConfig = configStub();
213218
const execaStub = sinon.stub().resolves();
214219
const useGhostUserStub = sinon.stub().returns(true);
215220

@@ -230,7 +235,6 @@ describe('Unit: Tasks > Migrator', function () {
230235

231236
it('throws config error with db host if database not found', function () {
232237
const config = configStub();
233-
const cliConfig = configStub();
234238
const execaStub = sinon.stub().returns(Promise.reject({stderr: 'CODE: ENOTFOUND'}));
235239
const useGhostUserStub = sinon.stub().returns(false);
236240

@@ -249,7 +253,6 @@ describe('Unit: Tasks > Migrator', function () {
249253

250254
it('throws config error with db user if access denied error', function () {
251255
const config = configStub();
252-
const cliConfig = configStub();
253256
const execaStub = sinon.stub().returns(Promise.reject({stderr: 'CODE: ER_ACCESS_DENIED_ERROR'}));
254257
const useGhostUserStub = sinon.stub().returns(false);
255258

@@ -268,7 +271,6 @@ describe('Unit: Tasks > Migrator', function () {
268271

269272
it('throws system error if sqlite3 error is thrown by knex', function () {
270273
const config = configStub();
271-
const cliConfig = configStub();
272274
const execaStub = sinon.stub().returns(Promise.reject({stdout: 'Knex: run\n$ npm install sqlite3 --save\nError:'}));
273275
const useGhostUserStub = sinon.stub().returns(false);
274276

@@ -287,7 +289,6 @@ describe('Unit: Tasks > Migrator', function () {
287289

288290
it('knex-migrator complains that no more migrations to rollback available', function () {
289291
const config = configStub();
290-
const cliConfig = configStub();
291292
const execaStub = sinon.stub().returns(Promise.reject({stderr: 'No migrations available to rollback'}));
292293
const useGhostUserStub = sinon.stub().returns(false);
293294

@@ -305,7 +306,6 @@ describe('Unit: Tasks > Migrator', function () {
305306
process.argv = ['node', 'ghost', 'update', '--rollback'];
306307

307308
const config = configStub();
308-
const cliConfig = configStub();
309309
const execaStub = sinon.stub().rejects({stderr: 'YA_GOOFED'});
310310
const useGhostUserStub = sinon.stub().returns(false);
311311

0 commit comments

Comments
 (0)