@nx/rspack 20.2.0-beta.2 → 20.2.0-beta.4

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 (103) hide show
  1. package/app-plugin.d.ts +2 -0
  2. package/app-plugin.js +5 -0
  3. package/generators.json +10 -0
  4. package/migrations.json +21 -1
  5. package/module-federation.d.ts +4 -1
  6. package/module-federation.js +7 -2
  7. package/package.json +10 -8
  8. package/react-plugin.d.ts +1 -0
  9. package/react-plugin.js +5 -0
  10. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
  11. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
  12. package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
  13. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
  14. package/src/executors/rspack/schema.d.ts +1 -1
  15. package/src/executors/rspack/schema.json +1 -1
  16. package/src/generators/application/application.js +0 -2
  17. package/src/generators/configuration/configuration.js +0 -2
  18. package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.d.ts +7 -0
  19. package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +92 -0
  20. package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +6 -0
  21. package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +106 -0
  22. package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.d.ts +2 -0
  23. package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.js +73 -0
  24. package/src/generators/convert-config-to-rspack-plugin/lib/utils.d.ts +1 -0
  25. package/src/generators/convert-config-to-rspack-plugin/lib/utils.js +13 -0
  26. package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.d.ts +9 -0
  27. package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.js +40 -0
  28. package/src/generators/convert-config-to-rspack-plugin/schema.json +19 -0
  29. package/src/generators/convert-to-inferred/__snapshots__/convert-to-inferred.spec.ts.snap +268 -0
  30. package/src/generators/convert-to-inferred/convert-to-inferred.d.ts +12 -0
  31. package/src/generators/convert-to-inferred/convert-to-inferred.js +114 -0
  32. package/src/generators/convert-to-inferred/schema.json +19 -0
  33. package/src/generators/convert-to-inferred/utils/ast.d.ts +3 -0
  34. package/src/generators/convert-to-inferred/utils/ast.js +40 -0
  35. package/src/generators/convert-to-inferred/utils/build-post-target-transformer.d.ts +6 -0
  36. package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +210 -0
  37. package/src/generators/convert-to-inferred/utils/index.d.ts +3 -0
  38. package/src/generators/convert-to-inferred/utils/index.js +6 -0
  39. package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.d.ts +6 -0
  40. package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +207 -0
  41. package/src/generators/convert-to-inferred/utils/types.d.ts +11 -0
  42. package/src/generators/convert-webpack/lib/transform-cjs.js +5 -5
  43. package/src/generators/convert-webpack/lib/transform-esm.js +5 -5
  44. package/src/generators/init/init.js +0 -2
  45. package/src/index.d.ts +1 -0
  46. package/src/index.js +1 -0
  47. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
  48. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
  49. package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +16 -0
  50. package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +43 -0
  51. package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts +8 -0
  52. package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.js +13 -0
  53. package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.d.ts +31 -0
  54. package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.js +73 -0
  55. package/src/plugins/utils/apply-base-config.js +3 -0
  56. package/src/plugins/utils/apply-web-config.d.ts +2 -2
  57. package/src/plugins/utils/apply-web-config.js +1 -1
  58. package/src/plugins/utils/plugins/normalize-options.js +1 -1
  59. package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +3 -2
  60. package/src/utils/create-compiler.js +3 -1
  61. package/src/utils/generator-utils.d.ts +2 -2
  62. package/src/utils/generator-utils.js +134 -67
  63. package/src/utils/has-plugin.d.ts +2 -0
  64. package/src/utils/has-plugin.js +10 -0
  65. package/src/utils/module-federation/build-static.remotes.d.ts +1 -1
  66. package/src/utils/versions.d.ts +2 -2
  67. package/src/utils/versions.js +2 -2
  68. package/src/utils/module-federation/dependencies.d.ts +0 -6
  69. package/src/utils/module-federation/dependencies.js +0 -56
  70. package/src/utils/module-federation/get-remotes-for-host.d.ts +0 -16
  71. package/src/utils/module-federation/get-remotes-for-host.js +0 -99
  72. package/src/utils/module-federation/index.d.ts +0 -6
  73. package/src/utils/module-federation/index.js +0 -9
  74. package/src/utils/module-federation/models/index.d.ts +0 -47
  75. package/src/utils/module-federation/package-json.d.ts +0 -8
  76. package/src/utils/module-federation/package-json.js +0 -12
  77. package/src/utils/module-federation/parse-static-remotes-config.d.ts +0 -13
  78. package/src/utils/module-federation/parse-static-remotes-config.js +0 -34
  79. package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +0 -3
  80. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +0 -54
  81. package/src/utils/module-federation/public-api.d.ts +0 -8
  82. package/src/utils/module-federation/public-api.js +0 -20
  83. package/src/utils/module-federation/remotes.d.ts +0 -19
  84. package/src/utils/module-federation/remotes.js +0 -85
  85. package/src/utils/module-federation/secondary-entry-points.d.ts +0 -12
  86. package/src/utils/module-federation/secondary-entry-points.js +0 -104
  87. package/src/utils/module-federation/share.d.ts +0 -48
  88. package/src/utils/module-federation/share.js +0 -235
  89. package/src/utils/module-federation/start-remote-proxies.d.ts +0 -5
  90. package/src/utils/module-federation/start-remote-proxies.js +0 -45
  91. package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +0 -5
  92. package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -59
  93. package/src/utils/module-federation/typescript.d.ts +0 -4
  94. package/src/utils/module-federation/typescript.js +0 -53
  95. package/src/utils/module-federation/with-module-federation/package-json.d.ts +0 -8
  96. package/src/utils/module-federation/with-module-federation/package-json.js +0 -12
  97. package/src/utils/module-federation/with-module-federation/utils.d.ts +0 -12
  98. package/src/utils/module-federation/with-module-federation/utils.js +0 -76
  99. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +0 -3
  100. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +0 -62
  101. package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +0 -8
  102. package/src/utils/module-federation/with-module-federation/with-module-federation.js +0 -70
  103. /package/src/{utils/module-federation/models/index.js → generators/convert-to-inferred/utils/types.js} +0 -0
