From bf9542a150a603d5c9379ab4dd923fb21c36e29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Mon, 3 Apr 2023 12:01:20 +0100 Subject: [PATCH] fix(angular): validate standalone option in the directive generator (#16051) --- .../packages/angular/generators/directive.json | 2 +- .../src/generators/directive/lib/validate-options.ts | 10 +++++++++- packages/angular/src/generators/directive/schema.json | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/generated/packages/angular/generators/directive.json b/docs/generated/packages/angular/generators/directive.json index 07a4e8b7d95b0..1dd939c7d4898 100644 --- a/docs/generated/packages/angular/generators/directive.json +++ b/docs/generated/packages/angular/generators/directive.json @@ -54,7 +54,7 @@ "description": "The HTML selector to use for this directive." }, "standalone": { - "description": "Whether the generated directive is standalone.", + "description": "Whether the generated directive is standalone. _Note: This is only supported in Angular versions >= 14.1.0_.", "type": "boolean", "default": false }, diff --git a/packages/angular/src/generators/directive/lib/validate-options.ts b/packages/angular/src/generators/directive/lib/validate-options.ts index a73bcccdc8878..7af9476ea0817 100644 --- a/packages/angular/src/generators/directive/lib/validate-options.ts +++ b/packages/angular/src/generators/directive/lib/validate-options.ts @@ -1,6 +1,8 @@ import type { Tree } from '@nrwl/devkit'; -import { getProjects } from '@nrwl/devkit'; +import { getProjects, stripIndents } from '@nrwl/devkit'; +import { lt } from 'semver'; import { checkPathUnderProjectRoot } from '../../utils/path'; +import { getInstalledAngularVersionInfo } from '../../utils/version-utils'; import type { Schema } from '../schema'; export function validateOptions(tree: Tree, options: Schema): void { @@ -10,4 +12,10 @@ export function validateOptions(tree: Tree, options: Schema): void { } checkPathUnderProjectRoot(tree, options.project, options.path); + + const installedAngularVersionInfo = getInstalledAngularVersionInfo(tree); + if (lt(installedAngularVersionInfo.version, '14.1.0') && options.standalone) { + throw new Error(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using "${installedAngularVersionInfo.version}". + You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); + } } diff --git a/packages/angular/src/generators/directive/schema.json b/packages/angular/src/generators/directive/schema.json index 3b499174bcb34..46ae84d8b7c4b 100644 --- a/packages/angular/src/generators/directive/schema.json +++ b/packages/angular/src/generators/directive/schema.json @@ -63,7 +63,7 @@ "description": "The HTML selector to use for this directive." }, "standalone": { - "description": "Whether the generated directive is standalone.", + "description": "Whether the generated directive is standalone. _Note: This is only supported in Angular versions >= 14.1.0_.", "type": "boolean", "default": false },