@nx/rspack 20.2.0-beta.2 → 20.2.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.
- package/app-plugin.d.ts +2 -0
- package/app-plugin.js +5 -0
- package/generators.json +10 -0
- package/migrations.json +21 -1
- package/module-federation.d.ts +4 -1
- package/module-federation.js +7 -2
- package/package.json +10 -8
- package/react-plugin.d.ts +1 -0
- package/react-plugin.js +5 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
- package/src/executors/rspack/schema.d.ts +1 -1
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.d.ts +7 -0
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +92 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +6 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +106 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.d.ts +2 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.js +73 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/utils.d.ts +1 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/utils.js +13 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.d.ts +9 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.js +40 -0
- package/src/generators/convert-config-to-rspack-plugin/schema.json +19 -0
- package/src/generators/convert-to-inferred/__snapshots__/convert-to-inferred.spec.ts.snap +268 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.d.ts +12 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js +114 -0
- package/src/generators/convert-to-inferred/schema.json +19 -0
- package/src/generators/convert-to-inferred/utils/ast.d.ts +3 -0
- package/src/generators/convert-to-inferred/utils/ast.js +40 -0
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +210 -0
- package/src/generators/convert-to-inferred/utils/index.d.ts +3 -0
- package/src/generators/convert-to-inferred/utils/index.js +6 -0
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +207 -0
- package/src/generators/convert-to-inferred/utils/types.d.ts +11 -0
- package/src/generators/convert-webpack/lib/transform-cjs.js +5 -5
- package/src/generators/convert-webpack/lib/transform-esm.js +5 -5
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
- package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +16 -0
- package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +43 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts +8 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.js +13 -0
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.d.ts +31 -0
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.js +73 -0
- package/src/plugins/utils/apply-base-config.js +1 -0
- package/src/plugins/utils/apply-web-config.d.ts +2 -2
- package/src/plugins/utils/apply-web-config.js +1 -1
- package/src/plugins/utils/plugins/normalize-options.js +1 -1
- package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +3 -2
- package/src/utils/create-compiler.js +3 -1
- package/src/utils/generator-utils.d.ts +2 -2
- package/src/utils/generator-utils.js +134 -67
- package/src/utils/has-plugin.d.ts +2 -0
- package/src/utils/has-plugin.js +10 -0
- package/src/utils/module-federation/build-static.remotes.d.ts +1 -1
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -2
- package/src/utils/module-federation/dependencies.d.ts +0 -6
- package/src/utils/module-federation/dependencies.js +0 -56
- package/src/utils/module-federation/get-remotes-for-host.d.ts +0 -16
- package/src/utils/module-federation/get-remotes-for-host.js +0 -99
- package/src/utils/module-federation/index.d.ts +0 -6
- package/src/utils/module-federation/index.js +0 -9
- package/src/utils/module-federation/models/index.d.ts +0 -47
- package/src/utils/module-federation/package-json.d.ts +0 -8
- package/src/utils/module-federation/package-json.js +0 -12
- package/src/utils/module-federation/parse-static-remotes-config.d.ts +0 -13
- package/src/utils/module-federation/parse-static-remotes-config.js +0 -34
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +0 -3
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +0 -54
- package/src/utils/module-federation/public-api.d.ts +0 -8
- package/src/utils/module-federation/public-api.js +0 -20
- package/src/utils/module-federation/remotes.d.ts +0 -19
- package/src/utils/module-federation/remotes.js +0 -85
- package/src/utils/module-federation/secondary-entry-points.d.ts +0 -12
- package/src/utils/module-federation/secondary-entry-points.js +0 -104
- package/src/utils/module-federation/share.d.ts +0 -48
- package/src/utils/module-federation/share.js +0 -235
- package/src/utils/module-federation/start-remote-proxies.d.ts +0 -5
- package/src/utils/module-federation/start-remote-proxies.js +0 -45
- package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +0 -5
- package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -59
- package/src/utils/module-federation/typescript.d.ts +0 -4
- package/src/utils/module-federation/typescript.js +0 -53
- package/src/utils/module-federation/with-module-federation/package-json.d.ts +0 -8
- package/src/utils/module-federation/with-module-federation/package-json.js +0 -12
- package/src/utils/module-federation/with-module-federation/utils.d.ts +0 -12
- package/src/utils/module-federation/with-module-federation/utils.js +0 -76
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +0 -3
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +0 -62
- package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +0 -8
- package/src/utils/module-federation/with-module-federation/with-module-federation.js +0 -70
- /package/src/{utils/module-federation/models/index.js → generators/convert-to-inferred/utils/types.js} +0 -0
package/app-plugin.d.ts
ADDED
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"
|
package/module-federation.d.ts
CHANGED
package/module-federation.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
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.
|
|
4
|
+
"version": "20.2.0-beta.3",
|
|
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.
|
|
28
|
-
"@nx/devkit": "20.2.0-beta.
|
|
29
|
-
"@nx/web": "20.2.0-beta.
|
|
27
|
+
"@nx/js": "20.2.0-beta.3",
|
|
28
|
+
"@nx/devkit": "20.2.0-beta.3",
|
|
29
|
+
"@nx/web": "20.2.0-beta.3",
|
|
30
|
+
"@nx/module-federation": "20.2.0-beta.3",
|
|
30
31
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
31
|
-
"@rspack/core": "^1.
|
|
32
|
-
"@rspack/dev-server": "^1.0.
|
|
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
|
|
57
|
-
"@module-federation/node": "~2.
|
|
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';
|
package/react-plugin.js
ADDED
|
@@ -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
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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),
|
package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js
CHANGED
|
@@ -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
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
176
|
+
(0, utils_1.startSsrRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
|
|
179
177
|
? {
|
|
180
178
|
pathToCert: options.sslCert,
|
|
181
179
|
pathToKey: options.sslKey,
|
package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExecutorContext } from 'nx/src/config/misc-interfaces';
|
|
2
|
-
import { StaticRemotesConfig } from '
|
|
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?: {
|
package/src/executors/module-federation-static-server/module-federation-static-server.impl.js
CHANGED
|
@@ -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
|
|
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,
|
|
174
|
-
const remotes = (0,
|
|
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,
|
|
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
|
|
31
|
+
rspackConfig?: string;
|
|
32
32
|
runtimeChunk?: boolean;
|
|
33
33
|
scripts?: Array<ExtraEntryPointClass | string>;
|
|
34
34
|
skipTypeChecking?: boolean;
|
|
@@ -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,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,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;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateProject = validateProject;
|
|
4
|
+
function hasAnotherRspackConfig(tree, projectRoot) {
|
|
5
|
+
const files = tree.children(projectRoot);
|
|
6
|
+
const projectJsonString = tree.read(`${projectRoot}/project.json`, 'utf-8');
|
|
7
|
+
for (const file of files) {
|
|
8
|
+
if (file !== 'rspack.config.js' &&
|
|
9
|
+
file.endsWith('.js') &&
|
|
10
|
+
file.includes('rspack.config') &&
|
|
11
|
+
projectJsonString.includes(file) &&
|
|
12
|
+
tree.exists(`${projectRoot}/rspack.config.js`)) {
|
|
13
|
+
return 'Cannot convert a project with multiple rspack config files. Please consolidate them into a single rspack.config.js file.';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function isNestProject(project) {
|
|
18
|
+
for (const target in project.targets) {
|
|
19
|
+
if (project.targets[target].executor === '@nx/js:node') {
|
|
20
|
+
return `The project ${project.name} is using the '@nx/js:node' executor. At the moment, we do not support migrating such projects.`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validates the project to ensure it can be migrated
|
|
26
|
+
*
|
|
27
|
+
* @param tree The virtual file system
|
|
28
|
+
* @param project the project configuration object for the project
|
|
29
|
+
* @returns A string if there is an error, otherwise undefined
|
|
30
|
+
*/
|
|
31
|
+
function validateProject(tree, project) {
|
|
32
|
+
const containsMfeExecutor = Object.keys(project.targets).some((target) => {
|
|
33
|
+
return ['@nx/rspack:module-federation-dev-server'].includes(project.targets[target].executor);
|
|
34
|
+
});
|
|
35
|
+
if (containsMfeExecutor) {
|
|
36
|
+
return `The project ${project.name} is using Module Federation. At the moment, we don't support migrating projects that use Module Federation.`;
|
|
37
|
+
}
|
|
38
|
+
const hasAnotherConfig = hasAnotherRspackConfig(tree, project.root);
|
|
39
|
+
return hasAnotherConfig || isNestProject(project);
|
|
40
|
+
}
|