@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,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NxModuleFederationDevServerPlugin = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const is_serve_mode_1 = require("../../../utils/is-serve-mode");
|
|
6
|
-
const pc = tslib_1.__importStar(require("picocolors"));
|
|
7
|
-
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
|
-
const PLUGIN_NAME = 'NxModuleFederationDevServerPlugin';
|
|
12
|
-
class NxModuleFederationDevServerPlugin {
|
|
13
|
-
constructor(_options) {
|
|
14
|
-
this._options = _options;
|
|
15
|
-
this.nxBin = require.resolve('nx/bin/nx');
|
|
16
|
-
this._options.devServerConfig ??= {
|
|
17
|
-
host: 'localhost',
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
apply(compiler) {
|
|
21
|
-
if (!(0, is_serve_mode_1.isServeMode)()) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
let initialized = false;
|
|
25
|
-
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, async (params, callback) => {
|
|
26
|
-
if (!initialized) {
|
|
27
|
-
initialized = true;
|
|
28
|
-
const staticRemotesConfig = await this.setup();
|
|
29
|
-
devkit_1.logger.info(`NX Starting module federation dev-server for ${pc.bold(this._options.config.name)} with ${Object.keys(staticRemotesConfig).length} remotes`);
|
|
30
|
-
const mappedLocationOfRemotes = await (0, utils_1.buildStaticRemotes)(staticRemotesConfig, this._options.devServerConfig, this.nxBin);
|
|
31
|
-
(0, utils_1.startStaticRemotesFileServer)(staticRemotesConfig, devkit_1.workspaceRoot, this._options.devServerConfig.staticRemotesPort);
|
|
32
|
-
await (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
33
|
-
pathToCert: this._options.devServerConfig.sslCert,
|
|
34
|
-
pathToKey: this._options.devServerConfig.sslKey,
|
|
35
|
-
}, false, this._options.devServerConfig.host);
|
|
36
|
-
new compiler.rspack.DefinePlugin({
|
|
37
|
-
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
38
|
-
}).apply(compiler);
|
|
39
|
-
}
|
|
40
|
-
callback();
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async setup() {
|
|
44
|
-
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
45
|
-
const { projects: workspaceProjects } = (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
|
|
46
|
-
const project = workspaceProjects[this._options.config.name];
|
|
47
|
-
if (!this._options.devServerConfig.pathToManifestFile) {
|
|
48
|
-
this._options.devServerConfig.pathToManifestFile =
|
|
49
|
-
(0, utils_1.getDynamicMfManifestFile)(project, devkit_1.workspaceRoot);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const userPathToManifestFile = this._options.devServerConfig.pathToManifestFile.startsWith(devkit_1.workspaceRoot)
|
|
53
|
-
? this._options.devServerConfig.pathToManifestFile
|
|
54
|
-
: (0, path_1.join)(devkit_1.workspaceRoot, this._options.devServerConfig.pathToManifestFile);
|
|
55
|
-
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
|
56
|
-
throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
|
|
57
|
-
}
|
|
58
|
-
else if ((0, path_1.extname)(this._options.devServerConfig.pathToManifestFile) !== '.json') {
|
|
59
|
-
throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
|
|
60
|
-
}
|
|
61
|
-
this._options.devServerConfig.pathToManifestFile = userPathToManifestFile;
|
|
62
|
-
}
|
|
63
|
-
const { remotes, staticRemotePort } = (0, utils_1.getRemotes)(this._options.config, projectGraph, this._options.devServerConfig.pathToManifestFile);
|
|
64
|
-
this._options.devServerConfig.staticRemotesPort ??= staticRemotePort;
|
|
65
|
-
const remotesConfig = (0, utils_1.parseRemotesConfig)(remotes, devkit_1.workspaceRoot, projectGraph);
|
|
66
|
-
const staticRemotesConfig = await (0, utils_1.getStaticRemotes)(remotesConfig.config ?? {}, this._options.devServerConfig?.devRemoteFindOptions, this._options.devServerConfig?.host);
|
|
67
|
-
const devRemotes = remotes.filter((r) => !staticRemotesConfig[r]);
|
|
68
|
-
process.env.NX_MF_DEV_REMOTES = JSON.stringify([
|
|
69
|
-
...(devRemotes.length > 0 ? devRemotes : []),
|
|
70
|
-
project.name,
|
|
71
|
-
]);
|
|
72
|
-
return staticRemotesConfig ?? {};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.NxModuleFederationDevServerPlugin = NxModuleFederationDevServerPlugin;
|
package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-plugin.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
-
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../../../utils/models';
|
|
3
|
-
export declare class NxModuleFederationPlugin implements RspackPluginInstance {
|
|
4
|
-
private _options;
|
|
5
|
-
private configOverride?;
|
|
6
|
-
constructor(_options: {
|
|
7
|
-
config: ModuleFederationConfig;
|
|
8
|
-
isServer?: boolean;
|
|
9
|
-
}, configOverride?: NxModuleFederationConfigOverride);
|
|
10
|
-
apply(compiler: Compiler): void;
|
|
11
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NxModuleFederationPlugin = void 0;
|
|
4
|
-
const utils_1 = require("../../../with-module-federation/angular/utils");
|
|
5
|
-
const utils_2 = require("../../../utils");
|
|
6
|
-
const rspack_version_1 = require("../../../utils/rspack-version");
|
|
7
|
-
const is_serve_mode_1 = require("../../../utils/is-serve-mode");
|
|
8
|
-
const devkit_1 = require("@nx/devkit");
|
|
9
|
-
class NxModuleFederationPlugin {
|
|
10
|
-
constructor(_options, configOverride) {
|
|
11
|
-
this._options = _options;
|
|
12
|
-
this.configOverride = configOverride;
|
|
13
|
-
}
|
|
14
|
-
apply(compiler) {
|
|
15
|
-
if (global.NX_GRAPH_CREATION) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
// This is required to ensure Module Federation will build the project correctly
|
|
19
|
-
compiler.options.optimization ??= {};
|
|
20
|
-
compiler.options.optimization.runtimeChunk =
|
|
21
|
-
(0, is_serve_mode_1.isServeMode)() && !this._options.config.exposes
|
|
22
|
-
? (compiler.options.optimization?.runtimeChunk ?? undefined)
|
|
23
|
-
: false;
|
|
24
|
-
if (compiler.options.optimization.splitChunks) {
|
|
25
|
-
compiler.options.optimization.splitChunks.cacheGroups ??= {};
|
|
26
|
-
compiler.options.optimization.splitChunks.cacheGroups.default = false;
|
|
27
|
-
compiler.options.optimization.splitChunks.cacheGroups.common = false;
|
|
28
|
-
}
|
|
29
|
-
compiler.options.output.publicPath = !compiler.options.output.publicPath
|
|
30
|
-
? 'auto'
|
|
31
|
-
: compiler.options.output.publicPath;
|
|
32
|
-
compiler.options.output.uniqueName = this._options.config.name;
|
|
33
|
-
// Ensure workspace root is in resolve.modules so that expose paths
|
|
34
|
-
// like "apps/remote/src/..." resolve correctly without baseUrl.
|
|
35
|
-
compiler.options.resolve ??= {};
|
|
36
|
-
compiler.options.resolve.modules = [
|
|
37
|
-
...(compiler.options.resolve.modules ?? ['node_modules']),
|
|
38
|
-
devkit_1.workspaceRoot,
|
|
39
|
-
];
|
|
40
|
-
if (this._options.isServer) {
|
|
41
|
-
compiler.options.target = 'async-node';
|
|
42
|
-
compiler.options.output.library ??= {
|
|
43
|
-
type: 'commonjs-module',
|
|
44
|
-
};
|
|
45
|
-
compiler.options.output.library.type = 'commonjs-module';
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
// Required so remoteEntry.js loads as a module, not a classic script.
|
|
49
|
-
// v2 folded experiments.outputModule into output.module.
|
|
50
|
-
compiler.options.output.module = true;
|
|
51
|
-
if (!(0, rspack_version_1.isRspackV2)(compiler)) {
|
|
52
|
-
compiler.options.experiments ??= {};
|
|
53
|
-
compiler.options.experiments.outputModule = true;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const config = (0, utils_1.getModuleFederationConfigSync)(this._options.config, {
|
|
57
|
-
isServer: this._options.isServer,
|
|
58
|
-
}, true);
|
|
59
|
-
const sharedLibraries = config.sharedLibraries;
|
|
60
|
-
const sharedDependencies = config.sharedDependencies;
|
|
61
|
-
const mappedRemotes = config.mappedRemotes;
|
|
62
|
-
const runtimePlugins = [];
|
|
63
|
-
if (this.configOverride?.runtimePlugins) {
|
|
64
|
-
runtimePlugins.push(...(this.configOverride.runtimePlugins ?? []));
|
|
65
|
-
}
|
|
66
|
-
if (this._options.isServer) {
|
|
67
|
-
runtimePlugins.push(require.resolve('@module-federation/node/runtimePlugin'));
|
|
68
|
-
}
|
|
69
|
-
new (require('@module-federation/enhanced/rspack').ModuleFederationPlugin)({
|
|
70
|
-
name: (0, utils_2.normalizeProjectName)(this._options.config.name),
|
|
71
|
-
filename: 'remoteEntry.js',
|
|
72
|
-
exposes: this._options.config.exposes,
|
|
73
|
-
remotes: mappedRemotes,
|
|
74
|
-
shared: {
|
|
75
|
-
...(sharedDependencies ?? {}),
|
|
76
|
-
},
|
|
77
|
-
...(this._options.isServer
|
|
78
|
-
? {
|
|
79
|
-
library: {
|
|
80
|
-
type: 'commonjs-module',
|
|
81
|
-
},
|
|
82
|
-
remoteType: 'script',
|
|
83
|
-
}
|
|
84
|
-
: { library: { type: 'module' } }),
|
|
85
|
-
...(this.configOverride ? this.configOverride : {}),
|
|
86
|
-
runtimePlugins,
|
|
87
|
-
}).apply(compiler);
|
|
88
|
-
if (sharedLibraries) {
|
|
89
|
-
sharedLibraries.getReplacementPlugin().apply(compiler);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.NxModuleFederationPlugin = NxModuleFederationPlugin;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
-
import { ModuleFederationConfig } from '../../../utils/models';
|
|
3
|
-
import { NxModuleFederationDevServerConfig } from '../../models';
|
|
4
|
-
export declare class NxModuleFederationSSRDevServerPlugin implements RspackPluginInstance {
|
|
5
|
-
private _options;
|
|
6
|
-
private devServerProcess;
|
|
7
|
-
private nxBin;
|
|
8
|
-
constructor(_options: {
|
|
9
|
-
config: ModuleFederationConfig;
|
|
10
|
-
devServerConfig?: NxModuleFederationDevServerConfig;
|
|
11
|
-
});
|
|
12
|
-
apply(compiler: Compiler): void;
|
|
13
|
-
private startServer;
|
|
14
|
-
private setup;
|
|
15
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NxModuleFederationSSRDevServerPlugin = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const is_serve_mode_1 = require("../../../utils/is-serve-mode");
|
|
6
|
-
const pc = tslib_1.__importStar(require("picocolors"));
|
|
7
|
-
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
|
-
const node_child_process_1 = require("node:child_process");
|
|
12
|
-
const PLUGIN_NAME = 'NxModuleFederationSSRDevServerPlugin';
|
|
13
|
-
class NxModuleFederationSSRDevServerPlugin {
|
|
14
|
-
constructor(_options) {
|
|
15
|
-
this._options = _options;
|
|
16
|
-
this.nxBin = require.resolve('nx/bin/nx');
|
|
17
|
-
this._options.devServerConfig ??= {
|
|
18
|
-
host: 'localhost',
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
apply(compiler) {
|
|
22
|
-
if (!(0, is_serve_mode_1.isServeMode)()) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
compiler.hooks.watchRun.tapAsync(PLUGIN_NAME, async (compiler, callback) => {
|
|
26
|
-
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, async (params, callback) => {
|
|
27
|
-
const staticRemotesConfig = await this.setup(compiler);
|
|
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
|
-
const mappedLocationOfRemotes = await (0, utils_1.buildStaticRemotes)(staticRemotesConfig, this._options.devServerConfig, this.nxBin);
|
|
30
|
-
(0, utils_1.startStaticRemotesFileServer)(staticRemotesConfig, devkit_1.workspaceRoot, this._options.devServerConfig.staticRemotesPort);
|
|
31
|
-
await (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
32
|
-
pathToCert: this._options.devServerConfig.sslCert,
|
|
33
|
-
pathToKey: this._options.devServerConfig.sslKey,
|
|
34
|
-
}, true, this._options.devServerConfig.host);
|
|
35
|
-
new compiler.rspack.DefinePlugin({
|
|
36
|
-
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
37
|
-
}).apply(compiler);
|
|
38
|
-
await this.startServer(compiler);
|
|
39
|
-
callback();
|
|
40
|
-
});
|
|
41
|
-
callback();
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
async startServer(compiler) {
|
|
45
|
-
compiler.hooks.done.tapAsync(PLUGIN_NAME, async (_, callback) => {
|
|
46
|
-
const serverPath = (0, path_1.join)(compiler.options.output.path, compiler.options.output.filename ?? 'server.js');
|
|
47
|
-
if (this.devServerProcess) {
|
|
48
|
-
await new Promise((res) => {
|
|
49
|
-
this.devServerProcess.on('exit', () => {
|
|
50
|
-
res();
|
|
51
|
-
});
|
|
52
|
-
this.devServerProcess.kill('SIGKILL');
|
|
53
|
-
this.devServerProcess = undefined;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (!(0, fs_1.existsSync)(serverPath)) {
|
|
57
|
-
for (let retries = 0; retries < 10; retries++) {
|
|
58
|
-
await new Promise((res) => setTimeout(res, 200));
|
|
59
|
-
if ((0, fs_1.existsSync)(serverPath)) {
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (!(0, fs_1.existsSync)(serverPath)) {
|
|
64
|
-
throw new Error(`Could not find server bundle at ${serverPath}.`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
this.devServerProcess = (0, node_child_process_1.fork)(serverPath);
|
|
68
|
-
process.on('exit', () => {
|
|
69
|
-
this.devServerProcess?.kill('SIGKILL');
|
|
70
|
-
});
|
|
71
|
-
process.on('SIGINT', () => {
|
|
72
|
-
this.devServerProcess?.kill('SIGKILL');
|
|
73
|
-
});
|
|
74
|
-
callback();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
async setup(compiler) {
|
|
78
|
-
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
79
|
-
const { projects: workspaceProjects } = (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
|
|
80
|
-
const project = workspaceProjects[this._options.config.name];
|
|
81
|
-
if (!this._options.devServerConfig.pathToManifestFile) {
|
|
82
|
-
this._options.devServerConfig.pathToManifestFile =
|
|
83
|
-
(0, utils_1.getDynamicMfManifestFile)(project, devkit_1.workspaceRoot);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
const userPathToManifestFile = (0, path_1.join)(devkit_1.workspaceRoot, this._options.devServerConfig.pathToManifestFile);
|
|
87
|
-
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
|
88
|
-
throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
|
|
89
|
-
}
|
|
90
|
-
else if ((0, path_1.extname)(this._options.devServerConfig.pathToManifestFile) !== '.json') {
|
|
91
|
-
throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
|
|
92
|
-
}
|
|
93
|
-
this._options.devServerConfig.pathToManifestFile = userPathToManifestFile;
|
|
94
|
-
}
|
|
95
|
-
const { remotes, staticRemotePort } = (0, utils_1.getRemotes)(this._options.config, projectGraph, this._options.devServerConfig.pathToManifestFile);
|
|
96
|
-
this._options.devServerConfig.staticRemotesPort ??= staticRemotePort;
|
|
97
|
-
const remotesConfig = (0, utils_1.parseRemotesConfig)(remotes, devkit_1.workspaceRoot, projectGraph, true);
|
|
98
|
-
const staticRemotesConfig = await (0, utils_1.getStaticRemotes)(remotesConfig.config ?? {});
|
|
99
|
-
const devRemotes = remotes.filter((r) => !staticRemotesConfig[r]);
|
|
100
|
-
process.env.NX_MF_DEV_REMOTES = JSON.stringify([
|
|
101
|
-
...(devRemotes.length > 0 ? devRemotes : []),
|
|
102
|
-
project.name,
|
|
103
|
-
]);
|
|
104
|
-
return staticRemotesConfig ?? {};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.NxModuleFederationSSRDevServerPlugin = NxModuleFederationSSRDevServerPlugin;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
-
import { ModuleFederationConfig } from '../../../utils/models';
|
|
3
|
-
import { NxModuleFederationDevServerConfig } from '../../models';
|
|
4
|
-
export declare class NxModuleFederationDevServerPlugin implements RspackPluginInstance {
|
|
5
|
-
private _options;
|
|
6
|
-
private nxBin;
|
|
7
|
-
constructor(_options: {
|
|
8
|
-
config: ModuleFederationConfig;
|
|
9
|
-
devServerConfig?: NxModuleFederationDevServerConfig;
|
|
10
|
-
});
|
|
11
|
-
apply(compiler: Compiler): void;
|
|
12
|
-
private setup;
|
|
13
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NxModuleFederationDevServerPlugin = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const is_serve_mode_1 = require("../../../utils/is-serve-mode");
|
|
6
|
-
const pc = tslib_1.__importStar(require("picocolors"));
|
|
7
|
-
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
|
-
const PLUGIN_NAME = 'NxModuleFederationDevServerPlugin';
|
|
12
|
-
class NxModuleFederationDevServerPlugin {
|
|
13
|
-
constructor(_options) {
|
|
14
|
-
this._options = _options;
|
|
15
|
-
this.nxBin = require.resolve('nx/bin/nx');
|
|
16
|
-
this._options.devServerConfig ??= {
|
|
17
|
-
host: 'localhost',
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
apply(compiler) {
|
|
21
|
-
if (!(0, is_serve_mode_1.isServeMode)()) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
let initialized = false;
|
|
25
|
-
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, async (params, callback) => {
|
|
26
|
-
if (!initialized) {
|
|
27
|
-
initialized = true;
|
|
28
|
-
const staticRemotesConfig = await this.setup();
|
|
29
|
-
devkit_1.logger.info(`NX Starting module federation dev-server for ${pc.bold(this._options.config.name)} with ${Object.keys(staticRemotesConfig).length} remotes`);
|
|
30
|
-
const mappedLocationOfRemotes = await (0, utils_1.buildStaticRemotes)(staticRemotesConfig, this._options.devServerConfig, this.nxBin);
|
|
31
|
-
(0, utils_1.startStaticRemotesFileServer)(staticRemotesConfig, devkit_1.workspaceRoot, this._options.devServerConfig.staticRemotesPort);
|
|
32
|
-
await (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
33
|
-
pathToCert: this._options.devServerConfig.sslCert,
|
|
34
|
-
pathToKey: this._options.devServerConfig.sslKey,
|
|
35
|
-
}, false, this._options.devServerConfig.host);
|
|
36
|
-
new compiler.rspack.DefinePlugin({
|
|
37
|
-
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
38
|
-
}).apply(compiler);
|
|
39
|
-
}
|
|
40
|
-
callback();
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async setup() {
|
|
44
|
-
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
45
|
-
const { projects: workspaceProjects } = (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
|
|
46
|
-
const project = workspaceProjects[this._options.config.name];
|
|
47
|
-
if (!this._options.devServerConfig.pathToManifestFile) {
|
|
48
|
-
this._options.devServerConfig.pathToManifestFile =
|
|
49
|
-
(0, utils_1.getDynamicMfManifestFile)(project, devkit_1.workspaceRoot);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const userPathToManifestFile = this._options.devServerConfig.pathToManifestFile.startsWith(devkit_1.workspaceRoot)
|
|
53
|
-
? this._options.devServerConfig.pathToManifestFile
|
|
54
|
-
: (0, path_1.join)(devkit_1.workspaceRoot, this._options.devServerConfig.pathToManifestFile);
|
|
55
|
-
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
|
56
|
-
throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
|
|
57
|
-
}
|
|
58
|
-
else if ((0, path_1.extname)(this._options.devServerConfig.pathToManifestFile) !== '.json') {
|
|
59
|
-
throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
|
|
60
|
-
}
|
|
61
|
-
this._options.devServerConfig.pathToManifestFile = userPathToManifestFile;
|
|
62
|
-
}
|
|
63
|
-
const { remotes, staticRemotePort } = (0, utils_1.getRemotes)(this._options.config, projectGraph, this._options.devServerConfig.pathToManifestFile);
|
|
64
|
-
this._options.devServerConfig.staticRemotesPort ??= staticRemotePort;
|
|
65
|
-
const remotesConfig = (0, utils_1.parseRemotesConfig)(remotes, devkit_1.workspaceRoot, projectGraph);
|
|
66
|
-
const staticRemotesConfig = await (0, utils_1.getStaticRemotes)(remotesConfig.config ?? {}, this._options.devServerConfig?.devRemoteFindOptions, this._options.devServerConfig?.host);
|
|
67
|
-
const devRemotes = remotes.filter((r) => !staticRemotesConfig[r]);
|
|
68
|
-
process.env.NX_MF_DEV_REMOTES = JSON.stringify([
|
|
69
|
-
...(devRemotes.length > 0 ? devRemotes : []),
|
|
70
|
-
project.name,
|
|
71
|
-
]);
|
|
72
|
-
return staticRemotesConfig ?? {};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.NxModuleFederationDevServerPlugin = NxModuleFederationDevServerPlugin;
|
package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-plugin.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
-
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../../../utils/models';
|
|
3
|
-
export declare class NxModuleFederationPlugin implements RspackPluginInstance {
|
|
4
|
-
private _options;
|
|
5
|
-
private configOverride?;
|
|
6
|
-
constructor(_options: {
|
|
7
|
-
config: ModuleFederationConfig;
|
|
8
|
-
isServer?: boolean;
|
|
9
|
-
}, configOverride?: NxModuleFederationConfigOverride);
|
|
10
|
-
apply(compiler: Compiler): void;
|
|
11
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NxModuleFederationPlugin = void 0;
|
|
4
|
-
const utils_1 = require("../../../with-module-federation/rspack/utils");
|
|
5
|
-
const utils_2 = require("../../../utils");
|
|
6
|
-
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
class NxModuleFederationPlugin {
|
|
8
|
-
constructor(_options, configOverride) {
|
|
9
|
-
this._options = _options;
|
|
10
|
-
this.configOverride = configOverride;
|
|
11
|
-
}
|
|
12
|
-
apply(compiler) {
|
|
13
|
-
if (global.NX_GRAPH_CREATION) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
// This is required to ensure Module Federation will build the project correctly
|
|
17
|
-
compiler.options.optimization ??= {};
|
|
18
|
-
compiler.options.optimization.runtimeChunk = false;
|
|
19
|
-
if (compiler.options.optimization.splitChunks) {
|
|
20
|
-
compiler.options.optimization.splitChunks.cacheGroups ??= {};
|
|
21
|
-
compiler.options.optimization.splitChunks.cacheGroups.default = false;
|
|
22
|
-
compiler.options.optimization.splitChunks.cacheGroups.common = false;
|
|
23
|
-
}
|
|
24
|
-
compiler.options.output.uniqueName = this._options.config.name;
|
|
25
|
-
// Ensure workspace root is in resolve.modules so that expose paths
|
|
26
|
-
// like "apps/remote/src/..." resolve correctly without baseUrl.
|
|
27
|
-
compiler.options.resolve ??= {};
|
|
28
|
-
compiler.options.resolve.modules = [
|
|
29
|
-
...(compiler.options.resolve.modules ?? ['node_modules']),
|
|
30
|
-
devkit_1.workspaceRoot,
|
|
31
|
-
];
|
|
32
|
-
if (compiler.options.output.scriptType === 'module') {
|
|
33
|
-
compiler.options.output.scriptType = undefined;
|
|
34
|
-
compiler.options.output.module = undefined;
|
|
35
|
-
}
|
|
36
|
-
if (this._options.isServer) {
|
|
37
|
-
compiler.options.target = 'async-node';
|
|
38
|
-
compiler.options.output.library ??= {
|
|
39
|
-
type: 'commonjs-module',
|
|
40
|
-
};
|
|
41
|
-
compiler.options.output.library.type = 'commonjs-module';
|
|
42
|
-
}
|
|
43
|
-
const config = (0, utils_1.getModuleFederationConfig)(this._options.config, {
|
|
44
|
-
isServer: this._options.isServer,
|
|
45
|
-
});
|
|
46
|
-
const sharedLibraries = config.sharedLibraries;
|
|
47
|
-
const sharedDependencies = config.sharedDependencies;
|
|
48
|
-
const mappedRemotes = config.mappedRemotes;
|
|
49
|
-
const runtimePlugins = [];
|
|
50
|
-
if (this.configOverride?.runtimePlugins) {
|
|
51
|
-
runtimePlugins.push(...(this.configOverride.runtimePlugins ?? []));
|
|
52
|
-
}
|
|
53
|
-
if (this._options.isServer) {
|
|
54
|
-
runtimePlugins.push(require.resolve('@module-federation/node/runtimePlugin'));
|
|
55
|
-
}
|
|
56
|
-
new (require('@module-federation/enhanced/rspack').ModuleFederationPlugin)({
|
|
57
|
-
name: (0, utils_2.normalizeProjectName)(this._options.config.name),
|
|
58
|
-
filename: 'remoteEntry.js',
|
|
59
|
-
exposes: this._options.config.exposes,
|
|
60
|
-
remotes: mappedRemotes,
|
|
61
|
-
shared: {
|
|
62
|
-
...(sharedDependencies ?? {}),
|
|
63
|
-
},
|
|
64
|
-
...(this._options.isServer
|
|
65
|
-
? {
|
|
66
|
-
library: {
|
|
67
|
-
type: 'commonjs-module',
|
|
68
|
-
},
|
|
69
|
-
remoteType: 'script',
|
|
70
|
-
}
|
|
71
|
-
: {}),
|
|
72
|
-
...(this.configOverride ? this.configOverride : {}),
|
|
73
|
-
runtimePlugins,
|
|
74
|
-
}).apply(compiler);
|
|
75
|
-
if (sharedLibraries) {
|
|
76
|
-
sharedLibraries.getReplacementPlugin().apply(compiler);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.NxModuleFederationPlugin = NxModuleFederationPlugin;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
-
import { ModuleFederationConfig } from '../../../utils/models';
|
|
3
|
-
import { NxModuleFederationDevServerConfig } from '../../models';
|
|
4
|
-
export declare class NxModuleFederationSSRDevServerPlugin implements RspackPluginInstance {
|
|
5
|
-
private _options;
|
|
6
|
-
private devServerProcess;
|
|
7
|
-
private nxBin;
|
|
8
|
-
constructor(_options: {
|
|
9
|
-
config: ModuleFederationConfig;
|
|
10
|
-
devServerConfig?: NxModuleFederationDevServerConfig;
|
|
11
|
-
});
|
|
12
|
-
apply(compiler: Compiler): void;
|
|
13
|
-
private startServer;
|
|
14
|
-
private setup;
|
|
15
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NxModuleFederationSSRDevServerPlugin = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const is_serve_mode_1 = require("../../../utils/is-serve-mode");
|
|
6
|
-
const pc = tslib_1.__importStar(require("picocolors"));
|
|
7
|
-
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
|
-
const node_child_process_1 = require("node:child_process");
|
|
12
|
-
const PLUGIN_NAME = 'NxModuleFederationSSRDevServerPlugin';
|
|
13
|
-
class NxModuleFederationSSRDevServerPlugin {
|
|
14
|
-
constructor(_options) {
|
|
15
|
-
this._options = _options;
|
|
16
|
-
this.nxBin = require.resolve('nx/bin/nx');
|
|
17
|
-
this._options.devServerConfig ??= {
|
|
18
|
-
host: 'localhost',
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
apply(compiler) {
|
|
22
|
-
if (!(0, is_serve_mode_1.isServeMode)()) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
compiler.hooks.watchRun.tapAsync(PLUGIN_NAME, async (compiler, callback) => {
|
|
26
|
-
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, async (params, callback) => {
|
|
27
|
-
const staticRemotesConfig = await this.setup(compiler);
|
|
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
|
-
const mappedLocationOfRemotes = await (0, utils_1.buildStaticRemotes)(staticRemotesConfig, this._options.devServerConfig, this.nxBin);
|
|
30
|
-
(0, utils_1.startStaticRemotesFileServer)(staticRemotesConfig, devkit_1.workspaceRoot, this._options.devServerConfig.staticRemotesPort);
|
|
31
|
-
await (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationOfRemotes, {
|
|
32
|
-
pathToCert: this._options.devServerConfig.sslCert,
|
|
33
|
-
pathToKey: this._options.devServerConfig.sslKey,
|
|
34
|
-
}, true, this._options.devServerConfig.host);
|
|
35
|
-
new compiler.rspack.DefinePlugin({
|
|
36
|
-
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
37
|
-
}).apply(compiler);
|
|
38
|
-
await this.startServer(compiler);
|
|
39
|
-
callback();
|
|
40
|
-
});
|
|
41
|
-
callback();
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
async startServer(compiler) {
|
|
45
|
-
compiler.hooks.done.tapAsync(PLUGIN_NAME, async (_, callback) => {
|
|
46
|
-
const serverPath = (0, path_1.join)(compiler.options.output.path, compiler.options.output.filename ?? 'server.js');
|
|
47
|
-
if (this.devServerProcess) {
|
|
48
|
-
await new Promise((res) => {
|
|
49
|
-
this.devServerProcess.on('exit', () => {
|
|
50
|
-
res();
|
|
51
|
-
});
|
|
52
|
-
this.devServerProcess.kill('SIGKILL');
|
|
53
|
-
this.devServerProcess = undefined;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (!(0, fs_1.existsSync)(serverPath)) {
|
|
57
|
-
for (let retries = 0; retries < 10; retries++) {
|
|
58
|
-
await new Promise((res) => setTimeout(res, 200));
|
|
59
|
-
if ((0, fs_1.existsSync)(serverPath)) {
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (!(0, fs_1.existsSync)(serverPath)) {
|
|
64
|
-
throw new Error(`Could not find server bundle at ${serverPath}.`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
this.devServerProcess = (0, node_child_process_1.fork)(serverPath);
|
|
68
|
-
process.on('exit', () => {
|
|
69
|
-
this.devServerProcess?.kill('SIGKILL');
|
|
70
|
-
});
|
|
71
|
-
process.on('SIGINT', () => {
|
|
72
|
-
this.devServerProcess?.kill('SIGKILL');
|
|
73
|
-
});
|
|
74
|
-
callback();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
async setup(compiler) {
|
|
78
|
-
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
79
|
-
const { projects: workspaceProjects } = (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
|
|
80
|
-
const project = workspaceProjects[this._options.config.name];
|
|
81
|
-
if (!this._options.devServerConfig.pathToManifestFile) {
|
|
82
|
-
this._options.devServerConfig.pathToManifestFile =
|
|
83
|
-
(0, utils_1.getDynamicMfManifestFile)(project, devkit_1.workspaceRoot);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
const userPathToManifestFile = (0, path_1.join)(devkit_1.workspaceRoot, this._options.devServerConfig.pathToManifestFile);
|
|
87
|
-
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
|
88
|
-
throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
|
|
89
|
-
}
|
|
90
|
-
else if ((0, path_1.extname)(this._options.devServerConfig.pathToManifestFile) !== '.json') {
|
|
91
|
-
throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
|
|
92
|
-
}
|
|
93
|
-
this._options.devServerConfig.pathToManifestFile = userPathToManifestFile;
|
|
94
|
-
}
|
|
95
|
-
const { remotes, staticRemotePort } = (0, utils_1.getRemotes)(this._options.config, projectGraph, this._options.devServerConfig.pathToManifestFile);
|
|
96
|
-
this._options.devServerConfig.staticRemotesPort ??= staticRemotePort;
|
|
97
|
-
const remotesConfig = (0, utils_1.parseRemotesConfig)(remotes, devkit_1.workspaceRoot, projectGraph, true);
|
|
98
|
-
const staticRemotesConfig = await (0, utils_1.getStaticRemotes)(remotesConfig.config ?? {});
|
|
99
|
-
const devRemotes = remotes.filter((r) => !staticRemotesConfig[r]);
|
|
100
|
-
process.env.NX_MF_DEV_REMOTES = JSON.stringify([
|
|
101
|
-
...(devRemotes.length > 0 ? devRemotes : []),
|
|
102
|
-
project.name,
|
|
103
|
-
]);
|
|
104
|
-
return staticRemotesConfig ?? {};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.NxModuleFederationSSRDevServerPlugin = NxModuleFederationSSRDevServerPlugin;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { StaticRemoteConfig } from '../../utils';
|
|
2
|
-
import { NxModuleFederationDevServerConfig } from '../models';
|
|
3
|
-
export declare function buildStaticRemotes(staticRemotesConfig: Record<string, StaticRemoteConfig>, options: NxModuleFederationDevServerConfig, nxBin: string): Promise<Record<string, string>>;
|