|
1 | 1 |
|
2 | 2 | // This function must be separate to avoid dependencies on C++ modules - it must execute precisely when other functions cannot |
3 | 3 |
|
4 | | -import {EOL} from "os"; |
5 | | -import * as semver from "semver"; |
| 4 | +// Use only ES5 code here - pure JavaScript can be executed with any Node.js version (even 0.10, 0.12). |
| 5 | +/* tslint:disable:no-var-keyword no-var-requires */ |
| 6 | +var os = require("os"), |
| 7 | + semver = require("semver"), |
| 8 | + util = require("util"); |
6 | 9 |
|
7 | 10 | // These versions cannot be used with CLI due to bugs in the node itself. |
8 | 11 | // We are absolutely sure we cannot work with them, so inform the user if he is trying to use any of them and exit the process. |
9 | | -let versionsCausingFailure = ["0.10.34", "4.0.0", "4.2.0", "5.0.0"]; |
| 12 | +var versionsCausingFailure = ["0.10.34", "4.0.0", "4.2.0", "5.0.0"]; |
| 13 | +var minimumRequiredVersion = "4.2.1"; |
10 | 14 |
|
11 | | -export function verifyNodeVersion(supportedVersionsRange: string, cliName: string, deprecationVersion: string): void { |
| 15 | +export function verifyNodeVersion(supportedVersionsRange: string, cliName: string): void { |
12 | 16 | // The colors module should not be assigned to variable because the lint task will fail for not used variable. |
13 | 17 | require("colors"); |
14 | | - let nodeVer = process.version.substr(1); |
15 | 18 |
|
16 | | - if (versionsCausingFailure.indexOf(nodeVer) !== -1) { |
17 | | - console.error(`${EOL}Node.js '${nodeVer}' is not supported. To be able to work with ${cliName} CLI, install any Node.js version in the following range: ${supportedVersionsRange}.${EOL}`.red.bold); |
| 19 | + var nodeVer = process.version.substr(1); |
| 20 | + |
| 21 | + if (versionsCausingFailure.indexOf(nodeVer) !== -1 || !semver.valid(nodeVer) || semver.lt(nodeVer, minimumRequiredVersion)) { |
| 22 | + console.error(util.format("%sNode.js '%s' is not supported. To be able to work with %s CLI, install any Node.js version in the following range: %s.%s", |
| 23 | + os.EOL, nodeVer, cliName, supportedVersionsRange, os.EOL).red.bold); |
18 | 24 | process.exit(1); |
19 | 25 | } |
20 | 26 |
|
21 | | - if (semver.satisfies(nodeVer, "~0.12.0")) { |
22 | | - console.warn(`${EOL}Support for Node.js 0.12.x is deprecated and will be removed in the ${cliName} ${deprecationVersion} release. Please, upgrade to the latest Node.js LTS version.${EOL}`.yellow.bold); |
23 | | - } else { |
24 | | - let checkSatisfied = semver.satisfies(nodeVer, supportedVersionsRange); |
25 | | - if (!checkSatisfied) { |
26 | | - console.log(`${EOL}Support for Node.js ${nodeVer} is not verified. This CLI might not install or run properly.${EOL}`.yellow.bold); |
27 | | - } |
| 27 | + var checkSatisfied = semver.satisfies(nodeVer, supportedVersionsRange); |
| 28 | + if (!checkSatisfied) { |
| 29 | + console.log(util.format("%sSupport for Node.js %s is not verified. This CLI might not install or run properly.%s", os.EOL, nodeVer, os.EOL).yellow.bold); |
28 | 30 | } |
29 | 31 | } |
| 32 | +/* tslint:enable */ |
0 commit comments