@@ -8,7 +8,7 @@ import RemoteModule from './RemoteModule';
88import { getFederationGlobalScope } from './runtime/utils' ;
99import type ExternalModule from 'webpack/lib/ExternalModule' ;
1010import type FallbackModule from './FallbackModule' ;
11- import type { RemotesOptions } from '@module-federation/webpack-bundler-runtime' ;
11+ import type { ModuleIdToRemoteDataMapping } from '@module-federation/webpack-bundler-runtime' ;
1212
1313const extractUrlAndGlobal = require (
1414 normalizeWebpackPath ( 'webpack/lib/util/extractUrlAndGlobal' ) ,
@@ -30,19 +30,7 @@ class RemoteRuntimeModule extends RuntimeModule {
3030 const { compilation, chunkGraph } = this ;
3131 const { runtimeTemplate, moduleGraph } = compilation as Compilation ;
3232 const chunkToRemotesMapping : Record < string , any > = { } ;
33- const idToExternalAndNameMapping : Record < string | number , any > = { } ;
34- const idToRemoteMap : RemotesOptions [ 'idToRemoteMap' ] = { } ;
35- // let chunkReferences: Set<Chunk> = new Set();
36-
37- // if (this.chunk && chunkGraph) {
38- // const requirements = chunkGraph.getTreeRuntimeRequirements(this.chunk);
39- // if (requirements.has('federation-entry-startup')) {
40- // chunkReferences = this.chunk.getAllReferencedChunks();
41- // } else {
42- // // remote entry doesnt need federation startup, can have async chunk map only
43- // chunkReferences = this.chunk.getAllAsyncChunks();
44- // }
45- // }
33+ const moduleIdToRemoteDataMapping : ModuleIdToRemoteDataMapping = { } ;
4634
4735 const allChunks = [
4836 ...Array . from ( this . chunk ?. getAllReferencedChunks ( ) || [ ] ) ,
@@ -78,7 +66,12 @@ class RemoteRuntimeModule extends RuntimeModule {
7866 //@ts -ignore
7967 remotes . push ( id ) ;
8068
81- idToExternalAndNameMapping [ id ] = [ shareScope , name , externalModuleId ] ;
69+ moduleIdToRemoteDataMapping [ id ] = {
70+ shareScope : shareScope as string ,
71+ name,
72+ externalModuleId : externalModuleId as string ,
73+ remoteName : '' ,
74+ } ;
8275 const remoteModules : ExternalModule [ ] = [ ] ;
8376 // FallbackModule has requests
8477 if ( 'requests' in externalModule && externalModule . requests ) {
@@ -93,7 +86,6 @@ class RemoteRuntimeModule extends RuntimeModule {
9386 remoteModules . push ( externalModule as ExternalModule ) ;
9487 }
9588
96- idToRemoteMap [ id ] = [ ] ;
9789 remoteModules . forEach ( ( remoteModule ) => {
9890 let remoteName = '' ;
9991 try {
@@ -104,17 +96,6 @@ class RemoteRuntimeModule extends RuntimeModule {
10496 } catch ( err ) {
10597 //noop
10698 }
107- const externalModuleId =
108- chunkGraph &&
109- remoteModule &&
110- // @ts -ignore
111- chunkGraph . getModuleId ( remoteModule ) ;
112-
113- idToRemoteMap [ id ] . push ( {
114- externalType : remoteModule . externalType ,
115- name : remoteModule . externalType === 'script' ? remoteName : '' ,
116- externalModuleId,
117- } ) ;
11899 } ) ;
119100 }
120101 }
@@ -124,22 +105,20 @@ class RemoteRuntimeModule extends RuntimeModule {
124105 ) ;
125106
126107 return Template . asString ( [
127- `var chunkMapping = ${ JSON . stringify (
108+ `${ RuntimeGlobals . require } .remotesLoadingData. chunkMapping = ${ JSON . stringify (
128109 chunkToRemotesMapping ,
129110 null ,
130111 '\t' ,
131112 ) } ;`,
132- `var idToExternalAndNameMapping = ${ JSON . stringify (
133- idToExternalAndNameMapping ,
113+ `${ RuntimeGlobals . require } .remotesLoadingData.moduleIdToRemoteDataMapping = ${ JSON . stringify (
114+ moduleIdToRemoteDataMapping ,
134115 null ,
135116 '\t' ,
136117 ) } ;`,
137- `var idToRemoteMap = ${ JSON . stringify ( idToRemoteMap , null , '\t' ) } ;` ,
138- `${ federationGlobal } .bundlerRuntimeOptions.remotes = {idToRemoteMap,chunkMapping, idToExternalAndNameMapping, webpackRequire:${ RuntimeGlobals . require } };` ,
139118 `${
140119 RuntimeGlobals . ensureChunkHandlers
141120 } .remotes = ${ runtimeTemplate . basicFunction ( 'chunkId, promises' , [
142- `${ federationGlobal } .bundlerRuntime.remotes({idToRemoteMap,chunkMapping, idToExternalAndNameMapping, chunkId, promises, webpackRequire:${ RuntimeGlobals . require } });` ,
121+ `${ federationGlobal } .bundlerRuntime.remotes({ chunkId, promises, webpackRequire:${ RuntimeGlobals . require } });` ,
143122 ] ) } `,
144123 ] ) ;
145124 }
0 commit comments