@@ -0,0 +1,2 @@
1
+ export { NxAppRspackPlugin } from './src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin';
2
+ export type { NxAppRspackPluginOptions } from './src/plugins/utils/models';
package/app-plugin.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxAppRspackPlugin = void 0;
4
+ var nx_app_rspack_plugin_1 = require("./src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin");
5
+ Object.defineProperty(exports, "NxAppRspackPlugin", { enumerable: true, get: function () { return nx_app_rspack_plugin_1.NxAppRspackPlugin; } });
package/generators.json CHANGED
@@ -31,6 +31,16 @@
31
31
  "factory": "./src/generators/convert-webpack/convert-webpack",
32
32
  "schema": "./src/generators/convert-webpack/schema.json",
33
33
  "description": "Convert a webpack application to use rspack."
34
+ },
35
+ "convert-config-to-rspack-plugin": {
36
+ "factory": "./src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin",
37
+ "schema": "./src/generators/convert-config-to-rspack-plugin/schema.json",
38
+ "description": "Convert the project to use the `NxAppRspackPlugin` and `NxReactRspackPlugin`."
39
+ },
40
+ "convert-to-inferred": {
41
+ "factory": "./src/generators/convert-to-inferred/convert-to-inferred#convertToInferred",
42
+ "schema": "./src/generators/convert-to-inferred/schema.json",
43
+ "description": "Convert existing Rspack project(s) using `@nx/rspack:rspack` executor to use `@nx/rspack/plugin`."
34
44
  }
35
45
  }
36
46
  }
package/migrations.json CHANGED
@@ -1,5 +1,12 @@
1
1
  {
2
- "generators": {},
2
+ "generators": {
3
+ "update-20-2-0-update-with-module-federation-import": {
4
+ "cli": "nx",
5
+ "version": "20.2.0-beta.3",
6
+ "description": "Update the withModuleFederation import use @nx/module-federation/rspack.",
7
+ "factory": "./src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package"
8
+ }
9
+ },
3
10
  "packageJsonUpdates": {
4
11
  "18.1.0": {
5
12
  "version": "18.1.0-beta.0",
@@ -68,6 +75,19 @@
68
75
  "alwaysAddToPackageJson": false
69
76
  }
70
77
  }
78
+ },
79
+ "20.2.0": {
80
+ "version": "20.2.0-beta.3",
81
+ "packages": {
82
+ "@rspack/core": {
83
+ "version": "^1.1.2",
84
+ "alwaysAddToPackageJson": false
85
+ },
86
+ "@rspack/dev-server": {
87
+ "version": "^1.0.9",
88
+ "alwaysAddToPackageJson": false
89
+ }
90
+ }
71
91
  }
72
92
  },
73
93
  "version": "0.1"
