fix(angular): validate standalone option in the directive generator (#16051)

This commit is contained in:
Leosvel Pérez Espinosa 2023-04-03 12:01:20 +01:00 committed by GitHub
parent 9b60863b7b
commit bf9542a150
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -54,7 +54,7 @@
"description": "The HTML selector to use for this directive." "description": "The HTML selector to use for this directive."
}, },
"standalone": { "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", "type": "boolean",
"default": false "default": false
}, },

View File

@ -1,6 +1,8 @@
import type { Tree } from '@nrwl/devkit'; 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 { checkPathUnderProjectRoot } from '../../utils/path';
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
import type { Schema } from '../schema'; import type { Schema } from '../schema';
export function validateOptions(tree: Tree, options: Schema): void { 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); 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.`);
}
} }

View File

@ -63,7 +63,7 @@
"description": "The HTML selector to use for this directive." "description": "The HTML selector to use for this directive."
}, },
"standalone": { "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", "type": "boolean",
"default": false "default": false
}, },