@nx/react 20.3.1 → 20.3.3

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2024 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2025 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/migrations.json CHANGED
@@ -47,6 +47,12 @@
47
47
  "version": "20.3.0-beta.2",
48
48
  "description": "If workspace includes Module Federation projects, ensure the new @nx/module-federation package is installed.",
49
49
  "factory": "./src/migrations/update-20-3-0/ensure-nx-module-federation-package"
50
+ },
51
+ "add-mf-env-var-to-target-defaults": {
52
+ "cli": "nx",
53
+ "version": "20.4.0-beta.0",
54
+ "description": "Add NX_MF_DEV_REMOTES to inputs for task hashing when '@nx/webpack:webpack' or '@nx/rspack:rspack' is used for Module Federation.",
55
+ "factory": "./src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults"
50
56
  }
51
57
  },
52
58
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "20.3.1",
3
+ "version": "20.3.3",
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": {
@@ -38,11 +38,11 @@
38
38
  "minimatch": "9.0.3",
39
39
  "picocolors": "^1.1.0",
40
40
  "tslib": "^2.3.0",
41
- "@nx/devkit": "20.3.1",
42
- "@nx/js": "20.3.1",
43
- "@nx/eslint": "20.3.1",
44
- "@nx/web": "20.3.1",
45
- "@nx/module-federation": "20.3.1",
41
+ "@nx/devkit": "20.3.3",
42
+ "@nx/js": "20.3.3",
43
+ "@nx/eslint": "20.3.3",
44
+ "@nx/web": "20.3.3",
45
+ "@nx/module-federation": "20.3.3",
46
46
  "express": "^4.19.2",
47
47
  "http-proxy-middleware": "^3.0.3"
48
48
  },
package/plugins/jest.js CHANGED
@@ -16,17 +16,12 @@ module.exports = {
16
16
  module.exports = {
17
17
  __esModule: true,
18
18
  default: ${assetFilename},
19
- ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
20
- return {
21
- $$typeof: Symbol.for('react.element'),
22
- type: 'svg',
23
- ref: ref,
24
- key: null,
25
- props: Object.assign({}, props, {
26
- children: ${assetFilename}
27
- })
28
- };
29
- }),
19
+ ReactComponent: function ${componentName}(props) {
20
+ return React.createElement(
21
+ 'svg',
22
+ Object.assign({}, props, { children: ${assetFilename} })
23
+ );
24
+ },
30
25
  };`,
31
26
  };
32
27
  }
@@ -25,6 +25,7 @@ const add_webpack_1 = require("./lib/bundlers/add-webpack");
25
25
  const add_rspack_1 = require("./lib/bundlers/add-rspack");
26
26
  const add_rsbuild_1 = require("./lib/bundlers/add-rsbuild");
27
27
  const add_vite_1 = require("./lib/bundlers/add-vite");
28
+ const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
28
29
  async function applicationGenerator(tree, schema) {
29
30
  return await applicationGeneratorInternal(tree, {
30
31
  addPlugin: false,
@@ -130,6 +131,7 @@ async function applicationGeneratorInternal(tree, schema) {
130
131
  if (options.isUsingTsSolutionConfig) {
131
132
  (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
132
133
  }
134
+ (0, sort_fields_1.sortPackageJsonFields)(tree, options.appProjectRoot);
133
135
  if (!options.skipFormat) {
134
136
  await (0, devkit_1.formatFiles)(tree);
135
137
  }
@@ -13,7 +13,7 @@ function getAppTests(options) {
13
13
  ${options.routing
14
14
  ? 'const { getByText } = render(<BrowserRouter><App /></BrowserRouter>);'
15
15
  : 'const { getByText } = render(<App />);'}
16
- expect(getByText(/Welcome ${options.projectName}/gi)).toBeTruthy();
16
+ expect(getByText(new RegExp('Welcome ${options.projectName}', 'gi'))).toBeTruthy();
17
17
  });
18
18
  `;
19
19
  }
