@nx/rspack 19.7.1 → 20.0.0-beta.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.
Files changed (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +70 -34
  3. package/executors.json +2 -2
  4. package/module-federation.js +0 -1
  5. package/package.json +14 -9
  6. package/plugin.js +0 -1
  7. package/src/executors/dev-server/dev-server.impl.js +39 -38
  8. package/src/executors/dev-server/lib/get-dev-server-config.js +1 -3
  9. package/src/executors/dev-server/lib/serve-path.js +0 -1
  10. package/src/executors/dev-server/schema.json +3 -9
  11. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +109 -98
  12. package/src/executors/module-federation-dev-server/schema.json +1 -3
  13. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +153 -148
  14. package/src/executors/module-federation-ssr-dev-server/schema.json +1 -4
  15. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +117 -125
  16. package/src/executors/rspack/rspack.impl.js +60 -67
  17. package/src/executors/rspack/schema.json +6 -26
  18. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +0 -1
  19. package/src/executors/ssr-dev-server/schema.json +1 -4
  20. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +26 -40
  21. package/src/generators/application/application.js +79 -76
  22. package/src/generators/application/lib/create-ts-config.js +5 -3
  23. package/src/generators/application/lib/normalize-options.js +12 -7
  24. package/src/generators/application/schema.json +1 -0
  25. package/src/generators/configuration/configuration.js +63 -65
  26. package/src/generators/configuration/schema.json +2 -1
  27. package/src/generators/init/init.js +58 -59
  28. package/src/generators/init/schema.json +2 -1
  29. package/src/generators/preset/preset.js +26 -29
  30. package/src/generators/preset/schema.json +1 -0
  31. package/src/index.js +0 -1
  32. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -7
  33. package/src/plugins/generate-package-json-plugin.js +1 -3
  34. package/src/plugins/plugin.js +81 -90
  35. package/src/utils/config.js +7 -11
  36. package/src/utils/create-compiler.js +21 -25
  37. package/src/utils/generator-utils.js +55 -66
  38. package/src/utils/get-copy-patterns.js +1 -3
  39. package/src/utils/jest-utils.js +0 -1
  40. package/src/utils/mode-utils.js +0 -1
  41. package/src/utils/model.js +0 -1
  42. package/src/utils/module-federation/build-static.remotes.js +57 -61
  43. package/src/utils/module-federation/dependencies.js +1 -3
  44. package/src/utils/module-federation/get-remotes-for-host.js +4 -8
  45. package/src/utils/module-federation/index.js +0 -1
  46. package/src/utils/module-federation/models/index.js +0 -1
  47. package/src/utils/module-federation/package-json.js +0 -1
  48. package/src/utils/module-federation/parse-static-remotes-config.js +2 -3
  49. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +1 -2
  50. package/src/utils/module-federation/public-api.js +0 -1
  51. package/src/utils/module-federation/remotes.js +0 -1
  52. package/src/utils/module-federation/secondary-entry-points.js +4 -5
  53. package/src/utils/module-federation/share.js +22 -19
  54. package/src/utils/module-federation/start-remote-proxies.js +0 -1
  55. package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -1
  56. package/src/utils/module-federation/typescript.js +6 -6
  57. package/src/utils/module-federation/with-module-federation/package-json.js +0 -1
  58. package/src/utils/module-federation/with-module-federation/utils.js +41 -43
  59. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +48 -35
  60. package/src/utils/module-federation/with-module-federation/with-module-federation.js +56 -38
  61. package/src/utils/normalize-assets.js +5 -3
  62. package/src/utils/read-rspack-options.js +23 -27
  63. package/src/utils/resolve-user-defined-rspack-config.js +0 -1
  64. package/src/utils/versions.d.ts +2 -2
  65. package/src/utils/versions.js +2 -3
  66. package/src/utils/with-nx.js +30 -13
  67. package/src/utils/with-react.js +11 -5
  68. package/src/utils/with-web.js +20 -11
  69. package/module-federation.js.map +0 -1
  70. package/plugin.js.map +0 -1
  71. package/src/executors/dev-server/dev-server.impl.js.map +0 -1
  72. package/src/executors/dev-server/lib/get-dev-server-config.js.map +0 -1
  73. package/src/executors/dev-server/lib/serve-path.js.map +0 -1
  74. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js.map +0 -1
  75. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js.map +0 -1
  76. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js.map +0 -1
  77. package/src/executors/rspack/rspack.impl.js.map +0 -1
  78. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js.map +0 -1
  79. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js.map +0 -1
  80. package/src/generators/application/application.js.map +0 -1
  81. package/src/generators/application/lib/create-ts-config.js.map +0 -1
  82. package/src/generators/application/lib/normalize-options.js.map +0 -1
  83. package/src/generators/configuration/configuration.js.map +0 -1
  84. package/src/generators/init/init.js.map +0 -1
  85. package/src/generators/preset/preset.js.map +0 -1
  86. package/src/index.js.map +0 -1
  87. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +0 -1
  88. package/src/plugins/generate-package-json-plugin.js.map +0 -1
  89. package/src/plugins/plugin.js.map +0 -1
  90. package/src/utils/config.js.map +0 -1
  91. package/src/utils/create-compiler.js.map +0 -1
  92. package/src/utils/generator-utils.js.map +0 -1
  93. package/src/utils/get-copy-patterns.js.map +0 -1
  94. package/src/utils/jest-utils.js.map +0 -1
  95. package/src/utils/mode-utils.js.map +0 -1
  96. package/src/utils/model.js.map +0 -1
  97. package/src/utils/module-federation/build-static.remotes.js.map +0 -1
  98. package/src/utils/module-federation/dependencies.js.map +0 -1
  99. package/src/utils/module-federation/get-remotes-for-host.js.map +0 -1
  100. package/src/utils/module-federation/index.js.map +0 -1
  101. package/src/utils/module-federation/models/index.js.map +0 -1
  102. package/src/utils/module-federation/package-json.js.map +0 -1
  103. package/src/utils/module-federation/parse-static-remotes-config.js.map +0 -1
  104. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js.map +0 -1
  105. package/src/utils/module-federation/public-api.js.map +0 -1
  106. package/src/utils/module-federation/remotes.js.map +0 -1
  107. package/src/utils/module-federation/secondary-entry-points.js.map +0 -1
  108. package/src/utils/module-federation/share.js.map +0 -1
  109. package/src/utils/module-federation/start-remote-proxies.js.map +0 -1
  110. package/src/utils/module-federation/start-ssr-remote-proxies.js.map +0 -1
  111. package/src/utils/module-federation/typescript.js.map +0 -1
  112. package/src/utils/module-federation/with-module-federation/package-json.js.map +0 -1
  113. package/src/utils/module-federation/with-module-federation/utils.js.map +0 -1
  114. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js.map +0 -1
  115. package/src/utils/module-federation/with-module-federation/with-module-federation.js.map +0 -1
  116. package/src/utils/normalize-assets.js.map +0 -1
  117. package/src/utils/read-rspack-options.js.map +0 -1
  118. package/src/utils/resolve-user-defined-rspack-config.js.map +0 -1
  119. package/src/utils/versions.js.map +0 -1
  120. package/src/utils/with-nx.js.map +0 -1
  121. package/src/utils/with-react.js.map +0 -1
  122. package/src/utils/with-web.js.map +0 -1
@@ -18,4 +18,3 @@ const with_module_federation_1 = require("./with-module-federation/with-module-f
18
18
  Object.defineProperty(exports, "withModuleFederation", { enumerable: true, get: function () { return with_module_federation_1.withModuleFederation; } });
19
19
  const with_module_federation_ssr_1 = require("./with-module-federation/with-module-federation-ssr");
20
20
  Object.defineProperty(exports, "withModuleFederationForSSR", { enumerable: true, get: function () { return with_module_federation_ssr_1.withModuleFederationForSSR; } });
21
- //# sourceMappingURL=public-api.js.map
@@ -75,4 +75,3 @@ function mapRemotesForSSR(remotes, remoteEntryExt, determineRemoteUrl) {
75
75
  }
76
76
  return mappedRemotes;
77
77
  }
78
- //# sourceMappingURL=remotes.js.map
@@ -15,10 +15,10 @@ function collectWorkspaceLibrarySecondaryEntryPoints(library, tsconfigPathAliase
15
15
  if (needsSecondaryEntryPointsCollected) {
16
16
  const tsConfigAliasesForLibWithSecondaryEntryPoints = Object.entries(tsconfigPathAliases).reduce((acc, [tsKey, tsPaths]) => {
17
17
  if (!tsKey.startsWith(library.importKey)) {
18
- return Object.assign({}, acc);
18
+ return { ...acc };
19
19
  }
20
20
  if (tsPaths.some((path) => path.startsWith(`${library.root}/`))) {
21
- acc = Object.assign(Object.assign({}, acc), { [tsKey]: tsPaths });
21
+ acc = { ...acc, [tsKey]: tsPaths };
22
22
  }
23
23
  return acc;
24
24
  }, {});
@@ -58,7 +58,7 @@ function recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion
58
58
  collectedPackages.push({ name, version: pkgVersion });
59
59
  }
60
60
  }
61
- catch (_a) {
61
+ catch {
62
62
  // do nothing
63
63
  }
64
64
  }
@@ -86,7 +86,7 @@ function collectPackageSecondaryEntryPoints(pkgName, pkgVersion, collectedPackag
86
86
  ({ path: packageJsonPath, packageJson } = (0, package_json_1.readModulePackageJson)(pkgName));
87
87
  pathToPackage = (0, path_1.dirname)(packageJsonPath);
88
88
  }
89
- catch (_a) {
89
+ catch {
90
90
  // the package.json might not resolve if the package has the "exports"
91
91
  // entry and is not exporting the package.json file, fall back to trying
92
92
  // to find it from the top-level node_modules
@@ -102,4 +102,3 @@ function collectPackageSecondaryEntryPoints(pkgName, pkgVersion, collectedPackag
102
102
  const subDirs = getNonNodeModulesSubDirs(pathToPackage);
103
103
  recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pathToPackage, exports, subDirs, collectedPackages);
104
104
  }
105
- //# sourceMappingURL=secondary-entry-points.js.map
@@ -19,9 +19,7 @@ const typescript_1 = require("./typescript");
19
19
  * @param workspaceLibs - The Nx Workspace Libraries to share
20
20
  * @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
21
21
  */
22
- function shareWorkspaceLibraries(workspaceLibs, tsConfigPath) {
23
- var _a;
24
- if (tsConfigPath === void 0) { tsConfigPath = (_a = process.env.NX_TSCONFIG_PATH) !== null && _a !== void 0 ? _a : (0, typescript_1.getRootTsConfigPath)(); }
22
+ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath = process.env.NX_TSCONFIG_PATH ?? (0, typescript_1.getRootTsConfigPath)()) {
25
23
  if (!workspaceLibs) {
26
24
  return getEmptySharedLibrariesConfig();
27
25
  }
@@ -54,10 +52,12 @@ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath) {
54
52
  });
55
53
  }
