@@ -8,7 +8,7 @@ import RemoteModule from './RemoteModule';
8
8
import { getFederationGlobalScope } from './runtime/utils' ;
9
9
import type ExternalModule from 'webpack/lib/ExternalModule' ;
10
10
import type FallbackModule from './FallbackModule' ;
11
- import type { RemotesOptions } from '@module-federation/webpack-bundler-runtime' ;
11
+ import type { ModuleIdToRemoteDataMapping } from '@module-federation/webpack-bundler-runtime' ;
12
12
13
13
const extractUrlAndGlobal = require (
14
14
normalizeWebpackPath ( 'webpack/lib/util/extractUrlAndGlobal' ) ,
@@ -30,19 +30,7 @@ class RemoteRuntimeModule extends RuntimeModule {
30
30
const { compilation, chunkGraph } = this ;
31
31
const { runtimeTemplate, moduleGraph } = compilation as Compilation ;
32
32
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 = { } ;
46
34
47
35
const allChunks = [
48
36
...Array . from ( this . chunk ?. getAllReferencedChunks ( ) || [ ] ) ,
@@ -78,7 +66,12 @@ class RemoteRuntimeModule extends RuntimeModule {
78
66
//@ts -ignore
79
67
remotes . push ( id ) ;
80
68
81
- idToExternalAndNameMapping [ id ] = [ shareScope , name , externalModuleId ] ;
69
+ moduleIdToRemoteDataMapping [ id ] = {
70
+ shareScope : shareScope as string ,
71
+ name,
72
+ externalModuleId : externalModuleId as string ,
73
+ remoteName : '' ,
74
+ } ;
82
75
const remoteModules : ExternalModule [ ] = [ ] ;
83
76
// FallbackModule has requests
84
77
if ( 'requests' in externalModule && externalModule . requests ) {
@@ -93,7 +86,6 @@ class RemoteRuntimeModule extends RuntimeModule {
93
86
remoteModules . push ( externalModule as ExternalModule ) ;
94
87
}
95
88
96
- idToRemoteMap [ id ] = [ ] ;
97
89
remoteModules . forEach ( ( remoteModule ) => {
98
90
let remoteName = '' ;
99
91
try {
@@ -104,17 +96,6 @@ class RemoteRuntimeModule extends RuntimeModule {
104
96
} catch ( err ) {
105
97
//noop
106
98
}
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
- } ) ;
118
99
} ) ;
119
100
}
120
101
}
@@ -124,22 +105,20 @@ class RemoteRuntimeModule extends RuntimeModule {
124
105
) ;
125
106
126
107
return Template . asString ( [
127
- `var chunkMapping = ${ JSON . stringify (
108
+ `${ RuntimeGlobals . require } .remotesLoadingData. chunkMapping = ${ JSON . stringify (
128
109
chunkToRemotesMapping ,
129
110
null ,
130
111
'\t' ,
131
112
) } ;`,
132
- `var idToExternalAndNameMapping = ${ JSON . stringify (
133
- idToExternalAndNameMapping ,
113
+ `${ RuntimeGlobals . require } .remotesLoadingData.moduleIdToRemoteDataMapping = ${ JSON . stringify (
114
+ moduleIdToRemoteDataMapping ,
134
115
null ,
135
116
'\t' ,
136
117
) } ;`,
137
- `var idToRemoteMap = ${ JSON . stringify ( idToRemoteMap , null , '\t' ) } ;` ,
138
- `${ federationGlobal } .bundlerRuntimeOptions.remotes = {idToRemoteMap,chunkMapping, idToExternalAndNameMapping, webpackRequire:${ RuntimeGlobals . require } };` ,
139
118
`${
140
119
RuntimeGlobals . ensureChunkHandlers
141
120
} .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 } });` ,
143
122
] ) } `,
144
123
] ) ;
145
124
}
0 commit comments