@nx/module-federation 24.0.0-beta.2 → 24.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/dist/angular.d.ts +1 -5
- package/dist/angular.js +7 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +0 -2
- package/dist/rspack.d.ts +1 -5
- package/dist/rspack.js +7 -6
- package/dist/src/migrations/update-24-0-0/inventory.d.ts +11 -0
- package/dist/src/migrations/update-24-0-0/inventory.js +139 -0
- package/dist/src/migrations/update-24-0-0/migrate-angular-module-federation.d.ts +5 -0
- package/dist/src/migrations/update-24-0-0/migrate-angular-module-federation.js +18 -0
- package/dist/src/migrations/update-24-0-0/migrate-module-federation.d.ts +10 -0
- package/dist/src/migrations/update-24-0-0/migrate-module-federation.js +26 -0
- package/dist/src/migrations/update-24-0-0/migrate-module-federation.md +1931 -0
- package/dist/src/migrations/update-24-0-0/migrate-react-module-federation.d.ts +5 -0
- package/dist/src/migrations/update-24-0-0/migrate-react-module-federation.js +18 -0
- package/dist/src/stubs/models.d.ts +26 -0
- package/dist/src/stubs/stubs.d.ts +19 -0
- package/dist/src/stubs/stubs.js +43 -0
- package/dist/webpack.d.ts +1 -2
- package/dist/webpack.js +4 -3
- package/migrations.json +6 -0
- package/package.json +5 -60
- package/readme-template.md +1 -3
- package/dist/internal.d.ts +0 -2
- package/dist/internal.js +0 -13
- package/dist/src/executors/utils/build-static-remotes.d.ts +0 -4
- package/dist/src/executors/utils/build-static-remotes.js +0 -67
- package/dist/src/executors/utils/index.d.ts +0 -4
- package/dist/src/executors/utils/index.js +0 -6
- package/dist/src/executors/utils/models.d.ts +0 -30
- package/dist/src/executors/utils/start-remote-iterators.d.ts +0 -25
- package/dist/src/executors/utils/start-remote-iterators.js +0 -52
- package/dist/src/executors/utils/start-static-remotes-file-server.d.ts +0 -15
- package/dist/src/executors/utils/start-static-remotes-file-server.js +0 -61
- package/dist/src/plugins/models/index.d.ts +0 -14
- package/dist/src/plugins/models/index.js +0 -2
- package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-dev-server-plugin.d.ts +0 -13
- package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-dev-server-plugin.js +0 -75
- package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-plugin.d.ts +0 -11
- package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-plugin.js +0 -93
- package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-ssr-dev-server-plugin.d.ts +0 -15
- package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-ssr-dev-server-plugin.js +0 -107
- package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-dev-server-plugin.d.ts +0 -13
- package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-dev-server-plugin.js +0 -75
- package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-plugin.d.ts +0 -11
- package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-plugin.js +0 -80
- package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-ssr-dev-server-plugin.d.ts +0 -15
- package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-ssr-dev-server-plugin.js +0 -107
- package/dist/src/plugins/utils/build-static-remotes.d.ts +0 -3
- package/dist/src/plugins/utils/build-static-remotes.js +0 -65
- package/dist/src/plugins/utils/get-dynamic-manifest-file.d.ts +0 -2
- package/dist/src/plugins/utils/get-dynamic-manifest-file.js +0 -18
- package/dist/src/plugins/utils/get-remotes.d.ts +0 -7
- package/dist/src/plugins/utils/get-remotes.js +0 -68
- package/dist/src/plugins/utils/get-static-remotes.d.ts +0 -3
- package/dist/src/plugins/utils/get-static-remotes.js +0 -27
- package/dist/src/plugins/utils/index.d.ts +0 -7
- package/dist/src/plugins/utils/index.js +0 -10
- package/dist/src/plugins/utils/parse-remotes-config.d.ts +0 -6
- package/dist/src/plugins/utils/parse-remotes-config.js +0 -35
- package/dist/src/plugins/utils/start-remote-proxies.d.ts +0 -5
- package/dist/src/plugins/utils/start-remote-proxies.js +0 -65
- package/dist/src/plugins/utils/start-static-remotes-file-server.d.ts +0 -2
- package/dist/src/plugins/utils/start-static-remotes-file-server.js +0 -46
- package/dist/src/utils/dependencies.d.ts +0 -6
- package/dist/src/utils/dependencies.js +0 -70
- package/dist/src/utils/framework-detection.d.ts +0 -2
- package/dist/src/utils/framework-detection.js +0 -20
- package/dist/src/utils/get-remotes-for-host.d.ts +0 -17
- package/dist/src/utils/get-remotes-for-host.js +0 -154
- package/dist/src/utils/index.d.ts +0 -11
- package/dist/src/utils/index.js +0 -14
- package/dist/src/utils/is-serve-mode.d.ts +0 -2
- package/dist/src/utils/is-serve-mode.js +0 -19
- package/dist/src/utils/models/index.d.ts +0 -47
- package/dist/src/utils/models/index.js +0 -2
- package/dist/src/utils/module-federation-config.d.ts +0 -57
- package/dist/src/utils/module-federation-config.js +0 -144
- package/dist/src/utils/normalize-project-name.d.ts +0 -1
- package/dist/src/utils/normalize-project-name.js +0 -10
- package/dist/src/utils/package-json.d.ts +0 -2
- package/dist/src/utils/package-json.js +0 -12
- package/dist/src/utils/parse-static-remotes-config.d.ts +0 -13
- package/dist/src/utils/parse-static-remotes-config.js +0 -62
- package/dist/src/utils/plugins/runtime-library-control.plugin.d.ts +0 -3
- package/dist/src/utils/plugins/runtime-library-control.plugin.js +0 -54
- package/dist/src/utils/port-utils.d.ts +0 -7
- package/dist/src/utils/port-utils.js +0 -22
- package/dist/src/utils/public-api.d.ts +0 -7
- package/dist/src/utils/public-api.js +0 -18
- package/dist/src/utils/remotes.d.ts +0 -19
- package/dist/src/utils/remotes.js +0 -75
- package/dist/src/utils/rspack-version.d.ts +0 -3
- package/dist/src/utils/rspack-version.js +0 -11
- package/dist/src/utils/secondary-entry-points.d.ts +0 -12
- package/dist/src/utils/secondary-entry-points.js +0 -125
- package/dist/src/utils/share.d.ts +0 -58
- package/dist/src/utils/share.js +0 -334
- package/dist/src/utils/start-remote-proxies.d.ts +0 -5
- package/dist/src/utils/start-remote-proxies.js +0 -55
- package/dist/src/utils/start-ssr-remote-proxies.d.ts +0 -5
- package/dist/src/utils/start-ssr-remote-proxies.js +0 -69
- package/dist/src/utils/typescript.d.ts +0 -4
- package/dist/src/utils/typescript.js +0 -53
- package/dist/src/utils/url-helpers.d.ts +0 -13
- package/dist/src/utils/url-helpers.js +0 -70
- package/dist/src/with-module-federation/angular/utils.d.ts +0 -28
- package/dist/src/with-module-federation/angular/utils.js +0 -83
- package/dist/src/with-module-federation/angular/with-module-federation-ssr.d.ts +0 -2
- package/dist/src/with-module-federation/angular/with-module-federation-ssr.js +0 -86
- package/dist/src/with-module-federation/angular/with-module-federation.d.ts +0 -2
- package/dist/src/with-module-federation/angular/with-module-federation.js +0 -85
- package/dist/src/with-module-federation/react/utils.d.ts +0 -2
- package/dist/src/with-module-federation/react/utils.js +0 -17
- package/dist/src/with-module-federation/rspack/utils.d.ts +0 -10
- package/dist/src/with-module-federation/rspack/utils.js +0 -32
- package/dist/src/with-module-federation/rspack/with-module-federation-ssr.d.ts +0 -4
- package/dist/src/with-module-federation/rspack/with-module-federation-ssr.js +0 -75
- package/dist/src/with-module-federation/rspack/with-module-federation.d.ts +0 -9
- package/dist/src/with-module-federation/rspack/with-module-federation.js +0 -82
- package/dist/src/with-module-federation/webpack/utils.d.ts +0 -10
- package/dist/src/with-module-federation/webpack/utils.js +0 -32
- package/dist/src/with-module-federation/webpack/with-module-federation-ssr.d.ts +0 -2
- package/dist/src/with-module-federation/webpack/with-module-federation-ssr.js +0 -69
- package/dist/src/with-module-federation/webpack/with-module-federation.d.ts +0 -5
- package/dist/src/with-module-federation/webpack/with-module-federation.js +0 -72
- package/dist/url-helpers.d.ts +0 -13
- package/dist/url-helpers.js +0 -78
- package/executors.json +0 -4
- /package/dist/src/{executors/utils → stubs}/models.js +0 -0
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBuildTargetNameFromMFDevServer = getBuildTargetNameFromMFDevServer;
|
|
4
|
-
exports.getRemotes = getRemotes;
|
|
5
|
-
exports.getModuleFederationConfig = getModuleFederationConfig;
|
|
6
|
-
const tslib_1 = require("tslib");
|
|
7
|
-
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const internal_1 = require("@nx/js/internal");
|
|
9
|
-
const pc = tslib_1.__importStar(require("picocolors"));
|
|
10
|
-
const path_1 = require("path");
|
|
11
|
-
const fs_1 = require("fs");
|
|
12
|
-
const internal_2 = require("@nx/devkit/internal");
|
|
13
|
-
function extractRemoteProjectsFromConfig(config, pathToManifestFile) {
|
|
14
|
-
const remotes = [];
|
|
15
|
-
const dynamicRemotes = [];
|
|
16
|
-
if (pathToManifestFile && (0, fs_1.existsSync)(pathToManifestFile)) {
|
|
17
|
-
const moduleFederationManifestJson = (0, fs_1.readFileSync)(pathToManifestFile, 'utf-8');
|
|
18
|
-
if (moduleFederationManifestJson) {
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* This should have shape of
|
|
22
|
-
* {
|
|
23
|
-
* "remoteName": "remoteLocation",
|
|
24
|
-
* }
|
|
25
|
-
* But users might have their own, enforce only that the key is the remote name
|
|
26
|
-
*/
|
|
27
|
-
const parsedManifest = JSON.parse(moduleFederationManifestJson);
|
|
28
|
-
// Get keys once instead of calling Object.keys twice
|
|
29
|
-
const manifestKeys = Object.keys(parsedManifest);
|
|
30
|
-
if (manifestKeys.every((key) => typeof key === 'string')) {
|
|
31
|
-
dynamicRemotes.push(...manifestKeys);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const staticRemotes = config.remotes?.map((r) => (Array.isArray(r) ? r[0] : r)) ?? [];
|
|
36
|
-
remotes.push(...staticRemotes);
|
|
37
|
-
return { remotes, dynamicRemotes };
|
|
38
|
-
}
|
|
39
|
-
// Find the target that uses the module-federation-dev-server executor
|
|
40
|
-
function getBuildTargetNameFromMFDevServer(projectConfig, projectGraph) {
|
|
41
|
-
if (projectConfig.targets) {
|
|
42
|
-
for (const [targetKey, targetConfig] of Object.entries(projectConfig.targets)) {
|
|
43
|
-
const executor = targetConfig.executor || '';
|
|
44
|
-
// Extract the portion after the `:` in the executor name
|
|
45
|
-
const executorParts = executor.split(':');
|
|
46
|
-
const executorName = executorParts.length > 1 ? executorParts[1] : executor;
|
|
47
|
-
if (executorName === 'module-federation-dev-server') {
|
|
48
|
-
// Extract the buildTarget from the options
|
|
49
|
-
if (targetConfig.options?.buildTarget) {
|
|
50
|
-
const parsedTarget = (0, devkit_1.parseTargetString)(targetConfig.options.buildTarget, projectGraph);
|
|
51
|
-
return parsedTarget.target;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return 'build';
|
|
57
|
-
}
|
|
58
|
-
function collectRemoteProjects(remote, collected, context) {
|
|
59
|
-
const remoteProject = context.projectGraph.nodes[remote]?.data;
|
|
60
|
-
if (!context.projectGraph.nodes[remote] || collected.has(remote)) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
collected.add(remote);
|
|
64
|
-
const remoteProjectRoot = remoteProject.root;
|
|
65
|
-
const buildTargetName = getBuildTargetNameFromMFDevServer(remoteProject, context.projectGraph);
|
|
66
|
-
let remoteProjectTsConfig = remoteProject.targets?.[buildTargetName]?.options?.tsConfig;
|
|
67
|
-
const remoteProjectConfig = getModuleFederationConfig(remoteProjectTsConfig, context.root, remoteProjectRoot);
|
|
68
|
-
const { remotes: remoteProjectRemotes } = extractRemoteProjectsFromConfig(remoteProjectConfig);
|
|
69
|
-
remoteProjectRemotes.forEach((r) => collectRemoteProjects(r, collected, context));
|
|
70
|
-
}
|
|
71
|
-
function getRemotes(devRemotes, skipRemotes, config, context, pathToManifestFile) {
|
|
72
|
-
const collectedRemotes = new Set();
|
|
73
|
-
const { remotes, dynamicRemotes } = extractRemoteProjectsFromConfig(config, pathToManifestFile);
|
|
74
|
-
remotes.forEach((r) => collectRemoteProjects(r, collectedRemotes, context));
|
|
75
|
-
const remotesToSkip = new Set((0, internal_2.findMatchingProjects)(skipRemotes, context.projectGraph.nodes) ?? []);
|
|
76
|
-
if (remotesToSkip.size > 0) {
|
|
77
|
-
devkit_1.logger.info(`Remotes not served automatically: ${[...remotesToSkip.values()].join(', ')}`);
|
|
78
|
-
}
|
|
79
|
-
const knownRemotes = Array.from(collectedRemotes).filter((r) => !remotesToSkip.has(r));
|
|
80
|
-
// With dynamic remotes, the manifest file may contain the names with `_` due to MF limitations on naming
|
|
81
|
-
// The project graph might contain these names with `-` rather than `_`. Check for both.
|
|
82
|
-
// This can occur after migration of existing remotes past Nx 19.8
|
|
83
|
-
const normalizedDynamicRemotes = dynamicRemotes.map((r) => {
|
|
84
|
-
// Compute replacement once instead of twice
|
|
85
|
-
const normalizedName = r.replace(/_/g, '-');
|
|
86
|
-
return context.projectGraph.nodes[normalizedName] ? normalizedName : r;
|
|
87
|
-
});
|
|
88
|
-
const knownDynamicRemotes = normalizedDynamicRemotes.filter((r) => !remotesToSkip.has(r) && context.projectGraph.nodes[r]);
|
|
89
|
-
devkit_1.logger.info(`NX Starting module federation dev-server for ${pc.bold(context.projectName)} with ${[...knownRemotes, ...knownDynamicRemotes].length} remotes`);
|
|
90
|
-
// Normalize devRemotes to array and call findMatchingProjects once
|
|
91
|
-
const devServeApps = new Set(!devRemotes
|
|
92
|
-
? []
|
|
93
|
-
: (0, internal_2.findMatchingProjects)(Array.isArray(devRemotes) ? devRemotes : [devRemotes], context.projectGraph.nodes));
|
|
94
|
-
const staticRemotes = knownRemotes.filter((r) => !devServeApps.has(r));
|
|
95
|
-
const devServeRemotes = [...knownRemotes, ...knownDynamicRemotes].filter((r) => devServeApps.has(r));
|
|
96
|
-
const staticDynamicRemotes = knownDynamicRemotes.filter((r) => !devServeApps.has(r));
|
|
97
|
-
// Helper to get port from remote project
|
|
98
|
-
const getRemotePort = (r) => context.projectGraph.nodes[r].data.targets['serve'].options.port;
|
|
99
|
-
// Collect ports for dev-served remotes (used in return value)
|
|
100
|
-
const remotePorts = [...devServeRemotes, ...staticDynamicRemotes].map(getRemotePort);
|
|
101
|
-
// Calculate max port in a single pass instead of creating intermediate arrays
|
|
102
|
-
let maxPort = -Infinity;
|
|
103
|
-
for (const port of remotePorts) {
|
|
104
|
-
if (port > maxPort)
|
|
105
|
-
maxPort = port;
|
|
106
|
-
}
|
|
107
|
-
for (const r of staticRemotes) {
|
|
108
|
-
const port = getRemotePort(r);
|
|
109
|
-
if (port > maxPort)
|
|
110
|
-
maxPort = port;
|
|
111
|
-
}
|
|
112
|
-
const staticRemotePort = staticRemotes.length === 0 && remotePorts.length === 0
|
|
113
|
-
? undefined
|
|
114
|
-
: maxPort + (remotesToSkip.size + 1);
|
|
115
|
-
return {
|
|
116
|
-
staticRemotes,
|
|
117
|
-
devRemotes: devServeRemotes,
|
|
118
|
-
dynamicRemotes: staticDynamicRemotes,
|
|
119
|
-
remotePorts,
|
|
120
|
-
staticRemotePort,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
function getModuleFederationConfig(tsconfigPath, workspaceRoot, projectRoot, pluginName = 'react') {
|
|
124
|
-
const moduleFederationConfigPathJS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.js');
|
|
125
|
-
const moduleFederationConfigPathTS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.ts');
|
|
126
|
-
let moduleFederationConfigPath = moduleFederationConfigPathJS;
|
|
127
|
-
tsconfigPath =
|
|
128
|
-
tsconfigPath ??
|
|
129
|
-
[
|
|
130
|
-
(0, path_1.join)(projectRoot, 'tsconfig.app.json'),
|
|
131
|
-
(0, path_1.join)(projectRoot, 'tsconfig.json'),
|
|
132
|
-
(0, path_1.join)(workspaceRoot, 'tsconfig.json'),
|
|
133
|
-
(0, path_1.join)(workspaceRoot, 'tsconfig.base.json'),
|
|
134
|
-
].find((p) => (0, fs_1.existsSync)(p));
|
|
135
|
-
if (!tsconfigPath) {
|
|
136
|
-
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.`);
|
|
137
|
-
}
|
|
138
|
-
const fullTSconfigPath = tsconfigPath.startsWith(workspaceRoot)
|
|
139
|
-
? tsconfigPath
|
|
140
|
-
: (0, path_1.join)(workspaceRoot, tsconfigPath);
|
|
141
|
-
const isTsConfig = (0, fs_1.existsSync)(moduleFederationConfigPathTS);
|
|
142
|
-
if (isTsConfig) {
|
|
143
|
-
moduleFederationConfigPath = moduleFederationConfigPathTS;
|
|
144
|
-
}
|
|
145
|
-
try {
|
|
146
|
-
const config = isTsConfig
|
|
147
|
-
? (0, internal_1.loadTsFile)(moduleFederationConfigPath, fullTSconfigPath)
|
|
148
|
-
: require(moduleFederationConfigPath);
|
|
149
|
-
return config.default || config;
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
throw new Error(`Could not load ${moduleFederationConfigPath}. Was this project generated with "@nx/${pluginName}:host"?\nSee: https://nx.dev/concepts/more-concepts/faster-builds-with-module-federation`);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './share';
|
|
2
|
-
export * from './dependencies';
|
|
3
|
-
export * from './package-json';
|
|
4
|
-
export * from './remotes';
|
|
5
|
-
export * from './models';
|
|
6
|
-
export * from './normalize-project-name';
|
|
7
|
-
export * from './get-remotes-for-host';
|
|
8
|
-
export * from './parse-static-remotes-config';
|
|
9
|
-
export * from './port-utils';
|
|
10
|
-
export * from './start-remote-proxies';
|
|
11
|
-
export * from './start-ssr-remote-proxies';
|
package/dist/src/utils/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./share"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./dependencies"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./package-json"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./remotes"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./models"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./normalize-project-name"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./get-remotes-for-host"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./parse-static-remotes-config"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./port-utils"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./start-remote-proxies"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./start-ssr-remote-proxies"), exports);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isServeMode = isServeMode;
|
|
4
|
-
exports.childBuildEnv = childBuildEnv;
|
|
5
|
-
// v1 dev-server sets WEBPACK_SERVE on module load; v2 sets RSPACK_SERVE.
|
|
6
|
-
// rspack-cli imports the dev-server before loading the user config.
|
|
7
|
-
function isServeMode() {
|
|
8
|
-
return !!process.env['WEBPACK_SERVE'] || !!process.env['RSPACK_SERVE'];
|
|
9
|
-
}
|
|
10
|
-
function childBuildEnv() {
|
|
11
|
-
const { WEBPACK_SERVE, RSPACK_SERVE, ...rest } = process.env;
|
|
12
|
-
return {
|
|
13
|
-
...rest,
|
|
14
|
-
// Static remotes for a dev-server session are development builds.
|
|
15
|
-
// angular-rspack picks production when no serve signal is present, which
|
|
16
|
-
// would enforce bundle budgets and optimization on a dev workflow.
|
|
17
|
-
NGRS_CONFIG: rest.NGRS_CONFIG ?? 'development',
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { moduleFederationPlugin } from '@module-federation/enhanced';
|
|
2
|
-
import type { NormalModuleReplacementPlugin as RspackNormalModuleReplacementPlugin } from '@rspack/core';
|
|
3
|
-
export type ModuleFederationLibrary = {
|
|
4
|
-
type: string;
|
|
5
|
-
name: string;
|
|
6
|
-
};
|
|
7
|
-
export type WorkspaceLibrary = {
|
|
8
|
-
name: string;
|
|
9
|
-
root: string;
|
|
10
|
-
importKey: string | undefined;
|
|
11
|
-
};
|
|
12
|
-
export type SharedWorkspaceLibraryConfig = {
|
|
13
|
-
getAliases: () => Record<string, string>;
|
|
14
|
-
getLibraries: (projectRoot: string, eager?: boolean) => Record<string, SharedLibraryConfig>;
|
|
15
|
-
getReplacementPlugin: () => InstanceType<typeof RspackNormalModuleReplacementPlugin> | import('webpack').NormalModuleReplacementPlugin;
|
|
16
|
-
};
|
|
17
|
-
export type Remotes = Array<string | [remoteName: string, remoteUrl: string]>;
|
|
18
|
-
export interface SharedLibraryConfig {
|
|
19
|
-
singleton?: boolean;
|
|
20
|
-
strictVersion?: boolean;
|
|
21
|
-
requiredVersion?: false | string;
|
|
22
|
-
eager?: boolean;
|
|
23
|
-
}
|
|
24
|
-
export type SharedFunction = (libraryName: string, sharedConfig: SharedLibraryConfig) => undefined | false | SharedLibraryConfig;
|
|
25
|
-
export type AdditionalSharedConfig = Array<string | [libraryName: string, sharedConfig: SharedLibraryConfig] | {
|
|
26
|
-
libraryName: string;
|
|
27
|
-
sharedConfig: SharedLibraryConfig;
|
|
28
|
-
}>;
|
|
29
|
-
export interface ModuleFederationConfig {
|
|
30
|
-
name: string;
|
|
31
|
-
remotes?: Remotes;
|
|
32
|
-
library?: ModuleFederationLibrary;
|
|
33
|
-
exposes?: Record<string, string>;
|
|
34
|
-
shared?: SharedFunction;
|
|
35
|
-
additionalShared?: AdditionalSharedConfig;
|
|
36
|
-
/**
|
|
37
|
-
* `nxRuntimeLibraryControlPlugin` is a runtime module federation plugin to ensure
|
|
38
|
-
* that shared libraries are resolved from a remote with live reload capabilities.
|
|
39
|
-
* If you run into any issues with loading shared libraries, try disabling this option.
|
|
40
|
-
*/
|
|
41
|
-
disableNxRuntimeLibraryControlPlugin?: boolean;
|
|
42
|
-
}
|
|
43
|
-
export type NxModuleFederationConfigOverride = Omit<moduleFederationPlugin.ModuleFederationPluginOptions, 'exposes' | 'remotes' | 'name' | 'shared' | 'filename'>;
|
|
44
|
-
export type WorkspaceLibrarySecondaryEntryPoint = {
|
|
45
|
-
name: string;
|
|
46
|
-
path: string;
|
|
47
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
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 };
|
|
@@ -1,144 +0,0 @@
|
|
|
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. Undeclared defaults
|
|
32
|
-
// are dropped; a real project dependency still warns when its version is missing.
|
|
33
|
-
let npmPackagesList = dependencies.npmPackages;
|
|
34
|
-
if (defaultPackagesToShare.length > 0 || packagesToAvoid.length > 0) {
|
|
35
|
-
npmPackagesList = Array.from(new Set([
|
|
36
|
-
...(0, index_1.filterPackagesDeclaredInRootPackageJson)(defaultPackagesToShare),
|
|
37
|
-
...dependencies.npmPackages.filter((pkg) => !packagesToAvoid.includes(pkg)),
|
|
38
|
-
]));
|
|
39
|
-
}
|
|
40
|
-
const npmPackages = (0, index_1.sharePackages)(npmPackagesList);
|
|
41
|
-
// Remove packages to avoid from final config
|
|
42
|
-
for (const pkgName of packagesToAvoid) {
|
|
43
|
-
if (pkgName in npmPackages) {
|
|
44
|
-
delete npmPackages[pkgName];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const sharedDependencies = {
|
|
48
|
-
...sharedLibraries.getLibraries(project.root),
|
|
49
|
-
...npmPackages,
|
|
50
|
-
};
|
|
51
|
-
// Apply framework-specific eager packages
|
|
52
|
-
if (applyEagerPackages) {
|
|
53
|
-
applyEagerPackages(sharedDependencies, projectGraph, mfConfig.name);
|
|
54
|
-
}
|
|
55
|
-
(0, index_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
|
|
56
|
-
(0, index_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
|
|
57
|
-
// Map remotes
|
|
58
|
-
const mapRemotesFunction = options.isServer ? index_1.mapRemotesForSSR : index_1.mapRemotes;
|
|
59
|
-
let mappedRemotes = {};
|
|
60
|
-
if (mfConfig.remotes && mfConfig.remotes.length > 0) {
|
|
61
|
-
const determineRemoteUrlFn = options.determineRemoteUrl ||
|
|
62
|
-
createDefaultRemoteUrlResolver(options.isServer, remoteEntryExt);
|
|
63
|
-
mappedRemotes = mapRemotesFunction(mfConfig.remotes, remoteEntryExt, determineRemoteUrlFn, mapRemotesExpose);
|
|
64
|
-
}
|
|
65
|
-
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
|
66
|
-
}
|
|
67
|
-
// Cache for parsed static remotes env variable
|
|
68
|
-
let cachedStaticRemotesEnv = undefined;
|
|
69
|
-
let cachedStaticRemotesMap = undefined;
|
|
70
|
-
/**
|
|
71
|
-
* Gets static remotes from env with caching.
|
|
72
|
-
* Invalidates cache if env variable changes.
|
|
73
|
-
*/
|
|
74
|
-
function getStaticRemotesFromEnv() {
|
|
75
|
-
const currentEnv = process.env.NX_MF_DEV_SERVER_STATIC_REMOTES;
|
|
76
|
-
if (currentEnv !== cachedStaticRemotesEnv) {
|
|
77
|
-
cachedStaticRemotesEnv = currentEnv;
|
|
78
|
-
cachedStaticRemotesMap = currentEnv ? JSON.parse(currentEnv) : undefined;
|
|
79
|
-
}
|
|
80
|
-
return cachedStaticRemotesMap;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Creates a default remote URL resolver function.
|
|
84
|
-
* This is extracted to avoid code duplication across bundler utils.
|
|
85
|
-
*/
|
|
86
|
-
function createDefaultRemoteUrlResolver(isServer = false, remoteEntryExt = 'js') {
|
|
87
|
-
const { readCachedProjectConfiguration } = require('@nx/devkit/internal');
|
|
88
|
-
const target = 'serve';
|
|
89
|
-
const remoteEntry = isServer
|
|
90
|
-
? 'server/remoteEntry.js'
|
|
91
|
-
: `remoteEntry.${remoteEntryExt}`;
|
|
92
|
-
return function (remote) {
|
|
93
|
-
const mappedStaticRemotesFromEnv = getStaticRemotesFromEnv();
|
|
94
|
-
if (mappedStaticRemotesFromEnv && mappedStaticRemotesFromEnv[remote]) {
|
|
95
|
-
return `${mappedStaticRemotesFromEnv[remote]}/${remoteEntry}`;
|
|
96
|
-
}
|
|
97
|
-
let remoteConfiguration = null;
|
|
98
|
-
try {
|
|
99
|
-
remoteConfiguration = readCachedProjectConfiguration(remote);
|
|
100
|
-
}
|
|
101
|
-
catch (e) {
|
|
102
|
-
throw new Error(`Cannot find remote "${remote}". Check that the remote name is correct in your module federation config file.\n`);
|
|
103
|
-
}
|
|
104
|
-
const serveTarget = remoteConfiguration?.targets?.[target];
|
|
105
|
-
if (!serveTarget) {
|
|
106
|
-
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "serve" target.\n` +
|
|
107
|
-
`You can also use the tuple syntax in your config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
108
|
-
}
|
|
109
|
-
const host = serveTarget.options?.host ??
|
|
110
|
-
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
|
111
|
-
const port = serveTarget.options?.port ?? 4201;
|
|
112
|
-
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Async version - tries cached graph first, falls back to creating new one.
|
|
117
|
-
* Used by webpack and angular async configs.
|
|
118
|
-
*/
|
|
119
|
-
async function getModuleFederationConfigAsync(mfConfig, options = {}, frameworkConfig) {
|
|
120
|
-
let projectGraph;
|
|
121
|
-
try {
|
|
122
|
-
projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
126
|
-
}
|
|
127
|
-
return buildModuleFederationConfig(mfConfig, options, frameworkConfig, projectGraph);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Sync version - only uses cached graph.
|
|
131
|
-
* Used by rspack and angular sync configs.
|
|
132
|
-
*/
|
|
133
|
-
function getModuleFederationConfigSync(mfConfig, options = {}, frameworkConfig) {
|
|
134
|
-
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
135
|
-
return buildModuleFederationConfig(mfConfig, options, frameworkConfig, projectGraph);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Clears the static remotes env cache.
|
|
139
|
-
* Useful for testing or when the env variable changes.
|
|
140
|
-
*/
|
|
141
|
-
function clearStaticRemotesEnvCache() {
|
|
142
|
-
cachedStaticRemotesEnv = undefined;
|
|
143
|
-
cachedStaticRemotesMap = undefined;
|
|
144
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function normalizeProjectName(name: string): string;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeProjectName = normalizeProjectName;
|
|
4
|
-
// normalize to allow only JavaScript var valid names
|
|
5
|
-
function normalizeProjectName(name) {
|
|
6
|
-
// Replace invalid starting characters with '_'
|
|
7
|
-
const normalized = name.replace(/^[^a-zA-Z_$]/, '_');
|
|
8
|
-
// Replace invalid subsequent characters with '_'
|
|
9
|
-
return normalized.replace(/[^a-zA-Z0-9_$]/g, '_');
|
|
10
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readRootPackageJson = readRootPackageJson;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
function readRootPackageJson() {
|
|
7
|
-
const pkgJsonPath = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'package.json');
|
|
8
|
-
if (!(0, fs_1.existsSync)(pkgJsonPath)) {
|
|
9
|
-
throw new Error('NX MF: Could not find root package.json to determine dependency versions.');
|
|
10
|
-
}
|
|
11
|
-
return (0, devkit_1.readJsonFile)(pkgJsonPath);
|
|
12
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
export type StaticRemoteConfig = {
|
|
3
|
-
basePath: string;
|
|
4
|
-
outputPath: string;
|
|
5
|
-
urlSegment: string;
|
|
6
|
-
port: number;
|
|
7
|
-
};
|
|
8
|
-
export type StaticRemotesConfig = {
|
|
9
|
-
remotes: string[];
|
|
10
|
-
config: Record<string, StaticRemoteConfig> | undefined;
|
|
11
|
-
};
|
|
12
|
-
export declare function parseStaticRemotesConfig(staticRemotes: string[] | undefined, context: ExecutorContext): StaticRemotesConfig;
|
|
13
|
-
export declare function parseStaticSsrRemotesConfig(staticRemotes: string[] | undefined, context: ExecutorContext): StaticRemotesConfig;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseStaticRemotesConfig = parseStaticRemotesConfig;
|
|
4
|
-
exports.parseStaticSsrRemotesConfig = parseStaticSsrRemotesConfig;
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const internal_1 = require("@nx/devkit/internal");
|
|
8
|
-
function parseStaticRemotesConfig(staticRemotes, context) {
|
|
9
|
-
if (!staticRemotes?.length) {
|
|
10
|
-
return { remotes: [], config: undefined };
|
|
11
|
-
}
|
|
12
|
-
const config = {};
|
|
13
|
-
for (const app of staticRemotes) {
|
|
14
|
-
const projectGraph = context.projectGraph;
|
|
15
|
-
const projectRoot = projectGraph.nodes[app].data.root;
|
|
16
|
-
let outputPath = (0, internal_1.interpolate)(projectGraph.nodes[app].data.targets?.['build']?.options?.outputPath ??
|
|
17
|
-
projectGraph.nodes[app].data.targets?.['build']?.outputs?.[0] ??
|
|
18
|
-
`${context.root}/${projectGraph.nodes[app].data.root}/dist`, {
|
|
19
|
-
projectName: projectGraph.nodes[app].data.name,
|
|
20
|
-
projectRoot,
|
|
21
|
-
workspaceRoot: context.root,
|
|
22
|
-
});
|
|
23
|
-
if (outputPath.startsWith(projectRoot)) {
|
|
24
|
-
outputPath = (0, devkit_1.joinPathFragments)(context.root, outputPath);
|
|
25
|
-
}
|
|
26
|
-
const basePath = ['', '/', '.'].some((p) => (0, path_1.dirname)(outputPath) === p)
|
|
27
|
-
? outputPath
|
|
28
|
-
: (0, path_1.dirname)(outputPath); // dist || dist/checkout -> dist
|
|
29
|
-
const urlSegment = app;
|
|
30
|
-
const port = context.projectGraph.nodes[app].data.targets['serve'].options.port;
|
|
31
|
-
config[app] = { basePath, outputPath, urlSegment, port };
|
|
32
|
-
}
|
|
33
|
-
return { remotes: staticRemotes, config };
|
|
34
|
-
}
|
|
35
|
-
function parseStaticSsrRemotesConfig(staticRemotes, context) {
|
|
36
|
-
if (!staticRemotes?.length) {
|
|
37
|
-
return { remotes: [], config: undefined };
|
|
38
|
-
}
|
|
39
|
-
const config = {};
|
|
40
|
-
for (const app of staticRemotes) {
|
|
41
|
-
const projectGraph = context.projectGraph;
|
|
42
|
-
const projectRoot = projectGraph.nodes[app].data.root;
|
|
43
|
-
let outputPath = (0, internal_1.interpolate)(projectGraph.nodes[app].data.targets?.['build']?.options?.outputPath ??
|
|
44
|
-
projectGraph.nodes[app].data.targets?.['build']?.outputs?.[0] ??
|
|
45
|
-
`${context.root}/${projectGraph.nodes[app].data.root}/dist`, {
|
|
46
|
-
projectName: projectGraph.nodes[app].data.name,
|
|
47
|
-
projectRoot,
|
|
48
|
-
workspaceRoot: context.root,
|
|
49
|
-
});
|
|
50
|
-
if (outputPath.startsWith(projectRoot)) {
|
|
51
|
-
outputPath = (0, devkit_1.joinPathFragments)(context.root, outputPath);
|
|
52
|
-
}
|
|
53
|
-
outputPath = (0, path_1.dirname)(outputPath);
|
|
54
|
-
const basePath = ['', '/', '.'].some((p) => (0, path_1.dirname)(outputPath) === p)
|
|
55
|
-
? outputPath
|
|
56
|
-
: (0, path_1.dirname)(outputPath); // dist || dist/checkout -> dist
|
|
57
|
-
const urlSegment = app;
|
|
58
|
-
const port = context.projectGraph.nodes[app].data.targets['serve'].options.port;
|
|
59
|
-
config[app] = { basePath, outputPath, urlSegment, port };
|
|
60
|
-
}
|
|
61
|
-
return { remotes: staticRemotes, config };
|
|
62
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const runtimeStore = {
|
|
4
|
-
sharedPackagesFromDev: {},
|
|
5
|
-
};
|
|
6
|
-
if (process.env.NX_MF_DEV_REMOTES) {
|
|
7
|
-
// process.env.NX_MF_DEV_REMOTES is replaced by an array value via DefinePlugin, even though the original value is a stringified array.
|
|
8
|
-
runtimeStore.devRemotes = process.env
|
|
9
|
-
.NX_MF_DEV_REMOTES;
|
|
10
|
-
}
|
|
11
|
-
const nxRuntimeLibraryControlPlugin = function () {
|
|
12
|
-
return {
|
|
13
|
-
name: 'nx-runtime-library-control-plugin',
|
|
14
|
-
beforeInit(args) {
|
|
15
|
-
runtimeStore.name = args.options.name;
|
|
16
|
-
return args;
|
|
17
|
-
},
|
|
18
|
-
resolveShare: (args) => {
|
|
19
|
-
const { shareScopeMap, scope, pkgName, version, GlobalFederation } = args;
|
|
20
|
-
const originalResolver = args.resolver;
|
|
21
|
-
args.resolver = function () {
|
|
22
|
-
if (!runtimeStore.sharedPackagesFromDev[pkgName]) {
|
|
23
|
-
if (!GlobalFederation.__INSTANCES__) {
|
|
24
|
-
return originalResolver();
|
|
25
|
-
}
|
|
26
|
-
else if (!runtimeStore.devRemotes) {
|
|
27
|
-
return originalResolver();
|
|
28
|
-
}
|
|
29
|
-
const devRemoteInstanceToUse = GlobalFederation.__INSTANCES__.find((instance) => instance.options.shared[pkgName] &&
|
|
30
|
-
runtimeStore.devRemotes.find((dr) => instance.name === dr));
|
|
31
|
-
if (!devRemoteInstanceToUse) {
|
|
32
|
-
return originalResolver();
|
|
33
|
-
}
|
|
34
|
-
runtimeStore.sharedPackagesFromDev[pkgName] =
|
|
35
|
-
devRemoteInstanceToUse.name;
|
|
36
|
-
}
|
|
37
|
-
const remoteInstanceName = runtimeStore.sharedPackagesFromDev[pkgName];
|
|
38
|
-
const remoteInstance = GlobalFederation.__INSTANCES__.find((instance) => instance.name === remoteInstanceName);
|
|
39
|
-
try {
|
|
40
|
-
const remotePkgInfo = remoteInstance.options.shared[pkgName].find((shared) => shared.from === remoteInstanceName);
|
|
41
|
-
remotePkgInfo.useIn.push(runtimeStore.name);
|
|
42
|
-
remotePkgInfo.useIn = Array.from(new Set(remotePkgInfo.useIn));
|
|
43
|
-
shareScopeMap[scope][pkgName][version] = remotePkgInfo;
|
|
44
|
-
return { shared: remotePkgInfo, useTreesShaking: false };
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return originalResolver();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
return args;
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
exports.default = nxRuntimeLibraryControlPlugin;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if a port is in use by attempting to bind to it. Binding is local and
|
|
3
|
-
* resolves immediately, so unlike a connection-based check it never stalls on
|
|
4
|
-
* the OS TCP connect timeout when `localhost` resolves to an unreachable address
|
|
5
|
-
* (e.g. IPv6 `::1`) -- the cause of the `nx serve` hang in #33909.
|
|
6
|
-
*/
|
|
7
|
-
export declare function isPortInUse(port: number, host?: string): Promise<boolean>;
|