@nx/rspack 21.2.1 → 21.2.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/package.json +6 -6
- package/src/executors/dev-server/dev-server.impl.js +3 -2
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +3 -3
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +6 -6
- 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 +8 -7
- package/src/executors/rspack/rspack.impl.js +3 -2
- package/src/generators/convert-webpack/lib/transform-cjs.js +21 -8
- package/src/generators/convert-webpack/lib/transform-esm.js +21 -8
- package/src/plugins/utils/apply-base-config.js +22 -5
- package/src/plugins/utils/apply-web-config.js +5 -4
- package/src/plugins/utils/plugins/normalize-options.d.ts +1 -1
- package/src/plugins/utils/plugins/normalize-options.js +4 -3
- package/src/utils/config.js +2 -1
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": "21.2.
|
|
4
|
+
"version": "21.2.3",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"generators": "./generators.json",
|
|
25
25
|
"executors": "./executors.json",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nx/js": "21.2.
|
|
28
|
-
"@nx/devkit": "21.2.
|
|
29
|
-
"@nx/web": "21.2.
|
|
30
|
-
"@nx/module-federation": "21.2.
|
|
27
|
+
"@nx/js": "21.2.3",
|
|
28
|
+
"@nx/devkit": "21.2.3",
|
|
29
|
+
"@nx/web": "21.2.3",
|
|
30
|
+
"@nx/module-federation": "21.2.3",
|
|
31
31
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
32
32
|
"@rspack/core": "^1.3.8",
|
|
33
33
|
"@rspack/dev-server": "^1.1.1",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"webpack-node-externals": "^3.0.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@module-federation/enhanced": "^0.
|
|
60
|
+
"@module-federation/enhanced": "^0.15.0",
|
|
61
61
|
"@module-federation/node": "^2.6.26"
|
|
62
62
|
},
|
|
63
63
|
"nx-migrations": {
|
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = runExecutor;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
6
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
6
7
|
const dev_server_1 = require("@rspack/dev-server");
|
|
7
8
|
const create_compiler_1 = require("../../utils/create-compiler");
|
|
8
9
|
const mode_utils_1 = require("../../utils/mode-utils");
|
|
9
|
-
const get_dev_server_config_1 = require("./lib/get-dev-server-config");
|
|
10
10
|
const normalize_options_1 = require("../rspack/lib/normalize-options");
|
|
11
|
+
const get_dev_server_config_1 = require("./lib/get-dev-server-config");
|
|
11
12
|
async function* runExecutor(options, context) {
|
|
12
13
|
process.env.NODE_ENV ??= options.mode ?? 'development';
|
|
13
14
|
if ((0, mode_utils_1.isMode)(process.env.NODE_ENV)) {
|
|
@@ -18,7 +19,7 @@ async function* runExecutor(options, context) {
|
|
|
18
19
|
process.env.NX_BUILD_LIBS_FROM_SOURCE = `${buildOptions.buildLibsFromSource}`;
|
|
19
20
|
process.env.NX_BUILD_TARGET = options.buildTarget;
|
|
20
21
|
const metadata = context.projectsConfigurations.projects[context.projectName];
|
|
21
|
-
const sourceRoot = metadata
|
|
22
|
+
const sourceRoot = (0, ts_solution_setup_1.getProjectSourceRoot)(metadata);
|
|
22
23
|
const normalizedBuildOptions = (0, normalize_options_1.normalizeOptions)(buildOptions, context.root, metadata.root, sourceRoot);
|
|
23
24
|
let devServerConfig = (0, get_dev_server_config_1.getDevServerOptions)(context.root, options, normalizedBuildOptions);
|
|
24
25
|
const compiler = await (0, create_compiler_1.createCompiler)({
|
|
@@ -4,11 +4,12 @@ exports.default = moduleFederationDevServer;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
|
+
const utils_1 = require("@nx/module-federation/src/executors/utils");
|
|
7
9
|
const file_server_impl_1 = tslib_1.__importDefault(require("@nx/web/src/executors/file-server/file-server.impl"));
|
|
8
10
|
const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
|
|
9
11
|
const fs_1 = require("fs");
|
|
10
12
|
const path_1 = require("path");
|
|
11
|
-
const utils_1 = require("@nx/module-federation/src/executors/utils");
|
|
12
13
|
const dev_server_impl_1 = tslib_1.__importDefault(require("../dev-server/dev-server.impl"));
|
|
13
14
|
const lib_1 = require("./lib");
|
|
14
15
|
async function* moduleFederationDevServer(schema, context) {
|
|
@@ -24,8 +25,7 @@ async function* moduleFederationDevServer(schema, context) {
|
|
|
24
25
|
}, context)
|
|
25
26
|
: (0, dev_server_impl_1.default)(options, context);
|
|
26
27
|
const p = context.projectsConfigurations.projects[context.projectName];
|
|
27
|
-
|
|
28
|
-
let pathToManifestFile = (0, path_1.join)(context.root, p.sourceRoot, 'assets/module-federation.manifest.json');
|
|
28
|
+
let pathToManifestFile = (0, path_1.join)(context.root, (0, ts_solution_setup_1.getProjectSourceRoot)(p), 'assets/module-federation.manifest.json');
|
|
29
29
|
if (options.pathToManifestFile) {
|
|
30
30
|
const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
|
|
31
31
|
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js
CHANGED
|
@@ -3,19 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = moduleFederationSsrDevServer;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const utils_1 = require("@nx/module-federation/src/executors/utils");
|
|
8
|
-
const ssr_dev_server_impl_1 = tslib_1.__importDefault(require("../ssr-dev-server/ssr-dev-server.impl"));
|
|
9
6
|
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
10
|
-
const
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
|
+
const utils_1 = require("@nx/module-federation/src/executors/utils");
|
|
11
9
|
const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const ssr_dev_server_impl_1 = tslib_1.__importDefault(require("../ssr-dev-server/ssr-dev-server.impl"));
|
|
12
13
|
const lib_1 = require("./lib");
|
|
13
14
|
async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
|
|
14
15
|
const options = (0, lib_1.normalizeOptions)(ssrDevServerOptions);
|
|
15
16
|
const iter = (0, ssr_dev_server_impl_1.default)(options, context);
|
|
16
17
|
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
17
|
-
|
|
18
|
-
let pathToManifestFile = (0, path_1.join)(context.root, projectConfig.sourceRoot, 'assets/module-federation.manifest.json');
|
|
18
|
+
let pathToManifestFile = (0, path_1.join)(context.root, (0, ts_solution_setup_1.getProjectSourceRoot)(projectConfig), 'assets/module-federation.manifest.json');
|
|
19
19
|
if (options.pathToManifestFile) {
|
|
20
20
|
const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
|
|
21
21
|
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExecutorContext } from 'nx/src/config/misc-interfaces';
|
|
2
1
|
import { StaticRemotesConfig } from '@nx/module-federation/src/utils';
|
|
2
|
+
import { ExecutorContext } from 'nx/src/config/misc-interfaces';
|
|
3
3
|
import { ModuleFederationDevServerOptions } from '../module-federation-dev-server/schema';
|
|
4
4
|
import { ModuleFederationStaticServerSchema } from './schema';
|
|
5
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
|
@@ -5,19 +5,20 @@ exports.default = moduleFederationStaticServer;
|
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
7
|
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
8
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
9
|
+
const utils_1 = require("@nx/module-federation/src/executors/utils");
|
|
10
|
+
const utils_2 = require("@nx/module-federation/src/utils");
|
|
8
11
|
const file_server_impl_1 = tslib_1.__importDefault(require("@nx/web/src/executors/file-server/file-server.impl"));
|
|
9
12
|
const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
|
|
10
13
|
const child_process_1 = require("child_process");
|
|
11
14
|
const fs_1 = require("fs");
|
|
12
15
|
const path_1 = require("path");
|
|
13
|
-
const utils_1 = require("@nx/module-federation/src/utils");
|
|
14
|
-
const utils_2 = require("@nx/module-federation/src/executors/utils");
|
|
15
16
|
function getBuildAndServeOptionsFromServeTarget(serveTarget, context) {
|
|
16
17
|
const target = (0, devkit_1.parseTargetString)(serveTarget, context);
|
|
17
18
|
const serveOptions = (0, devkit_1.readTargetOptions)(target, context);
|
|
18
19
|
const buildTarget = (0, devkit_1.parseTargetString)(serveOptions.buildTarget, context);
|
|
19
20
|
const buildOptions = (0, devkit_1.readTargetOptions)(buildTarget, context);
|
|
20
|
-
let pathToManifestFile = (0, path_1.join)(context.root, context.projectGraph.nodes[context.projectName].data
|
|
21
|
+
let pathToManifestFile = (0, path_1.join)(context.root, (0, ts_solution_setup_1.getProjectSourceRoot)(context.projectGraph.nodes[context.projectName].data), 'assets/module-federation.manifest.json');
|
|
21
22
|
if (serveOptions.pathToManifestFile) {
|
|
22
23
|
const userPathToManifestFile = (0, path_1.join)(context.root, serveOptions.pathToManifestFile);
|
|
23
24
|
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
|
@@ -169,15 +170,15 @@ async function* moduleFederationStaticServer(schema, context) {
|
|
|
169
170
|
// Get the remotes from the module federation config
|
|
170
171
|
const p = context.projectsConfigurations.projects[context.projectName];
|
|
171
172
|
const options = getBuildAndServeOptionsFromServeTarget(schema.serveTarget, context);
|
|
172
|
-
const moduleFederationConfig = (0,
|
|
173
|
-
const remotes = (0,
|
|
173
|
+
const moduleFederationConfig = (0, utils_2.getModuleFederationConfig)(options.buildOptions.tsConfig, context.root, p.root, 'react');
|
|
174
|
+
const remotes = (0, utils_2.getRemotes)([], options.serveOptions.skipRemotes, moduleFederationConfig, {
|
|
174
175
|
projectName: context.projectName,
|
|
175
176
|
projectGraph: context.projectGraph,
|
|
176
177
|
root: context.root,
|
|
177
178
|
}, options.pathToManifestFile);
|
|
178
|
-
const staticRemotesConfig = (0,
|
|
179
|
+
const staticRemotesConfig = (0, utils_2.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
|
|
179
180
|
options.serveOptions.staticRemotesPort ??= remotes.staticRemotePort;
|
|
180
|
-
const mappedLocationsOfStaticRemotes = await (0,
|
|
181
|
+
const mappedLocationsOfStaticRemotes = await (0, utils_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options.serveOptions);
|
|
181
182
|
// Build the host
|
|
182
183
|
const hostUrlSegment = (0, path_1.basename)(options.buildOptions.outputPath);
|
|
183
184
|
const mappedLocationOfHost = `http${options.serveOptions.ssl ? 's' : ''}://${options.serveOptions.host}:${options.serveOptions.staticRemotesPort}/${hostUrlSegment}`;
|
|
@@ -4,16 +4,17 @@ exports.default = runExecutor;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
6
6
|
const js_1 = require("@nx/js");
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
7
8
|
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = require("path");
|
|
8
10
|
const create_compiler_1 = require("../../utils/create-compiler");
|
|
9
11
|
const mode_utils_1 = require("../../utils/mode-utils");
|
|
10
12
|
const normalize_options_1 = require("./lib/normalize-options");
|
|
11
|
-
const path_1 = require("path");
|
|
12
13
|
async function* runExecutor(options, context) {
|
|
13
14
|
process.env.NODE_ENV ??= options.mode ?? 'production';
|
|
14
15
|
options.target ??= 'web';
|
|
15
16
|
const metadata = context.projectsConfigurations.projects[context.projectName];
|
|
16
|
-
const sourceRoot = metadata
|
|
17
|
+
const sourceRoot = (0, ts_solution_setup_1.getProjectSourceRoot)(metadata);
|
|
17
18
|
const normalizedOptions = (0, normalize_options_1.normalizeOptions)(options, context.root, metadata.root, sourceRoot);
|
|
18
19
|
if ((0, mode_utils_1.isMode)(process.env.NODE_ENV)) {
|
|
19
20
|
normalizedOptions.mode = process.env.NODE_ENV;
|
|
@@ -3,18 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformCjsConfigFile = transformCjsConfigFile;
|
|
4
4
|
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
5
5
|
function transformCjsConfigFile(tree, configPath) {
|
|
6
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
7
|
+
const usesJsExtensions = detectJsExtensions(configContents);
|
|
6
8
|
['@nx', '@nrwl'].forEach((scope) => {
|
|
7
9
|
transformComposePlugins(tree, configPath, scope);
|
|
8
10
|
transformWithNx(tree, configPath, scope);
|
|
9
11
|
transformWithWeb(tree, configPath, scope);
|
|
10
12
|
transformWithReact(tree, configPath, scope);
|
|
11
13
|
transformModuleFederationConfig(tree, configPath, scope);
|
|
12
|
-
transformWithModuleFederation(tree, configPath, scope);
|
|
13
|
-
transformWithModuleFederationSSR(tree, configPath, scope);
|
|
14
|
+
transformWithModuleFederation(tree, configPath, scope, usesJsExtensions);
|
|
15
|
+
transformWithModuleFederationSSR(tree, configPath, scope, usesJsExtensions);
|
|
14
16
|
});
|
|
15
17
|
// Add useLegacyHtmlPlugin: true to withWeb() calls
|
|
16
18
|
transformWithWebCalls(tree, configPath);
|
|
17
19
|
}
|
|
20
|
+
function detectJsExtensions(configContents) {
|
|
21
|
+
// Check if any require calls use .js extensions
|
|
22
|
+
const requireWithJsExtensionRegex = /require\s*\(\s*['"]@nx\/[^'"]*\.js['"]\s*\)/;
|
|
23
|
+
return requireWithJsExtensionRegex.test(configContents);
|
|
24
|
+
}
|
|
18
25
|
function transformWithWebCalls(tree, configPath) {
|
|
19
26
|
const configContents = tree.read(configPath, 'utf-8');
|
|
20
27
|
const ast = tsquery_1.tsquery.ast(configContents);
|
|
@@ -204,10 +211,10 @@ function transformModuleFederationConfig(tree, configPath, scope) {
|
|
|
204
211
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
205
212
|
tree.write(configPath, newContents);
|
|
206
213
|
}
|
|
207
|
-
function transformWithModuleFederation(tree, configPath, scope) {
|
|
214
|
+
function transformWithModuleFederation(tree, configPath, scope, usesJsExtensions) {
|
|
208
215
|
const configContents = tree.read(configPath, 'utf-8');
|
|
209
216
|
const ast = tsquery_1.tsquery.ast(configContents);
|
|
210
|
-
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederation]) > CallExpression:has(Identifier[name=require]) StringLiteral[value
|
|
217
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederation]) > CallExpression:has(Identifier[name=require]) StringLiteral[value="${scope}/module-federation/webpack${usesJsExtensions ? '.js' : ''}"]`;
|
|
211
218
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
212
219
|
if (nodes.length === 0) {
|
|
213
220
|
return;
|
|
@@ -222,14 +229,17 @@ function transformWithModuleFederation(tree, configPath, scope) {
|
|
|
222
229
|
if (configContents.charAt(endIndex) === ',') {
|
|
223
230
|
endIndex++;
|
|
224
231
|
}
|
|
225
|
-
const
|
|
232
|
+
const rspackImport = usesJsExtensions
|
|
233
|
+
? '@nx/module-federation/rspack.js'
|
|
234
|
+
: '@nx/module-federation/rspack';
|
|
235
|
+
const newContents = `const { withModuleFederation } = require('${rspackImport}');
|
|
226
236
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
227
237
|
tree.write(configPath, newContents);
|
|
228
238
|
}
|
|
229
|
-
function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
239
|
+
function transformWithModuleFederationSSR(tree, configPath, scope, usesJsExtensions) {
|
|
230
240
|
const configContents = tree.read(configPath, 'utf-8');
|
|
231
241
|
const ast = tsquery_1.tsquery.ast(configContents);
|
|
232
|
-
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) > CallExpression:has(Identifier[name=require]) StringLiteral[value
|
|
242
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) > CallExpression:has(Identifier[name=require]) StringLiteral[value="${scope}/module-federation/webpack${usesJsExtensions ? '.js' : ''}"]`;
|
|
233
243
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
234
244
|
if (nodes.length === 0) {
|
|
235
245
|
return;
|
|
@@ -244,7 +254,10 @@ function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
|
244
254
|
if (configContents.charAt(endIndex) === ',') {
|
|
245
255
|
endIndex++;
|
|
246
256
|
}
|
|
247
|
-
const
|
|
257
|
+
const rspackImport = usesJsExtensions
|
|
258
|
+
? '@nx/module-federation/rspack.js'
|
|
259
|
+
: '@nx/module-federation/rspack';
|
|
260
|
+
const newContents = `const { withModuleFederationForSSR } = require('${rspackImport}');
|
|
248
261
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
249
262
|
tree.write(configPath, newContents);
|
|
250
263
|
}
|
|
@@ -3,18 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformEsmConfigFile = transformEsmConfigFile;
|
|
4
4
|
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
5
5
|
function transformEsmConfigFile(tree, configPath) {
|
|
6
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
7
|
+
const usesJsExtensions = detectJsExtensions(configContents);
|
|
6
8
|
['@nx', '@nrwl'].forEach((scope) => {
|
|
7
9
|
transformComposePlugins(tree, configPath, scope);
|
|
8
10
|
transformWithNx(tree, configPath, scope);
|
|
9
11
|
transformWithWeb(tree, configPath, scope);
|
|
10
12
|
transformWithReact(tree, configPath, scope);
|
|
11
13
|
transformModuleFederationConfig(tree, configPath, scope);
|
|
12
|
-
transformWithModuleFederation(tree, configPath, scope);
|
|
13
|
-
transformWithModuleFederationSSR(tree, configPath, scope);
|
|
14
|
+
transformWithModuleFederation(tree, configPath, scope, usesJsExtensions);
|
|
15
|
+
transformWithModuleFederationSSR(tree, configPath, scope, usesJsExtensions);
|
|
14
16
|
});
|
|
15
17
|
// Add useLegacyHtmlPlugin: true to withWeb() calls
|
|
16
18
|
transformWithWebCalls(tree, configPath);
|
|
17
19
|
}
|
|
20
|
+
function detectJsExtensions(configContents) {
|
|
21
|
+
// Check if any imports use .js extensions
|
|
22
|
+
const importWithJsExtensionRegex = /from\s+['"]@nx\/[^'"]*\.js['"]/;
|
|
23
|
+
return importWithJsExtensionRegex.test(configContents);
|
|
24
|
+
}
|
|
18
25
|
function transformWithWebCalls(tree, configPath) {
|
|
19
26
|
const configContents = tree.read(configPath, 'utf-8');
|
|
20
27
|
const ast = tsquery_1.tsquery.ast(configContents);
|
|
@@ -182,10 +189,10 @@ function transformWithReact(tree, configPath, scope) {
|
|
|
182
189
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
183
190
|
tree.write(configPath, newContents);
|
|
184
191
|
}
|
|
185
|
-
function transformWithModuleFederation(tree, configPath, scope) {
|
|
192
|
+
function transformWithModuleFederation(tree, configPath, scope, usesJsExtension) {
|
|
186
193
|
const configContents = tree.read(configPath, 'utf-8');
|
|
187
194
|
const ast = tsquery_1.tsquery.ast(configContents);
|
|
188
|
-
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederation]) > StringLiteral[value
|
|
195
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederation]) > StringLiteral[value="${scope}/module-federation/webpack${usesJsExtension ? '.js' : ''}"]`;
|
|
189
196
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
190
197
|
if (nodes.length === 0) {
|
|
191
198
|
return;
|
|
@@ -200,7 +207,10 @@ function transformWithModuleFederation(tree, configPath, scope) {
|
|
|
200
207
|
if (configContents.charAt(endIndex) === ',') {
|
|
201
208
|
endIndex++;
|
|
202
209
|
}
|
|
203
|
-
const
|
|
210
|
+
const moduleFederationImport = usesJsExtension
|
|
211
|
+
? '@nx/module-federation/rspack.js'
|
|
212
|
+
: '@nx/module-federation/rspack';
|
|
213
|
+
const newContents = `import { withModuleFederation } from '${moduleFederationImport}';
|
|
204
214
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
205
215
|
tree.write(configPath, newContents);
|
|
206
216
|
}
|
|
@@ -226,10 +236,10 @@ function transformModuleFederationConfig(tree, configPath, scope) {
|
|
|
226
236
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
227
237
|
tree.write(configPath, newContents);
|
|
228
238
|
}
|
|
229
|
-
function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
239
|
+
function transformWithModuleFederationSSR(tree, configPath, scope, usesJsExtensions) {
|
|
230
240
|
const configContents = tree.read(configPath, 'utf-8');
|
|
231
241
|
const ast = tsquery_1.tsquery.ast(configContents);
|
|
232
|
-
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederationForSSR]) > StringLiteral[value
|
|
242
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederationForSSR]) > StringLiteral[value="${scope}/module-federation/webpack${usesJsExtensions ? '.js' : ''}"]`;
|
|
233
243
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
234
244
|
if (nodes.length === 0) {
|
|
235
245
|
return;
|
|
@@ -244,7 +254,10 @@ function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
|
244
254
|
if (configContents.charAt(endIndex) === ',') {
|
|
245
255
|
endIndex++;
|
|
246
256
|
}
|
|
247
|
-
const
|
|
257
|
+
const rspackImport = usesJsExtensions
|
|
258
|
+
? '@nx/module-federation/rspack.js'
|
|
259
|
+
: '@nx/module-federation/rspack';
|
|
260
|
+
const newContents = `import { withModuleFederationForSSR } from '${rspackImport}';
|
|
248
261
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
249
262
|
tree.write(configPath, newContents);
|
|
250
263
|
}
|
|
@@ -76,11 +76,28 @@ function applyNxIndependentConfig(options, config) {
|
|
|
76
76
|
options.sourceMap === true ? 'source-map' : options.sourceMap;
|
|
77
77
|
config.output = {
|
|
78
78
|
...(config.output ?? {}),
|
|
79
|
-
libraryTarget:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
libraryTarget: (() => {
|
|
80
|
+
const existingOutputConfig = config.output;
|
|
81
|
+
const existingLibraryTarget = existingOutputConfig?.libraryTarget;
|
|
82
|
+
const existingLibraryType = typeof existingOutputConfig?.library === 'object' &&
|
|
83
|
+
'type' in existingOutputConfig?.library
|
|
84
|
+
? existingOutputConfig?.library?.type
|
|
85
|
+
: undefined;
|
|
86
|
+
// If user is using modern library.type, don't set the deprecated libraryTarget
|
|
87
|
+
if (existingLibraryType !== undefined) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
// If user has set libraryTarget explicitly, use it
|
|
91
|
+
if (existingLibraryTarget !== undefined) {
|
|
92
|
+
return existingLibraryTarget;
|
|
93
|
+
}
|
|
94
|
+
// Set defaults based on target when user hasn't configured anything
|
|
95
|
+
if (options.target === 'node')
|
|
96
|
+
return 'commonjs';
|
|
97
|
+
if (options.target === 'async-node')
|
|
98
|
+
return 'commonjs-module';
|
|
99
|
+
return undefined;
|
|
100
|
+
})(),
|
|
84
101
|
path: config.output?.path ??
|
|
85
102
|
(options.outputPath
|
|
86
103
|
? // If path is relative, it is relative from project root (aka cwd).
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyWebConfig = applyWebConfig;
|
|
4
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
4
5
|
const core_1 = require("@rspack/core");
|
|
5
|
-
const write_index_html_plugin_1 = require("../write-index-html-plugin");
|
|
6
|
-
const instantiate_script_plugins_1 = require("./instantiate-script-plugins");
|
|
7
6
|
const path_1 = require("path");
|
|
7
|
+
const write_index_html_plugin_1 = require("../write-index-html-plugin");
|
|
8
8
|
const hash_format_1 = require("./hash-format");
|
|
9
|
-
const
|
|
9
|
+
const instantiate_script_plugins_1 = require("./instantiate-script-plugins");
|
|
10
10
|
const stylesheet_loaders_1 = require("./loaders/stylesheet-loaders");
|
|
11
|
+
const normalize_entry_1 = require("./normalize-entry");
|
|
11
12
|
function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
|
|
12
13
|
if (global.NX_GRAPH_CREATION)
|
|
13
14
|
return;
|
|
@@ -17,7 +18,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
|
|
|
17
18
|
options.generateIndexHtml ??= true;
|
|
18
19
|
options.index = options.index
|
|
19
20
|
? (0, path_1.join)(options.root, options.index)
|
|
20
|
-
: (0, path_1.join)(options.root, options.projectGraph.nodes[options.projectName].data
|
|
21
|
+
: (0, path_1.join)(options.root, (0, ts_solution_setup_1.getProjectSourceRoot)(options.projectGraph.nodes[options.projectName].data), 'index.html');
|
|
21
22
|
options.styles ??= [];
|
|
22
23
|
options.scripts ??= [];
|
|
23
24
|
const isProd = process.env.NODE_ENV === 'production' || options.mode === 'production';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AssetGlobPattern, FileReplacement,
|
|
1
|
+
import { AssetGlobPattern, FileReplacement, NormalizedNxAppRspackPluginOptions, NxAppRspackPluginOptions } from '../models';
|
|
2
2
|
export declare function normalizeOptions(options: NxAppRspackPluginOptions): NormalizedNxAppRspackPluginOptions;
|
|
3
3
|
export declare function normalizeAssets(assets: any[], root: string, sourceRoot: string, projectRoot: string, resolveRelativePathsToProjectRoot?: boolean): AssetGlobPattern[];
|
|
4
4
|
export declare function normalizeFileReplacements(root: string, fileReplacements: FileReplacement[]): FileReplacement[];
|
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.normalizeOptions = normalizeOptions;
|
|
4
4
|
exports.normalizeAssets = normalizeAssets;
|
|
5
5
|
exports.normalizeFileReplacements = normalizeFileReplacements;
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = require("path");
|
|
9
10
|
function normalizeOptions(options) {
|
|
10
11
|
const combinedPluginAndMaybeExecutorOptions = {};
|
|
11
12
|
const isProd = process.env.NODE_ENV === 'production';
|
|
@@ -48,7 +49,7 @@ function normalizeOptions(options) {
|
|
|
48
49
|
// executor options take precedence (especially for overriding with CLI args)
|
|
49
50
|
originalTargetOptions);
|
|
50
51
|
}
|
|
51
|
-
const sourceRoot =
|
|
52
|
+
const sourceRoot = (0, ts_solution_setup_1.getProjectSourceRoot)(projectNode.data);
|
|
52
53
|
if (!combinedPluginAndMaybeExecutorOptions.main) {
|
|
53
54
|
throw new Error(`Missing "main" option for the entry file. Set this option in your Nx rspack plugin.`);
|
|
54
55
|
}
|
package/src/utils/config.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.isNxRspackComposablePlugin = isNxRspackComposablePlugin;
|
|
|
5
5
|
exports.composePlugins = composePlugins;
|
|
6
6
|
exports.composePluginsSync = composePluginsSync;
|
|
7
7
|
const devkit_1 = require("@nx/devkit");
|
|
8
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
9
|
const configuration_1 = require("nx/src/config/configuration");
|
|
9
10
|
exports.nxRspackComposablePlugin = 'nxRspackComposablePlugin';
|
|
10
11
|
function isNxRspackComposablePlugin(a) {
|
|
@@ -49,7 +50,7 @@ function ensureNxRspackExecutionContext(ctx) {
|
|
|
49
50
|
ctx.options ??= {
|
|
50
51
|
root: devkit_1.workspaceRoot,
|
|
51
52
|
projectRoot: projectNode.data.root,
|
|
52
|
-
sourceRoot:
|
|
53
|
+
sourceRoot: (0, ts_solution_setup_1.getProjectSourceRoot)(projectNode.data),
|
|
53
54
|
// These aren't actually needed since NxRspackPlugin and withNx both support them being undefined.
|
|
54
55
|
assets: undefined,
|
|
55
56
|
outputFileName: undefined,
|