Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: node deprecation warning for <10 #458

Merged
merged 3 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions spec/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,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 @@ -299,9 +304,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