@@ -104,7 +104,7 @@ async function hostGenerator(host, schema) {
104
104
  if (!options.setParserOptionsProject) {
105
105
  host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.lint.json'));
106
106
  }
107
- (0, add_mf_env_to_inputs_1.addMfEnvToTargetDefaultInputs)(host);
107
+ (0, add_mf_env_to_inputs_1.addMfEnvToTargetDefaultInputs)(host, options.bundler);
108
108
  const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, { '@module-federation/enhanced': versions_1.moduleFederationEnhancedVersion }, {
109
109
  '@nx/web': versions_1.nxVersion,
110
110
  '@nx/module-federation': versions_1.nxVersion,
@@ -0,0 +1,3 @@
1
+ import type { PackageJson } from 'nx/src/utils/package-json';
2
+ import type { NormalizedSchema } from '../schema';
3
+ export declare function determineEntryFields(options: NormalizedSchema): Pick<PackageJson, 'main' | 'types' | 'exports'>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.determineEntryFields = determineEntryFields;
4
+ function determineEntryFields(options) {
5
+ if (options.bundler !== 'none') {
6
+ return {};
7
+ }
8
+ return {
9
+ main: options.js ? './src/index.js' : './src/index.ts',
10
+ types: options.js ? './src/index.js' : './src/index.ts',
11
+ exports: {
12
+ '.': options.js
13
+ ? './src/index.js'
14
+ : {
15
+ types: './src/index.ts',
16
+ import: './src/index.ts',
17
+ default: './src/index.ts',
18
+ },
19
+ './package.json': './package.json',
20
+ },
21
+ };
22
+ }
@@ -21,6 +21,8 @@ const create_ts_config_1 = require("../../utils/create-ts-config");
21
21
  const install_common_dependencies_1 = require("./lib/install-common-dependencies");
22
22
  const set_defaults_1 = require("./lib/set-defaults");
23
23
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
24
+ const determine_entry_fields_1 = require("./lib/determine-entry-fields");
25
+ const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
24
26
  async function libraryGenerator(host, schema) {
25
27
  return await libraryGeneratorInternal(host, {
26
28
  addPlugin: false,
@@ -47,16 +49,10 @@ async function libraryGeneratorInternal(host, schema) {
47
49
  });
48
50
  tasks.push(initTask);
49
51
  if (options.isUsingTsSolutionConfig) {
50
- const sourceEntry = options.bundler === 'none'
51
- ? options.js
52
- ? './src/index.js'
53
- : './src/index.ts'
54
- : undefined;
55
52
  (0, devkit_1.writeJson)(host, `${options.projectRoot}/package.json`, {
56
53
  name: options.importPath,
57
54
  version: '0.0.1',
58
- main: sourceEntry,
59
- types: sourceEntry,
55
+ ...(0, determine_entry_fields_1.determineEntryFields)(options),
60
56
  nx: {
61
57
  name: options.importPath === options.name ? undefined : options.name,
62
58
  projectType: 'library',
@@ -214,6 +210,7 @@ async function libraryGeneratorInternal(host, schema) {
214
210
  if (options.isUsingTsSolutionConfig) {
215
211
  (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
216
212
  }
213
+ (0, sort_fields_1.sortPackageJsonFields)(host, options.projectRoot);
217
214
  if (!options.skipFormat) {
218
215
  await (0, devkit_1.formatFiles)(host);
219
216
  }
@@ -122,7 +122,7 @@ async function remoteGenerator(host, schema) {
122
122
  const pathToMFManifest = (0, devkit_1.joinPathFragments)(hostConfig.sourceRoot, 'assets/module-federation.manifest.json');
123
123
  (0, add_remote_to_dynamic_host_1.addRemoteToDynamicHost)(host, options.projectName, options.devServerPort, pathToMFManifest);
124
124
  }
125
- (0, add_mf_env_to_inputs_1.addMfEnvToTargetDefaultInputs)(host);
125
+ (0, add_mf_env_to_inputs_1.addMfEnvToTargetDefaultInputs)(host, options.bundler);
126
126
  const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, {}, {
127
127
  '@module-federation/enhanced': versions_1.moduleFederationEnhancedVersion,
128
128
  '@nx/web': versions_1.nxVersion,
@@ -4,10 +4,11 @@ exports.default = default_1;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const add_mf_env_to_inputs_1 = require("../../utils/add-mf-env-to-inputs");
6
6
  async function default_1(tree) {
7
- if (!hasModuleFederationProject(tree)) {
7
+ const bundler = hasModuleFederationProject(tree);
8
+ if (!bundler) {
8
9
  return;
9
10
  }
10
- (0, add_mf_env_to_inputs_1.addMfEnvToTargetDefaultInputs)(tree);
11
+ (0, add_mf_env_to_inputs_1.addMfEnvToTargetDefaultInputs)(tree, bundler);
11
12
  await (0, devkit_1.formatFiles)(tree);
12
13
  }
13
14
  function hasModuleFederationProject(tree) {
@@ -15,10 +16,14 @@ function hasModuleFederationProject(tree) {
15
16
  for (const project of projects.values()) {
16
17
  const targets = project.targets || {};
17
18
  for (const [_, target] of Object.entries(targets)) {
18
- if (target.executor === '@nx/webpack:webpack' &&
19
- (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.ts')) ||
20
- tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.js')))) {
21
- return true;
19
+ if (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.ts')) ||
20
+ tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.js'))) {
21
+ if (target.executor === '@nx/webpack:webpack') {
22
+ return 'webpack';
23
+ }
24
+ else if (target.executor === '@nx/rspack:rspack') {
25
+ return 'rspack';
26
+ }
22
27
  }
23
28
  }
24
29
  }
@@ -1,2 +1,2 @@
1
1
  import { type Tree } from '@nx/devkit';
2
- export declare function addMfEnvToTargetDefaultInputs(tree: Tree): void;
2
+ export declare function addMfEnvToTargetDefaultInputs(tree: Tree, bundler: 'rspack' | 'webpack'): void;
@@ -2,27 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addMfEnvToTargetDefaultInputs = addMfEnvToTargetDefaultInputs;
4
4
  const devkit_1 = require("@nx/devkit");
5
- function addMfEnvToTargetDefaultInputs(tree) {
5
+ function addMfEnvToTargetDefaultInputs(tree, bundler) {
6
6
  const nxJson = (0, devkit_1.readNxJson)(tree);
7
- const webpackExecutor = '@nx/webpack:webpack';
7
+ const executor = bundler === 'rspack' ? '@nx/rspack:rspack' : '@nx/webpack:webpack';
8
8
  const mfEnvVar = 'NX_MF_DEV_REMOTES';
9
9
  nxJson.targetDefaults ??= {};
10
- nxJson.targetDefaults[webpackExecutor] ??= {};
11
- nxJson.targetDefaults[webpackExecutor].inputs ??= [
12
- 'production',
13
- '^production',
14
- ];
15
- nxJson.targetDefaults[webpackExecutor].dependsOn ??= ['^build'];
10
+ nxJson.targetDefaults[executor] ??= {};
11
+ nxJson.targetDefaults[executor].inputs ??= ['production', '^production'];
12
+ nxJson.targetDefaults[executor].dependsOn ??= ['^build'];
16
13
  let mfEnvVarExists = false;
17
- for (const input of nxJson.targetDefaults[webpackExecutor].inputs) {
14
+ for (const input of nxJson.targetDefaults[executor].inputs) {
18
15
  if (typeof input === 'object' && input['env'] === mfEnvVar) {
19
16
  mfEnvVarExists = true;
20
17
  break;
21
18
  }
22
19
  }
23
20
  if (!mfEnvVarExists) {
24
- nxJson.targetDefaults[webpackExecutor].inputs.push({ env: mfEnvVar });
21
+ nxJson.targetDefaults[executor].inputs.push({ env: mfEnvVar });
25
22
  }
26
- nxJson.targetDefaults[webpackExecutor].cache = true;
23
+ nxJson.targetDefaults[executor].cache = true;
27
24
  (0, devkit_1.updateNxJson)(tree, nxJson);
28
25
  }
@@ -35,8 +35,8 @@ export declare const typesExpressVersion = "4.17.17";
35
35
  export declare const isbotVersion = "^3.6.5";
36
36
  export declare const corsVersion = "~2.8.5";
37
37
  export declare const typesCorsVersion = "~2.8.12";
38
- export declare const moduleFederationNodeVersion = "~2.6.11";
39
- export declare const moduleFederationEnhancedVersion = "0.7.6";
38
+ export declare const moduleFederationNodeVersion = "^2.6.21";
39
+ export declare const moduleFederationEnhancedVersion = "^0.8.8";
40
40
  export declare const lessVersion = "3.12.2";
41
41
  export declare const sassVersion = "^1.55.0";
42
42
  export declare const rollupPluginUrlVersion = "^8.0.2";
@@ -40,8 +40,8 @@ exports.typesExpressVersion = '4.17.17';
40
40
  exports.isbotVersion = '^3.6.5';
41
41
  exports.corsVersion = '~2.8.5';
42
42
  exports.typesCorsVersion = '~2.8.12';
43
- exports.moduleFederationNodeVersion = '~2.6.11';
44
- exports.moduleFederationEnhancedVersion = '0.7.6';
43
+ exports.moduleFederationNodeVersion = '^2.6.21';
44
+ exports.moduleFederationEnhancedVersion = '^0.8.8';
45
45
  // style preprocessors
46
46
  exports.lessVersion = '3.12.2';
47
47
  exports.sassVersion = '^1.55.0';