From ba657da7c51c3e19c9156ece4ab85082db70087c Mon Sep 17 00:00:00 2001 From: Wenchen Li <9028430+neo@users.noreply.github.com> Date: Thu, 29 Sep 2022 23:16:50 +0800 Subject: [PATCH] fix(webpack): regression from #10432 to allow `//` prefix in remote (#12302) --- packages/angular/src/utils/mf/with-module-federation.ts | 8 ++++++-- .../react/src/module-federation/with-module-federation.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/angular/src/utils/mf/with-module-federation.ts b/packages/angular/src/utils/mf/with-module-federation.ts index 1ab476c4c9..e7d4bbcd3a 100644 --- a/packages/angular/src/utils/mf/with-module-federation.ts +++ b/packages/angular/src/utils/mf/with-module-federation.ts @@ -4,7 +4,7 @@ import { readCachedProjectGraph, } from '@nrwl/devkit'; import { readCachedProjectConfiguration } from 'nx/src/project-graph/project-graph'; -import { extname, join } from 'path'; +import { extname } from 'path'; import { getNpmPackageSharedConfig, SharedLibraryConfig, @@ -59,7 +59,11 @@ function mapRemotes(remotes: MFRemotes) { const remoteLocationExt = extname(remoteLocation); mappedRemotes[remoteName] = ['.js', '.mjs'].includes(remoteLocationExt) ? remoteLocation - : join(remoteLocation, 'remoteEntry.mjs'); + : `${ + remoteLocation.endsWith('/') + ? remoteLocation.slice(0, -1) + : remoteLocation + }/remoteEntry.mjs`; } else if (typeof remote === 'string') { mappedRemotes[remote] = determineRemoteUrl(remote); } diff --git a/packages/react/src/module-federation/with-module-federation.ts b/packages/react/src/module-federation/with-module-federation.ts index 9434c27f85..7a51e37d95 100644 --- a/packages/react/src/module-federation/with-module-federation.ts +++ b/packages/react/src/module-federation/with-module-federation.ts @@ -22,7 +22,7 @@ import { SharedLibraryConfig, } from './models'; import { readRootPackageJson } from './package-json'; -import { extname, join } from 'path'; +import { extname } from 'path'; import ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin'); function collectDependencies( @@ -133,7 +133,11 @@ function mapRemotes(remotes: Remotes, projectGraph: ProjectGraph) { const remoteLocationExt = extname(remoteLocation); mappedRemotes[remoteName] = ['.js', '.mjs'].includes(remoteLocationExt) ? remoteLocation - : join(remoteLocation, 'remoteEntry.js'); + : `${ + remoteLocation.endsWith('/') + ? remoteLocation.slice(0, -1) + : remoteLocation + }/remoteEntry.js`; } else if (typeof remote === 'string') { mappedRemotes[remote] = determineRemoteUrl(remote, projectGraph); }