56
54
  return {
57
- getAliases: () => pathMappings.reduce((aliases, library) => (Object.assign(Object.assign({}, aliases), {
55
+ getAliases: () => pathMappings.reduce((aliases, library) => ({
56
+ ...aliases,
58
57
  // If the library path ends in a wildcard, remove it as webpack can't handle this in resolve.alias
59
58
  // e.g. path/to/my/lib/* -> path/to/my/lib
60
- [library.name]: library.path.replace(/\/\*$/, '') })), {}),
59
+ [library.name]: library.path.replace(/\/\*$/, ''),
60
+ }), {}),
61
61
  getLibraries: (projectRoot, eager) => {
62
62
  let pkgJson = null;
63
63
  if (projectRoot &&
@@ -65,9 +65,8 @@ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath) {
65
65
  pkgJson = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'package.json'));
66
66
  }
67
67
  return pathMappings.reduce((libraries, library) => {
68
- var _a;
69
68
  // Check to see if the library version is declared in the app's package.json
70
- let version = (_a = pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.dependencies) === null || _a === void 0 ? void 0 : _a[library.name];
69
+ let version = pkgJson?.dependencies?.[library.name];
71
70
  if (!version && workspaceLibs.length > 0) {
72
71
  const workspaceLib = workspaceLibs.find((lib) => lib.importKey === library.name);
73
72
  const libPackageJsonPath = workspaceLib
@@ -80,12 +79,18 @@ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath) {
80
79
  }
81
80
  }
82
81
  }
