@nx/angular 17.0.0-beta.1 → 17.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/generators.json CHANGED
@@ -165,7 +165,7 @@
165
165
  "description": "Creates an Angular application."
166
166
  },
167
167
  "component": {
168
- "factory": "./src/generators/component/component",
168
+ "factory": "./src/generators/component/component#componentGeneratorInternal",
169
169
  "schema": "./src/generators/component/schema.json",
170
170
  "aliases": ["c"],
171
171
  "description": "Generate an Angular Component."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/angular",
3
- "version": "17.0.0-beta.1",
3
+ "version": "17.0.0-beta.2",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, and Cypress. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -79,14 +79,14 @@
79
79
  "webpack": "^5.80.0",
80
80
  "webpack-merge": "^5.8.0",
81
81
  "enquirer": "^2.3.6",
82
- "@nx/devkit": "17.0.0-beta.1",
83
- "@nx/cypress": "17.0.0-beta.1",
84
- "@nx/jest": "17.0.0-beta.1",
85
- "@nx/js": "17.0.0-beta.1",
86
- "@nx/linter": "17.0.0-beta.1",
87
- "@nx/webpack": "17.0.0-beta.1",
88
- "@nx/workspace": "17.0.0-beta.1",
89
- "@nrwl/angular": "17.0.0-beta.1"
82
+ "@nx/devkit": "17.0.0-beta.2",
83
+ "@nx/cypress": "17.0.0-beta.2",
84
+ "@nx/jest": "17.0.0-beta.2",
85
+ "@nx/js": "17.0.0-beta.2",
86
+ "@nx/linter": "17.0.0-beta.2",
87
+ "@nx/webpack": "17.0.0-beta.2",
88
+ "@nx/workspace": "17.0.0-beta.2",
89
+ "@nrwl/angular": "17.0.0-beta.2"
90
90
  },
