Skip to content

Commit

Permalink
fix(doctor): add install checks for various nvm edge cases
Browse files Browse the repository at this point in the history
closes TryGhost#281
- skip directory check if `--no-setup-linux-user` option is passed
- throw error if npm bin directory is not the same as the one used to install ghost-cli
  • Loading branch information
acburdine committed Jul 31, 2017
1 parent 106f4e8 commit 4439463
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions lib/commands/doctor/checks/install.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const fs = require('fs');
const fs = require('fs-extra');
const os = require('os');
const eol = require('os').EOL;
const path = require('path');
Expand All @@ -13,28 +13,39 @@ const isRoot = require('path-is-root');
const errors = require('../../../errors');
const cliPackage = require('../../../../package');

function checkDirectoryAndAbove(dir) {
function checkDirectoryAndAbove(dir, extra) {
if (isRoot(dir)) {
return;
}

let stats = fs.lstatSync(dir);
let mode = new Mode(stats);
return fs.lstat(dir).then((stats) => {
let mode = new Mode(stats);

if (!mode.others.read) {
throw new errors.SystemError(
`The path ${dir} is not readable by other users on the system.${eol}` +
'This can cause issues with the CLI, please either make this directory ' +
'readable by others or install in another location.'
);
}
if (!mode.others.read) {
return Promise.reject(new errors.SystemError(
`The path ${dir} is not readable by other users on the system.${eol}` +
'This can cause issues with the CLI, please either make this directory ' +
`readable by others or ${extra} in another location.`
));
}

return checkDirectoryAndAbove(path.join(dir, '../'));
return checkDirectoryAndAbove(path.join(dir, '../'), extra);
});
}

module.exports = [{
title: 'Checking system Node.js version',
task: () => {
task: (ctx) => {
let globalBin = execa.shellSync('npm bin -g').stdout;

if (!process.argv[1].startsWith(globalBin)) {
return Promise.reject(new errors.SystemError(
`The version of Ghost-CLI you are running was not installed with this version of Node.${eol}` +
`This means there are likely two versions of Node running on your system,${eol} please ensure` +
'that you are only running one global version of Node before continuing.'
));
}

if (process.env.GHOST_NODE_VERSION_CHECK !== 'false' &&
!semver.satisfies(process.versions.node, cliPackage.engines.node)) {
return Promise.reject(new errors.SystemError(
Expand All @@ -45,6 +56,12 @@ module.exports = [{
'for more information'
));
}

if (ctx.local || os.platform() !== 'linux' || (ctx.argv && ctx.argv['setup-linux-user'] === false)) {
return;
}

return checkDirectoryAndAbove(process.argv[0], 'install node and Ghost-CLI');
}
}, {
title: 'Checking current folder permissions',
Expand All @@ -58,11 +75,11 @@ module.exports = [{
));
}

if (ctx.local || os.platform() !== 'linux') {
if (ctx.local || os.platform() !== 'linux' || (ctx.argv && ctx.argv['setup-linux-user'] === false)) {
return;
}

checkDirectoryAndAbove(process.cwd());
return checkDirectoryAndAbove(process.cwd(), 'run `ghost install`');
}
}, {
title: 'Checking operating system',
Expand Down

0 comments on commit 4439463

Please sign in to comment.