@@ -1 +1,4 @@
1
- export * from './src/utils/module-federation/public-api';
1
+ /**
2
+ * @deprecated Use `@nx/module-federation/rspack` instead. This will be removed in Nx v22.
3
+ */
4
+ export { withModuleFederation, withModuleFederationForSSR, } from '@nx/module-federation/rspack';
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./src/utils/module-federation/public-api"), exports);
3
+ exports.withModuleFederationForSSR = exports.withModuleFederation = void 0;
4
+ /**
5
+ * @deprecated Use `@nx/module-federation/rspack` instead. This will be removed in Nx v22.
6
+ */
7
+ var rspack_1 = require("@nx/module-federation/rspack");
8
+ Object.defineProperty(exports, "withModuleFederation", { enumerable: true, get: function () { return rspack_1.withModuleFederation; } });
9
+ Object.defineProperty(exports, "withModuleFederationForSSR", { enumerable: true, get: function () { return rspack_1.withModuleFederationForSSR; } });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nx/rspack",
3
3
  "description": "The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.",
4
- "version": "20.2.0-beta.2",
4
+ "version": "20.2.0-beta.4",
5
5
  "type": "commonjs",
6
6
  "repository": {
7
7
  "type": "git",
@@ -24,12 +24,13 @@
24
24
  "generators": "./generators.json",
25
25
  "executors": "./executors.json",
26
26
  "dependencies": {
27
- "@nx/js": "20.2.0-beta.2",
28
- "@nx/devkit": "20.2.0-beta.2",
29
- "@nx/web": "20.2.0-beta.2",
27
+ "@nx/js": "20.2.0-beta.4",
28
+ "@nx/devkit": "20.2.0-beta.4",
29
+ "@nx/web": "20.2.0-beta.4",
30
+ "@nx/module-federation": "20.2.0-beta.4",
30
31
  "@phenomnomnominal/tsquery": "~5.0.1",
31
- "@rspack/core": "^1.0.4",
32
- "@rspack/dev-server": "^1.0.4",
32
+ "@rspack/core": "^1.1.2",
33
+ "@rspack/dev-server": "^1.0.9",
33
34
  "@rspack/plugin-react-refresh": "^1.0.0",
34
35
  "autoprefixer": "^10.4.9",
35
36
  "browserslist": "^4.21.4",
@@ -50,11 +51,12 @@
50
51
  "postcss-loader": "^8.1.1",
51
52
  "postcss": "^8.4.38",
52
53
  "tslib": "^2.3.0",
54
+ "webpack": "^5.80.0",
53
55
  "webpack-node-externals": "^3.0.0"
54
56
  },
55
57
  "peerDependencies": {
56
- "@module-federation/enhanced": "~0.6.0",
57
- "@module-federation/node": "~2.5.10"
58
+ "@module-federation/enhanced": "~0.7.6",
59
+ "@module-federation/node": "~2.6.11"
58
60
  },
59
61
  "nx-migrations": {
60
62
  "migrations": "./migrations.json"
@@ -0,0 +1 @@
1
+ export { NxReactRspackPlugin } from './src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxReactRspackPlugin = void 0;
4
+ var nx_react_rspack_plugin_1 = require("./src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin");
5
+ Object.defineProperty(exports, "NxReactRspackPlugin", { enumerable: true, get: function () { return nx_react_rspack_plugin_1.NxReactRspackPlugin; } });
@@ -8,10 +8,8 @@ const file_server_impl_1 = tslib_1.__importDefault(require("@nx/web/src/executor
8
8
  const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
9
9
  const fs_1 = require("fs");
10
10
  const path_1 = require("path");
11
- const module_federation_1 = require("../../utils/module-federation");
11
+ const utils_1 = require("@nx/module-federation/src/utils");
12
12
  const build_static_remotes_1 = require("../../utils/module-federation/build-static.remotes");
13
- const parse_static_remotes_config_1 = require("../../utils/module-federation/parse-static-remotes-config");
14
- const start_remote_proxies_1 = require("../../utils/module-federation/start-remote-proxies");
15
13
  const dev_server_impl_1 = tslib_1.__importDefault(require("../dev-server/dev-server.impl"));
16
14
  function getBuildOptions(buildTarget, context) {
17
15
  const target = (0, devkit_1.parseTargetString)(buildTarget, context);
@@ -121,9 +119,9 @@ async function* moduleFederationDevServer(options, context) {
121
119
  if (!options.isInitialHost) {
122
120
  return yield* currIter;
123
121
  }
124
- const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, p.root, 'react');
122
+ const moduleFederationConfig = (0, utils_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, p.root, 'react');
125
123
  const remoteNames = options.devRemotes?.map((r) => typeof r === 'string' ? r : r.remoteName);
126
- const remotes = (0, module_federation_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
124
+ const remotes = (0, utils_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
127
125
  projectName: context.projectName,
128
126
  projectGraph: context.projectGraph,
129
127
  root: context.root,
@@ -134,11 +132,11 @@ async function* moduleFederationDevServer(options, context) {
134
132
  ...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []).map((r) => r.replace(/-/g, '_')),
135
133
  p.name.replace(/-/g, '_'),
136
134
  ]);
137
- const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
135
+ const staticRemotesConfig = (0, utils_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
138
136
  const mappedLocationsOfStaticRemotes = await (0, build_static_remotes_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options);
139
137
  const devRemoteIters = await startRemotes(remotes.devRemotes, context, options, 'serve');
140
138
  const staticRemotesIter = startStaticRemotesFileServer(staticRemotesConfig, context, options);
141
- (0, start_remote_proxies_1.startRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
139
+ (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
142
140
  ? {
143
141
  pathToCert: (0, path_1.join)(devkit_1.workspaceRoot, options.sslCert),
144
142
  pathToKey: (0, path_1.join)(devkit_1.workspaceRoot, options.sslKey),
@@ -4,16 +4,14 @@ exports.default = moduleFederationSsrDevServer;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const path_1 = require("path");
7
- const module_federation_1 = require("../../utils/module-federation");
7
+ const utils_1 = require("@nx/module-federation/src/utils");
8
8
  const ssr_dev_server_impl_1 = tslib_1.__importDefault(require("../ssr-dev-server/ssr-dev-server.impl"));
9
9
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
10
10
  const child_process_1 = require("child_process");
11
11
  const fs_1 = require("fs");
12
- const parse_static_remotes_config_1 = require("../../utils/module-federation/parse-static-remotes-config");
13
12
  const file_server_impl_1 = tslib_1.__importDefault(require("@nx/web/src/executors/file-server/file-server.impl"));
14
13
  const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
15
14
  const cache_directory_1 = require("nx/src/utils/cache-directory");
16
- const start_ssr_remote_proxies_1 = require("../../utils/module-federation/start-ssr-remote-proxies");
17
15
  function normalizeOptions(options) {
18
16
  return {
19
17
  ...options,
@@ -159,9 +157,9 @@ async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
159
157
  if (!options.isInitialHost) {
160
158
  return yield* iter;
161
159
  }
162
- const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, projectConfig.root, 'react');
160
+ const moduleFederationConfig = (0, utils_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, projectConfig.root, 'react');
163
161
  const remoteNames = options.devRemotes?.map((remote) => typeof remote === 'string' ? remote : remote.remoteName);
164
- const remotes = (0, module_federation_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
162
+ const remotes = (0, utils_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
165
163
  projectName: context.projectName,
166
164
  projectGraph: context.projectGraph,
167
165
  root: context.root,
@@ -171,11 +169,11 @@ async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
171
169
  ...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []).map((r) => r.replace(/-/g, '_')),
172
170
  projectConfig.name.replace(/-/g, '_'),
173
171
  ]);
174
- const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticSsrRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
172
+ const staticRemotesConfig = (0, utils_1.parseStaticSsrRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
175
173
  const mappedLocationsOfStaticRemotes = await buildSsrStaticRemotes(staticRemotesConfig, nxBin, context, options);
176
174
  const devRemoteIters = await startRemotes(remotes.devRemotes, context, options);
177
175
  const staticRemotesIter = startSsrStaticRemotesFileServer(staticRemotesConfig, context, options);
178
- (0, start_ssr_remote_proxies_1.startSsrRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
176
+ (0, utils_1.startSsrRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
179
177
  ? {
180
178
  pathToCert: options.sslCert,
181
179
  pathToKey: options.sslKey,
@@ -1,5 +1,5 @@
1
1
  import { ExecutorContext } from 'nx/src/config/misc-interfaces';
2
- import { StaticRemotesConfig } from '../../utils/module-federation/parse-static-remotes-config';
2
+ import { StaticRemotesConfig } from '@nx/module-federation/src/utils';
3
3
  import { ModuleFederationDevServerOptions } from '../module-federation-dev-server/schema';
4
4
  import { ModuleFederationStaticServerSchema } from './schema';
5
5
  export declare function startProxies(staticRemotesConfig: StaticRemotesConfig, hostServeOptions: ModuleFederationDevServerOptions, mappedLocationOfHost: string, mappedLocationsOfRemotes: Record<string, string>, sslOptions?: {
@@ -10,9 +10,8 @@ const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
10
10
  const child_process_1 = require("child_process");
11
11
  const fs_1 = require("fs");
12
12
  const path_1 = require("path");
13
- const module_federation_1 = require("../../utils/module-federation");
13
+ const utils_1 = require("@nx/module-federation/src/utils");
14
14
  const build_static_remotes_1 = require("../../utils/module-federation/build-static.remotes");
15
- const parse_static_remotes_config_1 = require("../../utils/module-federation/parse-static-remotes-config");
16
15
  function getBuildAndServeOptionsFromServeTarget(serveTarget, context) {
17
16
  const target = (0, devkit_1.parseTargetString)(serveTarget, context);
18
17
  const serveOptions = (0, devkit_1.readTargetOptions)(target, context);
@@ -170,13 +169,13 @@ async function* moduleFederationStaticServer(schema, context) {
170
169
  // Get the remotes from the module federation config
171
170
  const p = context.projectsConfigurations.projects[context.projectName];
172
171
  const options = getBuildAndServeOptionsFromServeTarget(schema.serveTarget, context);
173
- const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(options.buildOptions.tsConfig, context.root, p.root, 'react');
174
- const remotes = (0, module_federation_1.getRemotes)([], options.serveOptions.skipRemotes, moduleFederationConfig, {
172
+ const moduleFederationConfig = (0, utils_1.getModuleFederationConfig)(options.buildOptions.tsConfig, context.root, p.root, 'react');
173
+ const remotes = (0, utils_1.getRemotes)([], options.serveOptions.skipRemotes, moduleFederationConfig, {
175
174
  projectName: context.projectName,
176
175
  projectGraph: context.projectGraph,
177
176
  root: context.root,
178
177
  }, options.pathToManifestFile);
179
- const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
178
+ const staticRemotesConfig = (0, utils_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
180
179
  options.serveOptions.staticRemotesPort ??= remotes.staticRemotePort;
181
180
  const mappedLocationsOfStaticRemotes = await (0, build_static_remotes_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options.serveOptions);
182
181
  // Build the host
@@ -28,7 +28,7 @@ export interface RspackExecutorSchema {
28
28
  progress?: boolean;
29
29
  publicPath?: string;
30
30
  rebaseRootRelative?: boolean;
31
- rspackConfig: string;
31
+ rspackConfig?: string;
32
32
  runtimeChunk?: boolean;
33
33
  scripts?: Array<ExtraEntryPointClass | string>;
34
34
  skipTypeChecking?: boolean;
@@ -97,7 +97,7 @@
97
97
  "extractLicenses": {
98
98
  "type": "boolean",
99
99
  "description": "Extract all licenses in a separate file.",
100
- "default": true
100
+ "default": false
101
101
  },
102
102
  "fileReplacements": {
103
103
  "description": "Replace files with other files in the build.",
@@ -3,13 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = default_1;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
6
  const package_json_1 = require("nx/package.json");
8
7
  const configuration_1 = tslib_1.__importDefault(require("../configuration/configuration"));
9
8
  const init_1 = tslib_1.__importDefault(require("../init/init"));
10
9
  const normalize_options_1 = require("./lib/normalize-options");
11
10
  async function default_1(tree, _options) {
12
- (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(tree, 'rspack', 'application');
13
11
  const tasks = [];
14
12
  const initTask = await (0, init_1.default)(tree, {
15
13
  ..._options,
@@ -3,12 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configurationGenerator = configurationGenerator;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
6
  const generator_utils_1 = require("../../utils/generator-utils");
8
7
  const create_ts_config_1 = require("../application/lib/create-ts-config");
9
8
  const init_1 = tslib_1.__importDefault(require("../init/init"));
10
9
  async function configurationGenerator(tree, options) {
11
- (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(tree, 'rspack', 'configuration');
12
10
  const task = await (0, init_1.default)(tree, {
13
11
  ...options,
14
12
  // TODO: Crystalize the default rspack.config.js file.
@@ -0,0 +1,7 @@
1
+ import { Tree } from '@nx/devkit';
2
+ interface Schema {
3
+ project?: string;
4
+ skipFormat?: boolean;
5
+ }
6
+ export declare function convertConfigToRspackPluginGenerator(tree: Tree, options: Schema): Promise<void>;
7
+ export default convertConfigToRspackPluginGenerator;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertConfigToRspackPluginGenerator = convertConfigToRspackPluginGenerator;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
+ const extract_rspack_options_1 = require("./lib/extract-rspack-options");
7
+ const normalize_path_options_1 = require("./lib/normalize-path-options");
8
+ const path_1 = require("path");
9
+ const validate_project_1 = require("./lib/validate-project");
10
+ // Make text JSON compatible
11
+ const preprocessText = (text) => {
12
+ return text
13
+ .replace(/(\w+):/g, '"$1":') // Quote property names
14
+ .replace(/'/g, '"') // Convert single quotes to double quotes
15
+ .replace(/,(\s*[}\]])/g, '$1') // Remove trailing commas
16
+ .replace(/(\r\n|\n|\r|\t)/gm, ''); // Remove newlines and tabs
17
+ };
18
+ async function convertConfigToRspackPluginGenerator(tree, options) {
19
+ let migrated = 0;
20
+ const projects = (0, devkit_1.getProjects)(tree);
21
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/rspack:rspack', (currentTargetOptions, projectName, targetName, configurationName) => {
22
+ if (options.project && projectName !== options.project) {
23
+ return;
24
+ }
25
+ if (!configurationName) {
26
+ const project = projects.get(projectName);
27
+ const target = project.targets[targetName];
28
+ const hasError = (0, validate_project_1.validateProject)(tree, project);
29
+ if (hasError) {
30
+ throw new Error(hasError);
31
+ }
32
+ const rspackConfigPath = currentTargetOptions?.rspackConfig || '';
33
+ if (rspackConfigPath && tree.exists(rspackConfigPath)) {
34
+ let { withNxConfig: rspackOptions, withReactConfig } = (0, extract_rspack_options_1.extractRspackOptions)(tree, rspackConfigPath);
35
+ // if rspackOptions === undefined
36
+ // withNx was not found in the rspack.config.js file so we should skip this project
37
+ if (rspackOptions !== undefined) {
38
+ let parsedOptions = {};
39
+ if (rspackOptions) {
40
+ parsedOptions = JSON.parse(preprocessText(rspackOptions.getText()));
41
+ parsedOptions = (0, normalize_path_options_1.normalizePathOptions)(project.root, parsedOptions);
42
+ }
43
+ target.options.standardRspackConfigFunction = true;
44
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
45
+ const { dir, name, ext } = (0, path_1.parse)(rspackConfigPath);
46
+ tree.rename(rspackConfigPath, `${(0, devkit_1.joinPathFragments)(dir, `${name}.old${ext}`)}`);
47
+ tree.write(rspackConfigPath, (0, devkit_1.stripIndents) `
48
+ const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
49
+ const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
50
+ const { useLegacyNxPlugin } = require('@nx/rspack');
51
+
52
+ // This file was migrated using @nx/rspack:convert-config-to-rspack-plugin from your './rspack.config.old.js'
53
+ // Please check that the options here are correct as they were moved from the old rspack.config.js to this file.
54
+ const options = ${rspackOptions ? JSON.stringify(parsedOptions, null, 2) : '{}'};
55
+
56
+ /**
57
+ * @type{import('@rspack/core').RspackOptionsNormalized}
58
+ */
59
+ module.exports = async () => ({
60
+ plugins: [
61
+ ${rspackOptions
62
+ ? 'new NxAppRspackPlugin(options)'
63
+ : 'new NxAppRspackPlugin()'},
64
+ ${withReactConfig
65
+ ? `new NxReactRspackPlugin(${withReactConfig.getText()})`
66
+ : `new NxReactRspackPlugin({
67
+ // Uncomment this line if you don't want to use SVGR
68
+ // See: https://react-svgr.com/
69
+ // svgr: false
70
+ })`},
71
+ // NOTE: useLegacyNxPlugin ensures that the non-standard Rspack configuration file previously used still works.
72
+ // To remove its usage, move options such as "plugins" into this file as standard Rspack configuration options.
73
+ // To enhance configurations after Nx plugins have applied, you can add a new plugin with the \`apply\` method.
74
+ // e.g. \`{ apply: (compiler) => { /* modify compiler.options */ }\`
75
+ // eslint-disable-next-line react-hooks/rules-of-hooks
76
+ await useLegacyNxPlugin(require('./rspack.config.old'), options),
77
+ ],
78
+ });
79
+ `);
80
+ migrated++;
81
+ }
82
+ }
83
+ }
84
+ });
85
+ if (migrated === 0) {
86
+ throw new Error('Could not find any projects to migrate.');
87
+ }
88
+ if (!options.skipFormat) {
89
+ await (0, devkit_1.formatFiles)(tree);
90
+ }
91
+ }
92
+ exports.default = convertConfigToRspackPluginGenerator;
@@ -0,0 +1,6 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import * as ts from 'typescript';
3
+ export declare function extractRspackOptions(tree: Tree, rspackConfigPath: string): {
4
+ withNxConfig: "" | ts.Node;
5
+ withReactConfig: "" | ts.Node;
6
+ };
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractRspackOptions = extractRspackOptions;
4
+ const tslib_1 = require("tslib");
5
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
6
+ const ts = tslib_1.__importStar(require("typescript"));
7
+ function extractRspackOptions(tree, rspackConfigPath) {
8
+ const source = tree.read(rspackConfigPath).toString('utf-8');
9
+ const ast = tsquery_1.tsquery.ast(source);
10
+ const withNxQuery = 'CallExpression:has(Identifier[name="withNx"])';
11
+ const withReactQuery = 'CallExpression:has(Identifier[name="withReact"])';
12
+ const withWebQuery = 'CallExpression:has(Identifier[name="withWeb"])';
13
+ const withNxCall = (0, tsquery_1.tsquery)(ast, withNxQuery);
14
+ const withReactCall = (0, tsquery_1.tsquery)(ast, withReactQuery);
15
+ const withWebCall = (0, tsquery_1.tsquery)(ast, withWebQuery);
16
+ // If the config is empty set to empty string to avoid undefined. Undefined is used to check if the withNx exists inside of the config file.
17
+ let withNxConfig, withReactConfig;
18
+ withWebCall.forEach((node) => {
19
+ const argument = node.arguments[0] || '';
20
+ withNxConfig = argument; // Since withWeb and withNx use the same config object and both should not exist in the same file, we can reuse the withNxConfig variable.
21
+ });
22
+ withNxCall.forEach((node) => {
23
+ const argument = node.arguments[0] || ''; // The first argument is the config object
24
+ withNxConfig = argument;
25
+ });
26
+ withReactCall.forEach((node) => {
27
+ const argument = node.arguments[0] || '';
28
+ withReactConfig = argument;
29
+ });
30
+ if (withNxConfig !== undefined) {
31
+ // Only remove the withNx and withReact calls if they exist
32
+ let updatedSource = removeCallExpressions(source, [
33
+ 'withNx',
34
+ 'withReact',
35
+ 'withWeb',
36
+ ]);
37
+ updatedSource = removeImportDeclarations(updatedSource, 'withNx', '@nx/rspack');
38
+ updatedSource = removeImportDeclarations(updatedSource, 'withWeb', '@nx/rspack');
39
+ updatedSource = removeImportDeclarations(updatedSource, 'withReact', '@nx/rspack');
40
+ tree.write(rspackConfigPath, updatedSource);
41
+ }
42
+ return { withNxConfig, withReactConfig };
43
+ }
44
+ function removeCallExpressions(source, functionNames) {
45
+ let modifiedSource = source;
46
+ functionNames.forEach((functionName) => {
47
+ const callExpressionQuery = `CallExpression:has(Identifier[name="composePlugins"]) > CallExpression:has(Identifier[name="${functionName}"])`;
48
+ modifiedSource = tsquery_1.tsquery.replace(modifiedSource, callExpressionQuery, () => {
49
+ return ''; // Removes the entire CallExpression
50
+ });
51
+ });
52
+ return modifiedSource;
53
+ }
54
+ function removeImportDeclarations(source, importName, moduleName) {
55
+ const sourceFile = tsquery_1.tsquery.ast(source);
56
+ const modifiedStatements = sourceFile.statements
57
+ .map((statement) => {
58
+ if (!ts.isVariableStatement(statement))
59
+ return statement;
60
+ const declarationList = statement.declarationList;
61
+ const newDeclarations = declarationList.declarations
62
+ .map((declaration) => {
63
+ if (!ts.isVariableDeclaration(declaration) ||
64
+ !declaration.initializer)
65
+ return declaration;
66
+ if (ts.isCallExpression(declaration.initializer) &&
67
+ ts.isIdentifier(declaration.initializer.expression)) {
68
+ const callExpr = declaration.initializer.expression;
69
+ if (callExpr.text === 'require' &&
70
+ declaration.initializer.arguments[0]
71
+ ?.getText()
72
+ .replace(/['"]/g, '') === moduleName) {
73
+ if (ts.isObjectBindingPattern(declaration.name)) {
74
+ const bindingElements = declaration.name.elements.filter((element) => {
75
+ const elementName = element.name.getText();
76
+ return elementName !== importName;
77
+ });
78
+ if (bindingElements.length > 0) {
79
+ const newBindingPattern = ts.factory.updateObjectBindingPattern(declaration.name, bindingElements);
80
+ // Update the variable declaration with the new binding pattern without the specified import name
81
+ return ts.factory.updateVariableDeclaration(declaration, newBindingPattern, declaration.exclamationToken, declaration.type, declaration.initializer);
82
+ }
83
+ else {
84
+ return null; // Remove this declaration entirely if no bindings remain
85
+ }
86
+ }
87
+ }
88
+ }
89
+ return declaration;
90
+ })
91
+ .filter(Boolean);
92
+ if (newDeclarations.length > 0) {
93
+ const newDeclarationList = ts.factory.updateVariableDeclarationList(declarationList, newDeclarations);
94
+ return ts.factory.updateVariableStatement(statement, statement.modifiers, newDeclarationList);
95
+ }
96
+ else {
97
+ return null; // Remove the entire statement
98
+ }
99
+ })
100
+ .filter(Boolean);
101
+ // Use printer to format the source code and rewrite the modified
102
+ const newSourceFile = ts.factory.updateSourceFile(sourceFile, modifiedStatements);
103
+ const printer = ts.createPrinter();
104
+ const formattedSource = printer.printFile(newSourceFile);
105
+ return formattedSource;
106
+ }
@@ -0,0 +1,2 @@
1
+ import { RspackExecutorSchema } from '../../../executors/rspack/schema';
2
+ export declare function normalizePathOptions(projectRoot: string, options: Partial<RspackExecutorSchema>): Partial<RspackExecutorSchema>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizePathOptions = normalizePathOptions;
4
+ const utils_1 = require("./utils");
5
+ const executorFieldsToNormalize = [
6
+ 'outputPath',
7
+ 'index',
8
+ 'main',
9
+ 'assets',
10
+ 'tsConfig',
11
+ 'styles',
12
+ 'additionalEntryPoints',
13
+ 'scripts',
14
+ 'fileReplacements',
15
+ 'postcssConfig',
16
+ 'stylePreprocessorOptions',
17
+ 'publicPath',
18
+ ];
19
+ function normalizePathOptions(projectRoot, options) {
20
+ for (const [key, value] of Object.entries(options)) {
21
+ if (!executorFieldsToNormalize.includes(key)) {
22
+ continue;
23
+ }
24
+ options[key] = normalizePath(projectRoot, key, value);
25
+ }
26
+ return options;
27
+ }
28
+ function normalizePath(projectRoot, key, value) {
29
+ if (!value)
30
+ return value;
31
+ switch (key) {
32
+ case 'assets':
33
+ return value.map((asset) => {
34
+ if (typeof asset === 'string') {
35
+ return (0, utils_1.toProjectRelativePath)(asset, projectRoot);
36
+ }
37
+ return {
38
+ ...asset,
39
+ input: (0, utils_1.toProjectRelativePath)(asset.input, projectRoot),
40
+ output: (0, utils_1.toProjectRelativePath)(asset.output, projectRoot),
41
+ };
42
+ });
43
+ case 'styles':
44
+ case 'scripts':
45
+ return value.map((item) => {
46
+ if (typeof item === 'string') {
47
+ return (0, utils_1.toProjectRelativePath)(item, projectRoot);
48
+ }
49
+ return {
50
+ ...item,
51
+ input: (0, utils_1.toProjectRelativePath)(item.input, projectRoot),
52
+ };
53
+ });
54
+ case 'additionalEntryPoints':
55
+ return value.map((entry) => {
56
+ return {
57
+ ...entry,
58
+ entryPath: (0, utils_1.toProjectRelativePath)(entry.entryPath, projectRoot),
59
+ };
60
+ });
61
+ case 'fileReplacements':
62
+ return value.map((replacement) => {
63
+ return {
64
+ replace: (0, utils_1.toProjectRelativePath)(replacement.replace, projectRoot),
65
+ with: (0, utils_1.toProjectRelativePath)(replacement.with, projectRoot),
66
+ };
67
+ });
68
+ default:
69
+ return Array.isArray(value)
70
+ ? value.map((item) => (0, utils_1.toProjectRelativePath)(item, projectRoot))
71
+ : (0, utils_1.toProjectRelativePath)(value, projectRoot);
72
+ }
73
+ }
@@ -0,0 +1 @@
1
+ export declare function toProjectRelativePath(path: string, projectRoot: string): string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toProjectRelativePath = toProjectRelativePath;
4
+ const posix_1 = require("path/posix");
5
+ const devkit_1 = require("@nx/devkit");
6
+ function toProjectRelativePath(path, projectRoot) {
7
+ if (projectRoot === '.') {
8
+ // workspace and project root are the same, we normalize it to ensure it
9
+ return path.startsWith('.') ? path : `./${path}`;
10
+ }
11
+ const relativePath = (0, posix_1.relative)((0, posix_1.resolve)(devkit_1.workspaceRoot, projectRoot), (0, posix_1.resolve)(devkit_1.workspaceRoot, path));
12
+ return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
13
+ }
@@ -0,0 +1,9 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ /**
3
+ * Validates the project to ensure it can be migrated
4
+ *
5
+ * @param tree The virtual file system
6
+ * @param project the project configuration object for the project
7
+ * @returns A string if there is an error, otherwise undefined
8
+ */
9
+ export declare function validateProject(tree: Tree, project: ProjectConfiguration): string;