@nx/module-federation 22.3.0-canary.20251211-205daee → 22.3.0-canary.20251216-71bfc21
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 +5 -5
- package/src/executors/utils/start-remote-iterators.d.ts +1 -1
- package/src/executors/utils/start-remote-iterators.d.ts.map +1 -1
- package/src/executors/utils/start-remote-iterators.js +4 -4
- package/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-dev-server-plugin.d.ts.map +1 -1
- package/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-dev-server-plugin.js +2 -2
- package/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-ssr-dev-server-plugin.d.ts.map +1 -1
- package/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-ssr-dev-server-plugin.js +2 -2
- package/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-dev-server-plugin.d.ts.map +1 -1
- package/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-dev-server-plugin.js +2 -2
- package/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-ssr-dev-server-plugin.d.ts.map +1 -1
- package/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-ssr-dev-server-plugin.js +2 -2
- package/src/plugins/utils/start-remote-proxies.d.ts +1 -1
- package/src/plugins/utils/start-remote-proxies.d.ts.map +1 -1
- package/src/plugins/utils/start-remote-proxies.js +18 -2
- package/src/utils/get-remotes-for-host.d.ts +1 -1
- package/src/utils/get-remotes-for-host.d.ts.map +1 -1
- package/src/utils/get-remotes-for-host.js +26 -16
- package/src/utils/index.d.ts +1 -0
- package/src/utils/index.d.ts.map +1 -1
- package/src/utils/index.js +1 -0
- package/src/utils/module-federation-config.d.ts +58 -0
- package/src/utils/module-federation-config.d.ts.map +1 -0
- package/src/utils/module-federation-config.js +143 -0
- package/src/utils/port-utils.d.ts +6 -0
- package/src/utils/port-utils.d.ts.map +1 -0
- package/src/utils/port-utils.js +17 -0
- package/src/utils/start-remote-proxies.d.ts +1 -1
- package/src/utils/start-remote-proxies.d.ts.map +1 -1
- package/src/utils/start-remote-proxies.js +20 -3
- package/src/utils/start-ssr-remote-proxies.d.ts +1 -1
- package/src/utils/start-ssr-remote-proxies.d.ts.map +1 -1
- package/src/utils/start-ssr-remote-proxies.js +20 -3
- package/src/utils/typescript.js +8 -8
- package/src/with-module-federation/angular/utils.d.ts +18 -16
- package/src/with-module-federation/angular/utils.d.ts.map +1 -1
- package/src/with-module-federation/angular/utils.js +45 -117
- package/src/with-module-federation/rspack/utils.d.ts +5 -7
- package/src/with-module-federation/rspack/utils.d.ts.map +1 -1
- package/src/with-module-federation/rspack/utils.js +22 -64
- package/src/with-module-federation/webpack/utils.d.ts +5 -7
- package/src/with-module-federation/webpack/utils.d.ts.map +1 -1
- package/src/with-module-federation/webpack/utils.js +22 -71
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/module-federation",
|
|
3
3
|
"description": "The Nx Plugin for Module Federation contains executors and utilities that support building applications using Module Federation.",
|
|
4
|
-
"version": "22.3.0-canary.
|
|
4
|
+
"version": "22.3.0-canary.20251216-71bfc21",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@module-federation/enhanced": "^0.21.2",
|
|
28
28
|
"@module-federation/node": "^2.7.21",
|
|
29
29
|
"@module-federation/sdk": "^0.21.2",
|
|
30
|
-
"@nx/devkit": "22.3.0-canary.
|
|
31
|
-
"@nx/js": "22.3.0-canary.
|
|
32
|
-
"@nx/web": "22.3.0-canary.
|
|
30
|
+
"@nx/devkit": "22.3.0-canary.20251216-71bfc21",
|
|
31
|
+
"@nx/js": "22.3.0-canary.20251216-71bfc21",
|
|
32
|
+
"@nx/web": "22.3.0-canary.20251216-71bfc21",
|
|
33
33
|
"@rspack/core": "^1.5.2",
|
|
34
34
|
"express": "^4.21.2",
|
|
35
35
|
"http-proxy-middleware": "^3.0.5",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"webpack": "^5.101.3"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"nx": "22.3.0-canary.
|
|
41
|
+
"nx": "22.3.0-canary.20251216-71bfc21"
|
|
42
42
|
},
|
|
43
43
|
"nx-migrations": {
|
|
44
44
|
"migrations": "./migrations.json"
|
|
@@ -5,7 +5,7 @@ export declare function startRemoteIterators(options: StartRemoteIteratorsOption
|
|
|
5
5
|
staticRemotes: string[];
|
|
6
6
|
devRemotes: any[];
|
|
7
7
|
dynamicRemotes: any[];
|
|
8
|
-
remotePorts:
|
|
8
|
+
remotePorts: number[];
|
|
9
9
|
staticRemotePort: number;
|
|
10
10
|
};
|
|
11
11
|
devRemoteIters: AsyncIterable<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-remote-iterators.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/executors/utils/start-remote-iterators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAgB3E,OAAO,EACL,KAAK,eAAe,EAErB,MAAM,YAAY,CAAC;AAEpB,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,eAAe,EACxB,aAAa,EAAE,aAAa,EAC5B,kBAAkB,EAAE,MAAM,GAAG,SAAS,EACtC,UAAU,GAAE,OAAO,GAAG,SAAmB,EACzC,QAAQ,UAAQ;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"start-remote-iterators.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/executors/utils/start-remote-iterators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAgB3E,OAAO,EACL,KAAK,eAAe,EAErB,MAAM,YAAY,CAAC;AAEpB,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,eAAe,EACxB,aAAa,EAAE,aAAa,EAC5B,kBAAkB,EAAE,MAAM,GAAG,SAAS,EACtC,UAAU,GAAE,OAAO,GAAG,SAAmB,EACzC,QAAQ,UAAQ;;;;;;;;;;;;;;;;;;;;;;GAuGjB"}
|
|
@@ -32,18 +32,18 @@ async function startRemoteIterators(options, context, startRemoteFn, pathToManif
|
|
|
32
32
|
? (0, start_static_remotes_file_server_1.startSsrStaticRemotesFileServer)(staticRemotesConfig, context, options)
|
|
33
33
|
: (0, start_static_remotes_file_server_1.startStaticRemotesFileServer)(staticRemotesConfig, context, options);
|
|
34
34
|
isServer
|
|
35
|
-
? (0, utils_1.startSsrRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
|
|
35
|
+
? await (0, utils_1.startSsrRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
|
|
36
36
|
? {
|
|
37
37
|
pathToCert: options.sslCert,
|
|
38
38
|
pathToKey: options.sslKey,
|
|
39
39
|
}
|
|
40
|
-
: undefined)
|
|
41
|
-
: (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
|
|
40
|
+
: undefined, options.host)
|
|
41
|
+
: await (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
|
|
42
42
|
? {
|
|
43
43
|
pathToCert: options.sslCert,
|
|
44
44
|
pathToKey: options.sslKey,
|
|
45
45
|
}
|
|
46
|
-
: undefined);
|
|
46
|
+
: undefined, options.host);
|
|
47
47
|
return {
|
|
48
48
|
remotes,
|
|
49
49
|
devRemoteIters,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-module-federation-dev-server-plugin.d.ts","sourceRoot":"","sources":["../../../../../../../packages/module-federation/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-dev-server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAER,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAIjE,qBAAa,iCAAkC,YAAW,oBAAoB;IAI1E,OAAO,CAAC,QAAQ;IAHlB,OAAO,CAAC,KAAK,CAAgC;gBAGnC,QAAQ,EAAE;QAChB,MAAM,EAAE,sBAAsB,CAAC;QAC/B,eAAe,CAAC,EAAE,iCAAiC,CAAC;KACrD;IAOH,KAAK,CAAC,QAAQ,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"nx-module-federation-dev-server-plugin.d.ts","sourceRoot":"","sources":["../../../../../../../packages/module-federation/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-dev-server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAER,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAIjE,qBAAa,iCAAkC,YAAW,oBAAoB;IAI1E,OAAO,CAAC,QAAQ;IAHlB,OAAO,CAAC,KAAK,CAAgC;gBAGnC,QAAQ,EAAE;QAChB,MAAM,EAAE,sBAAsB,CAAC;QAC/B,eAAe,CAAC,EAAE,iCAAiC,CAAC;KACrD;IAOH,KAAK,CAAC,QAAQ,EAAE,QAAQ;YAoDV,KAAK;CAyDpB"}
|
package/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-dev-server-plugin.js
CHANGED
|
@@ -27,10 +27,10 @@ class NxModuleFederationDevServerPlugin {
|
|
|
27
27
|
devkit_1.logger.info(`NX Starting module federation dev-server for ${pc.bold(this._options.config.name)} with ${Object.keys(staticRemotesConfig).length} remotes`);
|
|
28
28
|
const mappedLocationOfRemotes = await (0, utils_1.buildStaticRemotes)(staticRemotesConfig, this._options.devServerConfig, this.nxBin);
|
|
29
29
|
(0, utils_1.startStaticRemotesFileServer)(staticRemotesConfig, devkit_1.workspaceRoot, this._options.devServerConfig.staticRemotesPort);
|
|
30
|
-
(0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
30
|
+
await (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
31
31
|
pathToCert: this._options.devServerConfig.sslCert,
|
|
32
32
|
pathToKey: this._options.devServerConfig.sslCert,
|
|
33
|
-
});
|
|
33
|
+
}, false, this._options.devServerConfig.host);
|
|
34
34
|
new core_1.DefinePlugin({
|
|
35
35
|
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
36
36
|
}).apply(compiler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-module-federation-ssr-dev-server-plugin.d.ts","sourceRoot":"","sources":["../../../../../../../packages/module-federation/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-ssr-dev-server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAER,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAKjE,qBAAa,oCACX,YAAW,oBAAoB;IAM7B,OAAO,CAAC,QAAQ;IAJlB,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,KAAK,CAAgC;gBAGnC,QAAQ,EAAE;QAChB,MAAM,EAAE,sBAAsB,CAAC;QAC/B,eAAe,CAAC,EAAE,iCAAiC,CAAC;KACrD;IAOH,KAAK,CAAC,QAAQ,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"nx-module-federation-ssr-dev-server-plugin.d.ts","sourceRoot":"","sources":["../../../../../../../packages/module-federation/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-ssr-dev-server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAER,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAKjE,qBAAa,oCACX,YAAW,oBAAoB;IAM7B,OAAO,CAAC,QAAQ;IAJlB,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,KAAK,CAAgC;gBAGnC,QAAQ,EAAE;QAChB,MAAM,EAAE,sBAAsB,CAAC;QAC/B,eAAe,CAAC,EAAE,iCAAiC,CAAC;KACrD;IAOH,KAAK,CAAC,QAAQ,EAAE,QAAQ;YAsDV,WAAW;YAuCX,KAAK;CAmDpB"}
|
|
@@ -28,10 +28,10 @@ class NxModuleFederationSSRDevServerPlugin {
|
|
|
28
28
|
devkit_1.logger.info(`NX Starting module federation dev-server for ${pc.bold(this._options.config.name)} with ${Object.keys(staticRemotesConfig).length} remotes`);
|
|
29
29
|
const mappedLocationOfRemotes = await (0, utils_1.buildStaticRemotes)(staticRemotesConfig, this._options.devServerConfig, this.nxBin);
|
|
30
30
|
(0, utils_1.startStaticRemotesFileServer)(staticRemotesConfig, devkit_1.workspaceRoot, this._options.devServerConfig.staticRemotesPort);
|
|
31
|
-
(0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
31
|
+
await (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
32
32
|
pathToCert: this._options.devServerConfig.sslCert,
|
|
33
33
|
pathToKey: this._options.devServerConfig.sslCert,
|
|
34
|
-
}, true);
|
|
34
|
+
}, true, this._options.devServerConfig.host);
|
|
35
35
|
new core_1.DefinePlugin({
|
|
36
36
|
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
37
37
|
}).apply(compiler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-module-federation-dev-server-plugin.d.ts","sourceRoot":"","sources":["../../../../../../../packages/module-federation/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-dev-server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAER,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAIjE,qBAAa,iCAAkC,YAAW,oBAAoB;IAI1E,OAAO,CAAC,QAAQ;IAHlB,OAAO,CAAC,KAAK,CAAgC;gBAGnC,QAAQ,EAAE;QAChB,MAAM,EAAE,sBAAsB,CAAC;QAC/B,eAAe,CAAC,EAAE,iCAAiC,CAAC;KACrD;IAOH,KAAK,CAAC,QAAQ,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"nx-module-federation-dev-server-plugin.d.ts","sourceRoot":"","sources":["../../../../../../../packages/module-federation/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-dev-server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAER,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAIjE,qBAAa,iCAAkC,YAAW,oBAAoB;IAI1E,OAAO,CAAC,QAAQ;IAHlB,OAAO,CAAC,KAAK,CAAgC;gBAGnC,QAAQ,EAAE;QAChB,MAAM,EAAE,sBAAsB,CAAC;QAC/B,eAAe,CAAC,EAAE,iCAAiC,CAAC;KACrD;IAOH,KAAK,CAAC,QAAQ,EAAE,QAAQ;YAoDV,KAAK;CAyDpB"}
|
package/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-dev-server-plugin.js
CHANGED
|
@@ -27,10 +27,10 @@ class NxModuleFederationDevServerPlugin {
|
|
|
27
27
|
devkit_1.logger.info(`NX Starting module federation dev-server for ${pc.bold(this._options.config.name)} with ${Object.keys(staticRemotesConfig).length} remotes`);
|
|
28
28
|
const mappedLocationOfRemotes = await (0, utils_1.buildStaticRemotes)(staticRemotesConfig, this._options.devServerConfig, this.nxBin);
|
|
29
29
|
(0, utils_1.startStaticRemotesFileServer)(staticRemotesConfig, devkit_1.workspaceRoot, this._options.devServerConfig.staticRemotesPort);
|
|
30
|
-
(0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
30
|
+
await (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
31
31
|
pathToCert: this._options.devServerConfig.sslCert,
|
|
32
32
|
pathToKey: this._options.devServerConfig.sslCert,
|
|
33
|
-
});
|
|
33
|
+
}, false, this._options.devServerConfig.host);
|
|
34
34
|
new core_1.DefinePlugin({
|
|
35
35
|
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
36
36
|
}).apply(compiler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-module-federation-ssr-dev-server-plugin.d.ts","sourceRoot":"","sources":["../../../../../../../packages/module-federation/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-ssr-dev-server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAER,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAKjE,qBAAa,oCACX,YAAW,oBAAoB;IAM7B,OAAO,CAAC,QAAQ;IAJlB,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,KAAK,CAAgC;gBAGnC,QAAQ,EAAE;QAChB,MAAM,EAAE,sBAAsB,CAAC;QAC/B,eAAe,CAAC,EAAE,iCAAiC,CAAC;KACrD;IAOH,KAAK,CAAC,QAAQ,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"nx-module-federation-ssr-dev-server-plugin.d.ts","sourceRoot":"","sources":["../../../../../../../packages/module-federation/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-ssr-dev-server-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAER,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAKjE,qBAAa,oCACX,YAAW,oBAAoB;IAM7B,OAAO,CAAC,QAAQ;IAJlB,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,KAAK,CAAgC;gBAGnC,QAAQ,EAAE;QAChB,MAAM,EAAE,sBAAsB,CAAC;QAC/B,eAAe,CAAC,EAAE,iCAAiC,CAAC;KACrD;IAOH,KAAK,CAAC,QAAQ,EAAE,QAAQ;YAsDV,WAAW;YAuCX,KAAK;CAmDpB"}
|
package/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-ssr-dev-server-plugin.js
CHANGED
|
@@ -28,10 +28,10 @@ class NxModuleFederationSSRDevServerPlugin {
|
|
|
28
28
|
devkit_1.logger.info(`NX Starting module federation dev-server for ${pc.bold(this._options.config.name)} with ${Object.keys(staticRemotesConfig).length} remotes`);
|
|
29
29
|
const mappedLocationOfRemotes = await (0, utils_1.buildStaticRemotes)(staticRemotesConfig, this._options.devServerConfig, this.nxBin);
|
|
30
30
|
(0, utils_1.startStaticRemotesFileServer)(staticRemotesConfig, devkit_1.workspaceRoot, this._options.devServerConfig.staticRemotesPort);
|
|
31
|
-
(0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
31
|
+
await (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
32
32
|
pathToCert: this._options.devServerConfig.sslCert,
|
|
33
33
|
pathToKey: this._options.devServerConfig.sslCert,
|
|
34
|
-
}, true);
|
|
34
|
+
}, true, this._options.devServerConfig.host);
|
|
35
35
|
new core_1.DefinePlugin({
|
|
36
36
|
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
37
37
|
}).apply(compiler);
|
|
@@ -2,5 +2,5 @@ import { StaticRemoteConfig } from '../../utils';
|
|
|
2
2
|
export declare function startRemoteProxies(staticRemotesConfig: Record<string, StaticRemoteConfig>, mappedLocationsOfRemotes: Record<string, string>, sslOptions?: {
|
|
3
3
|
pathToCert: string;
|
|
4
4
|
pathToKey: string;
|
|
5
|
-
}, isServer?: boolean): void
|
|
5
|
+
}, isServer?: boolean, host?: string): Promise<void>;
|
|
6
6
|
//# sourceMappingURL=start-remote-proxies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-remote-proxies.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/plugins/utils/start-remote-proxies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"start-remote-proxies.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/plugins/utils/start-remote-proxies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAe,MAAM,aAAa,CAAC;AAI9D,wBAAsB,kBAAkB,CACtC,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,EACvD,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChD,UAAU,CAAC,EAAE;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,EACD,QAAQ,CAAC,EAAE,OAAO,EAClB,IAAI,GAAE,MAAoB,iBAwE3B"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.startRemoteProxies = startRemoteProxies;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
|
-
function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOptions, isServer) {
|
|
6
|
+
async function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOptions, isServer, host = '127.0.0.1') {
|
|
6
7
|
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
7
8
|
const express = require('express');
|
|
8
9
|
let sslCert;
|
|
@@ -21,8 +22,17 @@ function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOp
|
|
|
21
22
|
const https = require('https');
|
|
22
23
|
const remotes = Object.keys(staticRemotesConfig);
|
|
23
24
|
console.log(`NX Starting static remotes proxies...`);
|
|
25
|
+
let startedProxies = 0;
|
|
26
|
+
let skippedProxies = 0;
|
|
24
27
|
for (const app of remotes) {
|
|
25
28
|
const appConfig = staticRemotesConfig[app];
|
|
29
|
+
// Check if the port is already in use (another MF dev server may have already started a proxy)
|
|
30
|
+
const portInUse = await (0, utils_1.isPortInUse)(appConfig.port, host);
|
|
31
|
+
if (portInUse) {
|
|
32
|
+
console.log(`NX Skipping proxy for ${app} on port ${appConfig.port} - port already in use (likely served by another process)`);
|
|
33
|
+
skippedProxies++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
26
36
|
const expressProxy = express();
|
|
27
37
|
expressProxy.use(createProxyMiddleware({
|
|
28
38
|
target: mappedLocationsOfRemotes[app],
|
|
@@ -44,6 +54,12 @@ function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOp
|
|
|
44
54
|
.listen(appConfig.port);
|
|
45
55
|
process.on('SIGTERM', () => proxyServer.close());
|
|
46
56
|
process.on('exit', () => proxyServer.close());
|
|
57
|
+
startedProxies++;
|
|
58
|
+
}
|
|
59
|
+
if (skippedProxies > 0) {
|
|
60
|
+
console.info(`NX Static remotes proxies: started ${startedProxies}, skipped ${skippedProxies} (already running)`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.info(`NX Static remotes proxies started successfully`);
|
|
47
64
|
}
|
|
48
|
-
console.info(`NX Static remotes proxies started successfully`);
|
|
49
65
|
}
|
|
@@ -10,7 +10,7 @@ export declare function getRemotes(devRemotes: string[], skipRemotes: string[],
|
|
|
10
10
|
staticRemotes: string[];
|
|
11
11
|
devRemotes: any[];
|
|
12
12
|
dynamicRemotes: any[];
|
|
13
|
-
remotePorts:
|
|
13
|
+
remotePorts: number[];
|
|
14
14
|
staticRemotePort: number;
|
|
15
15
|
};
|
|
16
16
|
export declare function getModuleFederationConfig(tsconfigPath: string | undefined, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-remotes-for-host.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/get-remotes-for-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,YAAY,EAElB,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,UAAU,+BAA+B;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd;
|
|
1
|
+
{"version":3,"file":"get-remotes-for-host.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/get-remotes-for-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,YAAY,EAElB,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,UAAU,+BAA+B;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd;AAsCD,wBAAgB,iCAAiC,CAC/C,aAAa,EAAE,oBAAoB,EACnC,YAAY,EAAE,YAAY,UA0B3B;AAoCD,wBAAgB,UAAU,CACxB,UAAU,EAAE,MAAM,EAAE,EACpB,WAAW,EAAE,MAAM,EAAE,EACrB,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,+BAA+B,EACxC,kBAAkB,CAAC,EAAE,MAAM;;;;;;EA0F5B;AAED,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,UAAU,GAAE,OAAO,GAAG,SAAmB,OAkD1C"}
|
|
@@ -24,8 +24,10 @@ function extractRemoteProjectsFromConfig(config, pathToManifestFile) {
|
|
|
24
24
|
* But users might have their own, enforce only that the key is the remote name
|
|
25
25
|
*/
|
|
26
26
|
const parsedManifest = JSON.parse(moduleFederationManifestJson);
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
// Get keys once instead of calling Object.keys twice
|
|
28
|
+
const manifestKeys = Object.keys(parsedManifest);
|
|
29
|
+
if (manifestKeys.every((key) => typeof key === 'string')) {
|
|
30
|
+
dynamicRemotes.push(...manifestKeys);
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -77,30 +79,38 @@ function getRemotes(devRemotes, skipRemotes, config, context, pathToManifestFile
|
|
|
77
79
|
// With dynamic remotes, the manifest file may contain the names with `_` due to MF limitations on naming
|
|
78
80
|
// The project graph might contain these names with `-` rather than `_`. Check for both.
|
|
79
81
|
// This can occur after migration of existing remotes past Nx 19.8
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return r;
|
|
82
|
+
const normalizedDynamicRemotes = dynamicRemotes.map((r) => {
|
|
83
|
+
// Compute replacement once instead of twice
|
|
84
|
+
const normalizedName = r.replace(/_/g, '-');
|
|
85
|
+
return context.projectGraph.nodes[normalizedName] ? normalizedName : r;
|
|
85
86
|
});
|
|
86
87
|
const knownDynamicRemotes = normalizedDynamicRemotes.filter((r) => !remotesToSkip.has(r) && context.projectGraph.nodes[r]);
|
|
87
88
|
devkit_1.logger.info(`NX Starting module federation dev-server for ${pc.bold(context.projectName)} with ${[...knownRemotes, ...knownDynamicRemotes].length} remotes`);
|
|
89
|
+
// Normalize devRemotes to array and call findMatchingProjects once
|
|
88
90
|
const devServeApps = new Set(!devRemotes
|
|
89
91
|
? []
|
|
90
|
-
: Array.isArray(devRemotes)
|
|
91
|
-
? (0, find_matching_projects_1.findMatchingProjects)(devRemotes, context.projectGraph.nodes)
|
|
92
|
-
: (0, find_matching_projects_1.findMatchingProjects)([devRemotes], context.projectGraph.nodes));
|
|
92
|
+
: (0, find_matching_projects_1.findMatchingProjects)(Array.isArray(devRemotes) ? devRemotes : [devRemotes], context.projectGraph.nodes));
|
|
93
93
|
const staticRemotes = knownRemotes.filter((r) => !devServeApps.has(r));
|
|
94
94
|
const devServeRemotes = [...knownRemotes, ...knownDynamicRemotes].filter((r) => devServeApps.has(r));
|
|
95
95
|
const staticDynamicRemotes = knownDynamicRemotes.filter((r) => !devServeApps.has(r));
|
|
96
|
-
|
|
96
|
+
// Helper to get port from remote project
|
|
97
|
+
const getRemotePort = (r) => context.projectGraph.nodes[r].data.targets['serve'].options.port;
|
|
98
|
+
// Collect ports for dev-served remotes (used in return value)
|
|
99
|
+
const remotePorts = [...devServeRemotes, ...staticDynamicRemotes].map(getRemotePort);
|
|
100
|
+
// Calculate max port in a single pass instead of creating intermediate arrays
|
|
101
|
+
let maxPort = -Infinity;
|
|
102
|
+
for (const port of remotePorts) {
|
|
103
|
+
if (port > maxPort)
|
|
104
|
+
maxPort = port;
|
|
105
|
+
}
|
|
106
|
+
for (const r of staticRemotes) {
|
|
107
|
+
const port = getRemotePort(r);
|
|
108
|
+
if (port > maxPort)
|
|
109
|
+
maxPort = port;
|
|
110
|
+
}
|
|
97
111
|
const staticRemotePort = staticRemotes.length === 0 && remotePorts.length === 0
|
|
98
112
|
? undefined
|
|
99
|
-
:
|
|
100
|
-
...remotePorts,
|
|
101
|
-
...staticRemotes.map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port),
|
|
102
|
-
]) +
|
|
103
|
-
(remotesToSkip.size + 1);
|
|
113
|
+
: maxPort + (remotesToSkip.size + 1);
|
|
104
114
|
return {
|
|
105
115
|
staticRemotes,
|
|
106
116
|
devRemotes: devServeRemotes,
|
package/src/utils/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './models';
|
|
|
6
6
|
export * from './normalize-project-name';
|
|
7
7
|
export * from './get-remotes-for-host';
|
|
8
8
|
export * from './parse-static-remotes-config';
|
|
9
|
+
export * from './port-utils';
|
|
9
10
|
export * from './start-remote-proxies';
|
|
10
11
|
export * from './start-ssr-remote-proxies';
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/src/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
|
package/src/utils/index.js
CHANGED
|
@@ -9,5 +9,6 @@ tslib_1.__exportStar(require("./models"), exports);
|
|
|
9
9
|
tslib_1.__exportStar(require("./normalize-project-name"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./get-remotes-for-host"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./parse-static-remotes-config"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./port-utils"), exports);
|
|
12
13
|
tslib_1.__exportStar(require("./start-remote-proxies"), exports);
|
|
13
14
|
tslib_1.__exportStar(require("./start-ssr-remote-proxies"), exports);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ProjectGraph } from '@nx/devkit';
|
|
2
|
+
import { ModuleFederationConfig, SharedLibraryConfig, shareWorkspaceLibraries } from './index';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for module federation config generation.
|
|
5
|
+
*/
|
|
6
|
+
export interface ModuleFederationConfigOptions {
|
|
7
|
+
/** Whether this is for server-side rendering */
|
|
8
|
+
isServer?: boolean;
|
|
9
|
+
/** Custom function to determine remote URLs */
|
|
10
|
+
determineRemoteUrl?: (remote: string) => string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Framework-specific configuration for module federation.
|
|
14
|
+
*/
|
|
15
|
+
export interface FrameworkConfig {
|
|
16
|
+
/** Bundler type affects shared library config */
|
|
17
|
+
bundler: 'webpack' | 'rspack';
|
|
18
|
+
/** Remote entry file extension */
|
|
19
|
+
remoteEntryExt: 'js' | 'mjs';
|
|
20
|
+
/** Whether to pass true as 4th param to mapRemotes */
|
|
21
|
+
mapRemotesExpose?: boolean;
|
|
22
|
+
/** Function to apply eager packages for this framework */
|
|
23
|
+
applyEagerPackages?: (sharedConfig: Record<string, SharedLibraryConfig>, projectGraph: ProjectGraph, projectName: string) => void;
|
|
24
|
+
/** Default npm packages to always share */
|
|
25
|
+
defaultPackagesToShare?: string[];
|
|
26
|
+
/** npm packages to exclude from sharing */
|
|
27
|
+
packagesToAvoid?: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Result of getModuleFederationConfig
|
|
31
|
+
*/
|
|
32
|
+
export interface ModuleFederationConfigResult {
|
|
33
|
+
sharedLibraries: ReturnType<typeof shareWorkspaceLibraries>;
|
|
34
|
+
sharedDependencies: Record<string, SharedLibraryConfig>;
|
|
35
|
+
mappedRemotes: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a default remote URL resolver function.
|
|
39
|
+
* This is extracted to avoid code duplication across bundler utils.
|
|
40
|
+
*/
|
|
41
|
+
declare function createDefaultRemoteUrlResolver(isServer?: boolean, remoteEntryExt?: 'js' | 'mjs'): (remote: string) => string;
|
|
42
|
+
/**
|
|
43
|
+
* Async version - tries cached graph first, falls back to creating new one.
|
|
44
|
+
* Used by webpack and angular async configs.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getModuleFederationConfigAsync(mfConfig: ModuleFederationConfig, options: ModuleFederationConfigOptions, frameworkConfig: FrameworkConfig): Promise<ModuleFederationConfigResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Sync version - only uses cached graph.
|
|
49
|
+
* Used by rspack and angular sync configs.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getModuleFederationConfigSync(mfConfig: ModuleFederationConfig, options: ModuleFederationConfigOptions, frameworkConfig: FrameworkConfig): ModuleFederationConfigResult;
|
|
52
|
+
/**
|
|
53
|
+
* Clears the static remotes env cache.
|
|
54
|
+
* Useful for testing or when the env variable changes.
|
|
55
|
+
*/
|
|
56
|
+
export declare function clearStaticRemotesEnvCache(): void;
|
|
57
|
+
export { createDefaultRemoteUrlResolver };
|
|
58
|
+
//# sourceMappingURL=module-federation-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-federation-config.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/module-federation-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAEb,MAAM,YAAY,CAAC;AACpB,OAAO,EAML,sBAAsB,EACtB,mBAAmB,EAEnB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,gDAAgD;IAChD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+CAA+C;IAC/C,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,OAAO,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC9B,kCAAkC;IAClC,cAAc,EAAE,IAAI,GAAG,KAAK,CAAC;IAC7B,sDAAsD;IACtD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,0DAA0D;IAC1D,kBAAkB,CAAC,EAAE,CACnB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACjD,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,MAAM,KAChB,IAAI,CAAC;IACV,2CAA2C;IAC3C,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,2CAA2C;IAC3C,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,eAAe,EAAE,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC;IAC5D,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACxD,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAmID;;;GAGG;AACH,iBAAS,8BAA8B,CACrC,QAAQ,GAAE,OAAe,EACzB,cAAc,GAAE,IAAI,GAAG,KAAY,GAClC,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAwC5B;AAED;;;GAGG;AACH,wBAAsB,8BAA8B,CAClD,QAAQ,EAAE,sBAAsB,EAChC,OAAO,EAAE,6BAAkC,EAC3C,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,4BAA4B,CAAC,CAcvC;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,sBAAsB,EAChC,OAAO,EAAE,6BAAkC,EAC3C,eAAe,EAAE,eAAe,GAC/B,4BAA4B,CAQ9B;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,IAAI,CAGjD;AAGD,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getModuleFederationConfigAsync = getModuleFederationConfigAsync;
|
|
4
|
+
exports.getModuleFederationConfigSync = getModuleFederationConfigSync;
|
|
5
|
+
exports.clearStaticRemotesEnvCache = clearStaticRemotesEnvCache;
|
|
6
|
+
exports.createDefaultRemoteUrlResolver = createDefaultRemoteUrlResolver;
|
|
7
|
+
const devkit_1 = require("@nx/devkit");
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
/**
|
|
10
|
+
* Core implementation for generating module federation configuration.
|
|
11
|
+
* This is used by webpack, rspack, and angular utils.
|
|
12
|
+
*
|
|
13
|
+
* @param mfConfig - Module federation configuration
|
|
14
|
+
* @param options - Configuration options
|
|
15
|
+
* @param frameworkConfig - Framework-specific configuration
|
|
16
|
+
* @param projectGraph - The Nx project graph
|
|
17
|
+
*/
|
|
18
|
+
function buildModuleFederationConfig(mfConfig, options, frameworkConfig, projectGraph) {
|
|
19
|
+
const { bundler, remoteEntryExt, mapRemotesExpose, applyEagerPackages, defaultPackagesToShare = [], packagesToAvoid = [], } = frameworkConfig;
|
|
20
|
+
const project = projectGraph.nodes[mfConfig.name]?.data;
|
|
21
|
+
if (!project) {
|
|
22
|
+
throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
|
|
23
|
+
}
|
|
24
|
+
const dependencies = (0, index_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
|
|
25
|
+
// Filter dependencies if shared function provided
|
|
26
|
+
if (mfConfig.shared) {
|
|
27
|
+
dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
|
|
28
|
+
dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
|
|
29
|
+
}
|
|
30
|
+
const sharedLibraries = (0, index_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries, undefined, bundler);
|
|
31
|
+
// Build npm packages list with framework-specific defaults
|
|
32
|
+
let npmPackagesList = dependencies.npmPackages;
|
|
33
|
+
if (defaultPackagesToShare.length > 0 || packagesToAvoid.length > 0) {
|
|
34
|
+
npmPackagesList = Array.from(new Set([
|
|
35
|
+
...defaultPackagesToShare,
|
|
36
|
+
...dependencies.npmPackages.filter((pkg) => !packagesToAvoid.includes(pkg)),
|
|
37
|
+
]));
|
|
38
|
+
}
|
|
39
|
+
const npmPackages = (0, index_1.sharePackages)(npmPackagesList);
|
|
40
|
+
// Remove packages to avoid from final config
|
|
41
|
+
for (const pkgName of packagesToAvoid) {
|
|
42
|
+
if (pkgName in npmPackages) {
|
|
43
|
+
delete npmPackages[pkgName];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const sharedDependencies = {
|
|
47
|
+
...sharedLibraries.getLibraries(project.root),
|
|
48
|
+
...npmPackages,
|
|
49
|
+
};
|
|
50
|
+
// Apply framework-specific eager packages
|
|
51
|
+
if (applyEagerPackages) {
|
|
52
|
+
applyEagerPackages(sharedDependencies, projectGraph, mfConfig.name);
|
|
53
|
+
}
|
|
54
|
+
(0, index_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
|
|
55
|
+
(0, index_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
|
|
56
|
+
// Map remotes
|
|
57
|
+
const mapRemotesFunction = options.isServer ? index_1.mapRemotesForSSR : index_1.mapRemotes;
|
|
58
|
+
let mappedRemotes = {};
|
|
59
|
+
if (mfConfig.remotes && mfConfig.remotes.length > 0) {
|
|
60
|
+
const determineRemoteUrlFn = options.determineRemoteUrl ||
|
|
61
|
+
createDefaultRemoteUrlResolver(options.isServer, remoteEntryExt);
|
|
62
|
+
mappedRemotes = mapRemotesFunction(mfConfig.remotes, remoteEntryExt, determineRemoteUrlFn, mapRemotesExpose);
|
|
63
|
+
}
|
|
64
|
+
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
|
65
|
+
}
|
|
66
|
+
// Cache for parsed static remotes env variable
|
|
67
|
+
let cachedStaticRemotesEnv = undefined;
|
|
68
|
+
let cachedStaticRemotesMap = undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Gets static remotes from env with caching.
|
|
71
|
+
* Invalidates cache if env variable changes.
|
|
72
|
+
*/
|
|
73
|
+
function getStaticRemotesFromEnv() {
|
|
74
|
+
const currentEnv = process.env.NX_MF_DEV_SERVER_STATIC_REMOTES;
|
|
75
|
+
if (currentEnv !== cachedStaticRemotesEnv) {
|
|
76
|
+
cachedStaticRemotesEnv = currentEnv;
|
|
77
|
+
cachedStaticRemotesMap = currentEnv ? JSON.parse(currentEnv) : undefined;
|
|
78
|
+
}
|
|
79
|
+
return cachedStaticRemotesMap;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Creates a default remote URL resolver function.
|
|
83
|
+
* This is extracted to avoid code duplication across bundler utils.
|
|
84
|
+
*/
|
|
85
|
+
function createDefaultRemoteUrlResolver(isServer = false, remoteEntryExt = 'js') {
|
|
86
|
+
const { readCachedProjectConfiguration, } = require('nx/src/project-graph/project-graph');
|
|
87
|
+
const target = 'serve';
|
|
88
|
+
const remoteEntry = isServer
|
|
89
|
+
? 'server/remoteEntry.js'
|
|
90
|
+
: `remoteEntry.${remoteEntryExt}`;
|
|
91
|
+
return function (remote) {
|
|
92
|
+
const mappedStaticRemotesFromEnv = getStaticRemotesFromEnv();
|
|
93
|
+
if (mappedStaticRemotesFromEnv && mappedStaticRemotesFromEnv[remote]) {
|
|
94
|
+
return `${mappedStaticRemotesFromEnv[remote]}/${remoteEntry}`;
|
|
95
|
+
}
|
|
96
|
+
let remoteConfiguration = null;
|
|
97
|
+
try {
|
|
98
|
+
remoteConfiguration = readCachedProjectConfiguration(remote);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
throw new Error(`Cannot find remote "${remote}". Check that the remote name is correct in your module federation config file.\n`);
|
|
102
|
+
}
|
|
103
|
+
const serveTarget = remoteConfiguration?.targets?.[target];
|
|
104
|
+
if (!serveTarget) {
|
|
105
|
+
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "serve" target.\n` +
|
|
106
|
+
`You can also use the tuple syntax in your config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
107
|
+
}
|
|
108
|
+
const host = serveTarget.options?.host ??
|
|
109
|
+
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
|
110
|
+
const port = serveTarget.options?.port ?? 4201;
|
|
111
|
+
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Async version - tries cached graph first, falls back to creating new one.
|
|
116
|
+
* Used by webpack and angular async configs.
|
|
117
|
+
*/
|
|
118
|
+
async function getModuleFederationConfigAsync(mfConfig, options = {}, frameworkConfig) {
|
|
119
|
+
let projectGraph;
|
|
120
|
+
try {
|
|
121
|
+
projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
125
|
+
}
|
|
126
|
+
return buildModuleFederationConfig(mfConfig, options, frameworkConfig, projectGraph);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Sync version - only uses cached graph.
|
|
130
|
+
* Used by rspack and angular sync configs.
|
|
131
|
+
*/
|
|
132
|
+
function getModuleFederationConfigSync(mfConfig, options = {}, frameworkConfig) {
|
|
133
|
+
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
134
|
+
return buildModuleFederationConfig(mfConfig, options, frameworkConfig, projectGraph);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Clears the static remotes env cache.
|
|
138
|
+
* Useful for testing or when the env variable changes.
|
|
139
|
+
*/
|
|
140
|
+
function clearStaticRemotesEnvCache() {
|
|
141
|
+
cachedStaticRemotesEnv = undefined;
|
|
142
|
+
cachedStaticRemotesMap = undefined;
|
|
143
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a port is already in use by attempting to connect to it.
|
|
3
|
+
* Uses waitForPortOpen with retries: 0 for an immediate check.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isPortInUse(port: number, host?: string): Promise<boolean>;
|
|
6
|
+
//# sourceMappingURL=port-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/port-utils.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,MAAoB,GACzB,OAAO,CAAC,OAAO,CAAC,CAOlB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPortInUse = isPortInUse;
|
|
4
|
+
const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
|
|
5
|
+
/**
|
|
6
|
+
* Check if a port is already in use by attempting to connect to it.
|
|
7
|
+
* Uses waitForPortOpen with retries: 0 for an immediate check.
|
|
8
|
+
*/
|
|
9
|
+
async function isPortInUse(port, host = '127.0.0.1') {
|
|
10
|
+
try {
|
|
11
|
+
await (0, wait_for_port_open_1.waitForPortOpen)(port, { retries: 0, host });
|
|
12
|
+
return true; // Port is open/in use
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false; // Port is not in use
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -2,5 +2,5 @@ import { StaticRemotesConfig } from './parse-static-remotes-config';
|
|
|
2
2
|
export declare function startRemoteProxies(staticRemotesConfig: StaticRemotesConfig, mappedLocationsOfRemotes: Record<string, string>, sslOptions?: {
|
|
3
3
|
pathToCert: string;
|
|
4
4
|
pathToKey: string;
|
|
5
|
-
}): void
|
|
5
|
+
}, host?: string): Promise<void>;
|
|
6
6
|
//# sourceMappingURL=start-remote-proxies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-remote-proxies.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/start-remote-proxies.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"start-remote-proxies.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/start-remote-proxies.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAIpE,wBAAsB,kBAAkB,CACtC,mBAAmB,EAAE,mBAAmB,EACxC,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChD,UAAU,CAAC,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EACtD,IAAI,GAAE,MAAoB,iBA8D3B"}
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.startRemoteProxies = startRemoteProxies;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
|
-
|
|
6
|
+
const port_utils_1 = require("./port-utils");
|
|
7
|
+
async function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOptions, host = '127.0.0.1') {
|
|
7
8
|
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
8
9
|
const express = require('express');
|
|
9
10
|
let sslCert;
|
|
@@ -21,7 +22,17 @@ function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOp
|
|
|
21
22
|
const http = require('http');
|
|
22
23
|
const https = require('https');
|
|
23
24
|
devkit_1.logger.info(`NX Starting static remotes proxies...`);
|
|
25
|
+
let startedProxies = 0;
|
|
26
|
+
let skippedProxies = 0;
|
|
24
27
|
for (const app of staticRemotesConfig.remotes) {
|
|
28
|
+
const port = staticRemotesConfig.config[app].port;
|
|
29
|
+
// Check if the port is already in use (another MF dev server may have already started a proxy)
|
|
30
|
+
const portInUse = await (0, port_utils_1.isPortInUse)(port, host);
|
|
31
|
+
if (portInUse) {
|
|
32
|
+
devkit_1.logger.info(`NX Skipping proxy for ${app} on port ${port} - port already in use (likely served by another process)`);
|
|
33
|
+
skippedProxies++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
25
36
|
const expressProxy = express();
|
|
26
37
|
expressProxy.use(createProxyMiddleware({
|
|
27
38
|
target: mappedLocationsOfRemotes[app],
|
|
@@ -30,9 +41,15 @@ function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOp
|
|
|
30
41
|
}));
|
|
31
42
|
const proxyServer = (sslCert ? https : http)
|
|
32
43
|
.createServer({ cert: sslCert, key: sslKey }, expressProxy)
|
|
33
|
-
.listen(
|
|
44
|
+
.listen(port);
|
|
34
45
|
process.on('SIGTERM', () => proxyServer.close());
|
|
35
46
|
process.on('exit', () => proxyServer.close());
|
|
47
|
+
startedProxies++;
|
|
48
|
+
}
|
|
49
|
+
if (skippedProxies > 0) {
|
|
50
|
+
devkit_1.logger.info(`NX Static remotes proxies: started ${startedProxies}, skipped ${skippedProxies} (already running)`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
devkit_1.logger.info(`NX Static remotes proxies started successfully`);
|
|
36
54
|
}
|
|
37
|
-
devkit_1.logger.info(`NX Static remotes proxies started successfully`);
|
|
38
55
|
}
|
|
@@ -2,5 +2,5 @@ import type { StaticRemotesConfig } from './parse-static-remotes-config';
|
|
|
2
2
|
export declare function startSsrRemoteProxies(staticRemotesConfig: StaticRemotesConfig, mappedLocationsOfRemotes: Record<string, string>, sslOptions?: {
|
|
3
3
|
pathToCert: string;
|
|
4
4
|
pathToKey: string;
|
|
5
|
-
}): void
|
|
5
|
+
}, host?: string): Promise<void>;
|
|
6
6
|
//# sourceMappingURL=start-ssr-remote-proxies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-ssr-remote-proxies.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/start-ssr-remote-proxies.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"start-ssr-remote-proxies.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/start-ssr-remote-proxies.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAIzE,wBAAsB,qBAAqB,CACzC,mBAAmB,EAAE,mBAAmB,EACxC,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChD,UAAU,CAAC,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EACtD,IAAI,GAAE,MAAoB,iBA+E3B"}
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.startSsrRemoteProxies = startSsrRemoteProxies;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
|
-
|
|
6
|
+
const port_utils_1 = require("./port-utils");
|
|
7
|
+
async function startSsrRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOptions, host = '127.0.0.1') {
|
|
7
8
|
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
8
9
|
const express = require('express');
|
|
9
10
|
let sslCert;
|
|
@@ -21,7 +22,17 @@ function startSsrRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, ss
|
|
|
21
22
|
const http = require('http');
|
|
22
23
|
const https = require('https');
|
|
23
24
|
devkit_1.logger.info(`NX Starting static remotes proxies...`);
|
|
25
|
+
let startedProxies = 0;
|
|
26
|
+
let skippedProxies = 0;
|
|
24
27
|
for (const app of staticRemotesConfig.remotes) {
|
|
28
|
+
const port = staticRemotesConfig.config[app].port;
|
|
29
|
+
// Check if the port is already in use (another MF dev server may have already started a proxy)
|
|
30
|
+
const portInUse = await (0, port_utils_1.isPortInUse)(port, host);
|
|
31
|
+
if (portInUse) {
|
|
32
|
+
devkit_1.logger.info(`NX Skipping proxy for ${app} on port ${port} - port already in use (likely served by another process)`);
|
|
33
|
+
skippedProxies++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
25
36
|
const expressProxy = express();
|
|
26
37
|
/**
|
|
27
38
|
* SSR remotes have two output paths: one for the browser and one for the server.
|
|
@@ -44,9 +55,15 @@ function startSsrRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, ss
|
|
|
44
55
|
}));
|
|
45
56
|
const proxyServer = (sslCert ? https : http)
|
|
46
57
|
.createServer({ cert: sslCert, key: sslKey }, expressProxy)
|
|
47
|
-
.listen(
|
|
58
|
+
.listen(port);
|
|
48
59
|
process.on('SIGTERM', () => proxyServer.close());
|
|
49
60
|
process.on('exit', () => proxyServer.close());
|
|
61
|
+
startedProxies++;
|
|
62
|
+
}
|
|
63
|
+
if (skippedProxies > 0) {
|
|
64
|
+
devkit_1.logger.info(`NX SSR Static remotes proxies: started ${startedProxies}, skipped ${skippedProxies} (already running)`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
devkit_1.logger.info(`Nx SSR Static remotes proxies started successfully`);
|
|
50
68
|
}
|
|
51
|
-
devkit_1.logger.info(`Nx SSR Static remotes proxies started successfully`);
|
|
52
69
|
}
|
package/src/utils/typescript.js
CHANGED
|
@@ -15,14 +15,14 @@ function readTsPathMappings(tsConfigPath = process.env.NX_TSCONFIG_PATH ?? getRo
|
|
|
15
15
|
if (!tsConfig.has(tsConfigPath)) {
|
|
16
16
|
tsConfig.set(tsConfigPath, readTsConfiguration(tsConfigPath));
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return
|
|
18
|
+
// Build the processed paths object in a single pass instead of
|
|
19
|
+
// spreading on each iteration, which was O(n²) for n path aliases
|
|
20
|
+
const processedPaths = {};
|
|
21
|
+
for (const [alias, aliasPaths] of Object.entries(tsConfig.get(tsConfigPath).options?.paths ?? {})) {
|
|
22
|
+
processedPaths[alias] = aliasPaths.map((path) => path.replace(/^\.\//, ''));
|
|
23
|
+
}
|
|
24
|
+
tsPathMappings.set(tsConfigPath, processedPaths);
|
|
25
|
+
return processedPaths;
|
|
26
26
|
}
|
|
27
27
|
function readTsConfiguration(tsConfigPath) {
|
|
28
28
|
if (!(0, fs_1.existsSync)(tsConfigPath)) {
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { ModuleFederationConfig, SharedLibraryConfig } from '../../utils';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Default npm packages to always share for Angular projects.
|
|
4
|
+
*/
|
|
4
5
|
export declare const DEFAULT_ANGULAR_PACKAGES_TO_SHARE: string[];
|
|
6
|
+
/**
|
|
7
|
+
* npm packages to avoid sharing in Angular projects.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_NPM_PACKAGES_TO_AVOID: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Applies eager loading to default Angular packages.
|
|
12
|
+
* Exported for backward compatibility.
|
|
13
|
+
*/
|
|
14
|
+
export declare function applyDefaultEagerPackages(sharedConfig: Record<string, SharedLibraryConfig>, useRspack?: boolean): void;
|
|
15
|
+
/**
|
|
16
|
+
* Creates the default remote URL resolver for Angular.
|
|
17
|
+
* Kept for backward compatibility with existing configs.
|
|
18
|
+
*/
|
|
5
19
|
export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean, useRspack?: boolean): (remote: string) => string;
|
|
6
20
|
export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
|
|
7
21
|
isServer: boolean;
|
|
8
22
|
determineRemoteUrl?: (remote: string) => string;
|
|
9
|
-
}, bundler?: 'rspack' | 'webpack'): Promise<
|
|
10
|
-
sharedLibraries: import("../../utils").SharedWorkspaceLibraryConfig;
|
|
11
|
-
sharedDependencies: {
|
|
12
|
-
[x: string]: SharedLibraryConfig;
|
|
13
|
-
};
|
|
14
|
-
mappedRemotes: Record<string, string>;
|
|
15
|
-
}>;
|
|
23
|
+
}, bundler?: 'rspack' | 'webpack'): Promise<import("../../utils/module-federation-config").ModuleFederationConfigResult>;
|
|
16
24
|
export declare function getModuleFederationConfigSync(mfConfig: ModuleFederationConfig, options?: {
|
|
17
25
|
isServer: boolean;
|
|
18
26
|
determineRemoteUrl?: (remote: string) => string;
|
|
19
|
-
}, useRspack?: boolean):
|
|
20
|
-
sharedLibraries: import("../../utils").SharedWorkspaceLibraryConfig;
|
|
21
|
-
sharedDependencies: {
|
|
22
|
-
[x: string]: SharedLibraryConfig;
|
|
23
|
-
};
|
|
24
|
-
mappedRemotes: Record<string, string>;
|
|
25
|
-
};
|
|
27
|
+
}, useRspack?: boolean): import("../../utils/module-federation-config").ModuleFederationConfigResult;
|
|
26
28
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/angular/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/angular/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAQ1E;;GAEG;AACH,eAAO,MAAM,iCAAiC,UAI7C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B,UAKzC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACjD,SAAS,UAAQ,QAwBlB;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,QAAQ,GAAE,OAAe,EACzB,SAAS,UAAQ,8BAGlB;AAqBD,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,sBAAsB,EAChC,OAAO,GAAE;IACP,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3B,EACvB,OAAO,GAAE,QAAQ,GAAG,SAAoB,wFAQzC;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,sBAAsB,EAChC,OAAO,GAAE;IACP,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3B,EACvB,SAAS,UAAQ,+EAOlB"}
|
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DEFAULT_NPM_PACKAGES_TO_AVOID = exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE = void 0;
|
|
4
4
|
exports.applyDefaultEagerPackages = applyDefaultEagerPackages;
|
|
5
5
|
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
|
|
6
6
|
exports.getModuleFederationConfig = getModuleFederationConfig;
|
|
7
7
|
exports.getModuleFederationConfigSync = getModuleFederationConfigSync;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const module_federation_config_1 = require("../../utils/module-federation-config");
|
|
9
|
+
/**
|
|
10
|
+
* Default npm packages to always share for Angular projects.
|
|
11
|
+
*/
|
|
12
|
+
exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE = [
|
|
13
|
+
'@angular/core',
|
|
14
|
+
'@angular/animations',
|
|
15
|
+
'@angular/common',
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* npm packages to avoid sharing in Angular projects.
|
|
19
|
+
*/
|
|
20
|
+
exports.DEFAULT_NPM_PACKAGES_TO_AVOID = [
|
|
21
|
+
'zone.js',
|
|
22
|
+
'@nx/angular/mf',
|
|
23
|
+
'@nrwl/angular/mf',
|
|
24
|
+
'@nx/angular-rspack',
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* Applies eager loading to default Angular packages.
|
|
28
|
+
* Exported for backward compatibility.
|
|
29
|
+
*/
|
|
11
30
|
function applyDefaultEagerPackages(sharedConfig, useRspack = false) {
|
|
12
31
|
const DEFAULT_PACKAGES_TO_LOAD_EAGERLY = [
|
|
13
32
|
'@angular/localize',
|
|
@@ -32,123 +51,32 @@ function applyDefaultEagerPackages(sharedConfig, useRspack = false) {
|
|
|
32
51
|
sharedConfig[pkg] = { ...sharedConfig[pkg], eager: true };
|
|
33
52
|
}
|
|
34
53
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
'@nx/angular-rspack',
|
|
40
|
-
];
|
|
41
|
-
exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE = [
|
|
42
|
-
'@angular/core',
|
|
43
|
-
'@angular/animations',
|
|
44
|
-
'@angular/common',
|
|
45
|
-
];
|
|
54
|
+
/**
|
|
55
|
+
* Creates the default remote URL resolver for Angular.
|
|
56
|
+
* Kept for backward compatibility with existing configs.
|
|
57
|
+
*/
|
|
46
58
|
function getFunctionDeterminateRemoteUrl(isServer = false, useRspack = false) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
remoteConfiguration = (0, project_graph_1.readCachedProjectConfiguration)(remote);
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
throw new Error(`Cannot find remote "${remote}". Check that the remote name is correct in your module federation config file.\n`);
|
|
67
|
-
}
|
|
68
|
-
const serveTarget = remoteConfiguration?.targets?.[target];
|
|
69
|
-
if (!serveTarget) {
|
|
70
|
-
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "serve" target.\n
|
|
71
|
-
You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
72
|
-
}
|
|
73
|
-
const host = serveTarget.options?.host ??
|
|
74
|
-
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
|
75
|
-
const port = serveTarget.options?.port ?? 4201;
|
|
76
|
-
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
|
|
59
|
+
return (0, module_federation_config_1.createDefaultRemoteUrlResolver)(isServer, useRspack ? 'js' : 'mjs');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates framework config for Angular projects.
|
|
63
|
+
*/
|
|
64
|
+
function getAngularFrameworkConfig(bundler, useRspack) {
|
|
65
|
+
return {
|
|
66
|
+
bundler,
|
|
67
|
+
remoteEntryExt: useRspack ? 'js' : 'mjs',
|
|
68
|
+
mapRemotesExpose: false,
|
|
69
|
+
defaultPackagesToShare: exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE,
|
|
70
|
+
packagesToAvoid: exports.DEFAULT_NPM_PACKAGES_TO_AVOID,
|
|
71
|
+
applyEagerPackages: (sharedConfig) => {
|
|
72
|
+
applyDefaultEagerPackages(sharedConfig, useRspack);
|
|
73
|
+
},
|
|
77
74
|
};
|
|
78
75
|
}
|
|
79
76
|
async function getModuleFederationConfig(mfConfig, options = { isServer: false }, bundler = 'rspack') {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
86
|
-
}
|
|
87
|
-
if (!projectGraph.nodes[mfConfig.name]?.data) {
|
|
88
|
-
throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
|
|
89
|
-
}
|
|
90
|
-
const dependencies = (0, utils_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
|
|
91
|
-
if (mfConfig.shared) {
|
|
92
|
-
dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
|
|
93
|
-
dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
|
|
94
|
-
}
|
|
95
|
-
const sharedLibraries = (0, utils_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries, undefined, bundler);
|
|
96
|
-
const npmPackages = (0, utils_1.sharePackages)(Array.from(new Set([
|
|
97
|
-
...exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE,
|
|
98
|
-
...dependencies.npmPackages.filter((pkg) => !exports.DEFAULT_NPM_PACKAGES_TO_AVOID.includes(pkg)),
|
|
99
|
-
])));
|
|
100
|
-
exports.DEFAULT_NPM_PACKAGES_TO_AVOID.forEach((pkgName) => {
|
|
101
|
-
if (pkgName in npmPackages) {
|
|
102
|
-
delete npmPackages[pkgName];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
const sharedDependencies = {
|
|
106
|
-
...sharedLibraries.getLibraries(projectGraph.nodes[mfConfig.name].data.root),
|
|
107
|
-
...npmPackages,
|
|
108
|
-
};
|
|
109
|
-
applyDefaultEagerPackages(sharedDependencies);
|
|
110
|
-
(0, utils_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
|
|
111
|
-
(0, utils_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
|
|
112
|
-
const determineRemoteUrlFn = options.determineRemoteUrl ||
|
|
113
|
-
getFunctionDeterminateRemoteUrl(options.isServer);
|
|
114
|
-
const mapRemotesFunction = options.isServer ? utils_1.mapRemotesForSSR : utils_1.mapRemotes;
|
|
115
|
-
const mappedRemotes = !mfConfig.remotes || mfConfig.remotes.length === 0
|
|
116
|
-
? {}
|
|
117
|
-
: mapRemotesFunction(mfConfig.remotes, 'mjs', determineRemoteUrlFn);
|
|
118
|
-
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
|
77
|
+
// Angular async uses 'mjs' extension (webpack), not rspack
|
|
78
|
+
return (0, module_federation_config_1.getModuleFederationConfigAsync)(mfConfig, options, getAngularFrameworkConfig(bundler, false));
|
|
119
79
|
}
|
|
120
80
|
function getModuleFederationConfigSync(mfConfig, options = { isServer: false }, useRspack = false) {
|
|
121
|
-
|
|
122
|
-
if (!projectGraph.nodes[mfConfig.name]?.data) {
|
|
123
|
-
throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
|
|
124
|
-
}
|
|
125
|
-
const dependencies = (0, utils_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
|
|
126
|
-
if (mfConfig.shared) {
|
|
127
|
-
dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
|
|
128
|
-
dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
|
|
129
|
-
}
|
|
130
|
-
const sharedLibraries = (0, utils_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries, undefined, 'rspack');
|
|
131
|
-
const npmPackages = (0, utils_1.sharePackages)(Array.from(new Set([
|
|
132
|
-
...exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE,
|
|
133
|
-
...dependencies.npmPackages.filter((pkg) => !exports.DEFAULT_NPM_PACKAGES_TO_AVOID.includes(pkg)),
|
|
134
|
-
])));
|
|
135
|
-
exports.DEFAULT_NPM_PACKAGES_TO_AVOID.forEach((pkgName) => {
|
|
136
|
-
if (pkgName in npmPackages) {
|
|
137
|
-
delete npmPackages[pkgName];
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
const sharedDependencies = {
|
|
141
|
-
...sharedLibraries.getLibraries(projectGraph.nodes[mfConfig.name].data.root),
|
|
142
|
-
...npmPackages,
|
|
143
|
-
};
|
|
144
|
-
applyDefaultEagerPackages(sharedDependencies, useRspack);
|
|
145
|
-
(0, utils_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
|
|
146
|
-
(0, utils_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
|
|
147
|
-
const determineRemoteUrlFn = options.determineRemoteUrl ||
|
|
148
|
-
getFunctionDeterminateRemoteUrl(options.isServer, useRspack);
|
|
149
|
-
const mapRemotesFunction = options.isServer ? utils_1.mapRemotesForSSR : utils_1.mapRemotes;
|
|
150
|
-
const mappedRemotes = !mfConfig.remotes || mfConfig.remotes.length === 0
|
|
151
|
-
? {}
|
|
152
|
-
: mapRemotesFunction(mfConfig.remotes, useRspack ? 'js' : 'mjs', determineRemoteUrlFn);
|
|
153
|
-
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
|
81
|
+
return (0, module_federation_config_1.getModuleFederationConfigSync)(mfConfig, options, getAngularFrameworkConfig('rspack', useRspack));
|
|
154
82
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { ModuleFederationConfig } from '../../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the default remote URL resolver for rspack.
|
|
4
|
+
* Kept for backward compatibility with existing configs.
|
|
5
|
+
*/
|
|
2
6
|
export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean): (remote: string) => string;
|
|
3
7
|
export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
|
|
4
8
|
isServer: boolean;
|
|
5
9
|
determineRemoteUrl?: (remote: string) => string;
|
|
6
|
-
}):
|
|
7
|
-
sharedLibraries: import("../../utils").SharedWorkspaceLibraryConfig;
|
|
8
|
-
sharedDependencies: {
|
|
9
|
-
[x: string]: import("../../utils").SharedLibraryConfig;
|
|
10
|
-
};
|
|
11
|
-
mappedRemotes: {};
|
|
12
|
-
};
|
|
10
|
+
}): import("../../utils/module-federation-config").ModuleFederationConfigResult;
|
|
13
11
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/rspack/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/rspack/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAuB,MAAM,aAAa,CAAC;AAU1E;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,UAAQ,8BAE/D;AAsBD,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,sBAAsB,EAChC,OAAO,GAAE;IACP,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3B,+EAOxB"}
|
|
@@ -2,73 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
|
|
4
4
|
exports.getModuleFederationConfig = getModuleFederationConfig;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const utils_1 = require("../../utils");
|
|
8
|
-
const utils_2 = require("../react/utils");
|
|
5
|
+
const module_federation_config_1 = require("../../utils/module-federation-config");
|
|
6
|
+
const utils_1 = require("../react/utils");
|
|
9
7
|
const framework_detection_1 = require("../../utils/framework-detection");
|
|
8
|
+
/**
|
|
9
|
+
* Creates the default remote URL resolver for rspack.
|
|
10
|
+
* Kept for backward compatibility with existing configs.
|
|
11
|
+
*/
|
|
10
12
|
function getFunctionDeterminateRemoteUrl(isServer = false) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
throw new Error(`Cannot find remote: "${remote}". Check that the remote name is correct in your module federation config file.\n`);
|
|
27
|
-
}
|
|
28
|
-
const serveTarget = remoteConfiguration?.targets?.[target];
|
|
29
|
-
if (!serveTarget) {
|
|
30
|
-
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
|
|
31
|
-
You can also use the tuple syntax in your rspack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
32
|
-
}
|
|
33
|
-
const host = serveTarget.options?.host ??
|
|
34
|
-
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
|
35
|
-
const port = serveTarget.options?.port ?? 4201;
|
|
36
|
-
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
|
|
13
|
+
return (0, module_federation_config_1.createDefaultRemoteUrlResolver)(isServer, 'js');
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Framework config for rspack projects (React).
|
|
17
|
+
*/
|
|
18
|
+
function getRspackFrameworkConfig() {
|
|
19
|
+
return {
|
|
20
|
+
bundler: 'rspack',
|
|
21
|
+
remoteEntryExt: 'js',
|
|
22
|
+
mapRemotesExpose: true,
|
|
23
|
+
applyEagerPackages: (sharedConfig, projectGraph, projectName) => {
|
|
24
|
+
if ((0, framework_detection_1.isReactProject)(projectName, projectGraph)) {
|
|
25
|
+
(0, utils_1.applyDefaultEagerPackages)(sharedConfig);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
37
28
|
};
|
|
38
29
|
}
|
|
39
30
|
function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
|
|
40
|
-
|
|
41
|
-
const project = projectGraph.nodes[mfConfig.name]?.data;
|
|
42
|
-
if (!project) {
|
|
43
|
-
throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
|
|
44
|
-
}
|
|
45
|
-
const dependencies = (0, utils_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
|
|
46
|
-
if (mfConfig.shared) {
|
|
47
|
-
dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
|
|
48
|
-
dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
|
|
49
|
-
}
|
|
50
|
-
const sharedLibraries = (0, utils_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
|
|
51
|
-
const npmPackages = (0, utils_1.sharePackages)(dependencies.npmPackages);
|
|
52
|
-
const sharedDependencies = {
|
|
53
|
-
...sharedLibraries.getLibraries(project.root),
|
|
54
|
-
...npmPackages,
|
|
55
|
-
};
|
|
56
|
-
// Apply framework-specific eager packages
|
|
57
|
-
if ((0, framework_detection_1.isReactProject)(mfConfig.name, projectGraph)) {
|
|
58
|
-
(0, utils_2.applyDefaultEagerPackages)(sharedDependencies);
|
|
59
|
-
}
|
|
60
|
-
(0, utils_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
|
|
61
|
-
(0, utils_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
|
|
62
|
-
// Choose the correct mapRemotes function based on the server state.
|
|
63
|
-
const mapRemotesFunction = options.isServer ? utils_1.mapRemotesForSSR : utils_1.mapRemotes;
|
|
64
|
-
// Determine the URL function, either from provided options or by using a default.
|
|
65
|
-
const determineRemoteUrlFunction = options.determineRemoteUrl
|
|
66
|
-
? options.determineRemoteUrl
|
|
67
|
-
: getFunctionDeterminateRemoteUrl(options.isServer);
|
|
68
|
-
// Map the remotes if they exist, otherwise default to an empty object.
|
|
69
|
-
let mappedRemotes = {};
|
|
70
|
-
if (mfConfig.remotes && mfConfig.remotes.length > 0) {
|
|
71
|
-
mappedRemotes = mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFunction, true);
|
|
72
|
-
}
|
|
73
|
-
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
|
31
|
+
return (0, module_federation_config_1.getModuleFederationConfigSync)(mfConfig, options, getRspackFrameworkConfig());
|
|
74
32
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { ModuleFederationConfig } from '../../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the default remote URL resolver for webpack.
|
|
4
|
+
* Kept for backward compatibility with existing configs.
|
|
5
|
+
*/
|
|
2
6
|
export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean): (remote: string) => string;
|
|
3
7
|
export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
|
|
4
8
|
isServer: boolean;
|
|
5
9
|
determineRemoteUrl?: (remote: string) => string;
|
|
6
|
-
}, bundler?: 'rspack' | 'webpack'): Promise<
|
|
7
|
-
sharedLibraries: import("../../utils").SharedWorkspaceLibraryConfig;
|
|
8
|
-
sharedDependencies: {
|
|
9
|
-
[x: string]: import("../../utils").SharedLibraryConfig;
|
|
10
|
-
};
|
|
11
|
-
mappedRemotes: {};
|
|
12
|
-
}>;
|
|
10
|
+
}, bundler?: 'rspack' | 'webpack'): Promise<import("../../utils/module-federation-config").ModuleFederationConfigResult>;
|
|
13
11
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/webpack/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/webpack/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAuB,MAAM,aAAa,CAAC;AAU1E;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,GAAE,OAAe,8BAExE;AAwBD,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,sBAAsB,EAChC,OAAO,GAAE;IACP,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3B,EACvB,OAAO,GAAE,QAAQ,GAAG,SAAoB,wFAOzC"}
|
|
@@ -2,80 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
|
|
4
4
|
exports.getModuleFederationConfig = getModuleFederationConfig;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
|
8
|
-
const utils_2 = require("../react/utils");
|
|
5
|
+
const module_federation_config_1 = require("../../utils/module-federation-config");
|
|
6
|
+
const utils_1 = require("../react/utils");
|
|
9
7
|
const framework_detection_1 = require("../../utils/framework-detection");
|
|
8
|
+
/**
|
|
9
|
+
* Creates the default remote URL resolver for webpack.
|
|
10
|
+
* Kept for backward compatibility with existing configs.
|
|
11
|
+
*/
|
|
10
12
|
function getFunctionDeterminateRemoteUrl(isServer = false) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
throw new Error(`Cannot find remote: "${remote}". Check that the remote name is correct in your module federation config file.\n`);
|
|
27
|
-
}
|
|
28
|
-
const serveTarget = remoteConfiguration?.targets?.[target];
|
|
29
|
-
if (!serveTarget) {
|
|
30
|
-
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
|
|
31
|
-
You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
32
|
-
}
|
|
33
|
-
const host = serveTarget.options?.host ??
|
|
34
|
-
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
|
35
|
-
const port = serveTarget.options?.port ?? 4201;
|
|
36
|
-
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
|
|
13
|
+
return (0, module_federation_config_1.createDefaultRemoteUrlResolver)(isServer, 'js');
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Framework config for webpack projects (React).
|
|
17
|
+
*/
|
|
18
|
+
function getWebpackFrameworkConfig(bundler = 'rspack') {
|
|
19
|
+
return {
|
|
20
|
+
bundler,
|
|
21
|
+
remoteEntryExt: 'js',
|
|
22
|
+
mapRemotesExpose: true,
|
|
23
|
+
applyEagerPackages: (sharedConfig, projectGraph, projectName) => {
|
|
24
|
+
if ((0, framework_detection_1.isReactProject)(projectName, projectGraph)) {
|
|
25
|
+
(0, utils_1.applyDefaultEagerPackages)(sharedConfig);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
37
28
|
};
|
|
38
29
|
}
|
|
39
30
|
async function getModuleFederationConfig(mfConfig, options = { isServer: false }, bundler = 'rspack') {
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
46
|
-
}
|
|
47
|
-
const project = projectGraph.nodes[mfConfig.name]?.data;
|
|
48
|
-
if (!project) {
|
|
49
|
-
throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
|
|
50
|
-
}
|
|
51
|
-
const dependencies = (0, utils_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
|
|
52
|
-
if (mfConfig.shared) {
|
|
53
|
-
dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
|
|
54
|
-
dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
|
|
55
|
-
}
|
|
56
|
-
const sharedLibraries = (0, utils_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries, undefined, bundler);
|
|
57
|
-
const npmPackages = (0, utils_1.sharePackages)(dependencies.npmPackages);
|
|
58
|
-
const sharedDependencies = {
|
|
59
|
-
...sharedLibraries.getLibraries(project.root),
|
|
60
|
-
...npmPackages,
|
|
61
|
-
};
|
|
62
|
-
// Apply framework-specific eager packages
|
|
63
|
-
if ((0, framework_detection_1.isReactProject)(mfConfig.name, projectGraph)) {
|
|
64
|
-
(0, utils_2.applyDefaultEagerPackages)(sharedDependencies);
|
|
65
|
-
}
|
|
66
|
-
(0, utils_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
|
|
67
|
-
(0, utils_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
|
|
68
|
-
// Choose the correct mapRemotes function based on the server state.
|
|
69
|
-
const mapRemotesFunction = options.isServer ? utils_1.mapRemotesForSSR : utils_1.mapRemotes;
|
|
70
|
-
// Determine the URL function, either from provided options or by using a default.
|
|
71
|
-
const determineRemoteUrlFunction = options.determineRemoteUrl
|
|
72
|
-
? options.determineRemoteUrl
|
|
73
|
-
: getFunctionDeterminateRemoteUrl(options.isServer);
|
|
74
|
-
// Map the remotes if they exist, otherwise default to an empty object.
|
|
75
|
-
let mappedRemotes = {};
|
|
76
|
-
if (mfConfig.remotes && mfConfig.remotes.length > 0) {
|
|
77
|
-
const isLibraryTypeVar = mfConfig.library?.type === 'var';
|
|
78
|
-
mappedRemotes = mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFunction, true);
|
|
79
|
-
}
|
|
80
|
-
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
|
31
|
+
return (0, module_federation_config_1.getModuleFederationConfigAsync)(mfConfig, options, getWebpackFrameworkConfig(bundler));
|
|
81
32
|
}
|