@nx/react 23.2.0-canary.20260729-e3e16e9 → 23.2.0-canary.20260731-0634da3

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.
@@ -1,5 +1,6 @@
1
1
  export { addE2e } from './src/generators/application/lib/add-e2e';
2
2
  export { addRollupBuildTarget } from './src/generators/library/lib/add-rollup-build-target';
3
+ export { assertPackageIsInstalled } from './src/utils/assert-package';
3
4
  export { isComponent } from './src/utils/ct-utils';
4
5
  export { suppressReactComposeHelperWarnings } from './src/utils/deprecation';
5
6
  export { hasWebpackPlugin } from './src/utils/has-webpack-plugin';
package/dist/internal.js CHANGED
@@ -5,11 +5,13 @@
5
5
  // internal consumers and may change without semver protection. Mirrors
6
6
  // `@nx/devkit/internal`.
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.babelPresetReactVersion = exports.babelCoreVersion = exports.testingLibraryReactVersion = exports.testingLibraryDomVersion = exports.isReact18 = exports.getReactDependenciesVersionsToInstall = exports.hasWebpackPlugin = exports.suppressReactComposeHelperWarnings = exports.isComponent = exports.addRollupBuildTarget = exports.addE2e = void 0;
8
+ exports.babelPresetReactVersion = exports.babelCoreVersion = exports.testingLibraryReactVersion = exports.testingLibraryDomVersion = exports.isReact18 = exports.getReactDependenciesVersionsToInstall = exports.hasWebpackPlugin = exports.suppressReactComposeHelperWarnings = exports.isComponent = exports.assertPackageIsInstalled = exports.addRollupBuildTarget = exports.addE2e = void 0;
9
9
  var add_e2e_1 = require("./src/generators/application/lib/add-e2e");
10
10
  Object.defineProperty(exports, "addE2e", { enumerable: true, get: function () { return add_e2e_1.addE2e; } });
11
11
  var add_rollup_build_target_1 = require("./src/generators/library/lib/add-rollup-build-target");
12
12
  Object.defineProperty(exports, "addRollupBuildTarget", { enumerable: true, get: function () { return add_rollup_build_target_1.addRollupBuildTarget; } });
13
+ var assert_package_1 = require("./src/utils/assert-package");
14
+ Object.defineProperty(exports, "assertPackageIsInstalled", { enumerable: true, get: function () { return assert_package_1.assertPackageIsInstalled; } });
13
15
  var ct_utils_1 = require("./src/utils/ct-utils");
14
16
  Object.defineProperty(exports, "isComponent", { enumerable: true, get: function () { return ct_utils_1.isComponent; } });
15
17
  var deprecation_1 = require("./src/utils/deprecation");
@@ -4,18 +4,22 @@ exports.default = moduleFederationDevServer;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const internal_1 = require("@nx/devkit/internal");
6
6
  const internal_2 = require("@nx/js/internal");
7
- const internal_3 = require("@nx/module-federation/internal");
8
- const internal_4 = require("@nx/web/internal");
9
- const webpack_1 = require("@nx/webpack");
7
+ const internal_3 = require("@nx/web/internal");
10
8
  const fs_1 = require("fs");
11
9
  const path_1 = require("path");
12
10
  const lib_1 = require("./lib");
11
+ const assert_package_1 = require("../../utils/assert-package");
13
12
  const module_federation_deprecation_1 = require("../../utils/module-federation-deprecation");
