@nx/angular 18.0.0-beta.1 → 18.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.d.ts CHANGED
@@ -25,6 +25,6 @@ export * from './src/generators/setup-tailwind/setup-tailwind';
25
25
  export * from './src/generators/stories/stories';
26
26
  export * from './src/generators/storybook-configuration/storybook-configuration';
27
27
  export * from './src/generators/web-worker/web-worker';
28
- export * from './src/generators/cypress-component-configuration/cypress-component-configuration';
28
+ export { cypressComponentConfiguration } from './src/generators/cypress-component-configuration/cypress-component-configuration';
29
29
  export * from './src/generators/component-test/component-test';
30
30
  export * from './src/utils/test-runners';
package/generators.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cypressComponentConfiguration = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  tslib_1.__exportStar(require("./src/generators/add-linting/add-linting"), exports);
5
6
  tslib_1.__exportStar(require("./src/generators/application/application"), exports);
@@ -28,6 +29,7 @@ tslib_1.__exportStar(require("./src/generators/setup-tailwind/setup-tailwind"),
28
29
  tslib_1.__exportStar(require("./src/generators/stories/stories"), exports);
29
30
  tslib_1.__exportStar(require("./src/generators/storybook-configuration/storybook-configuration"), exports);
30
31
  tslib_1.__exportStar(require("./src/generators/web-worker/web-worker"), exports);
31
- tslib_1.__exportStar(require("./src/generators/cypress-component-configuration/cypress-component-configuration"), exports);
32
+ var cypress_component_configuration_1 = require("./src/generators/cypress-component-configuration/cypress-component-configuration");
33
+ Object.defineProperty(exports, "cypressComponentConfiguration", { enumerable: true, get: function () { return cypress_component_configuration_1.cypressComponentConfiguration; } });
32
34
  tslib_1.__exportStar(require("./src/generators/component-test/component-test"), exports);
33
35
  tslib_1.__exportStar(require("./src/utils/test-runners"), exports);
package/generators.json CHANGED
@@ -173,7 +173,7 @@
173
173
  "description": "Adds Storybook configuration to a project."
174
174
  },
