Skip to content

Commit 57640be

Browse files
committed
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
1 parent 5855374 commit 57640be

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/angular/cli/commands/version-impl.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import { colors } from '../utilities/color';
1313
import { getPackageManager } from '../utilities/package-manager';
1414
import { Schema as VersionCommandSchema } from './version';
1515

16+
/**
17+
* Major versions of Node.js that are officially supported by Angular.
18+
*/
19+
const SUPPORTED_NODE_MAJORS = [12, 14];
20+
1621
interface PartialPackageInfo {
1722
name: string;
1823
version: string;
@@ -30,6 +35,9 @@ export class VersionCommand extends Command<VersionCommandSchema> {
3035
workspacePackage = require(path.resolve(this.context.root, 'package.json'));
3136
} catch {}
3237

38+
const [nodeMajor] = process.versions.node.split('.').map((part) => Number(part));
39+
const unsupportedNodeVersion = !SUPPORTED_NODE_MAJORS.includes(nodeMajor);
40+
3341
const patterns = [
3442
/^@angular\/.*/,
3543
/^@angular-devkit\/.*/,
@@ -104,7 +112,7 @@ export class VersionCommand extends Command<VersionCommandSchema> {
104112
this.logger.info(
105113
`
106114
Angular CLI: ${ngCliVersion}
107-
Node: ${process.versions.node}
115+
Node: ${process.versions.node}${unsupportedNodeVersion ? ' (Unsupported)' : ''}
108116
Package Manager: ${await this.getPackageManager()}
109117
OS: ${process.platform} ${process.arch}
110118
@@ -134,6 +142,12 @@ export class VersionCommand extends Command<VersionCommandSchema> {
134142
.join('\n')}
135143
`.replace(/^ {6}/gm, ''),
136144
);
145+
146+
if (unsupportedNodeVersion) {
147+
this.logger.warn(
148+
`Warning: The current version of Node (${process.versions.node}) is not supported by Angular.`,
149+
);
150+
}
137151
}
138152

139153
private getVersion(moduleName: string): string {

tests/legacy-cli/e2e/tests/misc/version.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { deleteFile } from '../../utils/fs';
22
import { ng } from '../../utils/process';
33

4-
export default async function() {
4+
export default async function () {
55
const { stdout: commandOutput } = await ng('version');
66
const { stdout: optionOutput } = await ng('--version');
77
if (!optionOutput.includes('Angular CLI:')) {
@@ -12,6 +12,14 @@ export default async function() {
1212
throw new Error('version variants have differing output');
1313
}
1414

15+
if (commandOutput.includes(process.versions.node + ' (Unsupported)')) {
16+
throw new Error('Node version should not show unsupported entry');
17+
}
18+
19+
if (commandOutput.includes('Warning: The current version of Node ')) {
20+
throw new Error('Node support warning should not be shown');
21+
}
22+
1523
// doesn't fail on a project with missing angular.json
1624
await deleteFile('angular.json');
1725
await ng('version');

0 commit comments

Comments
 (0)