Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit e4222d6

Browse files
Merge pull request #851 from telerik/vladimirov/strict-node-ver
Break CLI process when Node is not supported
2 parents 03a88b7 + 7407382 commit e4222d6

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

verify-node-version.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11

22
// This function must be separate to avoid dependencies on C++ modules - it must execute precisely when other functions cannot
33

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");
69

710
// These versions cannot be used with CLI due to bugs in the node itself.
811
// 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";
1014

11-
export function verifyNodeVersion(supportedVersionsRange: string, cliName: string, deprecationVersion: string): void {
15+
export function verifyNodeVersion(supportedVersionsRange: string, cliName: string): void {
1216
// The colors module should not be assigned to variable because the lint task will fail for not used variable.
1317
require("colors");
14-
let nodeVer = process.version.substr(1);
1518

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);
1824
process.exit(1);
1925
}
2026

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);
2830
}
2931
}
32+
/* tslint:enable */

0 commit comments

Comments
 (0)