175
175
  "cypress-component-configuration": {
176
- "factory": "./src/generators/cypress-component-configuration/cypress-component-configuration",
176
+ "factory": "./src/generators/cypress-component-configuration/cypress-component-configuration#cypressComponentConfigurationInternal",
177
177
  "schema": "./src/generators/cypress-component-configuration/schema.json",
178
178
  "description": "Setup Cypress component testing for a project."
179
179
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/angular",
3
- "version": "18.0.0-beta.1",
3
+ "version": "18.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": {
@@ -78,16 +78,16 @@
78
78
  "tslib": "^2.3.0",
79
79
  "webpack": "^5.80.0",
80
80
  "webpack-merge": "^5.8.0",
81
- "@nx/devkit": "18.0.0-beta.1",
82
- "@nx/cypress": "18.0.0-beta.1",
83
- "@nx/jest": "18.0.0-beta.1",
84
- "@nx/js": "18.0.0-beta.1",
85
- "@nx/eslint": "18.0.0-beta.1",
86
- "@nx/webpack": "18.0.0-beta.1",
87
- "@nx/web": "18.0.0-beta.1",
88
- "@nx/workspace": "18.0.0-beta.1",
81
+ "@nx/devkit": "18.0.0-beta.2",
82
+ "@nx/cypress": "18.0.0-beta.2",
83
+ "@nx/jest": "18.0.0-beta.2",
84
+ "@nx/js": "18.0.0-beta.2",
85
+ "@nx/eslint": "18.0.0-beta.2",
86
+ "@nx/webpack": "18.0.0-beta.2",
87
+ "@nx/web": "18.0.0-beta.2",
88
+ "@nx/workspace": "18.0.0-beta.2",
89
89
  "piscina": "^4.2.1",
90
- "@nrwl/angular": "18.0.0-beta.1"
90
+ "@nrwl/angular": "18.0.0-beta.2"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "@angular-devkit/build-angular": ">= 15.0.0 < 18.0.0",
@@ -17,29 +17,4 @@ import { NxComponentTestingOptions } from '@nx/cypress/plugins/cypress-preset';
17
17
  * @param pathToConfig will be used for loading project options and to construct the output paths for videos and screenshots
18
18
  * @param options override options
19
19
  */
20
- export declare function nxComponentTestingPreset(pathToConfig: string, options?: NxComponentTestingOptions): {
21
- specPattern: string[];
22
- indexHtmlFile: string;
23
- devServer: {
24
- options: {
25
- projectConfig: {
26
- root: string;
27
- sourceRoot: string;
28
- buildOptions: import("@angular-devkit/build-angular").BrowserBuilderOptions & {
29
- customWebpackConfig?: {
30
- path: string;
31
- };
32
- indexFileTransformer?: string;
33
- buildLibsFromSource?: boolean;
34
- } & {
35
- workspaceRoot: string;
36
- };
37
- };
38
- };
39
- framework: "angular";
40
- bundler: "webpack";
41
- };
42
- videosFolder: string;
43
- screenshotsFolder: string;
44
- chromeWebSecurity: boolean;
45
- };
20
+ export declare function nxComponentTestingPreset(pathToConfig: string, options?: NxComponentTestingOptions): any;
@@ -26,6 +26,13 @@ const semver_1 = require("semver");
26
26
  * @param options override options
27
27
  */
28
28
  function nxComponentTestingPreset(pathToConfig, options) {
29
+ if (global.NX_GRAPH_CREATION || global.NX_CYPRESS_INIT_GENERATOR_RUNNING) {
30
+ // this is only used by plugins, so we don't need the component testing
31
+ // options, cast to any to avoid type errors
32
+ return (0, cypress_preset_1.nxBaseCypressPreset)(pathToConfig, {
33
+ testingType: 'component',
34
+ });
35
+ }
29
36
  let graph;
30
37
  try {
31
38
  graph = (0, devkit_1.readCachedProjectGraph)();
@@ -41,7 +48,10 @@ ${e.stack ? e.stack : e}`);
41
48
  const ctProjectConfig = (0, ct_helpers_1.getProjectConfigByPath)(graph, pathToConfig);
42
49
  const ctConfigurationName = process.env.NX_CYPRESS_TARGET_CONFIGURATION;
43
50
  const ctContext = (0, ct_helpers_1.createExecutorContext)(graph, ctProjectConfig.targets, ctProjectConfig.name, options?.ctTargetName || 'component-test', ctConfigurationName);
44
- const buildTarget = getBuildableTarget(ctContext);
51
+ const buildTarget = options?.buildTarget
52
+ ? (0, devkit_1.parseTargetString)(options.buildTarget, graph)
53
+ : // for backwards compat, if no buildTargetin the preset options, get it from the target options
54
+ getBuildableTarget(ctContext);
45
55
  if (!buildTarget.project && !graph.nodes?.[buildTarget.project]?.data) {
46
56
  throw new Error((0, devkit_1.stripIndents) `Unable to find project configuration for build target.
47
57
  Project Name? ${buildTarget.project}
@@ -20,6 +20,7 @@ async function addLintingGenerator(tree, options) {
20
20
  setParserOptionsProject: options.setParserOptionsProject,
21
21
  skipFormat: true,
22
22
  rootProject: rootProject,
23
+ addPlugin: options.addPlugin,
23
24
  });
24
25
  tasks.push(lintTask);
25
26
  if ((0, eslint_file_1.isEslintConfigSupported)(tree)) {
@@ -6,4 +6,5 @@ export interface AddLintingGeneratorSchema {
6
6
  skipFormat?: boolean;
7
7
  skipPackageJson?: boolean;
8
8
  unitTestRunner?: string;
9
+ addPlugin?: boolean;
9
10
  }
@@ -12,6 +12,7 @@ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-projec
12
12
  async function applicationGenerator(tree, schema) {
13
13
  return await applicationGeneratorInternal(tree, {
14
14
  projectNameAndRootFormat: 'derived',
15
+ addPlugin: false,
15
16
  ...schema,
16
17
  });
17
18
  }
@@ -746,6 +746,25 @@ nx g &#64;nx/angular:lib ui
746
746
  <span># Add a component</span>
747
747
  nx g &#64;nx/angular:component ui/src/lib/button</pre>
748
748
  </details>
749
+ <details>
750
+ <summary>
751
+ <svg
752
+ fill="none"
753
+ stroke="currentColor"
754
+ viewBox="0 0 24 24"
755
+ xmlns="http://www.w3.org/2000/svg"
756
+ >
757
+ <path
758
+ strokeLinecap="round"
759
+ strokeLinejoin="round"
760
+ strokeWidth="2"
761
+ d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
762
+ />
763
+ </svg>
764
+ View project details
765
+ </summary>
766
+ <pre>nx show project <%= appName %> --web</pre>
767
+ </details>
749
768
  <details>
750
769
  <summary>
751
770
  <svg
@@ -749,6 +749,25 @@ nx g &#64;nx/angular:lib ui
749
749
  <span># Add a component</span>
750
750
  nx g &#64;nx/angular:component ui/src/lib/button</pre>
751
751
  </details>
752
+ <details>
753
+ <summary>
754
+ <svg
755
+ fill="none"
756
+ stroke="currentColor"
757
+ viewBox="0 0 24 24"
758
+ xmlns="http://www.w3.org/2000/svg"
759
+ >
760
+ <path
761
+ strokeLinecap="round"
762
+ strokeLinejoin="round"
763
+ strokeWidth="2"
764
+ d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
765
+ />
766
+ </svg>
767
+ View project details
768
+ </summary>
769
+ <pre>nx show project <%= appName %> --web</pre>
770
+ </details>
752
771
  <details>
753
772
  <summary>
754
773
  <svg
@@ -26,6 +26,7 @@ async function addE2e(tree, options) {
26
26
  devServerTarget: `${options.name}:serve:development`,
27
27
  baseUrl: 'http://localhost:4200',
28
28
  rootProject: options.rootProject,
29
+ addPlugin: options.addPlugin,
29
30
  });
30
31
  }
31
32
  else if (options.e2eTestRunner === 'playwright') {
@@ -48,6 +49,7 @@ async function addE2e(tree, options) {
48
49
  webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.name}`,
49
50
  webServerAddress: `http://localhost:${options.port ?? 4200}`,
50
51
  rootProject: options.rootProject,
52
+ addPlugin: options.addPlugin,
51
53
  });
52
54
  }