83
- return Object.assign(Object.assign({}, libraries), { [library.name]: Object.assign(Object.assign({}, (version
84
- ? {
85
- requiredVersion: version,
86
- singleton: true,
87
- }
88
- : { requiredVersion: false })), { eager }) });
82
+ return {
83
+ ...libraries,
84
+ [library.name]: {
85
+ ...(version
86
+ ? {
87
+ requiredVersion: version,
88
+ singleton: true,
89
+ }
90
+ : { requiredVersion: false }),
91
+ eager,
92
+ },
93
+ };
89
94
  }, {});
90
95
  },
91
96
  getReplacementPlugin: () => new core_1.NormalModuleReplacementPlugin(/./, (req) => {
@@ -140,8 +145,7 @@ function sharePackages(packages) {
140
145
  const pkgJson = (0, package_json_1.readRootPackageJson)();
141
146
  const allPackages = [];
142
147
  packages.forEach((pkg) => {
143
- var _a, _b, _c;
144
- const pkgVersion = (_b = (_a = pkgJson.dependencies) === null || _a === void 0 ? void 0 : _a[pkg]) !== null && _b !== void 0 ? _b : (_c = pkgJson.devDependencies) === null || _c === void 0 ? void 0 : _c[pkg];
148
+ const pkgVersion = pkgJson.dependencies?.[pkg] ?? pkgJson.devDependencies?.[pkg];
145
149
  allPackages.push({ name: pkg, version: pkgVersion });
146
150
  (0, secondary_entry_points_1.collectPackageSecondaryEntryPoints)(pkg, pkgVersion, allPackages);
147
151
  });
@@ -205,13 +209,13 @@ function applyAdditionalShared(sharedConfig, additionalShared, projectGraph) {
205
209
  }
206
210
  }
207
211
  function addStringDependencyToSharedConfig(sharedConfig, dependency, projectGraph) {
208
- var _a, _b, _c, _d;
209
212
  if (projectGraph.nodes[dependency]) {
210
213
  sharedConfig[dependency] = { requiredVersion: false };
211
214
  }
212
- else if ((_a = projectGraph.externalNodes) === null || _a === void 0 ? void 0 : _a[`npm:${dependency}`]) {
215
+ else if (projectGraph.externalNodes?.[`npm:${dependency}`]) {
213
216
  const pkgJson = (0, package_json_1.readRootPackageJson)();
214
- const config = getNpmPackageSharedConfig(dependency, (_c = (_b = pkgJson.dependencies) === null || _b === void 0 ? void 0 : _b[dependency]) !== null && _c !== void 0 ? _c : (_d = pkgJson.devDependencies) === null || _d === void 0 ? void 0 : _d[dependency]);
217
+ const config = getNpmPackageSharedConfig(dependency, pkgJson.dependencies?.[dependency] ??
218
+ pkgJson.devDependencies?.[dependency]);
215
219
  if (!config) {
216
220
  return;
217
221
  }
@@ -229,4 +233,3 @@ function getEmptySharedLibrariesConfig() {
229
233
  getReplacementPlugin: () => new core_1.NormalModuleReplacementPlugin(/./, () => undefined),
230
234
  };
231
235
  }
232
- //# sourceMappingURL=share.js.map
@@ -43,4 +43,3 @@ function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOp
43
43
  }
44
44
  devkit_1.logger.info(`NX Static remotes proxies started successfully`);
45
45
  }
46
- //# sourceMappingURL=start-remote-proxies.js.map
@@ -57,4 +57,3 @@ function startSsrRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, ss
57
57
  }
58
58
  devkit_1.logger.info(`Nx SSR Static remotes proxies started successfully`);
59
59
  }
