@nx/module-federation 22.2.3 → 22.3.0-beta.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nx/module-federation",
3
3
  "description": "The Nx Plugin for Module Federation contains executors and utilities that support building applications using Module Federation.",
4
- "version": "22.2.3",
4
+ "version": "22.3.0-beta.0",
5
5
  "type": "commonjs",
6
6
  "repository": {
7
7
  "type": "git",
@@ -27,9 +27,9 @@
27
27
  "@module-federation/enhanced": "^0.21.2",
28
28
  "@module-federation/node": "^2.7.21",
29
29
  "@module-federation/sdk": "^0.21.2",
30
- "@nx/devkit": "22.2.3",
31
- "@nx/js": "22.2.3",
32
- "@nx/web": "22.2.3",
30
+ "@nx/devkit": "22.3.0-beta.0",
31
+ "@nx/js": "22.3.0-beta.0",
32
+ "@nx/web": "22.3.0-beta.0",
33
33
  "@rspack/core": "^1.5.2",
34
34
  "express": "^4.21.2",
35
35
  "http-proxy-middleware": "^3.0.5",
@@ -38,7 +38,7 @@
38
38
  "webpack": "^5.101.3"
39
39
  },
40
40
  "devDependencies": {
41
- "nx": "22.2.3"
41
+ "nx": "22.3.0-beta.0"
42
42
  },
