From 57640bebfd0de417456db6c5d3cead45d528c055 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Thu, 20 May 2021 20:17:42 -0400 Subject: [PATCH] feat(@angular/cli): show Node.js version support status in version command Unsupported versions of Node.js will now show an unsupported warning when the `ng version` command is executed. Currently Node.js major versions 12 and 14 are considered supported and tested. Closes #20879 --- packages/angular/cli/commands/version-impl.ts | 16 +++++++++++++++- tests/legacy-cli/e2e/tests/misc/version.ts | 10 +++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/angular/cli/commands/version-impl.ts b/packages/angular/cli/commands/version-impl.ts index ba2e07f7e293..757f28e10ade 100644 --- a/packages/angular/cli/commands/version-impl.ts +++ b/packages/angular/cli/commands/version-impl.ts @@ -13,6 +13,11 @@ import { colors } from '../utilities/color'; import { getPackageManager } from '../utilities/package-manager'; import { Schema as VersionCommandSchema } from './version'; +/** + * Major versions of Node.js that are officially supported by Angular. + */ +const SUPPORTED_NODE_MAJORS = [12, 14]; + interface PartialPackageInfo { name: string; version: string; @@ -30,6 +35,9 @@ export class VersionCommand extends Command { workspacePackage = require(path.resolve(this.context.root, 'package.json')); } catch {} + const [nodeMajor] = process.versions.node.split('.').map((part) => Number(part)); + const unsupportedNodeVersion = !SUPPORTED_NODE_MAJORS.includes(nodeMajor); + const patterns = [ /^@angular\/.*/, /^@angular-devkit\/.*/, @@ -104,7 +112,7 @@ export class VersionCommand extends Command { this.logger.info( ` Angular CLI: ${ngCliVersion} - Node: ${process.versions.node} + Node: ${process.versions.node}${unsupportedNodeVersion ? ' (Unsupported)' : ''} Package Manager: ${await this.getPackageManager()} OS: ${process.platform} ${process.arch} @@ -134,6 +142,12 @@ export class VersionCommand extends Command { .join('\n')} `.replace(/^ {6}/gm, ''), ); + + if (unsupportedNodeVersion) { + this.logger.warn( + `Warning: The current version of Node (${process.versions.node}) is not supported by Angular.`, + ); + } } private getVersion(moduleName: string): string { diff --git a/tests/legacy-cli/e2e/tests/misc/version.ts b/tests/legacy-cli/e2e/tests/misc/version.ts index 9d6858ac1362..c39c3167bf0b 100644 --- a/tests/legacy-cli/e2e/tests/misc/version.ts +++ b/tests/legacy-cli/e2e/tests/misc/version.ts @@ -1,7 +1,7 @@ import { deleteFile } from '../../utils/fs'; import { ng } from '../../utils/process'; -export default async function() { +export default async function () { const { stdout: commandOutput } = await ng('version'); const { stdout: optionOutput } = await ng('--version'); if (!optionOutput.includes('Angular CLI:')) { @@ -12,6 +12,14 @@ export default async function() { throw new Error('version variants have differing output'); } + if (commandOutput.includes(process.versions.node + ' (Unsupported)')) { + throw new Error('Node version should not show unsupported entry'); + } + + if (commandOutput.includes('Warning: The current version of Node ')) { + throw new Error('Node support warning should not be shown'); + } + // doesn't fail on a project with missing angular.json await deleteFile('angular.json'); await ng('version');