Skip to content

Commit 9b78843

Browse files
acburdinekirrg001
authored andcommitted
feat(db): remove knex-migrator dep, use one installed with Ghost (#505)
refs #503 - use knex-migrator version installed with Ghost itself - remove global knex-migrator dependency - remove "same node version" check
1 parent c897ae9 commit 9b78843

File tree

5 files changed

+29
-489
lines changed

5 files changed

+29
-489
lines changed

lib/commands/doctor/checks/install.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ const tasks = {
3737
});
3838
},
3939
nodeVersion: function nodeVersion(ctx) {
40-
const globalBin = execa.shellSync('npm bin -g', {preferLocal: false}).stdout;
41-
42-
if (process.argv[1] !== path.join(__dirname, '../../../../bin/ghost') && !process.argv[1].startsWith(globalBin)) {
43-
return Promise.reject(new errors.SystemError(
44-
`The version of Ghost-CLI you are running was not installed with this version of Node.${eol}` +
45-
`This means there are likely two versions of Node running on your system, please ensure${eol}` +
46-
'that you are only running one global version of Node before continuing.'
47-
));
48-
}
49-
5040
if (process.env.GHOST_NODE_VERSION_CHECK !== 'false' &&
5141
!semver.satisfies(process.versions.node, cliPackage.engines.node)) {
5242
return Promise.reject(new errors.SystemError(

lib/tasks/migrate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ module.exports = function runMigrations(context) {
2424
// If we're using sqlite and the ghost user owns the content folder, then
2525
// we should run sudo, otherwise run normally
2626
if (shouldUseGhostUser(contentDir)) {
27-
const knexMigratorPath = path.resolve(__dirname, '../../node_modules/.bin/knex-migrator-migrate');
27+
const knexMigratorPath = path.resolve(context.instance.dir, 'current/node_modules/.bin/knex-migrator-migrate');
2828
knexMigratorPromise = context.ui.sudo(`${knexMigratorPath} ${args.join(' ')}`, {sudoArgs: '-E -u ghost'});
2929
} else {
3030
knexMigratorPromise = execa('knex-migrator-migrate', args, {
3131
preferLocal: true,
32-
localDir: __dirname
32+
localDir: path.join(context.instance.dir, 'current')
3333
});
3434
}
3535

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"ghost-ignition": "2.8.14",
5454
"inquirer": "3.3.0",
5555
"is-running": "2.1.0",
56-
"knex-migrator": "2.1.7",
5756
"listr": "0.12.0",
5857
"lodash": "4.17.4",
5958
"log-symbols": "2.1.0",

test/unit/commands/doctor/install-spec.js

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,15 @@ describe('Unit: Doctor Checks > Install', function () {
3535
});
3636

3737
describe('node version check', function () {
38-
it('rejects if global bin is different than the one ghost is running from', function () {
39-
const execaStub = sinon.stub().returns({stdout: '/usr/local/bin'});
40-
const originalArgv = process.argv;
41-
process.argv = ['node', '/home/ghost/.nvm/versions/6.11.1/bin'];
42-
43-
const task = proxyquire(modulePath, {
44-
execa: {shellSync: execaStub}
45-
}).tasks.nodeVersion;
46-
47-
return task().then(() => {
48-
expect(false, 'error should be thrown').to.be.true;
49-
process.argv = originalArgv;
50-
}).catch((error) => {
51-
process.argv = originalArgv;
52-
expect(error).to.be.an.instanceof(errors.SystemError);
53-
expect(error.message).to.match(/version of Ghost-CLI you are running was not installed with this version of Node./);
54-
expect(execaStub.calledOnce).to.be.true;
55-
expect(execaStub.calledWithExactly('npm bin -g', {preferLocal: false})).to.be.true;
56-
});
57-
});
58-
5938
it('rejects if node version is not in range', function () {
6039
const cliPackage = {
6140
engines: {
6241
node: '0.10.0'
6342
}
6443
};
65-
const execaStub = sinon.stub().returns({stdout: process.argv[1]});
6644

6745
const task = proxyquire(modulePath, {
68-
'../../../../package': cliPackage,
69-
execa: {shellSync: execaStub}
46+
'../../../../package': cliPackage
7047
}).tasks.nodeVersion;
7148

7249
return task().then(() => {
@@ -77,7 +54,6 @@ describe('Unit: Doctor Checks > Install', function () {
7754

7855
expect(message).to.match(/Supported: 0.10.0/);
7956
expect(message).to.match(new RegExp(`Installed: ${process.versions.node}`));
80-
expect(execaStub.calledOnce).to.be.true;
8157
});
8258
});
8359

@@ -87,19 +63,16 @@ describe('Unit: Doctor Checks > Install', function () {
8763
node: process.versions.node // this future-proofs the test
8864
}
8965
};
90-
const execaStub = sinon.stub().returns({stdout: '/usr/local/bin'});
9166
const originalArgv = process.argv;
9267
process.argv = ['node', path.join(__dirname, '../../../../bin/ghost')];
9368

9469
const tasks = proxyquire(modulePath, {
95-
'../../../../package': cliPackage,
96-
execa: {shellSync: execaStub}
70+
'../../../../package': cliPackage
9771
}).tasks;
9872
const checkDirectoryStub = sinon.stub(tasks, 'checkDirectoryAndAbove').resolves();
9973

10074
return tasks.nodeVersion({local: true}).then(() => {
10175
process.argv = originalArgv;
102-
expect(execaStub.calledOnce).to.be.true;
10376
expect(checkDirectoryStub.called).to.be.false;
10477
});
10578
});
@@ -112,17 +85,14 @@ describe('Unit: Doctor Checks > Install', function () {
11285
}
11386
};
11487
process.env = {GHOST_NODE_VERSION_CHECK: 'false'};
115-
const execaStub = sinon.stub().returns({stdout: process.argv[1]});
11688

11789
const tasks = proxyquire(modulePath, {
118-
'../../../../package': cliPackage,
119-
execa: {shellSync: execaStub}
90+
'../../../../package': cliPackage
12091
}).tasks;
12192
const checkDirectoryStub = sinon.stub(tasks, 'checkDirectoryAndAbove').resolves();
12293

12394
return tasks.nodeVersion({local: true}).then(() => {
12495
process.env = originalEnv;
125-
expect(execaStub.calledOnce).to.be.true;
12696
expect(checkDirectoryStub.called).to.be.false;
12797
});
12898
});
@@ -133,16 +103,13 @@ describe('Unit: Doctor Checks > Install', function () {
133103
node: process.versions.node // this future-proofs the test
134104
}
135105
};
136-
const execaStub = sinon.stub().returns({stdout: process.argv[1]});
137106

138107
const tasks = proxyquire(modulePath, {
139-
'../../../../package': cliPackage,
140-
execa: {shellSync: execaStub}
108+
'../../../../package': cliPackage
141109
}).tasks;
142110
const checkDirectoryStub = sinon.stub(tasks, 'checkDirectoryAndAbove').resolves();
143111

144112
return tasks.nodeVersion({local: true}).then(() => {
145-
expect(execaStub.calledOnce).to.be.true;
146113
expect(checkDirectoryStub.called).to.be.false;
147114
});
148115
});
@@ -153,18 +120,15 @@ describe('Unit: Doctor Checks > Install', function () {
153120
node: process.versions.node // this future-proofs the test
154121
}
155122
};
156-
const execaStub = sinon.stub().returns({stdout: process.argv[1]});
157123
const platformStub = sinon.stub().returns('darwin');
158124

159125
const tasks = proxyquire(modulePath, {
160126
'../../../../package': cliPackage,
161-
execa: {shellSync: execaStub},
162127
os: {platform: platformStub}
163128
}).tasks;
164129
const checkDirectoryStub = sinon.stub(tasks, 'checkDirectoryAndAbove').resolves();
165130

166131
return tasks.nodeVersion({local: false}).then(() => {
167-
expect(execaStub.calledOnce).to.be.true;
168132
expect(checkDirectoryStub.called).to.be.false;
169133
});
170134
});
@@ -175,18 +139,15 @@ describe('Unit: Doctor Checks > Install', function () {
175139
node: process.versions.node // this future-proofs the test
176140
}
177141
};
178-
const execaStub = sinon.stub().returns({stdout: process.argv[1]});
179142
const platformStub = sinon.stub().returns('linux');
180143

181144
const tasks = proxyquire(modulePath, {
182145
'../../../../package': cliPackage,
183-
execa: {shellSync: execaStub},
184146
os: {platform: platformStub}
185147
}).tasks;
186148
const checkDirectoryStub = sinon.stub(tasks, 'checkDirectoryAndAbove').resolves();
187149

188150
return tasks.nodeVersion({local: false, argv: {'setup-linux-user': false}}).then(() => {
189-
expect(execaStub.calledOnce).to.be.true;
190151
expect(checkDirectoryStub.called).to.be.false;
191152
});
192153
});
@@ -197,18 +158,15 @@ describe('Unit: Doctor Checks > Install', function () {
197158
node: process.versions.node // this future-proofs the test
198159
}
199160
};
200-
const execaStub = sinon.stub().returns({stdout: process.argv[1]});
201161
const platformStub = sinon.stub().returns('linux');
202162

203163
const tasks = proxyquire(modulePath, {
204164
'../../../../package': cliPackage,
205-
execa: {shellSync: execaStub},
206165
os: {platform: platformStub}
207166
}).tasks;
208167
const checkDirectoryStub = sinon.stub(tasks, 'checkDirectoryAndAbove').resolves();
209168

210169
return tasks.nodeVersion({local: false, argv: {'setup-linux-user': true}}).then(() => {
211-
expect(execaStub.calledOnce).to.be.true;
212170
expect(checkDirectoryStub.calledOnce).to.be.true;
213171
expect(checkDirectoryStub.calledWith(process.argv[0])).to.be.true;
214172
});

0 commit comments

Comments
 (0)