Charles Lyding 415b966dd4 fix(@angular/cli): improve robustness of Node.js version check
This change ensures that both the global version and the project version Node.js version requirements are met before the CLI executes a command.  Previously an older global version of the CLI would allow a newer project version to execute even if the project version had more strict Node.js version requirements.  The Node.js version is now checked twice.  Once in an ES5 safe script to ensure that ancient Node.js versions are not in use.  And secondly in the CLI entry code that is executed after global/project bootstrapping.
2019-11-21 14:06:21 -08:00

29 lines
1.1 KiB
JavaScript
Executable File

#!/usr/bin/env node
'use strict';
// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
try {
process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
} catch (_) {
// If an error happened above, use the most basic title.
process.title = 'ng';
}
// This node version check ensures that extremely old versions of node are not used.
// These may not support ES2015 features such as const/let/async/await/etc.
// These would then crash with a hard to diagnose error message.
// tslint:disable-next-line: no-var-keyword
var version = process.versions.node.split('.').map(part => Number(part));
if (version[0] < 10 || version[0] === 11 || (version[0] === 10 && version[1] < 13)) {
process.stderr.write(
'Node.js version ' + process.verson + ' detected.\n' +
'The Angular CLI requires a minimum Node.js version of either v10.13 or v12.0.\n\n' +
'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
);
process.exit(3);
}
require('../lib/init');