@nx/react 18.1.0-beta.1 → 18.1.0-beta.10

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/migrations.json CHANGED
@@ -53,6 +53,12 @@
53
53
  "version": "18.0.0-beta.0",
54
54
  "description": "Add NX_MF_DEV_SERVER_STATIC_REMOTES to inputs for task hashing when '@nx/webpack:webpack' is used for Module Federation.",
55
55
  "factory": "./src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults"
56
+ },
57
+ "fix-target-defaults-for-webpack": {
58
+ "cli": "nx",
59
+ "version": "18.1.1-beta.0",
60
+ "description": "Ensure targetDefaults inputs for task hashing when '@nx/webpack:webpack' is used are correct for Module Federation.",
61
+ "factory": "./src/migrations/update-18-1-1/fix-target-defaults-inputs"
56
62
  }
57
63
  },
58
64
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "18.1.0-beta.1",
3
+ "version": "18.1.0-beta.10",
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, 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": {
@@ -36,11 +36,11 @@
36
36
  "chalk": "^4.1.0",
37
37
  "minimatch": "9.0.3",
38
38
  "tslib": "^2.3.0",
39
- "@nx/devkit": "18.1.0-beta.1",
40
- "@nx/js": "18.1.0-beta.1",
41
- "@nx/eslint": "18.1.0-beta.1",
42
- "@nx/web": "18.1.0-beta.1",
43
- "@nrwl/react": "18.1.0-beta.1"
39
+ "@nx/devkit": "18.1.0-beta.10",
40
+ "@nx/js": "18.1.0-beta.10",
41
+ "@nx/eslint": "18.1.0-beta.10",
42
+ "@nx/web": "18.1.0-beta.10",
43
+ "@nrwl/react": "18.1.0-beta.10"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"
@@ -198,8 +198,10 @@ async function* moduleFederationDevServer(options, context) {
198
198
  devkit_1.logger.info(`NX All remotes started, server ready at ${baseUrl}`);
199
199
  next({ success: true, baseUrl: baseUrl });
200
200
  }
201
- catch {
202
- throw new Error(`Timed out waiting for remote to start. Check above for any errors.`);
201
+ catch (err) {
202
+ throw new Error(`Failed to start remotes. Check above for any errors.`, {
203
+ cause: err,
204
+ });
203
205
  }
204
206
  finally {
205
207
  done();
@@ -19,7 +19,7 @@
19
19
  "items": {
20
20
  "type": "string"
21
21
  },
22
- "description": "List of remote applications to not automatically serve, either statically or in development mode.",
22
+ "description": "List of remote applications to not automatically serve, either statically or in development mode. This will not remove the remotes from the `module-federation.config` file, and therefore the application may still try to fetch these remotes.\nThis option is useful for when the `host` application is using a `remote` that does not live in the same workspace as the `host`.",
23
23
  "x-priority": "important"
24
24
  },
25
25
  "buildTarget": {
@@ -143,7 +143,7 @@ async function applicationGeneratorInternal(host, schema) {
143
143
  tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
144
144
  target: 'web',
145
145
  newProject: true,
146
- uiFramework: 'react',
146
+ framework: 'react',
147
147
  });
148
148
  tasks.push(rspackTask);
149
149
  }
@@ -201,8 +201,8 @@ async function applicationGeneratorInternal(host, schema) {
201
201
  devkit_1.logger.warn(`${chalk.bold('styled-jsx')} is not supported by ${chalk.bold('Rspack')}. We've added ${chalk.bold('babel-loader')} to your project, but using babel will slow down your build.`);
202
202
  tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {}, { 'babel-loader': versions_1.babelLoaderVersion }));
