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

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.
Files changed (123) hide show
  1. package/executors.json +0 -20
  2. package/generators.d.ts +1 -0
  3. package/generators.js +1 -0
  4. package/generators.json +6 -148
  5. package/package.json +11 -11
  6. package/src/executors/ng-packagr-lite/schema.json +0 -13
  7. package/src/executors/package/package.impl.js +2 -8
  8. package/src/executors/package/schema.d.ts +0 -12
  9. package/src/executors/package/schema.json +0 -13
  10. package/src/generators/directive/directive.js +6 -7
  11. package/src/generators/directive/files/__fileName__.spec.ts__tpl__ +8 -0
  12. package/src/generators/directive/files/{__directiveFileName__.directive.ts__tpl__ → __fileName__.ts__tpl__} +1 -1
  13. package/src/generators/directive/lib/normalize-options.d.ts +1 -1
  14. package/src/generators/directive/lib/normalize-options.js +20 -8
  15. package/src/generators/directive/lib/validate-options.js +0 -2
  16. package/src/generators/directive/schema.d.ts +20 -4
  17. package/src/generators/directive/schema.json +15 -11
  18. package/src/generators/federate-module/federate-module.d.ts +4 -0
  19. package/src/generators/federate-module/federate-module.js +39 -0
  20. package/src/generators/federate-module/lib/add-file-to-remote-tsconfig.d.ts +2 -0
  21. package/src/generators/federate-module/lib/add-file-to-remote-tsconfig.js +15 -0
  22. package/src/generators/federate-module/lib/add-path-to-exposes.d.ts +8 -0
  23. package/src/generators/federate-module/lib/add-path-to-exposes.js +78 -0
  24. package/src/generators/federate-module/lib/add-path-to-ts-config.d.ts +8 -0
  25. package/src/generators/federate-module/lib/add-path-to-ts-config.js +12 -0
  26. package/src/generators/federate-module/lib/add-remote.d.ts +7 -0
  27. package/src/generators/federate-module/lib/add-remote.js +47 -0
  28. package/src/generators/federate-module/lib/check-remote-exists.d.ts +2 -0
  29. package/src/generators/federate-module/lib/check-remote-exists.js +22 -0
  30. package/src/generators/federate-module/lib/index.d.ts +4 -0
  31. package/src/generators/federate-module/lib/index.js +7 -0
  32. package/src/generators/federate-module/schema.d.ts +14 -0
  33. package/src/generators/federate-module/schema.json +77 -0
  34. package/src/generators/pipe/files/__fileName__.spec.ts__tpl__ +8 -0
  35. package/src/generators/pipe/files/{__pipeFileName__.pipe.ts__tpl__ → __fileName__.ts__tpl__} +2 -2
  36. package/src/generators/pipe/lib/normalize-options.d.ts +1 -1
  37. package/src/generators/pipe/lib/normalize-options.js +20 -7
  38. package/src/generators/pipe/lib/validate-options.js +0 -2
  39. package/src/generators/pipe/pipe.js +7 -7
  40. package/src/generators/pipe/schema.d.ts +20 -4
  41. package/src/generators/pipe/schema.json +15 -11
  42. package/src/generators/scam/lib/convert-component-to-scam.js +3 -6
  43. package/src/generators/scam/lib/normalize-options.d.ts +1 -1
  44. package/src/generators/scam/lib/normalize-options.js +18 -5
  45. package/src/generators/scam/scam.js +1 -1
  46. package/src/generators/scam/schema.d.ts +18 -3
  47. package/src/generators/scam/schema.json +25 -18
  48. package/src/generators/scam-directive/lib/convert-directive-to-scam.js +3 -6
  49. package/src/generators/scam-directive/lib/normalize-options.d.ts +1 -1
  50. package/src/generators/scam-directive/lib/normalize-options.js +17 -7
  51. package/src/generators/scam-directive/scam-directive.js +1 -1
  52. package/src/generators/scam-directive/schema.d.ts +18 -5
  53. package/src/generators/scam-directive/schema.json +24 -17
  54. package/src/generators/scam-pipe/lib/convert-pipe-to-scam.js +3 -6
  55. package/src/generators/scam-pipe/lib/normalize-options.d.ts +1 -1
  56. package/src/generators/scam-pipe/lib/normalize-options.js +17 -7
  57. package/src/generators/scam-pipe/scam-pipe.js +1 -1
  58. package/src/generators/scam-pipe/schema.d.ts +18 -5
  59. package/src/generators/scam-pipe/schema.json +23 -16
  60. package/src/executors/browser-esbuild/compat.d.ts +0 -2
  61. package/src/executors/browser-esbuild/compat.js +0 -5
  62. package/src/executors/delegate-build/compat.d.ts +0 -2
  63. package/src/executors/delegate-build/compat.js +0 -5
  64. package/src/executors/ng-packagr-lite/compat.d.ts +0 -2
  65. package/src/executors/ng-packagr-lite/compat.js +0 -5
  66. package/src/executors/package/compat.d.ts +0 -2
  67. package/src/executors/package/compat.js +0 -5
  68. package/src/generators/add-linting/compat.d.ts +0 -2
  69. package/src/generators/add-linting/compat.js +0 -6
  70. package/src/generators/application/application.compat.d.ts +0 -1
  71. package/src/generators/application/application.compat.js +0 -7
  72. package/src/generators/component/component.compat.d.ts +0 -2
  73. package/src/generators/component/component.compat.js +0 -6
  74. package/src/generators/component-cypress-spec/compat.d.ts +0 -2
  75. package/src/generators/component-cypress-spec/compat.js +0 -6
  76. package/src/generators/component-story/compat.d.ts +0 -2
  77. package/src/generators/component-story/compat.js +0 -6
  78. package/src/generators/component-test/compat.d.ts +0 -2
  79. package/src/generators/component-test/compat.js +0 -6
  80. package/src/generators/convert-to-with-mf/convert-to-with-mf.compat.d.ts +0 -2
  81. package/src/generators/convert-to-with-mf/convert-to-with-mf.compat.js +0 -6
  82. package/src/generators/cypress-component-configuration/compat.d.ts +0 -2
  83. package/src/generators/cypress-component-configuration/compat.js +0 -6
  84. package/src/generators/directive/files/__directiveFileName__.directive.spec.ts__tpl__ +0 -8
  85. package/src/generators/host/host.compat.d.ts +0 -2
  86. package/src/generators/host/host.compat.js +0 -6
  87. package/src/generators/init/init.compat.d.ts +0 -1
  88. package/src/generators/init/init.compat.js +0 -7
  89. package/src/generators/library/library.compat.d.ts +0 -1
  90. package/src/generators/library/library.compat.js +0 -7
  91. package/src/generators/library-secondary-entry-point/compat.d.ts +0 -2
  92. package/src/generators/library-secondary-entry-point/compat.js +0 -6
  93. package/src/generators/move/compat.d.ts +0 -1
  94. package/src/generators/move/compat.js +0 -7
  95. package/src/generators/ng-add/compat.d.ts +0 -2
  96. package/src/generators/ng-add/compat.js +0 -5
  97. package/src/generators/ngrx/compat.d.ts +0 -2
  98. package/src/generators/ngrx/compat.js +0 -6
  99. package/src/generators/pipe/files/__pipeFileName__.pipe.spec.ts__tpl__ +0 -8
  100. package/src/generators/remote/remote.compat.d.ts +0 -2
  101. package/src/generators/remote/remote.compat.js +0 -6
  102. package/src/generators/scam/scam.compat.d.ts +0 -2
  103. package/src/generators/scam/scam.compat.js +0 -6
  104. package/src/generators/scam-directive/scam-directive.compat.d.ts +0 -2
  105. package/src/generators/scam-directive/scam-directive.compat.js +0 -6
  106. package/src/generators/scam-pipe/scam-pipe.compat.d.ts +0 -2
  107. package/src/generators/scam-pipe/scam-pipe.compat.js +0 -6
  108. package/src/generators/scam-to-standalone/compat.d.ts +0 -2
  109. package/src/generators/scam-to-standalone/compat.js +0 -6
  110. package/src/generators/setup-mf/setup-mf.compat.d.ts +0 -2
  111. package/src/generators/setup-mf/setup-mf.compat.js +0 -6
  112. package/src/generators/setup-ssr/setup-ssr.compat.d.ts +0 -2
  113. package/src/generators/setup-ssr/setup-ssr.compat.js +0 -6
  114. package/src/generators/setup-tailwind/setup-tailwind.compat.d.ts +0 -2
  115. package/src/generators/setup-tailwind/setup-tailwind.compat.js +0 -6
  116. package/src/generators/stories/compat.d.ts +0 -2
  117. package/src/generators/stories/compat.js +0 -6
  118. package/src/generators/storybook-configuration/compat.d.ts +0 -2
  119. package/src/generators/storybook-configuration/compat.js +0 -6
  120. package/src/generators/utils/warn-for-schematic-usage.d.ts +0 -1
  121. package/src/generators/utils/warn-for-schematic-usage.js +0 -8
  122. package/src/generators/web-worker/compat.d.ts +0 -2
  123. package/src/generators/web-worker/compat.js +0 -6
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addPathToExposes = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
6
+ let tsModule;
7
+ function addPathToExposes(tree, { projectPath, moduleName, modulePath }) {
8
+ const moduleFederationConfigPath = (0, devkit_1.joinPathFragments)(projectPath, tree.exists((0, devkit_1.joinPathFragments)(projectPath, 'module-federation.config.ts'))
9
+ ? 'module-federation.config.ts'
10
+ : 'module-federation.config.js');
11
+ updateExposesProperty(tree, moduleFederationConfigPath, moduleName, modulePath);
12
+ }
13
+ exports.addPathToExposes = addPathToExposes;
14
+ function updateExposesProperty(tree, moduleFederationConfigPath, moduleName, modulePath) {
15
+ if (!tsModule) {
16
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
17
+ }
18
+ const fileContent = tree.read(moduleFederationConfigPath, 'utf-8');
19
+ const source = tsModule.createSourceFile(moduleFederationConfigPath, fileContent, tsModule.ScriptTarget.ES2015, true);
20
+ const exposesObject = findExposes(source);
21
+ if (!exposesObject)
22
+ return;
23
+ const newEntry = createObjectEntry(moduleName, modulePath);
24
+ const updatedSourceFile = updateExposesPropertyinAST(source, exposesObject, newEntry);
25
+ writeToConfig(tree, moduleFederationConfigPath, source, updatedSourceFile);
26
+ }
27
+ function findExposes(sourceFile) {
28
+ if (!tsModule) {
29
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
30
+ }
31
+ let exposesObject = null;
32
+ const visit = (node) => {
33
+ if (tsModule.isPropertyAssignment(node) &&
34
+ tsModule.isIdentifier(node.name) &&
35
+ node.name.text === 'exposes' &&
36
+ tsModule.isObjectLiteralExpression(node.initializer)) {
37
+ exposesObject = node.initializer;
38
+ }
39
+ else {
40
+ tsModule.forEachChild(node, visit);
41
+ }
42
+ };
43
+ tsModule.forEachChild(sourceFile, visit);
44
+ return exposesObject;
45
+ }
46
+ // Create a new property assignment
47
+ function createObjectEntry(moduleName, modulePath) {
48
+ if (!tsModule) {
49
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
50
+ }
51
+ return tsModule.factory.createPropertyAssignment(tsModule.factory.createStringLiteral(`./${moduleName}`, true), tsModule.factory.createStringLiteral(modulePath, true));
52
+ }
53
+ // Update the exposes property in the AST
54
+ function updateExposesPropertyinAST(source, exposesObject, newEntry) {
55
+ if (!tsModule) {
56
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
57
+ }
58
+ const updatedExposes = tsModule.factory.updateObjectLiteralExpression(exposesObject, [...exposesObject.properties, newEntry]);
59
+ const transform = (context) => {
60
+ const visit = (node) => {
61
+ // Comparing nodes indirectly to ensure type compatibility. You must ensure that the nodes are identical.
62
+ return tsModule.isObjectLiteralExpression(node) && node === exposesObject
63
+ ? updatedExposes
64
+ : tsModule.visitEachChild(node, visit, context);
65
+ };
66
+ return (node) => tsModule.visitNode(node, visit);
67
+ };
68
+ return tsModule.transform(source, [transform]).transformed[0];
69
+ }
70
+ // Write the updated AST to the file (module-federation.config.js)
71
+ function writeToConfig(tree, filename, source, updatedSourceFile) {
72
+ if (!tsModule) {
73
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
74
+ }
75
+ const printer = tsModule.createPrinter();
76
+ const update = printer.printNode(tsModule.EmitHint.Unspecified, updatedSourceFile, source);
77
+ tree.write(filename, update);
78
+ }
@@ -0,0 +1,8 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ type AddPathToTsConfigOptions = {
3
+ remoteName: string;
4
+ moduleName: string;
5
+ pathToFile: string;
6
+ };
7
+ export declare function addPathToTsConfig(tree: Tree, { remoteName, moduleName, pathToFile }: AddPathToTsConfigOptions): void;
8
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addPathToTsConfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const js_1 = require("@nx/js");
6
+ function addPathToTsConfig(tree, { remoteName, moduleName, pathToFile }) {
7
+ const rootTsConfig = (0, devkit_1.readJson)(tree, (0, js_1.getRootTsConfigPathInTree)(tree));
8
+ if (!rootTsConfig.compilerOptions?.paths[`${remoteName}/${moduleName}`]) {
9
+ (0, js_1.addTsConfigPath)(tree, `${remoteName}/${moduleName}`, [pathToFile]);
10
+ }
11
+ }
12
+ exports.addPathToTsConfig = addPathToTsConfig;
@@ -0,0 +1,7 @@
1
+ import { GeneratorCallback, type Tree } from '@nx/devkit';
2
+ import { type Schema } from '../schema';
3
+ export declare function addRemote(tree: Tree, schema: Schema): Promise<{
4
+ tasks: GeneratorCallback[];
5
+ projectRoot: string;
6
+ remoteName: string;
7
+ }>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addRemote = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ const semver_1 = require("semver");
7
+ const check_remote_exists_1 = require("./check-remote-exists");
8
+ const version_utils_1 = require("../../utils/version-utils");
9
+ const remote_1 = require("../../remote/remote");
10
+ const test_runners_1 = require("../../../utils/test-runners");
11
+ async function addRemote(tree, schema) {
12
+ const tasks = [];
13
+ const remote = (0, check_remote_exists_1.getRemoteIfExists)(tree, schema.remote);
14
+ if (!remote) {
15
+ const installedAngularVersionInfo = (0, version_utils_1.getInstalledAngularVersionInfo)(tree);
16
+ if ((0, semver_1.lt)(installedAngularVersionInfo.version, '14.1.0') &&
17
+ schema.standalone) {
18
+ throw new Error((0, devkit_1.stripIndents) `The "standalone" option is only supported in Angular >= 14.1.0. You are currently using ${installedAngularVersionInfo.version}.
19
+ You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`);
20
+ }
21
+ const remoteGeneratorCallback = await (0, remote_1.default)(tree, {
22
+ name: schema.remote,
23
+ host: schema.host,
24
+ standalone: schema.standalone,
25
+ projectNameAndRootFormat: schema.projectNameAndRootFormat ?? 'derived',
26
+ unitTestRunner: schema.unitTestRunner ?? test_runners_1.UnitTestRunner.Jest,
27
+ e2eTestRunner: schema.e2eTestRunner ?? test_runners_1.E2eTestRunner.Cypress,
28
+ skipFormat: true,
29
+ });
30
+ tasks.push(remoteGeneratorCallback);
31
+ }
32
+ const { projectName, projectRoot: remoteRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
33
+ name: schema.remote,
34
+ projectType: 'application',
35
+ projectNameAndRootFormat: schema.projectNameAndRootFormat ?? 'derived',
36
+ callingGenerator: '@nx/angular:federate-module',
37
+ });
38
+ const projectRoot = remote ? remote.root : remoteRoot;
39
+ const remoteName = remote ? remote.name : projectName;
40
+ // TODO(Colum): add implicit dependency if the path points to a file in a different project
41
+ return {
42
+ tasks,
43
+ projectRoot,
44
+ remoteName,
45
+ };
46
+ }
47
+ exports.addRemote = addRemote;
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare function getRemoteIfExists(tree: Tree, remote: string): false | import("@nx/devkit").ProjectConfiguration;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRemoteIfExists = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function getRemoteIfExists(tree, remote) {
6
+ const remoteProject = getRemote(tree, remote);
7
+ if (!remoteProject) {
8
+ return false;
9
+ }
10
+ const hasModuleFederationConfig = tree.exists((0, devkit_1.joinPathFragments)(remoteProject.root, 'module-federation.config.ts')) ||
11
+ tree.exists((0, devkit_1.joinPathFragments)(remoteProject.root, 'module-federation.config.js'));
12
+ return hasModuleFederationConfig ? remoteProject : false;
13
+ }
14
+ exports.getRemoteIfExists = getRemoteIfExists;
15
+ function getRemote(tree, remote) {
16
+ try {
17
+ return (0, devkit_1.readProjectConfiguration)(tree, remote);
18
+ }
19
+ catch {
20
+ return false;
21
+ }
22
+ }
@@ -0,0 +1,4 @@
1
+ export * from './add-remote';
2
+ export * from './add-path-to-ts-config';
3
+ export * from './add-path-to-exposes';
4
+ export * from './add-file-to-remote-tsconfig';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./add-remote"), exports);
5
+ tslib_1.__exportStar(require("./add-path-to-ts-config"), exports);
6
+ tslib_1.__exportStar(require("./add-path-to-exposes"), exports);
7
+ tslib_1.__exportStar(require("./add-file-to-remote-tsconfig"), exports);
@@ -0,0 +1,14 @@
1
+ import { type ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import { UnitTestRunner, E2eTestRunner } from '../utils/testing';
3
+
4
+ export interface Schema {
5
+ name: string;
6
+ path: string;
7
+ remote: string;
8
+ host?: string;
9
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
10
+ unitTestRunner?: UnitTestRunner;
11
+ e2eTestRunner?: E2eTestRunner;
12
+ standalone?: boolean;
13
+ skipFormat?: boolean;
14
+ }
@@ -0,0 +1,77 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxReactFederateModule",
5
+ "title": "Federate Module",
6
+ "description": "Create a federated module, which is exposed by a remote and can be subsequently loaded by a host.",
7
+ "examples": [
8
+ {
9
+ "command": "nx g federate-module MyModule --path=./src/component/my-cmp.ts --remote=my-remote-app",
10
+ "description": "Create a federated module from my-remote-app, that exposes my-cmp from ./src/component/my-cmp.ts as MyModule."
11
+ }
12
+ ],
13
+ "type": "object",
14
+ "properties": {
15
+ "name": {
16
+ "description": "The name of the module.",
17
+ "type": "string",
18
+ "$default": {
19
+ "$source": "argv",
20
+ "index": 0
21
+ },
22
+ "x-prompt": "What name would you like to use for the module?",
23
+ "pattern": "^[a-zA-Z][^:]*$",
24
+ "x-priority": "important"
25
+ },
26
+ "path": {
27
+ "type": "string",
28
+ "description": "The path to locate the federated module.",
29
+ "x-prompt": "What is the path to the module to be federated?"
30
+ },
31
+ "remote": {
32
+ "type": "string",
33
+ "description": "The name of the remote.",
34
+ "x-prompt": "What is/should the remote be named?"
35
+ },
36
+ "projectNameAndRootFormat": {
37
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
38
+ "type": "string",
39
+ "enum": ["as-provided", "derived"]
40
+ },
41
+ "style": {
42
+ "description": "The file extension to be used for style files for the remote if one needs to be created.",
43
+ "type": "string",
44
+ "default": "css",
45
+ "enum": ["css", "scss", "sass", "less"]
46
+ },
47
+ "skipFormat": {
48
+ "description": "Skip formatting files.",
49
+ "type": "boolean",
50
+ "default": false,
51
+ "x-priority": "internal"
52
+ },
53
+ "unitTestRunner": {
54
+ "type": "string",
55
+ "enum": ["jest", "none"],
56
+ "description": "Test runner to use for unit tests of the remote if it needs to be created.",
57
+ "default": "jest"
58
+ },
59
+ "e2eTestRunner": {
60
+ "type": "string",
61
+ "enum": ["cypress", "none"],
62
+ "description": "Test runner to use for end to end (e2e) tests of the remote if it needs to be created.",
63
+ "default": "cypress"
64
+ },
65
+ "standalone": {
66
+ "description": "Whether to generate the remote application with standalone components if it needs to be created. _Note: This is only supported in Angular versions >= 14.1.0_",
67
+ "type": "boolean",
68
+ "default": false
69
+ },
70
+ "host": {
71
+ "type": "string",
72
+ "description": "The host / shell application for this remote."
73
+ }
74
+ },
75
+ "required": ["name", "path", "remote"],
76
+ "additionalProperties": false
77
+ }
@@ -0,0 +1,8 @@
1
+ import { <%= symbolName %> } from './<%= fileName %>';
2
+
3
+ describe('<%= symbolName %>', () => {
4
+ it('create an instance', () => {
5
+ const pipe = new <%= symbolName %>();
6
+ expect(pipe).toBeTruthy();
7
+ });
8
+ });
@@ -1,10 +1,10 @@
1
1
  import { Pipe, PipeTransform } from '@angular/core';
