Skip to content

Commit

Permalink
chore: node deprecation warning for <10 (#458)
Browse files Browse the repository at this point in the history
* chore: node deprecation warning for <10
* Simplify deprecation range by implicitly using NODE_VERSION_REQUIREMENT as lower bound
* Break long lines
  • Loading branch information
erisu authored Oct 17, 2019
1 parent e6272d8 commit 39141dd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
46 changes: 46 additions & 0 deletions spec/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,50 @@ describe('cordova cli', () => {
});
});
});

describe('node requirement', () => {
it('should warn users about unsupported node version', () => {
cli.__set__('NODE_VERSION', 'v6.1.0');
cli.__set__('NODE_VERSION_DEPRECATING_RANGE', null);
cli.__set__('NODE_VERSION_REQUIREMENT', '>=8');

return cli(['node', 'cordova']).then(() => {
const errorMsg = logger.warn.calls.argsFor(1).toString();
expect(errorMsg).toMatch(/v6.1.0 is no longer supported./);
});
});

it('should not warn users about unsupported node version', () => {
cli.__set__('NODE_VERSION', 'v8.0.0');
cli.__set__('NODE_VERSION_DEPRECATING_RANGE', null);
cli.__set__('NODE_VERSION_REQUIREMENT', '>=8');

return cli(['node', 'cordova']).then(() => {
const errorMsg = logger.warn.calls.argsFor(1).toString();
expect(errorMsg).toBeFalsy();
});
});

it('should warn users about deprecated node version', () => {
cli.__set__('NODE_VERSION', 'v8.0.0');
cli.__set__('NODE_VERSION_DEPRECATING_RANGE', '<10');
cli.__set__('NODE_VERSION_REQUIREMENT', '>=8');

return cli(['node', 'cordova']).then(() => {
const errorMsg = logger.warn.calls.argsFor(1).toString();
expect(errorMsg).toMatch(/v8.0.0 has been deprecated./);
});
});

it('should warn users about deprecated node version', () => {
cli.__set__('NODE_VERSION', 'v10.0.0');
cli.__set__('NODE_VERSION_DEPRECATING_RANGE', '<10');
cli.__set__('NODE_VERSION_REQUIREMENT', '>=8');

return cli(['node', 'cordova']).then(() => {
const errorMsg = logger.warn.calls.argsFor(1).toString();
expect(errorMsg).toBeFalsy();
});
});
});
});
21 changes: 18 additions & 3 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ var conf = new Configstore(pkg.name + '-config');
var editor = require('editor');
const semver = require('semver');

// process.version is not declared writable or has no setter so storing in const for Jasmine.
const NODE_VERSION = process.version;

// When there is no node version in the deprecation stage, set to null or false.
const NODE_VERSION_REQUIREMENT = '>=8';
const NODE_VERSION_DEPRECATING_RANGE = '<10';

var knownOpts = {
'verbose': Boolean,
Expand Down Expand Up @@ -298,9 +303,19 @@ function cli (inputArgs) {
}
}

// If the Node.js versions does not meet our requirements, it will then display warning.
if (!semver.satisfies(process.version, NODE_VERSION_REQUIREMENT)) {
logger.warn(`Warning: Node.js ${process.version} is no longer supported. Please upgrade to the latest Node.js version available (LTS version recommended).`);
let warningPartial = null;

// If the Node.js versions does not meet our requirements or in a deprecation stage, display a warning.
if (!semver.satisfies(NODE_VERSION, NODE_VERSION_REQUIREMENT)) {
warningPartial = 'is no longer supported';
} else if (NODE_VERSION_DEPRECATING_RANGE &&
semver.satisfies(NODE_VERSION, NODE_VERSION_DEPRECATING_RANGE)) {
warningPartial = 'has been deprecated';
}

if (warningPartial) {
const upgradeMsg = `Please upgrade to the latest Node.js version available (LTS version recommended).`;
logger.warn(`Warning: Node.js ${NODE_VERSION} ${warningPartial}. ${upgradeMsg}`);
}

// If there were arguments protected from nopt with a double dash, keep
Expand Down

0 comments on commit 39141dd

Please sign in to comment.