From 24b245b2d5d5c8a1739b688b31db9789005d97c6 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Mon, 20 Nov 2023 10:21:54 +0000 Subject: [PATCH] fix(module-federation): single file server should use project name for directory (#20278) --- .../module-federation-dev-server.impl.ts | 21 +++++++------------ .../module-federation-dev-server.impl.ts | 7 +++++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/angular/src/builders/module-federation-dev-server/module-federation-dev-server.impl.ts b/packages/angular/src/builders/module-federation-dev-server/module-federation-dev-server.impl.ts index ac74e8d6bb4ae..dc2445613ac89 100644 --- a/packages/angular/src/builders/module-federation-dev-server/module-federation-dev-server.impl.ts +++ b/packages/angular/src/builders/module-federation-dev-server/module-federation-dev-server.impl.ts @@ -109,7 +109,10 @@ function startStaticRemotesFileServer( if (!commonOutputDirectory) { commonOutputDirectory = directoryOfOutputPath; - } else if (commonOutputDirectory !== directoryOfOutputPath) { + } else if ( + commonOutputDirectory !== directoryOfOutputPath || + !outputPath.endsWith(app) + ) { shouldMoveToCommonLocation = true; } } @@ -119,18 +122,10 @@ function startStaticRemotesFileServer( for (const app of remotes.staticRemotes) { const outputPath = projectGraph.nodes[app].data.targets['build'].options.outputPath; - const outputPathParts = outputPath.split('/'); - cpSync( - outputPath, - join( - commonOutputDirectory, - outputPathParts[outputPathParts.length - 1] - ), - { - force: true, - recursive: true, - } - ); + cpSync(outputPath, join(commonOutputDirectory, app), { + force: true, + recursive: true, + }); } } 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 876c94918518f..6ece8dc0c316e 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 @@ -59,7 +59,10 @@ function startStaticRemotesFileServer( if (!commonOutputDirectory) { commonOutputDirectory = directoryOfOutputPath; - } else if (commonOutputDirectory !== directoryOfOutputPath) { + } else if ( + commonOutputDirectory !== directoryOfOutputPath || + !outputPath.endsWith(app) + ) { shouldMoveToCommonLocation = true; } } @@ -70,7 +73,7 @@ function startStaticRemotesFileServer( const outputPath = context.projectGraph.nodes[app].data.targets['build'].options .outputPath; - cpSync(outputPath, commonOutputDirectory, { + cpSync(outputPath, join(commonOutputDirectory, app), { force: true, recursive: true, });