@nx/react 18.1.0 → 18.1.1

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",
3
+ "version": "18.1.1",
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",
40
- "@nx/js": "18.1.0",
41
- "@nx/eslint": "18.1.0",
42
- "@nx/web": "18.1.0",
43
- "@nrwl/react": "18.1.0"
39
+ "@nx/devkit": "18.1.1",
40
+ "@nx/js": "18.1.1",
41
+ "@nx/eslint": "18.1.1",
42
+ "@nx/web": "18.1.1",
43
+ "@nrwl/react": "18.1.1"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"
@@ -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: [
@@ -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) {