@nx/react 19.5.1 → 19.5.2
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 +6 -6
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +0 -10
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +15 -36
- package/src/generators/host/lib/add-module-federation-files.js +5 -1
- package/src/generators/remote/lib/add-remote-to-dynamic-host.js +7 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "19.5.
|
|
3
|
+
"version": "19.5.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
|
|
6
6
|
"repository": {
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"minimatch": "9.0.3",
|
|
40
40
|
"tslib": "^2.3.0",
|
|
41
41
|
"@module-federation/enhanced": "~0.2.3",
|
|
42
|
-
"@nx/devkit": "19.5.
|
|
43
|
-
"@nx/js": "19.5.
|
|
44
|
-
"@nx/eslint": "19.5.
|
|
45
|
-
"@nx/web": "19.5.
|
|
46
|
-
"@nrwl/react": "19.5.
|
|
42
|
+
"@nx/devkit": "19.5.2",
|
|
43
|
+
"@nx/js": "19.5.2",
|
|
44
|
+
"@nx/eslint": "19.5.2",
|
|
45
|
+
"@nx/web": "19.5.2",
|
|
46
|
+
"@nrwl/react": "19.5.2"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
@@ -12,16 +12,6 @@ type ModuleFederationDevServerOptions = WebDevServerOptions & {
|
|
|
12
12
|
staticRemotesPort?: number;
|
|
13
13
|
pathToManifestFile?: string;
|
|
14
14
|
};
|
|
15
|
-
type StaticRemoteConfig = {
|
|
16
|
-
basePath: string;
|
|
17
|
-
outputPath: string;
|
|
18
|
-
urlSegment: string;
|
|
19
|
-
};
|
|
20
|
-
type StaticRemotesConfig = {
|
|
21
|
-
remotes: string[];
|
|
22
|
-
config: Record<string, StaticRemoteConfig> | undefined;
|
|
23
|
-
};
|
|
24
|
-
export declare function parseStaticRemotesConfig(staticRemotes: string[] | undefined, context: ExecutorContext): StaticRemotesConfig;
|
|
25
15
|
export default function moduleFederationDevServer(options: ModuleFederationDevServerOptions, context: ExecutorContext): AsyncIterableIterator<{
|
|
26
16
|
success: boolean;
|
|
27
17
|
baseUrl?: string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseStaticRemotesConfig = parseStaticRemotesConfig;
|
|
4
3
|
exports.default = moduleFederationDevServer;
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const dev_server_impl_1 = require("@nx/webpack/src/executors/dev-server/dev-server.impl");
|
|
@@ -14,6 +13,8 @@ const node_path_1 = require("node:path");
|
|
|
14
13
|
const node_fs_1 = require("node:fs");
|
|
15
14
|
const fs_1 = require("fs");
|
|
16
15
|
const path_1 = require("path");
|
|
16
|
+
const start_remote_proxies_1 = require("@nx/webpack/src/utils/module-federation/start-remote-proxies");
|
|
17
|
+
const parse_static_remotes_config_1 = require("@nx/webpack/src/utils/module-federation/parse-static-remotes-config");
|
|
17
18
|
function getBuildOptions(buildTarget, context) {
|
|
18
19
|
const target = (0, devkit_1.parseTargetString)(buildTarget, context);
|
|
19
20
|
const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
|
|
@@ -22,6 +23,10 @@ function getBuildOptions(buildTarget, context) {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
function startStaticRemotesFileServer(staticRemotesConfig, context, options) {
|
|
26
|
+
if (!staticRemotesConfig.remotes ||
|
|
27
|
+
staticRemotesConfig.remotes.length === 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
25
30
|
let shouldMoveToCommonLocation = false;
|
|
26
31
|
let commonOutputDirectory;
|
|
27
32
|
for (const app of staticRemotesConfig.remotes) {
|
|
@@ -56,6 +61,7 @@ function startStaticRemotesFileServer(staticRemotesConfig, context, options) {
|
|
|
56
61
|
ssl: options.ssl,
|
|
57
62
|
sslCert: options.sslCert,
|
|
58
63
|
sslKey: options.sslKey,
|
|
64
|
+
cacheSeconds: -1,
|
|
59
65
|
}, context);
|
|
60
66
|
return staticRemotesIter;
|
|
61
67
|
}
|
|
@@ -137,23 +143,9 @@ async function buildStaticRemotes(staticRemotesConfig, nxBin, context, options)
|
|
|
137
143
|
process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
|
|
138
144
|
process.on('exit', () => staticProcess.kill('SIGTERM'));
|
|
139
145
|
});
|
|
140
|
-
|
|
141
|
-
function parseStaticRemotesConfig(staticRemotes, context) {
|
|
142
|
-
if (!staticRemotes?.length) {
|
|
143
|
-
return { remotes: [], config: undefined };
|
|
144
|
-
}
|
|
145
|
-
const config = {};
|
|
146
|
-
for (const app of staticRemotes) {
|
|
147
|
-
const outputPath = context.projectGraph.nodes[app].data.targets['build'].options.outputPath;
|
|
148
|
-
const basePath = (0, node_path_1.dirname)(outputPath);
|
|
149
|
-
const urlSegment = (0, node_path_1.basename)(outputPath);
|
|
150
|
-
config[app] = { basePath, outputPath, urlSegment };
|
|
151
|
-
}
|
|
152
|
-
return { remotes: staticRemotes, config };
|
|
146
|
+
return mappedLocationOfRemotes;
|
|
153
147
|
}
|
|
154
148
|
async function* moduleFederationDevServer(options, context) {
|
|
155
|
-
const initialStaticRemotesPorts = options.staticRemotesPort;
|
|
156
|
-
options.staticRemotesPort ??= options.port + 1;
|
|
157
149
|
// Force Node to resolve to look for the nx binary that is inside node_modules
|
|
158
150
|
const nxBin = require.resolve('nx/bin/nx');
|
|
159
151
|
const currIter = options.static
|
|
@@ -163,6 +155,7 @@ async function* moduleFederationDevServer(options, context) {
|
|
|
163
155
|
withDeps: false,
|
|
164
156
|
spa: false,
|
|
165
157
|
cors: true,
|
|
158
|
+
cacheSeconds: -1,
|
|
166
159
|
}, context)
|
|
167
160
|
: (0, dev_server_impl_1.default)(options, context);
|
|
168
161
|
const p = context.projectsConfigurations.projects[context.projectName];
|
|
@@ -188,29 +181,15 @@ async function* moduleFederationDevServer(options, context) {
|
|
|
188
181
|
projectGraph: context.projectGraph,
|
|
189
182
|
root: context.root,
|
|
190
183
|
}, pathToManifestFile);
|
|
184
|
+
options.staticRemotesPort ??= remotes.staticRemotePort;
|
|
191
185
|
// Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
|
|
192
186
|
process.env.NX_MF_DEV_REMOTES = JSON.stringify(remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName)));
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const remoteName = typeof r === 'string' ? r : r.remoteName;
|
|
196
|
-
const remotePort = context.projectGraph.nodes[remoteName].data.targets['serve'].options
|
|
197
|
-
.port;
|
|
198
|
-
if (remotePort >= portToUse) {
|
|
199
|
-
return remotePort + 1;
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
return portToUse;
|
|
203
|
-
}
|
|
204
|
-
}, options.staticRemotesPort);
|
|
205
|
-
}
|
|
206
|
-
const staticRemotesConfig = parseStaticRemotesConfig(remotes.staticRemotes, context);
|
|
207
|
-
await buildStaticRemotes(staticRemotesConfig, nxBin, context, options);
|
|
187
|
+
const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
|
|
188
|
+
const mappedLocationsOfStaticRemotes = await buildStaticRemotes(staticRemotesConfig, nxBin, context, options);
|
|
208
189
|
const devRemoteIters = await startRemotes(remotes.devRemotes, context, options, 'serve');
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
: undefined;
|
|
213
|
-
return yield* (0, async_iterable_1.combineAsyncIterables)(currIter, ...devRemoteIters, ...dynamicRemotesIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
|
|
190
|
+
const staticRemotesIter = startStaticRemotesFileServer(staticRemotesConfig, context, options);
|
|
191
|
+
(0, start_remote_proxies_1.startRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes);
|
|
192
|
+
return yield* (0, async_iterable_1.combineAsyncIterables)(currIter, ...devRemoteIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
|
|
214
193
|
if (!options.isInitialHost) {
|
|
215
194
|
done();
|
|
216
195
|
return;
|
|
@@ -45,7 +45,11 @@ function addModuleFederationFiles(host, options, defaultRemoteManifest) {
|
|
|
45
45
|
processWebpackConfig(options, host, 'webpack.config.prod.js');
|
|
46
46
|
processWebpackConfig(options, host, 'webpack.config.prod.ts');
|
|
47
47
|
if (!host.exists(pathToMFManifest)) {
|
|
48
|
-
host.write(pathToMFManifest,
|
|
48
|
+
host.write(pathToMFManifest, `{
|
|
49
|
+
${defaultRemoteManifest
|
|
50
|
+
.map(({ name, port }) => `"${name}": "http://localhost:${port}"`)
|
|
51
|
+
.join(',\n')}
|
|
52
|
+
}`);
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addRemoteToDynamicHost = addRemoteToDynamicHost;
|
|
4
4
|
function addRemoteToDynamicHost(tree, remoteName, remotePort, pathToMfManifest) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
if (tree.exists(pathToMfManifest)) {
|
|
6
|
+
const current = tree.read(pathToMfManifest, 'utf8');
|
|
7
|
+
tree.write(pathToMfManifest, JSON.stringify({
|
|
8
|
+
...JSON.parse(current),
|
|
9
|
+
[remoteName]: `http://localhost:${remotePort}`,
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
10
12
|
}
|