Skip to content

Commit

Permalink
feat(node): log discovered node version
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine committed Mar 20, 2021
1 parent 16c8291 commit 20b93cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 9 additions & 7 deletions lib/commands/doctor/checks/node-version.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const chalk = require('chalk');
const semver = require('semver');

Expand All @@ -8,19 +7,22 @@ const checkDirectoryAndAbove = require('./check-directory');

const taskTitle = 'Checking system Node.js version';

function nodeVersion(ctx) {
if (process.env.GHOST_NODE_VERSION_CHECK !== 'false' && !semver.satisfies(process.versions.node, cliPackage.engines.node)) {
return Promise.reject(new errors.SystemError({
async function nodeVersion(ctx, task) {
const {node} = process.versions;
task.title = `${taskTitle} - found v${node}`;

if (process.env.GHOST_NODE_VERSION_CHECK !== 'false' && !semver.satisfies(node, cliPackage.engines.node)) {
throw new errors.SystemError({
message: `${chalk.red('The version of Node.js you are using is not supported.')}
${chalk.gray('Supported: ')}${cliPackage.engines.node}
${chalk.gray('Installed: ')}${process.versions.node}
See ${chalk.underline.blue('https://ghost.org/docs/faq/node-versions/')} for more information`,
task: taskTitle
}));
});
}

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

return checkDirectoryAndAbove(process.argv[0], 'install node and Ghost-CLI', taskTitle);
Expand All @@ -29,5 +31,5 @@ See ${chalk.underline.blue('https://ghost.org/docs/faq/node-versions/')} for mor
module.exports = {
title: taskTitle,
task: nodeVersion,
category: ['install', 'update']
category: ['install', 'update', 'start']
};
17 changes: 8 additions & 9 deletions test/unit/commands/doctor/checks/node-version-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const expect = require('chai').expect;
const sinon = require('sinon');
const stripAnsi = require('strip-ansi');
Expand Down Expand Up @@ -37,7 +36,7 @@ describe('Unit: Doctor Checks > nodeVersion', function () {
'../../../../package': cliPackage
}).task;

return nodeVersion().then(() => {
return nodeVersion({}, {}).then(() => {
expect(false, 'error should be thrown').to.be.true;
}).catch((error) => {
expect(error).to.be.an.instanceof(errors.SystemError);
Expand All @@ -62,7 +61,7 @@ describe('Unit: Doctor Checks > nodeVersion', function () {
'./check-directory': checkDirectoryStub
}).task;

return nodeVersion({local: true}).then(() => {
return nodeVersion({local: true}, {}).then(() => {
expect(checkDirectoryStub.called).to.be.false;
});
});
Expand All @@ -81,7 +80,7 @@ describe('Unit: Doctor Checks > nodeVersion', function () {
'./check-directory': checkDirectoryStub
}).task;

return nodeVersion({local: true}).then(() => {
return nodeVersion({local: true}, {}).then(() => {
expect(checkDirectoryStub.called).to.be.false;
});
});
Expand All @@ -100,7 +99,7 @@ describe('Unit: Doctor Checks > nodeVersion', function () {
'./check-directory': checkDirectoryStub
}).task;

return nodeVersion({local: true}).then(() => {
return nodeVersion({local: true}, {}).then(() => {
expect(checkDirectoryStub.called).to.be.false;
});
});
Expand All @@ -118,7 +117,7 @@ describe('Unit: Doctor Checks > nodeVersion', function () {
'./check-directory': checkDirectoryStub
}).task;

return nodeVersion({local: true}).then(() => {
return nodeVersion({local: true}, {}).then(() => {
expect(checkDirectoryStub.called).to.be.false;
});
});
Expand All @@ -137,7 +136,7 @@ describe('Unit: Doctor Checks > nodeVersion', function () {
'./check-directory': checkDirectoryStub
}).task;

return nodeVersion(ctx).then(() => {
return nodeVersion(ctx, {}).then(() => {
expect(checkDirectoryStub.called).to.be.false;
});
});
Expand All @@ -156,7 +155,7 @@ describe('Unit: Doctor Checks > nodeVersion', function () {
'./check-directory': checkDirectoryStub
}).task;

return nodeVersion(ctx).then(() => {
return nodeVersion(ctx, {}).then(() => {
expect(checkDirectoryStub.called).to.be.false;
});
});
Expand All @@ -175,7 +174,7 @@ describe('Unit: Doctor Checks > nodeVersion', function () {
'./check-directory': checkDirectoryStub
}).task;

return nodeVersion(ctx).then(() => {
return nodeVersion(ctx, {}).then(() => {
expect(checkDirectoryStub.calledOnce).to.be.true;
expect(checkDirectoryStub.calledWith(process.argv[0])).to.be.true;
});
Expand Down

0 comments on commit 20b93cf

Please sign in to comment.