-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathnode-version.ts
More file actions
74 lines (63 loc) · 2.26 KB
/
node-version.ts
File metadata and controls
74 lines (63 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
/**
* @fileoverview This file contains the supported Node.js version for the Angular CLI.
* @important This file must not import any other modules.
*/
/**
* The supported Node.js version for the Angular CLI.
*/
const SUPPORTED_NODE_VERSIONS = '0.0.0-ENGINES-NODE';
/**
* The supported Node.js versions.
*/
export const supportedNodeVersions = SUPPORTED_NODE_VERSIONS.replace(/[\^~<>=]/g, '')
.split('||')
.map((v) => v.trim());
/**
* Checks if the current Node.js version is supported.
* @returns `true` if the current Node.js version is supported, `false` otherwise.
*/
export function isNodeVersionSupported(): boolean {
if (SUPPORTED_NODE_VERSIONS.charAt(0) === '0') {
// Unlike `pkg_npm`, `ts_library` which is used to run unit tests does not support substitutions.
return true;
}
const [processMajor, processMinor, processPatch] = process.versions.node
.split('.', 3)
.map((part) => Number(part));
for (const version of supportedNodeVersions) {
const [major, minor, patch] = version.split('.', 3).map((part) => Number(part));
if (
(major === processMajor && processMinor === minor && processPatch >= patch) ||
(major === processMajor && processMinor > minor)
) {
return true;
}
}
return false;
}
/**
* Checks if the current Node.js version is the minimum supported version.
* @returns `true` if the current Node.js version is the minimum supported version, `false` otherwise.
*/
export function isNodeVersionMinSupported(): boolean {
if (SUPPORTED_NODE_VERSIONS.charAt(0) === '0') {
// Unlike `pkg_npm`, `ts_library` which is used to run unit tests does not support substitutions.
return true;
}
const [processMajor, processMinor, processPatch] = process.versions.node
.split('.', 3)
.map((part) => Number(part));
const [major, minor, patch] = supportedNodeVersions[0].split('.', 3).map((part) => Number(part));
return (
processMajor > major ||
(processMajor === major && processMinor > minor) ||
(processMajor === major && processMinor === minor && processPatch >= patch)
);
}