Skip to content

Commit

Permalink
feat(@angular/cli): show Node.js version support status in version co…
Browse files Browse the repository at this point in the history
…mmand

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
  • Loading branch information
clydin committed May 22, 2021
1 parent 5855374 commit 57640be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/angular/cli/commands/version-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +35,9 @@ export class VersionCommand extends Command<VersionCommandSchema> {
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\/.*/,
Expand Down Expand Up @@ -104,7 +112,7 @@ export class VersionCommand extends Command<VersionCommandSchema> {
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}
Expand Down Expand Up @@ -134,6 +142,12 @@ export class VersionCommand extends Command<VersionCommandSchema> {
.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 {
Expand Down
10 changes: 9 additions & 1 deletion tests/legacy-cli/e2e/tests/misc/version.ts
Original file line number Diff line number Diff line change
@@ -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:')) {
Expand All @@ -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');
Expand Down

0 comments on commit 57640be

Please sign in to comment.