53
55
  }
@@ -15,6 +15,7 @@ async function addLinting(host, options) {
15
15
  skipPackageJson: options.skipPackageJson,
16
16
  unitTestRunner: options.unitTestRunner,
17
17
  skipFormat: true,
18
+ addPlugin: options.addPlugin,
18
19
  });
19
20
  }
20
21
  exports.addLinting = addLinting;
@@ -10,6 +10,7 @@ async function addUnitTestRunner(host, options) {
10
10
  projectRoot: options.appProjectRoot,
11
11
  skipPackageJson: options.skipPackageJson,
12
12
  strict: options.strict,
13
+ addPlugin: options.addPlugin,
13
14
  });
14
15
  }
15
16
  }
@@ -19,6 +19,7 @@ async function normalizeOptions(host, options) {
19
19
  });
20
20
  options.rootProject = appProjectRoot === '.';
21
21
  options.projectNameAndRootFormat = projectNameAndRootFormat;
22
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
22
23
  const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
23
24
  const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
24
25
  const parsedTags = options.tags
@@ -31,4 +31,5 @@ export interface Schema {
31
31
  minimal?: boolean;
32
32
  bundler?: 'webpack' | 'esbuild';
33
33
  ssr?: boolean;
34
+ addPlugin?: boolean;
34
35
  }
@@ -1,8 +1,9 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { CypressComponentConfigSchema } from './schema';
3
+ export declare function cypressComponentConfiguration(tree: Tree, options: CypressComponentConfigSchema): Promise<import("@nx/devkit").GeneratorCallback>;
3
4
  /**
4
5
  * This is for cypress built in component testing, if you want to test with
5
6
  * storybook + cypress then use the componentCypressGenerator instead.
6
7
  */