60
- //# sourceMappingURL=start-ssr-remote-proxies.js.map
@@ -8,9 +8,7 @@ const path_1 = require("path");
8
8
  const devkit_1 = require("@nx/devkit");
9
9
  const tsConfig = new Map();
10
10
  const tsPathMappings = new Map();
11
- function readTsPathMappings(tsConfigPath) {
12
- var _a, _b, _c;
13
- if (tsConfigPath === void 0) { tsConfigPath = (_a = process.env.NX_TSCONFIG_PATH) !== null && _a !== void 0 ? _a : getRootTsConfigPath(); }
11
+ function readTsPathMappings(tsConfigPath = process.env.NX_TSCONFIG_PATH ?? getRootTsConfigPath()) {
14
12
  if (tsPathMappings.has(tsConfigPath)) {
15
13
  return tsPathMappings.get(tsConfigPath);
16
14
  }
@@ -18,8 +16,11 @@ function readTsPathMappings(tsConfigPath) {
18
16
  tsConfig.set(tsConfigPath, readTsConfiguration(tsConfigPath));
19
17
  }
20
18
  tsPathMappings.set(tsConfigPath, {});
21
- Object.entries((_c = (_b = tsConfig.get(tsConfigPath).options) === null || _b === void 0 ? void 0 : _b.paths) !== null && _c !== void 0 ? _c : {}).forEach(([alias, paths]) => {
22
- tsPathMappings.set(tsConfigPath, Object.assign(Object.assign({}, tsPathMappings.get(tsConfigPath)), { [alias]: paths.map((path) => path.replace(/^\.\//, '')) }));
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
+ });
23
24
  });
24
25
  return tsPathMappings.get(tsConfigPath);
25
26
  }
@@ -50,4 +51,3 @@ function getRootTsConfigFileName() {
50
51
  }
51
52
  return null;
52
53
  }
53
- //# sourceMappingURL=typescript.js.map
@@ -10,4 +10,3 @@ function readRootPackageJson() {
10
10
  }
11
11
  return (0, devkit_1.readJsonFile)(pkgJsonPath);
12
12
  }
13
- //# sourceMappingURL=package-json.js.map
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
4
4
  exports.getModuleFederationConfig = getModuleFederationConfig;
5
- const tslib_1 = require("tslib");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const project_graph_1 = require("nx/src/project-graph/project-graph");
8
7
  const dependencies_1 = require("../dependencies");
@@ -12,7 +11,6 @@ function getFunctionDeterminateRemoteUrl(isServer = false) {
12
11
  const target = 'serve';
13
12
  const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.js';
14
13
  return function (remote) {
15
- var _a, _b, _c, _d, _e;
16
14
  const mappedStaticRemotesFromEnv = process.env
17
15
  .NX_MF_DEV_SERVER_STATIC_REMOTES
18
16
  ? JSON.parse(process.env.NX_MF_DEV_SERVER_STATIC_REMOTES)
@@ -27,52 +25,52 @@ function getFunctionDeterminateRemoteUrl(isServer = false) {
27
25
  catch (e) {
28
26
  throw new Error(`Cannot find remote: "${remote}". Check that the remote name is correct in your module federation config file.\n`);
29
27
  }
30
- const serveTarget = (_a = remoteConfiguration === null || remoteConfiguration === void 0 ? void 0 : remoteConfiguration.targets) === null || _a === void 0 ? void 0 : _a[target];
28
+ const serveTarget = remoteConfiguration?.targets?.[target];
31
29
  if (!serveTarget) {
32
30
  throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
33
31
  You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
34
32
  }
35
- const host = (_c = (_b = serveTarget.options) === null || _b === void 0 ? void 0 : _b.host) !== null && _c !== void 0 ? _c : `http${serveTarget.options.ssl ? 's' : ''}://localhost`;
36
- const port = (_e = (_d = serveTarget.options) === null || _d === void 0 ? void 0 : _d.port) !== null && _e !== void 0 ? _e : 4201;
33
+ const host = serveTarget.options?.host ??
34
+ `http${serveTarget.options.ssl ? 's' : ''}://localhost`;
35
+ const port = serveTarget.options?.port ?? 4201;
37
36
  return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
38
37
  };
39
38
  }
40
- function getModuleFederationConfig(mfConfig_1) {
41
- return tslib_1.__awaiter(this, arguments, void 0, function* (mfConfig, options = { isServer: false }) {
42
- var _a;
43
- let projectGraph;
44
- try {
45
- projectGraph = (0, devkit_1.readCachedProjectGraph)();
46
- }
47
- catch (e) {
48
- projectGraph = yield (0, devkit_1.createProjectGraphAsync)();
49
- }
50
- const project = (_a = projectGraph.nodes[mfConfig.name]) === null || _a === void 0 ? void 0 : _a.data;
51
- if (!project) {
52
- throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
53
- }
54
- const dependencies = (0, dependencies_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
55
- if (mfConfig.shared) {
56
- dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
57
- dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
58
- }
59
- const sharedLibraries = (0, share_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
60
- const npmPackages = (0, share_1.sharePackages)(dependencies.npmPackages);
61
- const sharedDependencies = Object.assign(Object.assign({}, sharedLibraries.getLibraries(project.root)), npmPackages);
62
- (0, share_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
63
- (0, share_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
64
- // Choose the correct mapRemotes function based on the server state.
65
- const mapRemotesFunction = options.isServer ? remotes_1.mapRemotesForSSR : remotes_1.mapRemotes;
66
- // Determine the URL function, either from provided options or by using a default.
67
- const determineRemoteUrlFunction = options.determineRemoteUrl
68
- ? options.determineRemoteUrl
69
- : getFunctionDeterminateRemoteUrl(options.isServer);
70
- // Map the remotes if they exist, otherwise default to an empty object.
71
- let mappedRemotes = {};
72
- if (mfConfig.remotes && mfConfig.remotes.length > 0) {
73
- mappedRemotes = mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFunction);
74
- }
75
- return { sharedLibraries, sharedDependencies, mappedRemotes };
76
- });
39
+ async function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
40
+ let projectGraph;
41
+ try {
42
+ projectGraph = (0, devkit_1.readCachedProjectGraph)();
43
+ }
44
+ catch (e) {
45
+ projectGraph = await (0, devkit_1.createProjectGraphAsync)();
46
+ }
47
+ const project = projectGraph.nodes[mfConfig.name]?.data;
48
+ if (!project) {
49
+ throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
50
+ }
51
+ const dependencies = (0, dependencies_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
52
+ if (mfConfig.shared) {
53
+ dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
54
+ dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
55
+ }
56
+ const sharedLibraries = (0, share_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
57
+ const npmPackages = (0, share_1.sharePackages)(dependencies.npmPackages);
58
+ const sharedDependencies = {
59
+ ...sharedLibraries.getLibraries(project.root),
60
+ ...npmPackages,
61
+ };
62
+ (0, share_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
63
+ (0, share_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
64
+ // Choose the correct mapRemotes function based on the server state.
65
+ const mapRemotesFunction = options.isServer ? remotes_1.mapRemotesForSSR : remotes_1.mapRemotes;
66
+ // Determine the URL function, either from provided options or by using a default.
67
+ const determineRemoteUrlFunction = options.determineRemoteUrl
68
+ ? options.determineRemoteUrl
69
+ : getFunctionDeterminateRemoteUrl(options.isServer);
70
+ // Map the remotes if they exist, otherwise default to an empty object.
71
+ let mappedRemotes = {};
72
+ if (mfConfig.remotes && mfConfig.remotes.length > 0) {
73
+ mappedRemotes = mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFunction);
74
+ }
75
+ return { sharedLibraries, sharedDependencies, mappedRemotes };
77
76
  }
78
- //# sourceMappingURL=utils.js.map
@@ -1,42 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withModuleFederationForSSR = withModuleFederationForSSR;
4
- const tslib_1 = require("tslib");
5
4
  const core_1 = require("@rspack/core");
6
5
  const utils_1 = require("./utils");
7
- function withModuleFederationForSSR(options, configOverride) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- if (global.NX_GRAPH_CREATION) {
10
- return (config) => config;
11
- }
12
- const { sharedLibraries, sharedDependencies, mappedRemotes } = yield (0, utils_1.getModuleFederationConfig)(options, {
13
- isServer: true,
14
- });
15
- return (config, { context }) => {
16
- var _a, _b, _c;
17
- config.target = 'async-node';
18
- config.output.uniqueName = options.name;
19
- config.optimization = Object.assign(Object.assign({}, ((_a = config.optimization) !== null && _a !== void 0 ? _a : {})), { runtimeChunk: false });
20
- config.plugins.push(
21
- // eslint-disable-next-line @typescript-eslint/no-var-requires
22
- new (require('@module-federation/enhanced/rspack').ModuleFederationPlugin)(Object.assign(Object.assign({ name: options.name, filename: 'remoteEntry.js', exposes: options.exposes, remotes: mappedRemotes, shared: Object.assign({}, sharedDependencies), isServer: true }, (configOverride ? configOverride : {})), { runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
23
- !options.disableNxRuntimeLibraryControlPlugin
24
- ? [
25
- ...((_b = configOverride === null || configOverride === void 0 ? void 0 : configOverride.runtimePlugins) !== null && _b !== void 0 ? _b : []),
26
- require.resolve('@module-federation/node/runtimePlugin'),
27
- require.resolve('@nx/rspack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
28
- ]
29
- : [
30
- ...((_c = configOverride === null || configOverride === void 0 ? void 0 : configOverride.runtimePlugins) !== null && _c !== void 0 ? _c : []),
31
- require.resolve('@module-federation/node/runtimePlugin'),
32
- ], virtualRuntimeEntry: true }), {}), sharedLibraries.getReplacementPlugin());
33
- // The env var is only set from the module-federation-dev-server
34
- // Attach the runtime plugin
35
- config.plugins.push(new core_1.DefinePlugin({
36
- 'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
37
- }));
38
- return config;
39
- };
6
+ async function withModuleFederationForSSR(options, configOverride) {
7
+ if (global.NX_GRAPH_CREATION) {
8
+ return (config) => config;
9
+ }
10
+ const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options, {
11
+ isServer: true,
40
12
  });
13
+ return (config, { context }) => {
14
+ config.target = 'async-node';
15
+ config.output.uniqueName = options.name;
16
+ config.optimization = {
17
+ ...(config.optimization ?? {}),
18
+ runtimeChunk: false,
19
+ };
20
+ config.plugins.push(
21
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
22
+ new (require('@module-federation/enhanced/rspack').ModuleFederationPlugin)({
23
+ name: options.name,
24
+ filename: 'remoteEntry.js',
25
+ exposes: options.exposes,
26
+ remotes: mappedRemotes,
27
+ shared: {
28
+ ...sharedDependencies,
29
+ },
30
+ isServer: true,
31
+ /**
32
+ * Apply user-defined config overrides
33
+ */
34
+ ...(configOverride ? configOverride : {}),
35
+ runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
36
+ !options.disableNxRuntimeLibraryControlPlugin
37
+ ? [
38
+ ...(configOverride?.runtimePlugins ?? []),
39
+ require.resolve('@module-federation/node/runtimePlugin'),
40
+ require.resolve('@nx/rspack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
41
+ ]
42
+ : [
43
+ ...(configOverride?.runtimePlugins ?? []),
44
+ require.resolve('@module-federation/node/runtimePlugin'),
45
+ ],
46
+ virtualRuntimeEntry: true,
47
+ }, {}), sharedLibraries.getReplacementPlugin());
48
+ // The env var is only set from the module-federation-dev-server
49
+ // Attach the runtime plugin
50
+ config.plugins.push(new core_1.DefinePlugin({
51
+ 'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
52
+ }));
53
+ return config;
54
+ };
41
55
  }
42
- //# sourceMappingURL=with-module-federation-ssr.js.map
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withModuleFederation = withModuleFederation;
4
- const tslib_1 = require("tslib");
5
4
  const rspack_1 = require("@module-federation/enhanced/rspack");
6
5
  const core_1 = require("@rspack/core");
7
6
  const utils_1 = require("./utils");
@@ -10,43 +9,62 @@ const isVarOrWindow = (libType) => libType === 'var' || libType === 'window';
10
9
  * @param {ModuleFederationConfig} options
11
10
  * @param {NxModuleFederationConfigOverride} configOverride
12
11
  */
13
- function withModuleFederation(options, configOverride) {
14
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
- var _a;
16
- if (global.NX_GRAPH_CREATION) {
17
- return function makeConfig(config) {
18
- return config;
19
- };
20
- }
21
- const { sharedDependencies, sharedLibraries, mappedRemotes } = yield (0, utils_1.getModuleFederationConfig)(options);
22
- const isGlobal = isVarOrWindow((_a = options.library) === null || _a === void 0 ? void 0 : _a.type);
23
- return function makeConfig(config, { context }) {
24
- var _a, _b;
25
- config.output.uniqueName = options.name;
26
- config.output.publicPath = 'auto';
27
- if (isGlobal) {
28
- config.output.scriptType = 'text/javascript';
29
- }
30
- config.optimization = Object.assign(Object.assign({}, ((_a = config.optimization) !== null && _a !== void 0 ? _a : {})), { runtimeChunk: false });
31
- if (config.mode === 'development' &&
32
- Object.keys(mappedRemotes).length > 1 &&
33
- !options.exposes) {
34
- config.optimization.runtimeChunk = 'single';
35
- }
36
- config.plugins.push(new rspack_1.ModuleFederationPlugin(Object.assign(Object.assign(Object.assign({ name: options.name, filename: 'remoteEntry.js', exposes: options.exposes, remotes: mappedRemotes, shared: Object.assign({}, sharedDependencies) }, (isGlobal ? { remoteType: 'script' } : {})), (configOverride ? configOverride : {})), { runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
37
- !options.disableNxRuntimeLibraryControlPlugin
38
- ? [
39
- ...((_b = configOverride === null || configOverride === void 0 ? void 0 : configOverride.runtimePlugins) !== null && _b !== void 0 ? _b : []),
40
- require.resolve('@nx/rspack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
41
- ]
42
- : configOverride === null || configOverride === void 0 ? void 0 : configOverride.runtimePlugins, virtualRuntimeEntry: true })), sharedLibraries.getReplacementPlugin());
43
- // The env var is only set from the module-federation-dev-server
44
- // Attach the runtime plugin
45
- config.plugins.push(new core_1.DefinePlugin({
46
- 'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
47
- }));
12
+ async function withModuleFederation(options, configOverride) {
13
+ if (global.NX_GRAPH_CREATION) {
14
+ return function makeConfig(config) {
48
15
  return config;
49
16
  };
50
- });
17
+ }
18
+ const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
19
+ const isGlobal = isVarOrWindow(options.library?.type);
20
+ return function makeConfig(config, { context }) {
21
+ config.output.uniqueName = options.name;
22
+ config.output.publicPath = 'auto';
23
+ if (isGlobal) {
24
+ config.output.scriptType = 'text/javascript';
25
+ }
26
+ config.optimization = {
27
+ ...(config.optimization ?? {}),
28
+ runtimeChunk: false,
29
+ };
30
+ if (config.mode === 'development' &&
31
+ Object.keys(mappedRemotes).length > 1 &&
32
+ !options.exposes) {
33
+ config.optimization.runtimeChunk = 'single';
34
+ }
35
+ config.plugins.push(new rspack_1.ModuleFederationPlugin({
36
+ name: options.name,
37
+ filename: 'remoteEntry.js',
38
+ exposes: options.exposes,
39
+ remotes: mappedRemotes,
40
+ shared: {
41
+ ...sharedDependencies,
42
+ },
43
+ /**
44
+ * remoteType: 'script' is required for the remote to be loaded as a script tag.
45
+ * remotes will need to be defined as:
46
+ * { appX: 'appX@http://localhost:3001/remoteEntry.js' }
47
+ * { appY: 'appY@http://localhost:3002/remoteEntry.js' }
48
+ */
49
+ ...(isGlobal ? { remoteType: 'script' } : {}),
50
+ /**
51
+ * Apply user-defined config overrides
52
+ */
53
+ ...(configOverride ? configOverride : {}),
54
+ runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
55
+ !options.disableNxRuntimeLibraryControlPlugin
56
+ ? [
57
+ ...(configOverride?.runtimePlugins ?? []),
58
+ require.resolve('@nx/rspack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
59
+ ]
60
+ : configOverride?.runtimePlugins,
61
+ virtualRuntimeEntry: true,
62
+ }), sharedLibraries.getReplacementPlugin());
63
+ // The env var is only set from the module-federation-dev-server
64
+ // Attach the runtime plugin
65
+ config.plugins.push(new core_1.DefinePlugin({
66
+ 'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
67
+ }));
68
+ return config;
69
+ };
51
70
  }
52
- //# sourceMappingURL=with-module-federation.js.map
@@ -31,10 +31,12 @@ function normalizeAssets(assets, root, sourceRoot) {
31
31
  }
32
32
  const assetPath = (0, devkit_1.normalizePath)(asset.input);
33
33
  const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
34
- return Object.assign(Object.assign({}, asset), { input: resolvedAssetPath,
34
+ return {
35
+ ...asset,
36
+ input: resolvedAssetPath,
35
37
  // Now we remove starting slash to make Webpack place it from the output root.
36
- output: asset.output.replace(/^\//, '') });
38
+ output: asset.output.replace(/^\//, ''),
39
+ };
37
40
  }
38
41
  });
39
42
  }
40
- //# sourceMappingURL=normalize-assets.js.map
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readRspackOptions = readRspackOptions;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const config_1 = require("./config");
7
6
  /**
@@ -12,30 +11,27 @@ const config_1 = require("./config");
12
11
  *
13
12
  * @param rspackConfig
14
13
  */
15
- function readRspackOptions(rspackConfig) {
16
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
17
- let config;
18
- if ((0, config_1.isNxRspackComposablePlugin)(rspackConfig)) {
19
- config = yield rspackConfig({}, {
20
- // These values are only used during build-time, so passing stubs here just to read out
21
- // the returned config object.
22
- options: {
23
- root: devkit_1.workspaceRoot,
24
- projectRoot: '',
25
- sourceRoot: '',
26
- },
27
- context: { root: devkit_1.workspaceRoot, cwd: undefined, isVerbose: false },
28
- });
29
- }
30
- else if (typeof rspackConfig === 'function') {
31
- config = yield rspackConfig({
32
- production: true, // we want the production build options
33
- }, {});
34
- }
35
- else {
36
- config = rspackConfig;
37
- }
38
- return config;
39
- });
14
+ async function readRspackOptions(rspackConfig) {
15
+ let config;
16
+ if ((0, config_1.isNxRspackComposablePlugin)(rspackConfig)) {
17
+ config = await rspackConfig({}, {
18
+ // These values are only used during build-time, so passing stubs here just to read out
19
+ // the returned config object.
20
+ options: {
21
+ root: devkit_1.workspaceRoot,
22
+ projectRoot: '',
23
+ sourceRoot: '',
24
+ },
25
+ context: { root: devkit_1.workspaceRoot, cwd: undefined, isVerbose: false },
26
+ });
27
+ }
28
+ else if (typeof rspackConfig === 'function') {
29
+ config = await rspackConfig({
30
+ production: true, // we want the production build options
31
+ }, {});
32
+ }
33
+ else {
34
+ config = rspackConfig;
35
+ }
36
+ return config;
40
37
  }
41
- //# sourceMappingURL=read-rspack-options.js.map
@@ -36,4 +36,3 @@ reload = false) {
36
36
  : maybeCustomRspackConfig;
37
37
  return customRspackConfig;
38
38
  }
39
- //# sourceMappingURL=resolve-user-defined-rspack-config.js.map
@@ -1,5 +1,5 @@
1
- export declare const rspackCoreVersion = "^1.0.2";
2
- export declare const rspackDevServerVersion = "^1.0.2";
1
+ export declare const rspackCoreVersion = "1.0.5";
2
+ export declare const rspackDevServerVersion = "1.0.5";
3
3
  export declare const rspackPluginMinifyVersion = "^0.7.5";
4
4
  export declare const rspackPluginReactRefreshVersion = "^1.0.0";
5
5
  export declare const lessLoaderVersion = "~11.1.3";
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.stylusVersion = exports.sassVersion = exports.lessVersion = exports.nestjsMicroservicesVersion = exports.nestjsPlatformExpressVersion = exports.nestjsCoreVersion = exports.nestjsCommonVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.reactDomVersion = exports.reactRefreshVersion = exports.reactVersion = exports.lessLoaderVersion = exports.rspackPluginReactRefreshVersion = exports.rspackPluginMinifyVersion = exports.rspackDevServerVersion = exports.rspackCoreVersion = void 0;
4
- exports.rspackCoreVersion = '^1.0.2';
5
- exports.rspackDevServerVersion = '^1.0.2';
4
+ exports.rspackCoreVersion = '1.0.5';
5
+ exports.rspackDevServerVersion = '1.0.5';
6
6
  exports.rspackPluginMinifyVersion = '^0.7.5';
7
7
  exports.rspackPluginReactRefreshVersion = '^1.0.0';
8
8
  exports.lessLoaderVersion = '~11.1.3';
@@ -22,4 +22,3 @@ exports.eslintPluginImportVersion = '2.27.5';
22
22
  exports.eslintPluginJsxA11yVersion = '6.7.1';
23
23
  exports.eslintPluginReactVersion = '7.32.2';
24
24
  exports.eslintPluginReactHooksVersion = '4.6.0';
25
- //# sourceMappingURL=versions.js.map