43
43
  "nx-migrations": {
44
44
  "migrations": "./migrations.json"
@@ -5,7 +5,7 @@ export declare function startRemoteIterators(options: StartRemoteIteratorsOption
5
5
  staticRemotes: string[];
6
6
  devRemotes: any[];
7
7
  dynamicRemotes: any[];
8
- remotePorts: any[];
8
+ remotePorts: number[];
9
9
  staticRemotePort: number;
10
10
  };
11
11
  devRemoteIters: AsyncIterable<{
@@ -10,7 +10,7 @@ export declare function getRemotes(devRemotes: string[], skipRemotes: string[],
10
10
  staticRemotes: string[];
11
11
  devRemotes: any[];
12
12
  dynamicRemotes: any[];
13
- remotePorts: any[];
13
+ remotePorts: number[];
14
14
  staticRemotePort: number;
15
15
  };
16
16
  export declare function getModuleFederationConfig(tsconfigPath: string | undefined, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
@@ -1 +1 @@
1
- {"version":3,"file":"get-remotes-for-host.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/get-remotes-for-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,YAAY,EAElB,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,UAAU,+BAA+B;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd;AAoCD,wBAAgB,iCAAiC,CAC/C,aAAa,EAAE,oBAAoB,EACnC,YAAY,EAAE,YAAY,UA0B3B;AAoCD,wBAAgB,UAAU,CACxB,UAAU,EAAE,MAAM,EAAE,EACpB,WAAW,EAAE,MAAM,EAAE,EACrB,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,+BAA+B,EACxC,kBAAkB,CAAC,EAAE,MAAM;;;;;;EAkF5B;AAED,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,UAAU,GAAE,OAAO,GAAG,SAAmB,OAkD1C"}
1
+ {"version":3,"file":"get-remotes-for-host.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/get-remotes-for-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,YAAY,EAElB,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,UAAU,+BAA+B;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd;AAsCD,wBAAgB,iCAAiC,CAC/C,aAAa,EAAE,oBAAoB,EACnC,YAAY,EAAE,YAAY,UA0B3B;AAoCD,wBAAgB,UAAU,CACxB,UAAU,EAAE,MAAM,EAAE,EACpB,WAAW,EAAE,MAAM,EAAE,EACrB,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,+BAA+B,EACxC,kBAAkB,CAAC,EAAE,MAAM;;;;;;EA0F5B;AAED,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,UAAU,GAAE,OAAO,GAAG,SAAmB,OAkD1C"}
@@ -24,8 +24,10 @@ function extractRemoteProjectsFromConfig(config, pathToManifestFile) {
24
24
  * But users might have their own, enforce only that the key is the remote name
25
25
  */
26
26
  const parsedManifest = JSON.parse(moduleFederationManifestJson);
27
- if (Object.keys(parsedManifest).every((key) => typeof key === 'string')) {
28
- dynamicRemotes.push(...Object.keys(parsedManifest));
27
+ // Get keys once instead of calling Object.keys twice
28
+ const manifestKeys = Object.keys(parsedManifest);
29
+ if (manifestKeys.every((key) => typeof key === 'string')) {
30
+ dynamicRemotes.push(...manifestKeys);
29
31
  }
30
32
  }
31
33
  }
@@ -77,30 +79,38 @@ function getRemotes(devRemotes, skipRemotes, config, context, pathToManifestFile
77
79
  // With dynamic remotes, the manifest file may contain the names with `_` due to MF limitations on naming
78
80
  // The project graph might contain these names with `-` rather than `_`. Check for both.
79
81
  // This can occur after migration of existing remotes past Nx 19.8
80
- let normalizedDynamicRemotes = dynamicRemotes.map((r) => {
81
- if (context.projectGraph.nodes[r.replace(/_/g, '-')]) {
82
- return r.replace(/_/g, '-');
83
- }
84
- return r;
82
+ const normalizedDynamicRemotes = dynamicRemotes.map((r) => {
83
+ // Compute replacement once instead of twice
84
+ const normalizedName = r.replace(/_/g, '-');
85
+ return context.projectGraph.nodes[normalizedName] ? normalizedName : r;
85
86
  });
86
87
  const knownDynamicRemotes = normalizedDynamicRemotes.filter((r) => !remotesToSkip.has(r) && context.projectGraph.nodes[r]);
87
88
  devkit_1.logger.info(`NX Starting module federation dev-server for ${pc.bold(context.projectName)} with ${[...knownRemotes, ...knownDynamicRemotes].length} remotes`);
89
+ // Normalize devRemotes to array and call findMatchingProjects once
88
90
  const devServeApps = new Set(!devRemotes
89
91
  ? []
90
- : Array.isArray(devRemotes)
91
- ? (0, find_matching_projects_1.findMatchingProjects)(devRemotes, context.projectGraph.nodes)
92
- : (0, find_matching_projects_1.findMatchingProjects)([devRemotes], context.projectGraph.nodes));
92
+ : (0, find_matching_projects_1.findMatchingProjects)(Array.isArray(devRemotes) ? devRemotes : [devRemotes], context.projectGraph.nodes));
93
93
  const staticRemotes = knownRemotes.filter((r) => !devServeApps.has(r));
94
94
  const devServeRemotes = [...knownRemotes, ...knownDynamicRemotes].filter((r) => devServeApps.has(r));
95
95
  const staticDynamicRemotes = knownDynamicRemotes.filter((r) => !devServeApps.has(r));
96
- const remotePorts = [...devServeRemotes, ...staticDynamicRemotes].map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port);
96
+ // Helper to get port from remote project
97
+ const getRemotePort = (r) => context.projectGraph.nodes[r].data.targets['serve'].options.port;
98
+ // Collect ports for dev-served remotes (used in return value)
99
+ const remotePorts = [...devServeRemotes, ...staticDynamicRemotes].map(getRemotePort);
100
+ // Calculate max port in a single pass instead of creating intermediate arrays
101
+ let maxPort = -Infinity;
102
+ for (const port of remotePorts) {
103
+ if (port > maxPort)
104
+ maxPort = port;
105
+ }
106
+ for (const r of staticRemotes) {
107
+ const port = getRemotePort(r);
108
+ if (port > maxPort)
109
+ maxPort = port;
110
+ }
97
111
  const staticRemotePort = staticRemotes.length === 0 && remotePorts.length === 0
98
112
  ? undefined
99
- : Math.max(...[
100
- ...remotePorts,
101
- ...staticRemotes.map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port),
102
- ]) +
103
- (remotesToSkip.size + 1);
113
+ : maxPort + (remotesToSkip.size + 1);
104
114
  return {
105
115
  staticRemotes,
106
116
  devRemotes: devServeRemotes,
@@ -15,14 +15,14 @@ function readTsPathMappings(tsConfigPath = process.env.NX_TSCONFIG_PATH ?? getRo
15
15
  if (!tsConfig.has(tsConfigPath)) {
16
16
  tsConfig.set(tsConfigPath, readTsConfiguration(tsConfigPath));
17
17
  }
18
- tsPathMappings.set(tsConfigPath, {});
19
- Object.entries(tsConfig.get(tsConfigPath).options?.paths ?? {}).forEach(([alias, paths]) => {
20
- tsPathMappings.set(tsConfigPath, {
21
- ...tsPathMappings.get(tsConfigPath),
22
- [alias]: paths.map((path) => path.replace(/^\.\//, '')),
23
- });
24
- });
25
- return tsPathMappings.get(tsConfigPath);
18
+ // Build the processed paths object in a single pass instead of
19
+ // spreading on each iteration, which was O(n²) for n path aliases
20
+ const processedPaths = {};
21
+ for (const [alias, aliasPaths] of Object.entries(tsConfig.get(tsConfigPath).options?.paths ?? {})) {
22
+ processedPaths[alias] = aliasPaths.map((path) => path.replace(/^\.\//, ''));
23
+ }
24
+ tsPathMappings.set(tsConfigPath, processedPaths);
25
+ return processedPaths;
26
26
  }
27
27
  function readTsConfiguration(tsConfigPath) {
28
28
  if (!(0, fs_1.existsSync)(tsConfigPath)) {