13
+ const executorName = '@nx/react:module-federation-dev-server';
14
14
  async function* moduleFederationDevServer(schema, context) {
15
+ (0, assert_package_1.assertPackageIsInstalled)('@nx/module-federation', executorName);
16
+ (0, assert_package_1.assertPackageIsInstalled)('@nx/webpack', executorName);
17
+ const { startRemoteIterators } = await import('@nx/module-federation/internal');
18
+ const { devServerExecutor } = await import('@nx/webpack');
15
19
  (0, module_federation_deprecation_1.warnReactMfDevServerExecutorDeprecation)();
16
20
  const options = (0, lib_1.normalizeOptions)(schema);
17
21
  const currIter = options.static
18
- ? (0, internal_4.fileServerExecutor)({
22
+ ? (0, internal_3.fileServerExecutor)({
19
23
  ...options,
20
24
  parallel: false,
21
25
  withDeps: false,
@@ -24,7 +28,7 @@ async function* moduleFederationDevServer(schema, context) {
24
28
  cacheSeconds: -1,
25
29
  }, context)
26
30
  : // TODO(JamesHenry): remove type assertion once the nx repo is updated to use https://github.com/nrwl/nx/pull/33095
27
- (0, webpack_1.devServerExecutor)(options, context);
31
+ devServerExecutor(options, context);
28
32
  const p = context.projectsConfigurations.projects[context.projectName];
29
33
  let pathToManifestFile = (0, path_1.join)(context.root, (0, internal_2.getProjectSourceRoot)(p), 'assets/module-federation.manifest.json');
30
34
  if (options.pathToManifestFile) {
@@ -40,7 +44,7 @@ async function* moduleFederationDevServer(schema, context) {
40
44
  if (!options.isInitialHost) {
41
45
  return yield* currIter;
42
46
  }
43
- const { staticRemotesIter, devRemoteIters, remotes } = await (0, internal_3.startRemoteIterators)(options, context, lib_1.startRemotes, pathToManifestFile, 'react');
47
+ const { staticRemotesIter, devRemoteIters, remotes } = await startRemoteIterators(options, context, lib_1.startRemotes, pathToManifestFile, 'react');
44
48
  return yield* (0, internal_1.combineAsyncIterables)(currIter, ...devRemoteIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, internal_1.createAsyncIterable)(async ({ next, done }) => {
45
49
  if (!options.isInitialHost) {
46
50
  done();
@@ -56,7 +60,7 @@ async function* moduleFederationDevServer(schema, context) {
56
60
  const portsToWaitFor = staticRemotesIter && options.staticRemotesPort
57
61
  ? [options.staticRemotesPort, ...remotes.remotePorts]
58
62
  : [...remotes.remotePorts];
59
- await Promise.all(portsToWaitFor.map((port) => (0, internal_4.waitForPortOpen)(port, {
63
+ await Promise.all(portsToWaitFor.map((port) => (0, internal_3.waitForPortOpen)(port, {
60
64
  retries: 480,
61
65
  retryDelay: 2500,
62
66
  host: host,
@@ -4,18 +4,22 @@ exports.default = moduleFederationSsrDevServer;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const internal_1 = require("@nx/devkit/internal");
6
6
  const internal_2 = require("@nx/js/internal");
7
- const internal_3 = require("@nx/module-federation/internal");
8
- const internal_4 = require("@nx/web/internal");
9
- const internal_5 = require("@nx/webpack/internal");
7
+ const internal_3 = require("@nx/web/internal");
10
8
  const fs_1 = require("fs");
11
9
  const path_1 = require("path");
12
10
  const lib_1 = require("./lib");
11
+ const assert_package_1 = require("../../utils/assert-package");
13
12
  const module_federation_deprecation_1 = require("../../utils/module-federation-deprecation");
13
+ const executorName = '@nx/react:module-federation-ssr-dev-server';
14
14
  async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
15
+ (0, assert_package_1.assertPackageIsInstalled)('@nx/module-federation', executorName);
16
+ (0, assert_package_1.assertPackageIsInstalled)('@nx/webpack', executorName);
17
+ const { startRemoteIterators } = await import('@nx/module-federation/internal');
18
+ const { ssrDevServerExecutor } = await import('@nx/webpack/internal');
15
19
  (0, module_federation_deprecation_1.warnReactMfSsrDevServerExecutorDeprecation)();
16
20
  const options = (0, lib_1.normalizeOptions)(ssrDevServerOptions);
17
21
  // TODO(JamesHenry): remove type assertion once the nx repo is updated to use https://github.com/nrwl/nx/pull/33095
18
- let iter = (0, internal_5.ssrDevServerExecutor)(options, context);
22
+ let iter = ssrDevServerExecutor(options, context);
19
23
  const projectConfig = context.projectsConfigurations.projects[context.projectName];
20
24
  let pathToManifestFile = (0, path_1.join)(context.root, (0, internal_2.getProjectSourceRoot)(projectConfig), 'assets/module-federation.manifest.json');
21
25
  if (options.pathToManifestFile) {
@@ -31,7 +35,7 @@ async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
31
35
  if (!options.isInitialHost) {
32
36
  return yield* iter;
33
37
  }
34
- const { staticRemotesIter, devRemoteIters, remotes } = await (0, internal_3.startRemoteIterators)(options, context, lib_1.startRemotes, pathToManifestFile, 'react', true);
38
+ const { staticRemotesIter, devRemoteIters, remotes } = await startRemoteIterators(options, context, lib_1.startRemotes, pathToManifestFile, 'react', true);
35
39
  const combined = (0, internal_1.combineAsyncIterables)(staticRemotesIter, ...devRemoteIters);
36
40
  let refs = 1 + (devRemoteIters?.length ?? 0);
37
41
  for await (const result of combined) {
@@ -59,7 +63,7 @@ async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
59
63
  const portsToWaitFor = staticRemotesIter && options.staticRemotesPort
60
64
  ? [options.staticRemotesPort, ...remotes.remotePorts]
61
65
  : [...remotes.remotePorts];
62
- await Promise.all(portsToWaitFor.map((port) => (0, internal_4.waitForPortOpen)(port, {
66
+ await Promise.all(portsToWaitFor.map((port) => (0, internal_3.waitForPortOpen)(port, {
63
67
  retries: 480,
64
68
  retryDelay: 2500,
65
69
  host,
@@ -1,4 +1,4 @@
1
- import { StaticRemotesConfig } from '@nx/module-federation/internal';
1
+ import type { StaticRemotesConfig } from '@nx/module-federation/internal';
2
2
  import { ExecutorContext } from 'nx/src/config/misc-interfaces';
3
3
  import { ModuleFederationDevServerOptions } from '../module-federation-dev-server/schema';
4
4
  import { ModuleFederationStaticServerSchema } from './schema';
@@ -5,8 +5,8 @@ exports.default = moduleFederationStaticServer;
5
5
  const internal_1 = require("@nx/devkit/internal");
6
6
  const devkit_1 = require("@nx/devkit");
7
7
  const internal_2 = require("@nx/js/internal");
8
- const internal_3 = require("@nx/module-federation/internal");
9
- const internal_4 = require("@nx/web/internal");
8
+ const internal_3 = require("@nx/web/internal");
9
+ const assert_package_1 = require("../../utils/assert-package");
10
10
  const module_federation_deprecation_1 = require("../../utils/module-federation-deprecation");
11
11
  const child_process_1 = require("child_process");
12
12
  const fs_1 = require("fs");
@@ -157,21 +157,26 @@ function startProxies(staticRemotesConfig, hostServeOptions, mappedLocationOfHos
157
157
  devkit_1.logger.info('NX Static Consumer (host) proxy started successfully');
158
158
  }
159
159
  async function* moduleFederationStaticServer(schema, context) {
160
+ const executorName = '@nx/react:module-federation-static-server';
161
+ (0, assert_package_1.assertPackageIsInstalled)('@nx/module-federation', executorName);
162
+ (0, assert_package_1.assertPackageIsInstalled)('express', executorName);
163
+ (0, assert_package_1.assertPackageIsInstalled)('http-proxy-middleware', executorName);
164
+ const { buildStaticRemotes, getModuleFederationConfig, getRemotes, parseStaticRemotesConfig, } = await import('@nx/module-federation/internal');
160
165
  (0, module_federation_deprecation_1.warnReactMfStaticServerExecutorDeprecation)();
161
166
  // Force Node to resolve to look for the nx binary that is inside node_modules
162
167
  const nxBin = require.resolve('nx/bin/nx');
163
168
  // Get the remotes from the module federation config
164
169
  const p = context.projectsConfigurations.projects[context.projectName];
165
170
  const options = getBuildAndServeOptionsFromServeTarget(schema.serveTarget, context);
166
- const moduleFederationConfig = (0, internal_3.getModuleFederationConfig)(options.buildOptions.tsConfig, context.root, p.root, 'react');
167
- const remotes = (0, internal_3.getRemotes)([], options.serveOptions.skipRemotes, moduleFederationConfig, {
171
+ const moduleFederationConfig = getModuleFederationConfig(options.buildOptions.tsConfig, context.root, p.root, 'react');
172
+ const remotes = getRemotes([], options.serveOptions.skipRemotes, moduleFederationConfig, {
168
173
  projectName: context.projectName,
169
174
  projectGraph: context.projectGraph,
170
175
  root: context.root,
171
176
  }, options.pathToManifestFile);
172
- const staticRemotesConfig = (0, internal_3.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
177
+ const staticRemotesConfig = parseStaticRemotesConfig([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
173
178
  options.serveOptions.staticRemotesPort ??= remotes.staticRemotePort;
174
- const mappedLocationsOfStaticRemotes = await (0, internal_3.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options.serveOptions);
179
+ const mappedLocationsOfStaticRemotes = await buildStaticRemotes(staticRemotesConfig, nxBin, context, options.serveOptions);
175
180
  // Build the host
176
181
  const hostUrlSegment = (0, path_1.basename)(options.buildOptions.outputPath);
177
182
  const mappedLocationOfHost = `http${options.serveOptions.ssl ? 's' : ''}://${options.serveOptions.host}:${options.serveOptions.staticRemotesPort}/${hostUrlSegment}`;
@@ -179,7 +184,7 @@ async function* moduleFederationStaticServer(schema, context) {
179
184
  // Move to a temporary directory
180
185
  const commonOutputDirectory = moveToTmpDirectory(staticRemotesConfig, options.buildOptions.outputPath, hostUrlSegment);
181
186
  // File Serve the temporary directory
182
- const staticFileServerIter = (0, internal_4.fileServerExecutor)({
187
+ const staticFileServerIter = (0, internal_3.fileServerExecutor)({
183
188
  cors: true,
184
189
  watch: false,
185
190
  staticFilePath: commonOutputDirectory,
@@ -205,7 +210,7 @@ async function* moduleFederationStaticServer(schema, context) {
205
210
  const baseUrl = `http${options.serveOptions.ssl ? 's' : ''}://${host}:${options.serveOptions.port}`;
206
211
  if (remotes.remotePorts.length === 0) {
207
212
  const portsToWaitFor = [options.serveOptions.staticRemotesPort];
208
- await Promise.all(portsToWaitFor.map((port) => (0, internal_4.waitForPortOpen)(port, {
213
+ await Promise.all(portsToWaitFor.map((port) => (0, internal_3.waitForPortOpen)(port, {
209
214
  retries: 480,
210
215
  retryDelay: 2500,
211
216
  host: host,
@@ -219,7 +224,7 @@ async function* moduleFederationStaticServer(schema, context) {
219
224
  const portsToWaitFor = staticFileServerIter && options.serveOptions.staticRemotesPort
220
225
  ? [options.serveOptions.staticRemotesPort, ...remotes.remotePorts]
221
226
  : [...remotes.remotePorts];
222
- await Promise.all(portsToWaitFor.map((port) => (0, internal_4.waitForPortOpen)(port, {
227
+ await Promise.all(portsToWaitFor.map((port) => (0, internal_3.waitForPortOpen)(port, {
223
228
  retries: 480,
224
229
  retryDelay: 2500,
225
230
  host: host,
@@ -130,6 +130,14 @@ async function hostGenerator(host, schema) {
130
130
  const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, { '@module-federation/enhanced': versions_1.moduleFederationEnhancedVersion }, {
131
131
  '@nx/web': versions_1.nxVersion,
132
132
  '@nx/module-federation': versions_1.nxVersion,
133
+ // The webpack path also generates a `serve-static` target running the
134
+ // `module-federation-static-server` executor, which proxies via express.
135
+ ...(options.bundler !== 'rspack'
136
+ ? {
137
+ express: versions_1.expressVersion,
138
+ 'http-proxy-middleware': versions_1.httpProxyMiddlewareVersion,
139
+ }
140
+ : {}),
133
141
  }, undefined, true);
134
142
  tasks.push(installTask);
135
143
  if (!options.skipFormat) {
@@ -4,10 +4,11 @@ exports.setupTspathForRemote = setupTspathForRemote;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const js_1 = require("@nx/js");
6
6
  const maybe_js_1 = require("../../../utils/maybe-js");
7
- const module_federation_1 = require("@nx/module-federation");
7
+ const versions_1 = require("../../../utils/versions");
8
8
  function setupTspathForRemote(tree, options) {
9
+ const { normalizeProjectName } = (0, devkit_1.ensurePackage)('@nx/module-federation', versions_1.nxVersion);
9
10
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
10
11
  const exportPath = (0, maybe_js_1.maybeJs)(options, './src/remote-entry.ts');
11
12
  const exportName = 'Module';
12
- (0, js_1.addTsConfigPath)(tree, `${(0, module_federation_1.normalizeProjectName)(options.projectName)}/${exportName}`, [(0, devkit_1.joinPathFragments)(project.root, exportPath)]);
13
+ (0, js_1.addTsConfigPath)(tree, `${normalizeProjectName(options.projectName)}/${exportName}`, [(0, devkit_1.joinPathFragments)(project.root, exportPath)]);
13
14
  }
@@ -173,6 +173,14 @@ async function remoteGenerator(host, schema) {
173
173
  '@module-federation/enhanced': versions_1.moduleFederationEnhancedVersion,
174
174
  '@nx/web': versions_1.nxVersion,
175
175
  '@nx/module-federation': versions_1.nxVersion,
176
+ // The webpack path also generates a `serve-static` target running the
177
+ // `module-federation-static-server` executor, which proxies via express.
178
+ ...(options.bundler !== 'rspack'
179
+ ? {
180
+ express: versions_1.expressVersion,
181
+ 'http-proxy-middleware': versions_1.httpProxyMiddlewareVersion,
182
+ }
183
+ : {}),
176
184
  }, undefined, true);
177
185
  tasks.push(installTask);
178
186
  if (!options.skipFormat) {
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function addOptionalModuleFederationPackages(tree: Tree): Promise<import("@nx/devkit").GeneratorCallback>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = addOptionalModuleFederationPackages;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../utils/versions");
6
+ const moduleFederationExecutors = new Set([
7
+ '@nx/react:module-federation-dev-server',
8
+ '@nx/react:module-federation-ssr-dev-server',
9
+ '@nx/react:module-federation-static-server',
10
+ ]);
11
+ const staticServerExecutor = '@nx/react:module-federation-static-server';
12
+ function collectExecutors(targetDefaults) {
13
+ // targetDefaults are keyed by target name or executor, and a default can set
14
+ // an executor that an empty project target inherits, so scan the keys and any
15
+ // executor on the default (both the object and array forms).
16
+ const executors = [];
17
+ for (const [targetOrExecutor, config] of Object.entries(targetDefaults ?? {})) {
18
+ executors.push(targetOrExecutor);
19
+ for (const entry of Array.isArray(config) ? config : [config]) {
20
+ if (entry.executor != null) {
21
+ executors.push(entry.executor);
22
+ }
23
+ }
24
+ }
25
+ return executors;
26
+ }
27
+ async function addOptionalModuleFederationPackages(tree) {
28
+ const projects = (0, devkit_1.getProjects)(tree);
29
+ const nxJson = (0, devkit_1.readNxJson)(tree);
30
+ let needsModuleFederation = false;
31
+ let needsStaticServer = false;
32
+ for (const [, project] of projects) {
33
+ for (const target of Object.values(project.targets ?? {})) {
34
+ needsModuleFederation ||= moduleFederationExecutors.has(target.executor);
35
+ needsStaticServer ||= target.executor === staticServerExecutor;
36
+ }
37
+ // Remotes get a plain dev-server (no Module Federation executor) but still
38
+ // generate a module-federation.config that requires @nx/module-federation
39
+ // at build time, so detect them by that config file too. This covers
40
+ // remotes whose host lives in a different workspace.
41
+ needsModuleFederation ||=
42
+ tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.ts')) ||
43
+ tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.js'));
44
+ }
45
+ for (const executor of collectExecutors(nxJson?.targetDefaults)) {
46
+ needsModuleFederation ||= moduleFederationExecutors.has(executor);
47
+ needsStaticServer ||= executor === staticServerExecutor;
48
+ }
49
+ if (!needsModuleFederation && !needsStaticServer) {
50
+ return;
51
+ }
52
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
53
+ ...(needsModuleFederation ? { '@nx/module-federation': versions_1.nxVersion } : {}),
54
+ ...(needsStaticServer
55
+ ? {
56
+ express: versions_1.expressVersion,
57
+ 'http-proxy-middleware': versions_1.httpProxyMiddlewareVersion,
58
+ }
59
+ : {}),
60
+ }, undefined, true);
61
+ }
@@ -0,0 +1,37 @@
1
+ #### Add Optional Module Federation Packages
2
+
3
+ Adds `@nx/module-federation`, `express`, and `http-proxy-middleware` to the workspace when existing targets require them.
4
+
5
+ These packages are no longer direct dependencies of `@nx/react`; they are now optional peer dependencies, so installing `@nx/react` no longer pulls the Module Federation toolchain into workspaces that never use it. This migration backfills them for workspaces that already use Module Federation so those builds keep working after upgrading. Packages that are already present are left untouched.
6
+
7
+ A package is added only when a matching target exists:
8
+
9
+ - `@nx/module-federation`: an `@nx/react:module-federation-dev-server`, `@nx/react:module-federation-ssr-dev-server`, or `@nx/react:module-federation-static-server` target, or a project with a `module-federation.config.{js,ts}` file (covers remotes whose host lives in another workspace).
10
+ - `express` and `http-proxy-middleware`: an `@nx/react:module-federation-static-server` target, which proxies the static remotes.
11
+
12
+ Targets that inherit their executor from an `nx.json` `targetDefaults` entry are detected too.
13
+
14
+ #### Examples
15
+
16
+ For a workspace with an `@nx/react:module-federation-dev-server` serve target, the migration adds the Module Federation packages to `devDependencies`.
17
+
18
+ ##### Before
19
+
20
+ ```jsonc title="package.json"
21
+ {
22
+ "devDependencies": {
23
+ "@nx/react": "23.1.0",
24
+ },
25
+ }
26
+ ```
27
+
28
+ ##### After
29
+
30
+ ```jsonc title="package.json"
31
+ {
32
+ "devDependencies": {
33
+ "@nx/module-federation": "23.2.0",
34
+ "@nx/react": "23.1.0",
35
+ },
36
+ }
37
+ ```
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function addSvgrWebpackIfUsed(tree: Tree): Promise<import("@nx/devkit").GeneratorCallback>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = addSvgrWebpackIfUsed;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../utils/versions");
6
+ // The Nx 22 `add-svgr-to-webpack-config` migration inlined a `withSvgr` helper
7
+ // that resolves `@svgr/webpack` into user webpack configs, but never added the
8
+ // package to the workspace - it only resolved transitively through `@nx/react`.
9
+ // Now that `@nx/react` no longer depends on it, backfill it where a webpack
10
+ // config actually references it.
11
+ const webpackConfigFileNames = [
12
+ 'webpack.config.js',
13
+ 'webpack.config.ts',
14
+ 'webpack.config.cjs',
15
+ 'webpack.config.mjs',
16
+ 'webpack.config.prod.js',
17
+ 'webpack.config.prod.ts',
18
+ 'webpack.server.config.js',
19
+ 'webpack.server.config.ts',
20
+ ];
21
+ async function addSvgrWebpackIfUsed(tree) {
22
+ let needsSvgr = false;
23
+ for (const [, project] of (0, devkit_1.getProjects)(tree)) {
24
+ // Configs referenced by executor targets can live anywhere.
25
+ for (const target of Object.values(project.targets ?? {})) {
26
+ for (const options of [
27
+ target.options,
28
+ ...Object.values(target.configurations ?? {}),
29
+ ]) {
30
+ const webpackConfig = options?.webpackConfig;
31
+ if (typeof webpackConfig === 'string') {
32
+ needsSvgr ||= referencesSvgrWebpack(tree, webpackConfig);
33
+ }
34
+ }
35
+ }
36
+ // Inferred setups have no executor options pointing at a config, so also
37
+ // check the conventional config file names at the project root.
38
+ for (const fileName of webpackConfigFileNames) {
39
+ needsSvgr ||= referencesSvgrWebpack(tree, (0, devkit_1.joinPathFragments)(project.root, fileName));
40
+ }
41
+ if (needsSvgr) {
42
+ break;
43
+ }
44
+ }
45
+ if (!needsSvgr) {
46
+ return;
47
+ }
48
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@svgr/webpack': versions_1.svgrWebpackVersion }, undefined, true);
49
+ }
50
+ function referencesSvgrWebpack(tree, path) {
51
+ if (!tree.exists(path)) {
52
+ return false;
53
+ }
54
+ return tree.read(path, 'utf-8').includes('@svgr/webpack');
55
+ }
@@ -0,0 +1,28 @@
1
+ #### Add `@svgr/webpack` If Used
2
+
3
+ Adds `@svgr/webpack` to the workspace when a webpack config references it.
4
+
5
+ `@svgr/webpack` is no longer a dependency of `@nx/react`, so workspaces whose webpack configs resolve it - which is what the Nx 22 `add-svgr-to-webpack-config` migration inlined - must declare it themselves. This migration backfills it for those workspaces. Configs referenced by executor targets are checked, as well as the conventional config file names at each project root. Workspaces that already have `@svgr/webpack` are left untouched.
6
+
7
+ #### Examples
8
+
9
+ ##### Before
10
+
11
+ ```jsonc title="package.json"
12
+ {
13
+ "devDependencies": {
14
+ "@nx/react": "23.1.0",
15
+ },
16
+ }
17
+ ```
18
+
19
+ ##### After
20
+
21
+ ```jsonc title="package.json"
22
+ {
23
+ "devDependencies": {
24
+ "@nx/react": "23.1.0",
25
+ "@svgr/webpack": "^8.0.1",
26
+ },
27
+ }
28
+ ```
@@ -0,0 +1 @@
1
+ export declare function assertPackageIsInstalled(packageName: string, requiredBy: string): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertPackageIsInstalled = assertPackageIsInstalled;
4
+ function assertPackageIsInstalled(packageName, requiredBy) {
5
+ try {
6
+ require.resolve(packageName);
7
+ }
8
+ catch (e) {
9
+ // Only a missing module means "not installed"; surface other resolution
10
+ // errors (e.g. a malformed package's exports) as-is instead of mislabeling.
11
+ const code = e.code;
12
+ if (code !== 'MODULE_NOT_FOUND' && code !== 'ERR_MODULE_NOT_FOUND') {
13
+ throw e;
14
+ }
15
+ throw new Error(`The "${packageName}" package is required by "${requiredBy}" but is not installed. Please install it and try again.`);
16
+ }
17
+ }
@@ -33,6 +33,7 @@ export declare const postcssVersion = "8.4.38";
33
33
  export declare const autoprefixerVersion = "10.4.13";
34
34
  export declare const expressVersion = "^4.21.2";
35
35
  export declare const typesExpressVersion = "^4.17.21";
36
+ export declare const httpProxyMiddlewareVersion = "^3.0.5";
36
37
  export declare const isbotVersion = "^3.6.5";
37
38
  export declare const corsVersion = "~2.8.5";
38
39
  export declare const typesCorsVersion = "~2.8.12";
@@ -41,3 +42,4 @@ export declare const moduleFederationEnhancedVersion = "^2.1.0";
41
42
  export declare const sassVersion = "^1.97.2";
42
43
  export declare const rollupPluginUrlVersion = "^8.0.2";
43
44
  export declare const svgrRollupVersion = "^8.1.0";
45
+ export declare const svgrWebpackVersion = "^8.0.1";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.svgrRollupVersion = exports.rollupPluginUrlVersion = exports.sassVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.typesCorsVersion = exports.corsVersion = exports.isbotVersion = exports.typesExpressVersion = exports.expressVersion = exports.autoprefixerVersion = exports.postcssVersion = exports.tsLibVersion = exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.reactReduxVersion = exports.reduxjsToolkitVersion = exports.testingLibraryDomVersion = exports.testingLibraryReactVersion = exports.reactRouterIsBotVersion = exports.reactRouterVersion = exports.reactRouterDomVersion = exports.babelCoreVersion = exports.babelPresetReactVersion = exports.typesNodeVersion = exports.reactViteVersion = exports.typesReactIsVersion = exports.typesReactIsV18Version = exports.typesReactDomVersion = exports.typesReactDomV18Version = exports.typesReactVersion = exports.typesReactV18Version = exports.swcLoaderVersion = exports.reactIsV18Version = exports.reactIsVersion = exports.reactDomV18Version = exports.reactDomVersion = exports.reactV18Version = exports.reactVersion = exports.minSupportedReactVersion = exports.nxVersion = void 0;
3
+ exports.svgrWebpackVersion = exports.svgrRollupVersion = exports.rollupPluginUrlVersion = exports.sassVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.typesCorsVersion = exports.corsVersion = exports.isbotVersion = exports.httpProxyMiddlewareVersion = exports.typesExpressVersion = exports.expressVersion = exports.autoprefixerVersion = exports.postcssVersion = exports.tsLibVersion = exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.reactReduxVersion = exports.reduxjsToolkitVersion = exports.testingLibraryDomVersion = exports.testingLibraryReactVersion = exports.reactRouterIsBotVersion = exports.reactRouterVersion = exports.reactRouterDomVersion = exports.babelCoreVersion = exports.babelPresetReactVersion = exports.typesNodeVersion = exports.reactViteVersion = exports.typesReactIsVersion = exports.typesReactIsV18Version = exports.typesReactDomVersion = exports.typesReactDomV18Version = exports.typesReactVersion = exports.typesReactV18Version = exports.swcLoaderVersion = exports.reactIsV18Version = exports.reactIsVersion = exports.reactDomV18Version = exports.reactDomVersion = exports.reactV18Version = exports.reactVersion = exports.minSupportedReactVersion = exports.nxVersion = void 0;
4
4
  const path_1 = require("path");
5
5
  exports.nxVersion = require((0, path_1.join)('@nx/react', 'package.json')).version;
6
6
  exports.minSupportedReactVersion = '18.0.0';
@@ -41,6 +41,7 @@ exports.autoprefixerVersion = '10.4.13';
41
41
  // SSR and Module Federation
42
42
  exports.expressVersion = '^4.21.2';
43
43
  exports.typesExpressVersion = '^4.17.21';
44
+ exports.httpProxyMiddlewareVersion = '^3.0.5';
44
45
  exports.isbotVersion = '^3.6.5';
45
46
  exports.corsVersion = '~2.8.5';
46
47
  exports.typesCorsVersion = '~2.8.12';
@@ -51,3 +52,4 @@ exports.sassVersion = '^1.97.2';
51
52
  // rollup plugins (if needed)
52
53
  exports.rollupPluginUrlVersion = '^8.0.2';
53
54
  exports.svgrRollupVersion = '^8.1.0';
55
+ exports.svgrWebpackVersion = '^8.0.1';
package/migrations.json CHANGED
@@ -39,6 +39,18 @@
39
39
  "description": "Create AI instructions to help migrate workspaces from React 18 to 19.",
40
40
  "prompt": "./dist/src/migrations/update-23-1-0/ai-instructions-for-react-19.md",
41
41
  "documentation": "./dist/src/migrations/update-23-1-0/upgrade-to-react-19.md"
42
+ },
43
+ "update-23-2-0-add-optional-module-federation-packages": {
44
+ "version": "23.2.0-beta.4",
45
+ "description": "Add optional Module Federation packages when existing targets require them.",
46
+ "implementation": "./dist/src/migrations/update-23-2-0/add-optional-module-federation-packages",
47
+ "documentation": "./dist/src/migrations/update-23-2-0/add-optional-module-federation-packages.md"
48
+ },
49
+ "update-23-2-0-add-svgr-webpack-if-used": {
50
+ "version": "23.2.0-beta.4",
51
+ "description": "Add `@svgr/webpack` when a webpack config references it.",
52
+ "implementation": "./dist/src/migrations/update-23-2-0/add-svgr-webpack-if-used",
53
+ "documentation": "./dist/src/migrations/update-23-2-0/add-svgr-webpack-if-used.md"
42
54
  }
43
55
  },
44
56
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "23.2.0-canary.20260729-e3e16e9",
3
+ "version": "23.2.0-canary.20260731-0634da3",
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": {
@@ -93,40 +93,52 @@
93
93
  "peerDependencies": {
94
94
  "babel-plugin-react-compiler": "^1.0.0",
95
95
  "react": ">=18.0.0 <20.0.0",
96
- "react-dom": ">=18.0.0 <20.0.0"
96
+ "react-dom": ">=18.0.0 <20.0.0",
97
+ "express": "^4.21.2",
98
+ "http-proxy-middleware": "^3.0.5",
99
+ "@nx/module-federation": "23.2.0-canary.20260731-0634da3"
97
100
  },
98
101
  "peerDependenciesMeta": {
99
102
  "babel-plugin-react-compiler": {
100
103
  "optional": true
104
+ },
105
+ "@nx/module-federation": {
106
+ "optional": true
107
+ },
108
+ "express": {
109
+ "optional": true
110
+ },
111
+ "http-proxy-middleware": {
112
+ "optional": true
101
113
  }
102
114
  },
103
115
  "dependencies": {
116
+ "@babel/preset-react": "^7.22.5",
104
117
  "@phenomnomnominal/tsquery": "~6.2.0",
105
- "@svgr/webpack": "^8.0.1",
106
118
  "minimatch": "10.2.5",
107
119
  "tslib": "^2.3.0",
108
- "express": "^4.21.2",
109
- "http-proxy-middleware": "^3.0.5",
110
120
  "semver": "^7.6.3",
111
- "@nx/devkit": "23.2.0-canary.20260729-e3e16e9",
112
- "@nx/js": "23.2.0-canary.20260729-e3e16e9",
113
- "@nx/eslint": "23.2.0-canary.20260729-e3e16e9",
114
- "@nx/web": "23.2.0-canary.20260729-e3e16e9",
115
- "@nx/module-federation": "23.2.0-canary.20260729-e3e16e9",
116
- "@nx/rollup": "23.2.0-canary.20260729-e3e16e9"
121
+ "@nx/devkit": "23.2.0-canary.20260731-0634da3",
122
+ "@nx/js": "23.2.0-canary.20260731-0634da3",
123
+ "@nx/eslint": "23.2.0-canary.20260731-0634da3",
124
+ "@nx/web": "23.2.0-canary.20260731-0634da3"
117
125
  },
118
126
  "devDependencies": {
119
- "@nx/cypress": "23.2.0-canary.20260729-e3e16e9",
120
- "@nx/playwright": "23.2.0-canary.20260729-e3e16e9",
121
- "@nx/rsbuild": "23.2.0-canary.20260729-e3e16e9",
122
- "@nx/vite": "23.2.0-canary.20260729-e3e16e9",
123
- "@nx/vitest": "23.2.0-canary.20260729-e3e16e9",
124
- "@nx/webpack": "23.2.0-canary.20260729-e3e16e9",
125
- "@nx/storybook": "23.2.0-canary.20260729-e3e16e9",
126
- "nx": "23.2.0-canary.20260729-e3e16e9"
127
+ "express": "^4.21.2",
128
+ "http-proxy-middleware": "^3.0.5",
129
+ "@nx/cypress": "23.2.0-canary.20260731-0634da3",
130
+ "@nx/module-federation": "23.2.0-canary.20260731-0634da3",
131
+ "@nx/playwright": "23.2.0-canary.20260731-0634da3",
132
+ "@nx/rollup": "23.2.0-canary.20260731-0634da3",
133
+ "@nx/vite": "23.2.0-canary.20260731-0634da3",
134
+ "@nx/vitest": "23.2.0-canary.20260731-0634da3",
135
+ "@nx/rsbuild": "23.2.0-canary.20260731-0634da3",
136
+ "@nx/webpack": "23.2.0-canary.20260731-0634da3",
137
+ "@nx/storybook": "23.2.0-canary.20260731-0634da3",
138
+ "nx": "23.2.0-canary.20260731-0634da3"
127
139
  },
128
140
  "optionalDependencies": {
129
- "@nx/vite": "23.2.0-canary.20260729-e3e16e9"
141
+ "@nx/vite": "23.2.0-canary.20260731-0634da3"
130
142
  },
131
143
  "publishConfig": {
132
144
  "access": "public"