7
- export declare function cypressComponentConfiguration(tree: Tree, options: CypressComponentConfigSchema): Promise<import("@nx/devkit").GeneratorCallback>;
8
+ export declare function cypressComponentConfigurationInternal(tree: Tree, options: CypressComponentConfigSchema): Promise<import("@nx/devkit").GeneratorCallback>;
8
9
  export default cypressComponentConfiguration;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cypressComponentConfiguration = void 0;
3
+ exports.cypressComponentConfigurationInternal = exports.cypressComponentConfiguration = void 0;
4
4
  const cypress_1 = require("@nx/cypress");
5
5
  const config_1 = require("@nx/cypress/src/utils/config");
6
6
  const find_target_options_1 = require("@nx/cypress/src/utils/find-target-options");
@@ -10,28 +10,34 @@ const component_test_1 = require("../component-test/component-test");
10
10
  const component_info_1 = require("../utils/storybook-ast/component-info");
11
11
  const entry_point_1 = require("../utils/storybook-ast/entry-point");
12
12
  const module_info_1 = require("../utils/storybook-ast/module-info");
13
+ function cypressComponentConfiguration(tree, options) {
14
+ return cypressComponentConfigurationInternal(tree, {
15
+ addPlugin: false,
16
+ ...options,
17
+ });
18
+ }
19
+ exports.cypressComponentConfiguration = cypressComponentConfiguration;
13
20
  /**
14
21
  * This is for cypress built in component testing, if you want to test with
15
22
  * storybook + cypress then use the componentCypressGenerator instead.
16
23
  */
17
- async function cypressComponentConfiguration(tree, options) {
24
+ async function cypressComponentConfigurationInternal(tree, options) {
25
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
18
26
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
19
27
  const installTask = await (0, cypress_1.componentConfigurationGenerator)(tree, {
20
28
  project: options.project,
21
29
  skipFormat: true,
30
+ addPlugin: options.addPlugin,
22
31
  });
23
- await updateProjectConfig(tree, options);
32
+ await configureCypressCT(tree, options);
24
33
  await addFiles(tree, projectConfig, options);
25
34
  if (!options.skipFormat) {
26
35
  await (0, devkit_1.formatFiles)(tree);
27
36
  }
28
37
  return installTask;
29
38
  }
30
- exports.cypressComponentConfiguration = cypressComponentConfiguration;
39
+ exports.cypressComponentConfigurationInternal = cypressComponentConfigurationInternal;
31
40
  async function addFiles(tree, projectConfig, options) {
32
- const cyConfigFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts');
33
- const updatedCyConfig = await (0, config_1.addDefaultCTConfig)(tree.read(cyConfigFile, 'utf-8'));
34
- tree.write(cyConfigFile, `import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';\n${updatedCyConfig}`);
35
41
  const componentFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'component.ts');
36
42
  const updatedCmpContents = await (0, config_1.addMountDefinition)(tree.read(componentFile, 'utf-8'));
37
43
  tree.write(componentFile, `import { mount } from 'cypress/angular';\n${updatedCmpContents}`);
@@ -57,7 +63,7 @@ async function addFiles(tree, projectConfig, options) {
57
63
  }
58
64
  }
59
65
  }
