@nx/module-federation 22.2.2 → 22.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 +5 -5
- 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/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.2.
|
|
4
|
+
"version": "22.2.3",
|
|
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.2.
|
|
31
|
-
"@nx/js": "22.2.
|
|
32
|
-
"@nx/web": "22.2.
|
|
30
|
+
"@nx/devkit": "22.2.3",
|
|
31
|
+
"@nx/js": "22.2.3",
|
|
32
|
+
"@nx/web": "22.2.3",
|
|
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.2.
|
|
41
|
+
"nx": "22.2.3"
|
|
42
42
|
},
|
|
43
43
|
"nx-migrations": {
|
|
44
44
|
"migrations": "./migrations.json"
|
|
@@ -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
|
+
}
|
|
@@ -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
|
}
|