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