203
203
  host.write((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rspack.config.js'), (0, devkit_1.stripIndents) `
204
- const { composePlugins, withNx, withWeb } = require('@nx/rspack');
205
- module.exports = composePlugins(withNx(), withWeb(), (config) => {
204
+ const { composePlugins, withNx, withReact } = require('@nx/rspack');
205
+ module.exports = composePlugins(withNx(), withReact(), (config) => {
206
206
  config.module.rules.push({
207
207
  test: /\\.[jt]sx$/i,
208
208
  use: [
@@ -34,7 +34,7 @@ async function addE2e(tree, options) {
34
34
  bundler: options.bundler === 'rspack' ? 'webpack' : options.bundler,
35
35
  skipFormat: true,
36
36
  devServerTarget: `${options.projectName}:serve`,
37
- baseUrl: 'http://localhost:4200',
37
+ baseUrl: `http://localhost:${options.devServerPort ?? 4200}`,
38
38
  jsx: true,
39
39
  rootProject: options.rootProject,
40
40
  webServerCommands: hasNxBuildPlugin
@@ -66,7 +66,7 @@ async function addE2e(tree, options) {
66
66
  linter: options.linter,
67
67
  setParserOptionsProject: options.setParserOptionsProject,
68
68
  webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.name}`,
69
- webServerAddress: 'http://localhost:4200',
69
+ webServerAddress: `http://localhost:${options.devServerPort ?? 4200}`,
70
70
  rootProject: options.rootProject,
71
71
  addPlugin: options.addPlugin,
72
72
  });
@@ -26,7 +26,10 @@ async function normalizeOptions(host, options, callingGenerator = '@nx/react:app
26
26
  rootProject: options.rootProject,
27
27
  callingGenerator,
28
28
  });
29
- options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
29
+ const nxJson = (0, devkit_1.readNxJson)(host);
30
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
31
+ nxJson.useInferencePlugins !== false;
32
+ options.addPlugin ??= addPlugin;
30
33
  options.rootProject = appProjectRoot === '.';
31
34
  options.projectNameAndRootFormat = projectNameAndRootFormat;
32
35
  const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
@@ -19,7 +19,10 @@ exports.cypressComponentConfigGenerator = cypressComponentConfigGenerator;
19
19
  */
20
20
  async function cypressComponentConfigGeneratorInternal(tree, options) {
21
21
  const { componentConfigurationGenerator: baseCyCtConfig } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
22
- options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
22
+ const nxJson = (0, devkit_1.readNxJson)(tree);
23
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
24
+ nxJson.useInferencePlugins !== false;
25
+ options.addPlugin ??= addPlugin;
23
26
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
24
27
  const installTask = await baseCyCtConfig(tree, {
25
28
  project: options.project,
@@ -5,11 +5,13 @@ const devkit_1 = require("@nx/devkit");
5
5
  function updateModuleFederationE2eProject(host, options) {
6
6
  try {
7
7
  let projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.e2eProjectName);
8
- projectConfig.targets.e2e.options = {
9
- ...projectConfig.targets.e2e.options,
10
- baseUrl: `http://localhost:${options.devServerPort}`,
11
- };
12
- (0, devkit_1.updateProjectConfiguration)(host, options.e2eProjectName, projectConfig);
8
+ if (projectConfig.targets.e2e.executor !== '@nx/playwright:playwright') {
9
+ projectConfig.targets.e2e.options = {
10
+ ...projectConfig.targets.e2e.options,
11
+ baseUrl: `http://localhost:${options.devServerPort}`,
12
+ };
13
+ (0, devkit_1.updateProjectConfiguration)(host, options.e2eProjectName, projectConfig);
14
+ }
13
15
  }
14
16
  catch {
15
17
  // nothing
@@ -13,7 +13,10 @@ async function normalizeOptions(host, options) {
13
13
  projectNameAndRootFormat: options.projectNameAndRootFormat,
14
14
  callingGenerator: '@nx/react:library',
15
15
  });
16
- options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
16
+ const nxJson = (0, devkit_1.readNxJson)(host);
17
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
18
+ nxJson.useInferencePlugins !== false;
19
+ options.addPlugin ??= addPlugin;
17
20
  const fileName = options.simpleName
18
21
  ? projectNames.projectSimpleName
19
22
  : projectNames.projectFileName;
@@ -28,7 +28,10 @@ function storybookConfigurationGenerator(host, schema) {
28
28
  }
29
29
  exports.storybookConfigurationGenerator = storybookConfigurationGenerator;
30
30
  async function storybookConfigurationGeneratorInternal(host, schema) {
31
- schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
31
+ const nxJson = (0, devkit_1.readNxJson)(host);
32
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
33
+ nxJson.useInferencePlugins !== false;
34
+ schema.addPlugin ??= addPluginDefault;
32
35
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
33
36
  let uiFramework = '@storybook/react-vite';
34
37
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, schema.project);
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ async function default_1(tree) {
5
+ if (!hasModuleFederationProject(tree)) {
6
+ return;
7
+ }
8
+ ensureTargetDefaultsContainProductionInputs(tree);
9
+ await (0, devkit_1.formatFiles)(tree);
10
+ }
11
+ exports.default = default_1;
12
+ function ensureTargetDefaultsContainProductionInputs(tree) {
13
+ const nxJson = (0, devkit_1.readNxJson)(tree);
14
+ const webpackExecutor = '@nx/webpack:webpack';
15
+ const mfEnvVar = 'NX_MF_DEV_SERVER_STATIC_REMOTES';
16
+ nxJson.targetDefaults[webpackExecutor] ??= {};
17
+ nxJson.targetDefaults[webpackExecutor].inputs ??= [
18
+ 'production',
19
+ '^production',
20
+ { env: mfEnvVar },
21
+ ];
22
+ if (!nxJson.targetDefaults[webpackExecutor].inputs.includes('production')) {
23
+ nxJson.targetDefaults[webpackExecutor].inputs.push('production');
24
+ }
25
+ if (!nxJson.targetDefaults[webpackExecutor].inputs.includes('^production')) {
26
+ nxJson.targetDefaults[webpackExecutor].inputs.push('^production');
27
+ }
28
+ let mfEnvVarExists = false;
29
+ for (const input of nxJson.targetDefaults[webpackExecutor].inputs) {
30
+ if (typeof input === 'object' && input['env'] === mfEnvVar) {
31
+ mfEnvVarExists = true;
32
+ break;
33
+ }
34
+ }
35
+ if (!mfEnvVarExists) {
36
+ nxJson.targetDefaults[webpackExecutor].inputs.push({ env: mfEnvVar });
37
+ }
38
+ (0, devkit_1.updateNxJson)(tree, nxJson);
39
+ }
40
+ function hasModuleFederationProject(tree) {
41
+ const projects = (0, devkit_1.getProjects)(tree);
42
+ for (const project of projects.values()) {
43
+ const targets = project.targets || {};
44
+ for (const [_, target] of Object.entries(targets)) {
45
+ if (target.executor === '@nx/webpack:webpack' &&
46
+ (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.ts')) ||
47
+ tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.js')))) {
48
+ return true;
49
+ }
50
+ }
51
+ }
52
+ return false;
53
+ }
@@ -8,7 +8,10 @@ function addMfEnvToTargetDefaultInputs(tree) {
8
8
  const mfEnvVar = 'NX_MF_DEV_SERVER_STATIC_REMOTES';
9
9
  nxJson.targetDefaults ??= {};
10
10
  nxJson.targetDefaults[webpackExecutor] ??= {};
11
- nxJson.targetDefaults[webpackExecutor].inputs ??= [];
11
+ nxJson.targetDefaults[webpackExecutor].inputs ??= [
12
+ 'production',
13
+ '^production',
14
+ ];
12
15
  let mfEnvVarExists = false;
13
16
  for (const input of nxJson.targetDefaults[webpackExecutor].inputs) {
14
17
  if (typeof input === 'object' && input['env'] === mfEnvVar) {