@nx/react 24.0.0-beta.3 → 24.0.0-beta.4

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.
@@ -19,15 +19,11 @@ async function cypressComponentConfigGeneratorInternal(tree, options) {
19
19
  (0, assert_supported_react_version_1.assertSupportedReactVersion)(tree);
20
20
  const { componentConfigurationGenerator: baseCyCtConfig } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
21
21
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
22
- const { found, bundler } = await (0, ct_utils_1.resolveCypressCTTarget)(tree, {
22
+ const { found, bundler: buildBundler } = await (0, ct_utils_1.resolveCypressCTTarget)(tree, {
23
23
  project: options.project,
24
24
  buildTarget: options.buildTarget,
25
- bundler: options.bundler,
26
- validExecutorNames: new Set([
27
- '@nx/webpack:webpack',
28
- '@nx/vite:build',
29
- ]),
30
25
  });
26
+ const bundler = options.bundler ?? buildBundler;
31
27
  const installTask = await baseCyCtConfig(tree, {
32
28
  project: options.project,
33
29
  skipFormat: true,
@@ -35,7 +31,7 @@ async function cypressComponentConfigGeneratorInternal(tree, options) {
35
31
  bundler,
36
32
  });
37
33
  await (0, ct_utils_1.configureCypressCT)(tree, { project: options.project, found, bundler });
38
- await (0, add_files_1.addFiles)(tree, projectConfig, options, found);
34
+ await (0, add_files_1.addFiles)(tree, projectConfig, options, buildBundler);
39
35
  if (!options.skipFormat) {
40
36
  await (0, devkit_1.formatFiles)(tree);
41
37
  }
@@ -1,4 +1,3 @@
1
- import type { FoundTarget } from '@nx/cypress/internal';
2
1
  import { ProjectConfiguration, Tree } from '@nx/devkit';
3
2
  import type { CypressComponentConfigurationSchema } from '../schema';
4
- export declare function addFiles(tree: Tree, projectConfig: ProjectConfiguration, options: CypressComponentConfigurationSchema, found: FoundTarget): Promise<void>;
3
+ export declare function addFiles(tree: Tree, projectConfig: ProjectConfiguration, options: CypressComponentConfigurationSchema, buildBundler: 'vite' | 'webpack'): Promise<void>;
@@ -6,12 +6,14 @@ const internal_1 = require("@nx/js/internal");
6
6
  const ct_utils_1 = require("../../../utils/ct-utils");
7
7
  const component_test_1 = require("../../component-test/component-test");
8
8
  const internal_2 = require("@nx/devkit/internal");
9
- async function addFiles(tree, projectConfig, options, found) {
9
+ async function addFiles(tree, projectConfig, options, buildBundler) {
10
10
  // must dynamicaly import to prevent packages not using cypress from erroring out
11
11
  // when importing react
12
12
  const { addMountDefinition, getInstalledCypressMajorVersion, } = require('@nx/cypress/internal');
13
13
  const installedCypressMajorVersion = getInstalledCypressMajorVersion(tree);
14
- const actualBundler = await (0, ct_utils_1.getActualBundler)(tree, options, found);
14
+ const actualBundler = options.buildTarget !== undefined && options.bundler
15
+ ? options.bundler
16
+ : buildBundler;
15
17
  if (options.bundler && options.bundler !== actualBundler) {
16
18
  devkit_1.logger.warn(`You have specified ${options.bundler} as the bundler but this project is configured to use ${actualBundler}.
17
19
  This may cause errors. If you are seeing errors, try removing the --bundler option.`);
@@ -100,11 +100,6 @@ async function storiesGenerator(host, schema) {
100
100
  }
101
101
  }
102
102
  async function isNextJsProject(tree, config) {
103
- const { findStorybookAndBuildTargetsAndCompiler, } = require('@nx/storybook/src/utils/utilities');
104
- const { nextBuildTarget } = findStorybookAndBuildTargetsAndCompiler(config.targets);
105
- if (nextBuildTarget) {
106
- return true;
107
- }
108
103
  for (const configFile of ['next.config.js', 'next.config.ts']) {
109
104
  if (tree.exists((0, path_1.join)(config.root, configFile))) {
110
105
  return true;
@@ -3,8 +3,6 @@ import { type FoundTarget } from '@nx/cypress/internal';
3
3
  export declare function resolveCypressCTTarget(tree: Tree, options: {
4
4
  project: string;
5
5
  buildTarget: string;
6
- bundler: 'vite' | 'webpack';
7
- validExecutorNames: Set<string>;
8
6
  }): Promise<{
9
7
  found: FoundTarget;
10
8
  bundler: 'vite' | 'webpack';
@@ -14,9 +12,4 @@ export declare function configureCypressCT(tree: Tree, options: {
14
12
  found: FoundTarget;
15
13
  bundler: 'vite' | 'webpack';
16
14
  }): Promise<void>;
17
- export declare function getBundlerFromTarget(found: FoundTarget, tree: Tree): Promise<'vite' | 'webpack'>;
18
- export declare function getActualBundler(tree: Tree, options: {
19
- buildTarget?: string;
20
- bundler?: 'vite' | 'webpack';
21
- }, found: FoundTarget): Promise<"vite" | "webpack">;
22
15
  export declare function isComponent(tree: Tree, filePath: string): boolean;
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveCypressCTTarget = resolveCypressCTTarget;
4
4
  exports.configureCypressCT = configureCypressCT;
5
- exports.getBundlerFromTarget = getBundlerFromTarget;
6
- exports.getActualBundler = getActualBundler;
7
5
  exports.isComponent = isComponent;
8
6
  const devkit_1 = require("@nx/devkit");
9
7
  const internal_1 = require("@nx/devkit/internal");
@@ -14,7 +12,6 @@ const allowedFileExt = new RegExp(/\.[jt]sx?/);
14
12
  const isSpecFile = new RegExp(/(spec|test)\./);
15
13
  // Resolved before the shared cypress generator runs, so the bundler reaches it.
16
14
  async function resolveCypressCTTarget(tree, options) {
17
- let found = { target: options.buildTarget, config: undefined };
18
15
  const graph = await (0, devkit_1.createProjectGraphAsync)();
19
16
  const parsed = options.buildTarget
20
17
  ? (0, devkit_1.parseTargetString)(options.buildTarget, graph)
@@ -25,40 +22,40 @@ async function resolveCypressCTTarget(tree, options) {
25
22
  options.project,
26
23
  ...Object.keys(graph.dependencies).filter((name) => graph.dependencies[name].some((dep) => dep.target === options.project)),
27
24
  ];
25
+ let overridden;
28
26
  for (const project of candidates) {
29
27
  const native = await findNativeBuild(tree, project, parsed?.target);
30
- if (native) {
31
- return {
32
- found: {
33
- target: options.buildTarget ?? native.target,
34
- config: { command: `${native.bundler} build` },
35
- },
36
- bundler: options.bundler ?? native.bundler,
28
+ if (!native)
29
+ continue;
30
+ if (native.overridingExecutor) {
31
+ overridden ??= {
32
+ project,
33
+ target: native.target,
34
+ executor: native.overridingExecutor,
37
35
  };
36
+ continue;
38
37
  }
38
+ return {
39
+ found: {
40
+ target: options.buildTarget ?? native.target,
41
+ config: { command: `${native.bundler} build` },
42
+ },
43
+ bundler: native.bundler,
44
+ };
39
45
  }
40
- if (options.buildTarget === undefined) {
41
- const { findBuildConfig, } = require('@nx/cypress/internal');
42
- found = await findBuildConfig(tree, {
43
- project: options.project,
44
- buildTarget: options.buildTarget,
45
- validExecutorNames: options.validExecutorNames,
46
- });
47
- assertValidConfig(found?.config);
46
+ if (parsed) {
47
+ const executor = (0, devkit_1.readProjectConfiguration)(tree, parsed.project).targets?.[parsed.target]?.executor;
48
+ throw notInferredBuildTargetError(options.buildTarget, parsed.project, executor);
48
49
  }
49
- else if (options.buildTarget) {
50
- const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
51
- const { project, target } = (0, devkit_1.parseTargetString)(options.buildTarget, projectGraph);
52
- const buildTargetProject = (0, devkit_1.readProjectConfiguration)(tree, project);
53
- const executor = buildTargetProject.targets?.[target]?.executor;
54
- if (!executor || !options.validExecutorNames.has(executor)) {
55
- throw new Error(`Cypress Component Testing is not currently supported for this project. Either 'executer' is not defined in '${target} target' of '${project} project.json' or executer present is not valid one. Valid ones are ${JSON.stringify([...options.validExecutorNames])}. Please check https://github.com/nrwl/nx/issues/21546 for more information.`);
56
- }
50
+ if (overridden) {
51
+ throw notInferredBuildTargetError(overridden.target, overridden.project, overridden.executor);
57
52
  }
58
- return {
59
- found,
60
- bundler: options.bundler ?? (await getActualBundler(tree, options, found)),
61
- };
53
+ throw new Error(`Unable to find a build target inferred by @nx/vite/plugin or @nx/webpack/plugin for project "${options.project}" or the projects that depend on it. Pass one with --build-target=<project>:<target>[:<configuration>].`);
54
+ }
55
+ function notInferredBuildTargetError(buildTarget, project, executor) {
56
+ return new Error(`Cypress Component Testing needs a build target inferred by @nx/vite/plugin or @nx/webpack/plugin, and "${buildTarget}" is not one.${executor && executor !== 'nx:run-commands'
57
+ ? ` It uses the "${executor}" executor. Convert it to an inferred target first, for example with "nx g @nx/workspace:infer-targets --project=${project}".`
58
+ : ''}`);
62
59
  }
63
60
  async function configureCypressCT(tree, options) {
64
61
  const { found } = options;
@@ -72,30 +69,8 @@ async function configureCypressCT(tree, options) {
72
69
  const updatedCyConfig = await addDefaultCTConfig(tree.read(cypressConfigFilePath, 'utf-8'), ctConfigOptions, '@nx/react/plugins/component-testing', getInstalledCypressMajorVersion(tree));
73
70
  tree.write(cypressConfigFilePath, updatedCyConfig);
74
71
  }
75
- function assertValidConfig(config) {
76
- if (!config) {
77
- throw new Error('Unable to find a valid build configuration. Try passing in a target for an app. --build-target=<project>:<target>[:<configuration>]');
78
- }
79
- }
80
- async function getBundlerFromTarget(found, tree) {
81
- if (found.target && found.config?.executor) {
82
- return found.config.executor === '@nx/vite:build' ? 'vite' : 'webpack';
83
- }
84
- const { target, project } = (0, devkit_1.parseTargetString)(found.target, await (0, devkit_1.createProjectGraphAsync)());
85
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
86
- const native = await findNativeBuild(tree, project, target);
87
- if (native)
88
- return native.bundler;
89
- const executor = projectConfig?.targets?.[target]?.executor;
90
- return executor === '@nx/vite:build' ? 'vite' : 'webpack';
91
- }
92
72
  async function findNativeBuild(tree, project, target) {
93
73
  const config = (0, devkit_1.readProjectConfiguration)(tree, project);
94
- if (target &&
95
- config.targets?.[target]?.executor &&
96
- config.targets[target].executor !== 'nx:run-commands') {
97
- return;
98
- }
99
74
  for (const bundler of ['vite', 'webpack']) {
100
75
  for (const ext of ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs']) {
101
76
  const path = (0, devkit_1.joinPathFragments)(config.root, `${bundler}.config.${ext}`);
@@ -110,16 +85,17 @@ async function findNativeBuild(tree, project, target) {
110
85
  ?.buildTargetName ?? 'build');
111
86
  if (target && target !== buildTarget)
112
87
  continue;
113
- return { target: `${project}:${buildTarget}`, bundler };
88
+ // A project.json or package.json target on another executor replaces the
89
+ // inferred one (nx.json targetDefaults can't change its executor).
90
+ const executor = config.targets?.[buildTarget]?.executor;
91
+ return {
92
+ target: `${project}:${buildTarget}`,
93
+ bundler,
94
+ overridingExecutor: executor && executor !== 'nx:run-commands' ? executor : undefined,
95
+ };
114
96
  }
115
97
  }
116
98
  }
117
- async function getActualBundler(tree, options, found) {
118
- const actualBundler = options.buildTarget !== undefined && options.bundler
119
- ? options.bundler
120
- : await getBundlerFromTarget(found, tree);
121
- return actualBundler;
122
- }
123
99
  function isComponent(tree, filePath) {
124
100
  if (!tsModule) {
125
101
  tsModule = (0, internal_2.ensureTypescript)();
@@ -4,9 +4,7 @@ exports.getUiFramework = getUiFramework;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  function getUiFramework(tree, project) {
6
6
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
7
- if (findWebpackConfig(tree, projectConfig.root) ||
8
- projectConfig.targets?.['build']?.executor === '@nx/rollup:rollup' ||
9
- projectConfig.targets?.['build']?.executor === '@nx/expo:build') {
7
+ if (findWebpackConfig(tree, projectConfig.root)) {
10
8
  return '@storybook/react-webpack5';
11
9
  }
12
10
  return '@storybook/react-vite';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "24.0.0-beta.3",
3
+ "version": "24.0.0-beta.4",
4
4
  "private": false,
5
5
  "description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -99,26 +99,26 @@
99
99
  "@phenomnomnominal/tsquery": "~6.2.0",
100
100
  "minimatch": "10.2.5",
101
101
  "tslib": "^2.3.0",
102
- "@nx/devkit": "24.0.0-beta.3",
103
- "@nx/js": "24.0.0-beta.3",
104
- "@nx/eslint": "24.0.0-beta.3",
105
- "@nx/web": "24.0.0-beta.3",
102
+ "@nx/devkit": "24.0.0-beta.4",
103
+ "@nx/js": "24.0.0-beta.4",
104
+ "@nx/eslint": "24.0.0-beta.4",
105
+ "@nx/web": "24.0.0-beta.4",
106
106
  "semver": "^7.6.3"
107
107
  },
108
108
  "devDependencies": {
109
- "@nx/cypress": "24.0.0-beta.3",
110
- "@nx/playwright": "24.0.0-beta.3",
111
- "@nx/rollup": "24.0.0-beta.3",
112
- "@nx/rsbuild": "24.0.0-beta.3",
113
- "@nx/rspack": "24.0.0-beta.3",
114
- "@nx/vite": "24.0.0-beta.3",
115
- "@nx/vitest": "24.0.0-beta.3",
116
- "@nx/webpack": "24.0.0-beta.3",
117
- "@nx/storybook": "24.0.0-beta.3",
118
- "nx": "24.0.0-beta.3"
109
+ "@nx/cypress": "24.0.0-beta.4",
110
+ "@nx/playwright": "24.0.0-beta.4",
111
+ "@nx/rollup": "24.0.0-beta.4",
112
+ "@nx/rsbuild": "24.0.0-beta.4",
113
+ "@nx/rspack": "24.0.0-beta.4",
114
+ "@nx/vite": "24.0.0-beta.4",
115
+ "@nx/vitest": "24.0.0-beta.4",
116
+ "@nx/webpack": "24.0.0-beta.4",
117
+ "@nx/storybook": "24.0.0-beta.4",
118
+ "nx": "24.0.0-beta.4"
119
119
  },
120
120
  "optionalDependencies": {
121
- "@nx/vite": "24.0.0-beta.3"
121
+ "@nx/vite": "24.0.0-beta.4"
122
122
  },
123
123
  "publishConfig": {
124
124
  "access": "public"