91
91
  "peerDependencies": {
92
92
  "@angular-devkit/build-angular": ">= 14.0.0 < 17.0.0",
@@ -1,4 +1,5 @@
1
1
  import type { Tree } from '@nx/devkit';
2
2
  import type { Schema } from './schema';
3
3
  export declare function componentGenerator(tree: Tree, rawOptions: Schema): Promise<void>;
4
+ export declare function componentGeneratorInternal(tree: Tree, rawOptions: Schema): Promise<void>;
4
5
  export default componentGenerator;
@@ -1,19 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.componentGenerator = void 0;
3
+ exports.componentGeneratorInternal = exports.componentGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const utils_1 = require("../utils");
6
6
  const lib_1 = require("./lib");
7
7
  async function componentGenerator(tree, rawOptions) {
8
+ await componentGeneratorInternal(tree, {
9
+ nameAndDirectoryFormat: 'derived',
10
+ ...rawOptions,
11
+ });
12
+ }
13
+ exports.componentGenerator = componentGenerator;
14
+ async function componentGeneratorInternal(tree, rawOptions) {
8
15
  (0, lib_1.validateOptions)(tree, rawOptions);
9
- const options = (0, lib_1.normalizeOptions)(tree, rawOptions);
10
- const componentNames = (0, devkit_1.names)(options.name);
11
- const typeNames = (0, devkit_1.names)(options.type);
16
+ const options = await (0, lib_1.normalizeOptions)(tree, rawOptions);
12
17
  (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), options.directory, {
13
- fileName: componentNames.fileName,
14
- className: componentNames.className,
15
- type: typeNames.fileName,
16
- typeClassName: typeNames.className,
18
+ name: options.name,
19
+ fileName: options.fileName,
20
+ symbolName: options.symbolName,
17
21
  style: options.style,
18
22
  inlineStyle: options.inlineStyle,
19
23
  inlineTemplate: options.inlineTemplate,
@@ -26,25 +30,25 @@ async function componentGenerator(tree, rawOptions) {
26
30
  tpl: '',
27
31
  });
28
32
  if (options.skipTests) {
29
- const pathToSpecFile = (0, devkit_1.joinPathFragments)(options.directory, `${componentNames.fileName}.${typeNames.fileName}.spec.ts`);
33
+ const pathToSpecFile = (0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.spec.ts`);
30
34
  tree.delete(pathToSpecFile);
31
35
  }
32
36
  if (options.inlineTemplate) {
33
- const pathToTemplateFile = (0, devkit_1.joinPathFragments)(options.directory, `${componentNames.fileName}.${typeNames.fileName}.html`);
37
+ const pathToTemplateFile = (0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.html`);
34
38
  tree.delete(pathToTemplateFile);
35
39
  }
36
40
  if (options.style === 'none' || options.inlineStyle) {
37
- const pathToStyleFile = (0, devkit_1.joinPathFragments)(options.directory, `${componentNames.fileName}.${typeNames.fileName}.${options.style}`);
41
+ const pathToStyleFile = (0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.${options.style}`);
38
42
  tree.delete(pathToStyleFile);
39
43
  }
40
44
  if (!options.skipImport && !options.standalone) {
41
45
  const modulePath = (0, lib_1.findModuleFromOptions)(tree, options, options.projectRoot);
42
- (0, utils_1.addToNgModule)(tree, options.path, modulePath, componentNames.fileName, `${componentNames.className}${typeNames.className}`, `${componentNames.fileName}.${typeNames.fileName}`, 'declarations', options.flat, options.export);
46
+ (0, utils_1.addToNgModule)(tree, options.directory, modulePath, options.name, options.symbolName, options.fileName, 'declarations', true, options.export);
43
47
  }
44
48
  (0, lib_1.exportComponentInEntryPoint)(tree, options);
45
49
  if (!options.skipFormat) {
46
50
  await (0, devkit_1.formatFiles)(tree);
47
51
  }
48
52
  }
49
- exports.componentGenerator = componentGenerator;
53
+ exports.componentGeneratorInternal = componentGeneratorInternal;
50
54
  exports.default = componentGenerator;
@@ -0,0 +1 @@
1
+ <p><%= name %> works!</p>
@@ -0,0 +1,22 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { <%= symbolName %> } from './<%= fileName %>';
3
+
4
+ describe('<%= symbolName %>', () => {
5
+ let component: <%= symbolName %>;
6
+ let fixture: ComponentFixture<<%= symbolName %>>;
7
+
8
+ beforeEach(async () => {
9
+ await TestBed.configureTestingModule({
10
+ <%= standalone ? 'imports' : 'declarations' %>: [ <%= symbolName %> ]
11
+ })
12
+ .compileComponents();
13
+
14
+ fixture = TestBed.createComponent(<%= symbolName %>);
15
+ component = fixture.componentInstance;
16
+ fixture.detectChanges();
17
+ });
18
+
19
+ it('should create', () => {
20
+ expect(component).toBeTruthy();
21
+ });
22
+ });
@@ -5,8 +5,8 @@ import { CommonModule } from '@angular/common';<% } %>
5
5
  selector: '<%= selector %>',<%}%><% if(standalone) {%>
6
6
  standalone: true,
7
7
  imports: [CommonModule],<%}%><% if(inlineTemplate) { %>
8
- template: `<p><%= fileName %> works!</p>`<% } else { %>
9
- templateUrl: './<%= fileName %><%= type ? '.' + type : '' %>.html'<% } if(inlineStyle) { %>,
8
+ template: `<p><%= name %> works!</p>`<% } else { %>
9
+ templateUrl: './<%= fileName %>.html'<% } if(inlineStyle) { %>,
10
10
  styles: [<% if(displayBlock){ %>
11
11
  `
12
12
  :host {
@@ -14,8 +14,8 @@ import { CommonModule } from '@angular/common';<% } %>
14
14
  }
15
15
  `<% } %>
16
16
  ]<% } else if (style !== 'none') { %>,
17
- styleUrls: ['./<%= fileName %><%= type ? '.' + type : '' %>.<%= style %>']<% } %><% if(!!viewEncapsulation) { %>,
17
+ styleUrls: ['./<%= fileName %>.<%= style %>']<% } %><% if(!!viewEncapsulation) { %>,
18
18
  encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
19
19
  changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
20
20
  })
21
- export class <%= className %><%= typeClassName %> {}
21
+ export class <%= symbolName %> {}
@@ -12,10 +12,10 @@ function findModuleFromOptions(tree, options, projectRoot) {
12
12
  return (0, devkit_1.normalizePath)(findModule(tree, options.directory, projectRoot));
13
13
  }
14
14
  else {
15
- const modulePath = (0, devkit_1.joinPathFragments)(options.path, options.module);
15
+ const modulePath = (0, devkit_1.joinPathFragments)(options.directory, options.module);
16
16
  const componentPath = options.directory;
17
17
  const moduleBaseName = (0, path_1.basename)(modulePath);
18
- const candidateSet = new Set([options.path]);
18
+ const candidateSet = new Set([options.directory]);
19
19
  const projectRootParent = (0, path_1.dirname)(projectRoot);
20
20
  for (let dir = modulePath; dir !== projectRootParent; dir = (0, path_1.dirname)(dir)) {
21
21
  candidateSet.add(dir);
@@ -1,3 +1,3 @@
1
1
  import type { Tree } from '@nx/devkit';
2
2
  import type { NormalizedSchema, Schema } from '../schema';
3
- export declare function normalizeOptions(tree: Tree, options: Schema): NormalizedSchema;
3
+ export declare function normalizeOptions(tree: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -2,23 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const path_1 = require("../../utils/path");
5
+ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
6
6
  const selector_1 = require("../../utils/selector");
7
- function normalizeOptions(tree, options) {
7
+ async function normalizeOptions(tree, options) {
8
8
  options.type ??= 'component';
9
- const { directory, filePath, name, path, root, sourceRoot } = (0, path_1.normalizeNameAndPaths)(tree, options);
10
- const { prefix } = (0, devkit_1.readProjectConfiguration)(tree, options.project);
9
+ const { artifactName: name, directory, fileName, filePath, project, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
10
+ artifactType: 'component',
11
+ callingGenerator: '@nx/angular:component',
12
+ name: options.name,
13
+ directory: options.directory ?? options.path,
14
+ flat: options.flat,
15
+ nameAndDirectoryFormat: options.nameAndDirectoryFormat,
16
+ project: options.project,
17
+ suffix: options.type ?? 'component',
18
+ });
19
+ const { className } = (0, devkit_1.names)(name);
20
+ const { className: suffixClassName } = (0, devkit_1.names)(options.type);
21
+ const symbolName = `${className}${suffixClassName}`;
22
+ const { prefix, root, sourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
11
23
  const selector = options.selector ??
12
24
  (0, selector_1.buildSelector)(tree, name, options.prefix, prefix, 'fileName');
13
25
  return {
14
26
  ...options,
15
27
  name,
28
+ project,
16
29
  changeDetection: options.changeDetection ?? 'Default',
17
30
  style: options.style ?? 'css',
18
- flat: options.flat ?? false,
19
31
  directory,
32
+ fileName,
20
33
  filePath,
21
- path,
34
+ symbolName,
22
35
  projectSourceRoot: sourceRoot,
23
36
  projectRoot: root,
24
37
  selector,
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateOptions = void 0;
4
4
  const validations_1 = require("../../utils/validations");
5
5
  function validateOptions(tree, options) {
6
- (0, validations_1.validateProject)(tree, options.project);
7
- (0, validations_1.validatePathIsUnderProjectRoot)(tree, options.project, options.path);
8
6
  (0, validations_1.validateStandaloneOption)(tree, options.standalone);
9
7
  }
10
8
  exports.validateOptions = validateOptions;
@@ -1,7 +1,9 @@
1
+ import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
2
+
1
3
  export interface Schema {
2
4
  name: string;
3
- project: string;
4
- path?: string;
5
+ directory?: string;
6
+ nameAndDirectoryFormat?: NameAndDirectoryFormat;
5
7
  displayBlock?: boolean;
6
8
  inlineStyle?: boolean;
7
9
  inlineTemplate?: boolean;
@@ -11,7 +13,6 @@ export interface Schema {
11
13
  style?: 'css' | 'scss' | 'sass' | 'less' | 'none';
12
14
  skipTests?: boolean;
13
15
  type?: string;
14
- flat?: boolean;
15
16
  skipImport?: boolean;
16
17
  selector?: string;
17
18
  module?: string;
@@ -19,12 +20,29 @@ export interface Schema {
19
20
  export?: boolean;
20
21
  prefix?: string;
21
22
  skipFormat?: boolean;
23
+
24
+ /**
25
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18.
26
+ */
27
+ flat?: boolean;
28
+ /**
29
+ * @deprecated Provide the `directory` option instead. It will be removed in Nx v18.
30
+ */
31
+ path?: string;
32
+ /**
33
+ * @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v18.
34
+ */
35
+ project?: string;
22
36
  }
23
37
 
24
38
  export interface NormalizedSchema extends Schema {
25
39
  directory: string;
26
40
  filePath: string;
41
+ project: string;
27
42
  projectSourceRoot: string;
28
43
  projectRoot: string;
29
44
  selector: string;
45
+
46
+ fileName: string;
47
+ symbolName: string;
30
48
  }
@@ -4,23 +4,9 @@
4
4
  "title": "Angular Component Schema",
5
5
  "cli": "nx",
6
6
  "type": "object",
7
- "description": "Creates a new, generic Angular component definition in the given or default project.",
7
+ "description": "Creates a new Angular component.",
8
8
  "additionalProperties": false,
9
9
  "properties": {
10
- "path": {
11
- "type": "string",
12
- "format": "path",
13
- "description": "The path at which to create the component file, relative to the current workspace. Default is a folder with the same name as the component in the project root.",
14
- "visible": false
15
- },
16
- "project": {
17
- "type": "string",
18
- "description": "The name of the project.",
19
- "$default": {
20
- "$source": "projectName"
21
- },
22
- "x-dropdown": "projects"
23
- },
24
10
  "name": {
25
11
  "type": "string",
26
12
  "description": "The name of the component.",
@@ -30,6 +16,26 @@
30
16
  },
31
17
  "x-prompt": "What name would you like to use for the component?"
32
18
  },
19
+ "directory": {
20
+ "type": "string",
21
+ "description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
22
+ "aliases": ["dir", "path"],
23
+ "x-priority": "important"
24
+ },
25
+ "nameAndDirectoryFormat": {
26
+ "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
27
+ "type": "string",
28
+ "enum": ["as-provided", "derived"]
29
+ },
30
+ "project": {
31
+ "type": "string",
32
+ "description": "The name of the project.",
33
+ "$default": {
34
+ "$source": "projectName"
35
+ },
36
+ "x-dropdown": "projects",
37
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
38
+ },
33
39
  "prefix": {
34
40
  "type": "string",
35
41
  "description": "The prefix to apply to the generated component selector.",
@@ -91,7 +97,8 @@
91
97
  "flat": {
92
98
  "type": "boolean",
93
99
  "description": "Create the new files at the top level of the current project.",
94
- "default": false
100
+ "default": false,
101
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
95
102
  },
96
103
  "skipImport": {
97
104
  "type": "boolean",
@@ -126,6 +133,6 @@
126
133
  "x-priority": "internal"
127
134
  }
128
135
  },
129
- "required": ["name", "project"],
136
+ "required": ["name"],
130
137
  "examplesFile": "../../../docs/component-examples.md"
131
138
  }
@@ -14,12 +14,9 @@ function updateNgPackage(tree, schema) {
14
14
  }
15
15
  const rootOffset = (0, devkit_1.normalizePath)((0, path_1.relative)((0, path_1.join)(devkit_1.workspaceRoot, project.root), devkit_1.workspaceRoot));
16
16
  const outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)({
17
- target: {
18
- project: schema.newProjectName,
19
- target: 'build',
20
- },
21
- overrides: {},
22
- }, {
17
+ project: schema.newProjectName,
18
+ target: 'build',
19
+ }, {}, {
23
20
  name: schema.newProjectName,
24
21
  type: 'lib',
25
22
  data: {
@@ -42,7 +42,10 @@ function findModule(tree, path, module) {
42
42
  return modulePath;
43
43
  }
44
44
  exports.findModule = findModule;
45
- function addToNgModule(tree, path, modulePath, name, className, fileName, ngModuleProperty, isFlat = true, isExported = false) {
45
+ function addToNgModule(tree, path, modulePath, name, className, fileName, ngModuleProperty,
46
+ // TODO(leo): remove once all consumers are updated
47
+ // // check if exported in the public api
48
+ isFlat = true, isExported = false) {
46
49
  if (!tsModule) {
47
50
  tsModule = (0, ensure_typescript_1.ensureTypescript)();
48
51
  }
@@ -1 +0,0 @@
1
- <p><%= fileName %> works!</p>
@@ -1,22 +0,0 @@
1
- import { ComponentFixture, TestBed } from '@angular/core/testing';
2
- import { <%= className %><%= typeClassName %> } from './<%= fileName %><%= type ? '.' + type: '' %>';
3
-
4
- describe('<%= className %><%= typeClassName %>', () => {
5
- let component: <%= className %><%= typeClassName %>;
6
- let fixture: ComponentFixture<<%= className %><%= typeClassName %>>;
7
-
8
- beforeEach(async () => {
9
- await TestBed.configureTestingModule({
10
- <%= standalone ? 'imports' : 'declarations' %>: [ <%= className %><%= typeClassName %> ]
11
- })
12
- .compileComponents();
13
-
14
- fixture = TestBed.createComponent(<%= className %><%= typeClassName %>);
15
- component = fixture.componentInstance;
16
- fixture.detectChanges();
17
- });
18
-
19
- it('should create', () => {
20
- expect(component).toBeTruthy();
21
- });
22
- });