@nx/module-federation 21.0.4-beta.0 → 21.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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": "21.0.4
|
|
4
|
+
"version": "21.0.4",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"executors": "./executors.json",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"tslib": "^2.3.0",
|
|
28
|
-
"@nx/devkit": "21.0.4
|
|
29
|
-
"@nx/js": "21.0.4
|
|
30
|
-
"@nx/web": "21.0.4
|
|
28
|
+
"@nx/devkit": "21.0.4",
|
|
29
|
+
"@nx/js": "21.0.4",
|
|
30
|
+
"@nx/web": "21.0.4",
|
|
31
31
|
"picocolors": "^1.1.0",
|
|
32
32
|
"webpack": "^5.88.0",
|
|
33
33
|
"@rspack/core": "^1.3.8",
|
|
@@ -9,7 +9,8 @@ async function startRemoteIterators(options, context, startRemoteFn, pathToManif
|
|
|
9
9
|
const nxBin = require.resolve('nx/bin/nx');
|
|
10
10
|
const { projects: workspaceProjects } = (0, devkit_1.readProjectsConfigurationFromProjectGraph)(context.projectGraph);
|
|
11
11
|
const project = workspaceProjects[context.projectName];
|
|
12
|
-
const
|
|
12
|
+
const buildTargetName = (0, utils_1.getBuildTargetNameFromMFDevServer)(project, context.projectGraph);
|
|
13
|
+
const moduleFederationConfig = (0, utils_1.getModuleFederationConfig)(project.targets?.[buildTargetName]?.options?.tsConfig, context.root, project.root, pluginName);
|
|
13
14
|
const remoteNames = options.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName);
|
|
14
15
|
const remotes = (0, utils_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
|
|
15
16
|
projectName: project.name,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { type ProjectGraph } from '@nx/devkit';
|
|
1
|
+
import { type ProjectConfiguration, type ProjectGraph } from '@nx/devkit';
|
|
2
2
|
import { ModuleFederationConfig } from './models';
|
|
3
3
|
interface ModuleFederationExecutorContext {
|
|
4
4
|
projectName: string;
|
|
5
5
|
projectGraph: ProjectGraph;
|
|
6
6
|
root: string;
|
|
7
7
|
}
|
|
8
|
+
export declare function getBuildTargetNameFromMFDevServer(projectConfig: ProjectConfiguration, projectGraph: ProjectGraph): string;
|
|
8
9
|
export declare function getRemotes(devRemotes: string[], skipRemotes: string[], config: ModuleFederationConfig, context: ModuleFederationExecutorContext, pathToManifestFile?: string): {
|
|
9
10
|
staticRemotes: string[];
|
|
10
11
|
devRemotes: any[];
|
|
@@ -12,5 +13,5 @@ export declare function getRemotes(devRemotes: string[], skipRemotes: string[],
|
|
|
12
13
|
remotePorts: any[];
|
|
13
14
|
staticRemotePort: number;
|
|
14
15
|
};
|
|
15
|
-
export declare function getModuleFederationConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
|
|
16
|
+
export declare function getModuleFederationConfig(tsconfigPath: string | undefined, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
|
|
16
17
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBuildTargetNameFromMFDevServer = getBuildTargetNameFromMFDevServer;
|
|
3
4
|
exports.getRemotes = getRemotes;
|
|
4
5
|
exports.getModuleFederationConfig = getModuleFederationConfig;
|
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
|
@@ -28,17 +29,10 @@ function extractRemoteProjectsFromConfig(config, pathToManifestFile) {
|
|
|
28
29
|
remotes.push(...staticRemotes);
|
|
29
30
|
return { remotes, dynamicRemotes };
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
collected.add(remote);
|
|
37
|
-
const remoteProjectRoot = remoteProject.root;
|
|
38
|
-
// Find the target that uses the module-federation-dev-server executor
|
|
39
|
-
let buildTargetName = 'build';
|
|
40
|
-
if (remoteProject.targets) {
|
|
41
|
-
for (const [targetKey, targetConfig] of Object.entries(remoteProject.targets)) {
|
|
32
|
+
// Find the target that uses the module-federation-dev-server executor
|
|
33
|
+
function getBuildTargetNameFromMFDevServer(projectConfig, projectGraph) {
|
|
34
|
+
if (projectConfig.targets) {
|
|
35
|
+
for (const [targetKey, targetConfig] of Object.entries(projectConfig.targets)) {
|
|
42
36
|
const executor = targetConfig.executor || '';
|
|
43
37
|
// Extract the portion after the `:` in the executor name
|
|
44
38
|
const executorParts = executor.split(':');
|
|
@@ -46,23 +40,23 @@ function collectRemoteProjects(remote, collected, context) {
|
|
|
46
40
|
if (executorName === 'module-federation-dev-server') {
|
|
47
41
|
// Extract the buildTarget from the options
|
|
48
42
|
if (targetConfig.options?.buildTarget) {
|
|
49
|
-
const parsedTarget = (0, devkit_1.parseTargetString)(targetConfig.options.buildTarget,
|
|
50
|
-
|
|
51
|
-
break;
|
|
43
|
+
const parsedTarget = (0, devkit_1.parseTargetString)(targetConfig.options.buildTarget, projectGraph);
|
|
44
|
+
return parsedTarget.target;
|
|
52
45
|
}
|
|
53
46
|
}
|
|
54
47
|
}
|
|
55
48
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
].find((p) => (0, fs_1.existsSync)(p));
|
|
63
|
-
if (!remoteProjectTsConfig) {
|
|
64
|
-
throw new Error(`Could not find a tsconfig for remote project ${remote}. Please add a tsconfig.app.json or tsconfig.json to the project.`);
|
|
49
|
+
return 'build';
|
|
50
|
+
}
|
|
51
|
+
function collectRemoteProjects(remote, collected, context) {
|
|
52
|
+
const remoteProject = context.projectGraph.nodes[remote]?.data;
|
|
53
|
+
if (!context.projectGraph.nodes[remote] || collected.has(remote)) {
|
|
54
|
+
return;
|
|
65
55
|
}
|
|
56
|
+
collected.add(remote);
|
|
57
|
+
const remoteProjectRoot = remoteProject.root;
|
|
58
|
+
const buildTargetName = getBuildTargetNameFromMFDevServer(remoteProject, context.projectGraph);
|
|
59
|
+
let remoteProjectTsConfig = remoteProject.targets?.[buildTargetName]?.options?.tsConfig;
|
|
66
60
|
const remoteProjectConfig = getModuleFederationConfig(remoteProjectTsConfig, context.root, remoteProjectRoot);
|
|
67
61
|
const { remotes: remoteProjectRemotes } = extractRemoteProjectsFromConfig(remoteProjectConfig);
|
|
68
62
|
remoteProjectRemotes.forEach((r) => collectRemoteProjects(r, collected, context));
|
|
@@ -113,6 +107,17 @@ function getModuleFederationConfig(tsconfigPath, workspaceRoot, projectRoot, plu
|
|
|
113
107
|
const moduleFederationConfigPathJS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.js');
|
|
114
108
|
const moduleFederationConfigPathTS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.ts');
|
|
115
109
|
let moduleFederationConfigPath = moduleFederationConfigPathJS;
|
|
110
|
+
tsconfigPath =
|
|
111
|
+
tsconfigPath ??
|
|
112
|
+
[
|
|
113
|
+
(0, path_1.join)(projectRoot, 'tsconfig.app.json'),
|
|
114
|
+
(0, path_1.join)(projectRoot, 'tsconfig.json'),
|
|
115
|
+
(0, path_1.join)(workspaceRoot, 'tsconfig.json'),
|
|
116
|
+
(0, path_1.join)(workspaceRoot, 'tsconfig.base.json'),
|
|
117
|
+
].find((p) => (0, fs_1.existsSync)(p));
|
|
118
|
+
if (!tsconfigPath) {
|
|
119
|
+
throw new Error(`Could not find a tsconfig for remote project located at ${projectRoot}. Please add a tsconfig.app.json or tsconfig.json to the project.`);
|
|
120
|
+
}
|
|
116
121
|
// create a no-op so this can be called with issue
|
|
117
122
|
const fullTSconfigPath = tsconfigPath.startsWith(workspaceRoot)
|
|
118
123
|
? tsconfigPath
|