Skip to content

Commit 3142624

Browse files
authored
fix(module-federation): module federation does not depend on static remotes port (#32363)
## Current Behavior If a host does not have any remotes, it fails to serve as the `staticRemotesPort` returns as `-Infinity`. ## Expected Behavior When a host has no remotes, set `staticRemotesPort` to `undefined` and use this to determine whether we should wait for it.
1 parent 18ba315 commit 3142624

File tree

8 files changed

+40
-31
lines changed

8 files changed

+40
-31
lines changed

packages/angular/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ export async function* moduleFederationSsrDevServerExecutor(
111111
return;
112112
}
113113
try {
114-
const portsToWaitFor = staticRemotesIter
115-
? [options.staticRemotesPort, ...remotes.remotePorts]
116-
: [...remotes.remotePorts];
114+
const portsToWaitFor =
115+
staticRemotesIter && options.staticRemotesPort
116+
? [options.staticRemotesPort, ...remotes.remotePorts]
117+
: [...remotes.remotePorts];
117118
await Promise.all(
118119
portsToWaitFor.map((port) =>
119120
waitForPortOpen(port, {

packages/module-federation/src/utils/get-remotes-for-host.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,18 @@ export function getRemotes(
184184
(r) => context.projectGraph.nodes[r].data.targets['serve'].options.port
185185
);
186186
const staticRemotePort =
187-
Math.max(
188-
...([
189-
...remotePorts,
190-
...staticRemotes.map(
191-
(r) =>
192-
context.projectGraph.nodes[r].data.targets['serve'].options.port
193-
),
194-
] as number[])
195-
) +
196-
(remotesToSkip.size + 1);
187+
staticRemotes.length === 0 && remotePorts.length === 0
188+
? undefined
189+
: Math.max(
190+
...([
191+
...remotePorts,
192+
...staticRemotes.map(
193+
(r) =>
194+
context.projectGraph.nodes[r].data.targets['serve'].options.port
195+
),
196+
] as number[])
197+
) +
198+
(remotesToSkip.size + 1);
197199

198200
return {
199201
staticRemotes,

packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ export default async function* moduleFederationDevServer(
8989
const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${
9090
options.port
9191
}`;
92-
const portsToWaitFor = staticRemotesIter
93-
? [options.staticRemotesPort, ...remotes.remotePorts]
94-
: [...remotes.remotePorts];
92+
const portsToWaitFor =
93+
staticRemotesIter && options.staticRemotesPort
94+
? [options.staticRemotesPort, ...remotes.remotePorts]
95+
: [...remotes.remotePorts];
9596
await Promise.all(
9697
portsToWaitFor.map((port) =>
9798
waitForPortOpen(port, {

packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ export default async function* moduleFederationSsrDevServer(
8989
}
9090

9191
try {
92-
const portsToWaitFor = staticRemotesIter
93-
? [options.staticRemotesPort, ...remotes.remotePorts]
94-
: [...remotes.remotePorts];
92+
const portsToWaitFor =
93+
staticRemotesIter && options.staticRemotesPort
94+
? [options.staticRemotesPort, ...remotes.remotePorts]
95+
: [...remotes.remotePorts];
9596

9697
await Promise.all(
9798
portsToWaitFor.map((port) =>

packages/react/src/executors/module-federation-static-server/module-federation-static-server.impl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,10 @@ export default async function* moduleFederationStaticServer(
363363
}
364364

365365
try {
366-
const portsToWaitFor = staticFileServerIter
367-
? [options.serveOptions.staticRemotesPort, ...remotes.remotePorts]
368-
: [...remotes.remotePorts];
366+
const portsToWaitFor =
367+
staticFileServerIter && options.serveOptions.staticRemotesPort
368+
? [options.serveOptions.staticRemotesPort, ...remotes.remotePorts]
369+
: [...remotes.remotePorts];
369370
await Promise.all(
370371
portsToWaitFor.map((port) =>
371372
waitForPortOpen(port, {

packages/rspack/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ export default async function* moduleFederationDevServer(
8989
const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${
9090
options.port
9191
}`;
92-
const portsToWaitFor = staticRemotesIter
93-
? [options.staticRemotesPort, ...remotes.remotePorts]
94-
: [...remotes.remotePorts];
92+
const portsToWaitFor =
93+
staticRemotesIter && options.staticRemotesPort
94+
? [options.staticRemotesPort, ...remotes.remotePorts]
95+
: [...remotes.remotePorts];
9596
await Promise.all(
9697
portsToWaitFor.map((port) =>
9798
waitForPortOpen(port, {

packages/rspack/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ export default async function* moduleFederationSsrDevServer(
8181
const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${
8282
options.port
8383
}`;
84-
const portsToWaitFor = staticRemotesIter
85-
? [options.staticRemotesPort, ...remotes.remotePorts]
86-
: [...remotes.remotePorts];
84+
const portsToWaitFor =
85+
staticRemotesIter && options.staticRemotesPort
86+
? [options.staticRemotesPort, ...remotes.remotePorts]
87+
: [...remotes.remotePorts];
8788

8889
await Promise.all(
8990
portsToWaitFor.map((port) =>

packages/rspack/src/executors/module-federation-static-server/module-federation-static-server.impl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,10 @@ export default async function* moduleFederationStaticServer(
367367
}
368368

369369
try {
370-
const portsToWaitFor = staticFileServerIter
371-
? [options.serveOptions.staticRemotesPort, ...remotes.remotePorts]
372-
: [...remotes.remotePorts];
370+
const portsToWaitFor =
371+
staticFileServerIter && options.serveOptions.staticRemotesPort
372+
? [options.serveOptions.staticRemotesPort, ...remotes.remotePorts]
373+
: [...remotes.remotePorts];
373374
await Promise.all(
374375
portsToWaitFor.map((port) =>
375376
waitForPortOpen(port, {

0 commit comments

Comments
 (0)