Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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.`);
}
}
2 changes: 1 addition & 1 deletion packages/angular/src/generators/directive/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down