From f20624bf9700e6e1017b7e6eb8d3e090b1ce9bda Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Mon, 19 Aug 2024 16:29:16 +0100 Subject: [PATCH] fix(module-federation): ensure shared packages can be shared from host #27162 --- .../module-federation-dev-server.impl.ts | 9 ++++++--- .../module-federation-ssr-dev-server.impl.ts | 5 ++++- .../module-federation-dev-server.impl.ts | 9 ++++++--- .../module-federation-ssr-dev-server.impl.ts | 9 ++++++--- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/angular/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts b/packages/angular/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts index fc031d03c202e..f55e0d90247a4 100644 --- a/packages/angular/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts +++ b/packages/angular/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts @@ -127,9 +127,12 @@ export async function* moduleFederationDevServerExecutor( options.staticRemotesPort ??= remotes.staticRemotePort; // Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin - process.env.NX_MF_DEV_REMOTES = JSON.stringify( - remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName)) - ); + process.env.NX_MF_DEV_REMOTES = JSON.stringify([ + ...(remotes.devRemotes.map((r) => + typeof r === 'string' ? r : r.remoteName + ) ?? []), + project.name, + ]); const staticRemotesConfig = parseStaticRemotesConfig( [...remotes.staticRemotes, ...remotes.dynamicRemotes], diff --git a/packages/angular/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts b/packages/angular/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts index 016b1f002b086..d595caa508600 100644 --- a/packages/angular/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts +++ b/packages/angular/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts @@ -123,7 +123,10 @@ export async function* moduleFederationSsrDevServerExecutor( ); // Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin - process.env.NX_MF_DEV_REMOTES = JSON.stringify(options.devRemotes); + process.env.NX_MF_DEV_REMOTES = JSON.stringify([ + ...(options.devRemotes ?? []), + project.name, + ]); const devRemotes = await startRemotes( remotes.devRemotes, diff --git a/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts b/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts index 0f01bc03a1506..bed4992d74e58 100644 --- a/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts +++ b/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts @@ -332,9 +332,12 @@ export default async function* moduleFederationDevServer( options.staticRemotesPort ??= remotes.staticRemotePort; // Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin - process.env.NX_MF_DEV_REMOTES = JSON.stringify( - remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName)) - ); + process.env.NX_MF_DEV_REMOTES = JSON.stringify([ + ...(remotes.devRemotes.map((r) => + typeof r === 'string' ? r : r.remoteName + ) ?? []), + p.name, + ]); const staticRemotesConfig = parseStaticRemotesConfig( [...remotes.staticRemotes, ...remotes.dynamicRemotes], diff --git a/packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts b/packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts index d0488357b970d..af547876e9a5a 100644 --- a/packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts +++ b/packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts @@ -310,9 +310,12 @@ export default async function* moduleFederationSsrDevServer( options.staticRemotesPort ??= remotes.staticRemotePort; - process.env.NX_MF_DEV_REMOTES = JSON.stringify( - remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName)) - ); + process.env.NX_MF_DEV_REMOTES = JSON.stringify([ + ...(remotes.devRemotes.map((r) => + typeof r === 'string' ? r : r.remoteName + ) ?? []), + projectConfig.name, + ]); const staticRemotesConfig = parseStaticSsrRemotesConfig( [...remotes.staticRemotes, ...remotes.dynamicRemotes],