2
2
 
3
3
  @Pipe({
4
- name: '<%= pipePropertyName %>'<% if(standalone) {%>,
4
+ name: '<%= selector %>'<% if(standalone) {%>,
5
5
  standalone: true<%}%>
6
6
  })
7
- export class <%= pipeClassName %>Pipe implements PipeTransform {
7
+ export class <%= symbolName %> implements PipeTransform {
8
8
 
9
9
  transform(value: unknown, ...args: unknown[]): unknown {
10
10
  return null;
@@ -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>;
@@ -1,17 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const path_1 = require("../../utils/path");
5
- function normalizeOptions(tree, options) {
6
- const { directory, name, path } = (0, path_1.normalizeNameAndPaths)(tree, {
7
- ...options,
8
- type: 'pipe',
4
+ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
5
+ const devkit_1 = require("@nx/devkit");
6
+ async function normalizeOptions(tree, options) {
7
+ const { artifactName: name, directory, fileName, filePath, project, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
8
+ artifactType: 'pipe',
9
+ callingGenerator: '@nx/angular:pipe',
10
+ name: options.name,
11
+ directory: options.directory ?? options.path,
12
+ flat: options.flat,
13
+ nameAndDirectoryFormat: options.nameAndDirectoryFormat,
14
+ project: options.project,
15
+ suffix: 'pipe',
9
16
  });
17
+ const { className } = (0, devkit_1.names)(name);
18
+ const { className: suffixClassName } = (0, devkit_1.names)('pipe');
19
+ const symbolName = `${className}${suffixClassName}`;
10
20
  return {
11
21
  ...options,
12
- directory,
22
+ project,
13
23
  name,
14
- path,
24
+ directory,
25
+ fileName,
26
+ filePath,
27
+ symbolName,
15
28
  };
16
29
  }
17
30
  exports.normalizeOptions = normalizeOptions;
@@ -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;
@@ -6,22 +6,22 @@ const utils_1 = require("../utils");
6
6
  const lib_1 = require("./lib");
7
7
  async function pipeGenerator(tree, rawOptions) {
8
8
  (0, lib_1.validateOptions)(tree, rawOptions);
9
- const options = (0, lib_1.normalizeOptions)(tree, rawOptions);
9
+ const options = await (0, lib_1.normalizeOptions)(tree, rawOptions);
10
10
  const pipeNames = (0, devkit_1.names)(options.name);
11
11
  (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), options.directory, {
12
- pipeClassName: pipeNames.className,
13
- pipeFileName: pipeNames.fileName,
14
- pipePropertyName: pipeNames.propertyName,
12
+ symbolName: options.symbolName,
13
+ fileName: options.fileName,
14
+ selector: pipeNames.propertyName,
15
15
  standalone: options.standalone,
16
16
  tpl: '',
17
17
  });
18
18
  if (options.skipTests) {
19
- const pathToSpecFile = (0, devkit_1.joinPathFragments)(options.directory, `${pipeNames.fileName}.pipe.spec.ts`);
19
+ const pathToSpecFile = (0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.spec.ts`);
20
20
  tree.delete(pathToSpecFile);
21
21
  }
22
22
  if (!options.skipImport && !options.standalone) {
23
- const modulePath = (0, utils_1.findModule)(tree, options.path, options.module);
24
- (0, utils_1.addToNgModule)(tree, options.path, modulePath, pipeNames.fileName, `${pipeNames.className}Pipe`, `${pipeNames.fileName}.pipe`, 'declarations', options.flat, options.export);
23
+ const modulePath = (0, utils_1.findModule)(tree, options.directory, options.module);
24
+ (0, utils_1.addToNgModule)(tree, options.directory, modulePath, '', options.symbolName, options.fileName, 'declarations', options.flat, options.export);
25
25
  }
26
26
  if (!options.skipFormat) {
27
27
  await (0, devkit_1.formatFiles)(tree);
@@ -1,17 +1,33 @@
1
+ import { 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
- flat?: boolean;
5
+ directory?: string;
6
+ nameAndDirectoryFormat?: NameAndDirectoryFormat;
6
7
  skipTests?: boolean;
7
8
  skipImport?: boolean;
8
9
  standalone?: boolean;
9
10
  module?: string;
10
11
  export?: boolean;
11
12
  skipFormat?: boolean;
13
+ /**
14
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18.
15
+ */
16
+ flat?: boolean;
17
+ /**
18
+ * @deprecated Provide the `directory` option instead. It will be removed in Nx v18.
19
+ */
20
+ path?: string;
21
+ /**
22
+ * @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v18.
23
+ */
24
+ project?: string;
12
25
  }
13
26
 
14
27
  export interface NormalizedSchema extends Schema {
15
28
  directory: string;
16
- path: string;
29
+ filePath: string;
30
+ project: string;
31
+ fileName: string;
32
+ symbolName: string;
17
33
  }
@@ -5,7 +5,7 @@
5
5
  "type": "object",
6
6
  "cli": "nx",
7
7
  "additionalProperties": false,
8
- "description": "Creates a new, generic pipe definition in the given project.",
8
+ "description": "Creates an Angular pipe.",
9
9
  "properties": {
10
10
  "name": {
11
11
  "type": "string",
@@ -16,14 +16,16 @@
16
16
  },
17
17
  "x-prompt": "What name would you like to use for the pipe?"
18
18
  },
19
- "path": {
19
+ "directory": {
20
20
  "type": "string",
21
- "format": "path",
22
- "$default": {
23
- "$source": "workingDirectory"
24
- },
25
- "description": "The path at which to create the pipe, relative to the workspace root.",
26
- "visible": false
21
+ "description": "The directory at which to create the pipe 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 pipe 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"]
27
29
  },
28
30
  "project": {
29
31
  "type": "string",
@@ -31,12 +33,14 @@
31
33
  "$default": {
32
34
  "$source": "projectName"
33
35
  },
34
- "x-dropdown": "projects"
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."
35
38
  },
36
39
  "flat": {
37
40
  "type": "boolean",
38
41
  "default": true,
39
- "description": "When true (the default) creates files at the top level of the project."
42
+ "description": "When true (the default) creates files at the top level of the project.",
43
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
40
44
  },
41
45
  "skipTests": {
42
46
  "type": "boolean",
@@ -69,5 +73,5 @@
69
73
  "description": "Skip formatting of files."
70
74
  }
71
75
  },
72
- "required": ["name", "project"]
76
+ "required": ["name"]
73
77
  }
@@ -9,9 +9,6 @@ function convertComponentToScam(tree, options) {
9
9
  if (!tree.exists(options.filePath)) {
10
10
  throw new Error(`Couldn't find component at path ${options.filePath} to add SCAM setup.`);
11
11
  }
12
- const componentNames = (0, devkit_1.names)(options.name);
13
- const typeNames = (0, devkit_1.names)(options.type ?? 'component');
14
- const componentClassName = `${componentNames.className}${typeNames.className}`;
15
12
  if (!tsModule) {
16
13
  tsModule = (0, ensure_typescript_1.ensureTypescript)();
17
14
  }
@@ -21,12 +18,12 @@ function convertComponentToScam(tree, options) {
21
18
  source = (0, js_1.insertImport)(tree, source, options.filePath, 'NgModule', '@angular/core');
22
19
  source = (0, js_1.insertImport)(tree, source, options.filePath, 'CommonModule', '@angular/common');
23
20
  let updatedComponentSource = source.getText();
24
- updatedComponentSource = `${updatedComponentSource}${getNgModuleDeclaration(componentClassName)}`;
21
+ updatedComponentSource = `${updatedComponentSource}${getNgModuleDeclaration(options.symbolName)}`;
25
22
  tree.write(options.filePath, updatedComponentSource);
26
23
  return;
27
24
  }
28
- const moduleFilePath = (0, devkit_1.joinPathFragments)(options.directory, `${componentNames.fileName}.module.ts`);
29
- tree.write(moduleFilePath, getModuleFileContent(componentClassName, options.fileName));
25
+ const moduleFilePath = (0, devkit_1.joinPathFragments)(options.directory, `${options.name}.module.ts`);
26
+ tree.write(moduleFilePath, getModuleFileContent(options.symbolName, options.fileName));
30
27
  }
31
28
  exports.convertComponentToScam = convertComponentToScam;
32
29
  function getModuleFileContent(componentClassName, componentFileName) {
@@ -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>;
@@ -1,12 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const path_1 = require("../../utils/path");
5
- function normalizeOptions(tree, options) {
6
- const { directory, fileName, filePath, name } = (0, path_1.normalizeNameAndPaths)(tree, {
7
- ...options,
8
- type: options.type ?? 'component',
4
+ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
5
+ const devkit_1 = require("@nx/devkit");
6
+ async function normalizeOptions(tree, options) {
7
+ options.type ??= 'component';
8
+ const { artifactName: name, directory, fileName, filePath, project, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
9
+ artifactType: options.type,
10
+ callingGenerator: '@nx/angular:scam',
11
+ name: options.name,
12
+ directory: options.directory ?? options.path,
13
+ flat: options.flat,
14
+ nameAndDirectoryFormat: options.nameAndDirectoryFormat,
15
+ project: options.project,
16
+ suffix: options.type ?? 'component',
9
17
  });
18
+ const { className } = (0, devkit_1.names)(name);
19
+ const { className: suffixClassName } = (0, devkit_1.names)(options.type);
20
+ const symbolName = `${className}${suffixClassName}`;
10
21
  return {
11
22
  ...options,
12
23
  export: options.export ?? true,
@@ -15,6 +26,8 @@ function normalizeOptions(tree, options) {
15
26
  fileName,
16
27
  filePath,
17
28
  name,
29
+ symbolName,
30
+ project,
18
31
  };
19
32
  }
20
33
  exports.normalizeOptions = normalizeOptions;
@@ -15,7 +15,7 @@ async function scamGenerator(tree, rawOptions) {
15
15
  standalone: false,
16
16
  skipFormat: true,
17
17
  });
18
- const options = (0, lib_1.normalizeOptions)(tree, rawOptions);
18
+ const options = await (0, lib_1.normalizeOptions)(tree, rawOptions);
19
19
  (0, lib_1.convertComponentToScam)(tree, options);
20
20
  (0, export_scam_1.exportScam)(tree, options);
21
21
  if (!options.skipFormat) {
@@ -1,7 +1,9 @@
1
+ import { 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,18 +13,31 @@ export interface Schema {
11
13
  skipTests?: boolean;
12
14
  inlineScam?: boolean;
13
15
  type?: string;
14
- flat?: boolean;
15
16
  prefix?: string;
16
17
  selector?: string;
17
18
  skipSelector?: boolean;
18
19
  export?: boolean;
19
20
  skipFormat?: boolean;
21
+ /**
22
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18.
23
+ */
24
+ flat?: boolean;
25
+ /**
26
+ * @deprecated Provide the `directory` option instead. It will be removed in Nx v18.
27
+ */
28
+ path?: string;
29
+ /**
30
+ * @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v18.
31
+ */
32
+ project?: string;
20
33
  }
21
34
 
22
35
  export interface NormalizedSchema extends Schema {
23
36
  directory: string;
37
+ project: string;
24
38
  fileName: string;
25
39
  filePath: string;
40
+ symbolName: string;
26
41
  export: boolean;
27
42
  inlineScam: boolean;
28
43
  }