60
- async function updateProjectConfig(tree, options) {
66
+ async function configureCypressCT(tree, options) {
61
67
  let found = { target: options.buildTarget, config: undefined };
62
68
  if (!options.buildTarget) {
63
69
  found = await (0, find_target_options_1.findBuildConfig)(tree, {
@@ -71,13 +77,23 @@ async function updateProjectConfig(tree, options) {
71
77
  });
72
78
  assertValidConfig(found?.config);
73
79
  }
80
+ const ctConfigOptions = {};
74
81
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
75
- projectConfig.targets['component-test'].options = {
76
- ...projectConfig.targets['component-test'].options,
77
- skipServe: true,
78
- devServerTarget: found.target,
79
- };
80
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
82
+ if (projectConfig.targets?.['component-test']?.executor ===
83
+ '@nx/cypress:cypress') {
84
+ projectConfig.targets['component-test'].options = {
85
+ ...projectConfig.targets['component-test'].options,
86
+ skipServe: true,
87
+ devServerTarget: found.target,
88
+ };
89
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
90
+ }
91
+ else {
92
+ ctConfigOptions.buildTarget = found.target;
93
+ }
94
+ const cypressConfigPath = (0, config_1.getProjectCypressConfigPath)(tree, projectConfig.root);
95
+ const updatedCyConfig = await (0, config_1.addDefaultCTConfig)(tree.read(cypressConfigPath, 'utf-8'), ctConfigOptions);
96
+ tree.write(cypressConfigPath, `import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';\n${updatedCyConfig}`);
81
97
  }
82
98
  function assertValidConfig(config) {
83
99
  if (!config) {
@@ -3,4 +3,5 @@ export interface CypressComponentConfigSchema {
3
3
  generateTests: boolean;
4
4
  skipFormat?: boolean;
5
5
  buildTarget?: string;
6
+ addPlugin?: boolean;
6
7
  }
@@ -2,7 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addProject = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
5
6
  function addProject(tree, libraryOptions) {
7
+ const executor = libraryOptions.publishable
8
+ ? '@nx/angular:package'
9
+ : '@nx/angular:ng-packagr-lite';
10
+ (0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, executor);
6
11
  const project = {
7
12
  name: libraryOptions.name,
8
13
  root: libraryOptions.projectRoot,
@@ -13,9 +18,7 @@ function addProject(tree, libraryOptions) {
13
18
  targets: {
14
19
  build: libraryOptions.buildable || libraryOptions.publishable
15
20
  ? {
16
- executor: libraryOptions.publishable
17
- ? '@nx/angular:package'
18
- : '@nx/angular:ng-packagr-lite',
21
+ executor,
19
22
  outputs: ['{workspaceRoot}/dist/{projectRoot}'],
20
23
  options: {
21
24
  project: `${libraryOptions.projectRoot}/ng-package.json`,
@@ -242,6 +242,7 @@ class E2eMigrator extends project_migrator_1.ProjectMigrator {
242
242
  // any target would do, we replace it later with the target existing in the project being migrated
243
243
  devServerTarget: `${this.appName}:serve`,
244
244
  baseUrl: 'http://localhost:4200',
245
+ addPlugin: process.env.NX_ADD_PLUGINS !== 'false',
245
246
  });
246
247
  const cypressConfigFilePath = this.updateOrCreateCypressConfigFile(oldCypressConfigFilePath);
247
248
  this.updateCypressProjectConfiguration(cypressConfigFilePath);
@@ -150,7 +150,9 @@ function updatePackageJson(tree) {
150
150
  }
151
151
  exports.updatePackageJson = updatePackageJson;
152
152
  async function updateRootEsLintConfig(tree, existingEsLintConfig, unitTestRunner) {
153
- await (0, eslint_1.lintInitGenerator)(tree, {});
153
+ await (0, eslint_1.lintInitGenerator)(tree, {
154
+ addPlugin: process.env.NX_ADD_PLUGINS !== 'false',
155
+ });
154
156
  if (!existingEsLintConfig) {
155
157
  // There was no eslint config in the root, so we set it up and use it as-is
156
158
  (0, setup_root_eslint_1.setupRootEsLint)(tree, { unitTestRunner });
@@ -4,5 +4,6 @@ export type AddJestOptions = {
4
4
  projectRoot: string;
5
5
  skipPackageJson: boolean;
6
6
  strict: boolean;
7
+ addPlugin?: boolean;
7
8
  };
8
9
  export declare function addJest(tree: Tree, options: AddJestOptions): Promise<void>;
@@ -17,6 +17,7 @@ async function addJest(tree, options) {
17
17
  skipSerializers: false,
18
18
  skipPackageJson: options.skipPackageJson,
19
19
  skipFormat: true,
20
+ addPlugin: options.addPlugin,
20
21
  });
21
22
  const setupFile = (0, devkit_1.joinPathFragments)(options.projectRoot, 'src', 'test-setup.ts');
22
23
  if (options.strict && tree.exists(setupFile)) {