@@ -190,13 +190,15 @@ class ContainerPlugin {
190190
191191 compiler . hooks . make . tapAsync (
192192 PLUGIN_NAME ,
193- (
193+ async (
194194 compilation : Compilation ,
195195 callback : ( error ?: WebpackError | null | undefined ) => void ,
196196 ) => {
197197 const hasSingleRuntimeChunk =
198198 compilation . options ?. optimization ?. runtimeChunk ;
199199 const hooks = FederationModulesPlugin . getCompilationHooks ( compilation ) ;
200+ const federationRuntimeDependency =
201+ federationRuntimePluginInstance . getDependency ( compiler ) ;
200202 const dep = new ContainerEntryDependency (
201203 name ,
202204 //@ts -ignore
@@ -206,78 +208,96 @@ class ContainerPlugin {
206208 this . _options . experiments ,
207209 ) ;
208210 dep . loc = { name } ;
209- compilation . addEntry (
210- compilation . options . context || '' ,
211- dep ,
212- {
213- name,
214- filename,
215- runtime : hasSingleRuntimeChunk ? false : runtime ,
216- library,
217- } ,
218- ( error : WebpackError | null | undefined ) => {
219- if ( error ) return callback ( error ) ;
220- hooks . addContainerEntryModule . call ( dep ) ;
221- callback ( ) ;
222- } ,
223- ) ;
211+
212+ await new Promise ( ( resolve , reject ) => {
213+ compilation . addEntry (
214+ compilation . options . context || '' ,
215+ dep ,
216+ {
217+ name,
218+ filename,
219+ runtime : hasSingleRuntimeChunk ? false : runtime ,
220+ library,
221+ } ,
222+ ( error : WebpackError | null | undefined ) => {
223+ if ( error ) return reject ( error ) ;
224+ hooks . addContainerEntryModule . call ( dep ) ;
225+ resolve ( undefined ) ;
226+ } ,
227+ ) ;
228+ } ) . catch ( callback ) ;
229+
230+ await new Promise ( ( resolve , reject ) => {
231+ compilation . addInclude (
232+ compiler . context ,
233+ federationRuntimeDependency ,
234+ { name : undefined } ,
235+ ( err , module ) => {
236+ if ( err ) {
237+ return reject ( err ) ;
238+ }
239+ hooks . addFederationRuntimeModule . call (
240+ federationRuntimeDependency ,
241+ ) ;
242+ resolve ( undefined ) ;
243+ } ,
244+ ) ;
245+ } ) . catch ( callback ) ;
246+
247+ callback ( ) ;
224248 } ,
225249 ) ;
226250
227251 // this will still be copied into child compiler, so it needs a check to avoid running hook on child
228252 // we have to use finishMake in order to check the entries created and see if there are multiple runtime chunks
229253 compiler . hooks . finishMake . tapAsync (
230254 PLUGIN_NAME ,
231- async ( compilation , callback ) => {
232- // its a child compiler
255+ ( compilation : Compilation , callback ) => {
233256 if (
234257 compilation . compiler . parentCompilation &&
235258 compilation . compiler . parentCompilation !== compilation
236259 ) {
237- // dont include dependencies on child compilations
238260 return callback ( ) ;
239261 }
240262
241263 const hooks = FederationModulesPlugin . getCompilationHooks ( compilation ) ;
242- const createdRuntimes = new Set ( ) ;
264+ const createdRuntimes = new Set < string > ( ) ;
265+
243266 for ( const entry of compilation . entries . values ( ) ) {
244- if ( entry . options . runtime ) {
245- if ( createdRuntimes . has ( entry . options . runtime ) ) {
246- continue ;
247- }
248- createdRuntimes . add ( entry . options . runtime ) ;
267+ const runtime = entry . options . runtime ;
268+ if ( runtime ) {
269+ createdRuntimes . add ( runtime ) ;
249270 }
250271 }
251272
252- // if it has multiple runtime chunks - make another with no name or runtime assigned
253273 if (
254- createdRuntimes . size !== 0 ||
255- compilation . options ?. optimization ?. runtimeChunk
274+ createdRuntimes . size === 0 &&
275+ ! compilation . options ?. optimization ?. runtimeChunk
256276 ) {
257- const dep = new ContainerEntryDependency (
258- name ,
259- //@ts -ignore
260- exposes ,
261- shareScope ,
262- federationRuntimePluginInstance . entryFilePath ,
263- this . _options . experiments ,
264- ) ;
277+ return callback ( ) ;
278+ }
279+
280+ const dep = new ContainerEntryDependency (
281+ name ,
282+ //@ts -ignore
283+ exposes ,
284+ shareScope ,
285+ federationRuntimePluginInstance . entryFilePath ,
286+ this . _options . experiments ,
287+ ) ;
265288
266- dep . loc = { name } ;
289+ dep . loc = { name } ;
267290
268- compilation . addInclude (
269- compilation . options . context || '' ,
270- dep ,
271- { name : undefined } ,
272- ( error : WebpackError | null | undefined ) => {
273- if ( error ) return callback ( error ) ;
274- hooks . addContainerEntryModule . call ( dep ) ;
275- callback ( ) ;
276- } ,
277- ) ;
278- } else {
279- callback ( ) ;
280- }
291+ compilation . addInclude (
292+ compilation . options . context || '' ,
293+ dep ,
294+ { name : undefined } ,
295+ ( error : WebpackError | null | undefined ) => {
296+ if ( error ) return callback ( error ) ;
297+ hooks . addContainerEntryModule . call ( dep ) ;
298+ callback ( ) ;
299+ } ,
300+ ) ;
281301 } ,
282302 ) ;
283303
@@ -301,11 +321,6 @@ class ContainerPlugin {
301321 compiler . hooks . thisCompilation . tap (
302322 PLUGIN_NAME ,
303323 ( compilation : Compilation , { normalModuleFactory } ) => {
304- const federationRuntimeDependency =
305- federationRuntimePluginInstance . getDependency ( compiler ) ;
306-
307- const logger = compilation . getLogger ( 'ContainerPlugin' ) ;
308- const hooks = FederationModulesPlugin . getCompilationHooks ( compilation ) ;
309324 compilation . dependencyFactories . set (
310325 FederationRuntimeDependency ,
311326 normalModuleFactory ,
@@ -314,21 +329,6 @@ class ContainerPlugin {
314329 FederationRuntimeDependency ,
315330 new ModuleDependency . Template ( ) ,
316331 ) ;
317-
318- compilation . addInclude (
319- compiler . context ,
320- federationRuntimeDependency ,
321- { name : undefined } ,
322- ( err , module ) => {
323- if ( err ) {
324- return logger . error (
325- 'Error adding federation runtime module:' ,
326- err ,
327- ) ;
328- }
329- hooks . addFederationRuntimeModule . call ( federationRuntimeDependency ) ;
330- } ,
331- ) ;
332332 } ,
333333 ) ;
334334 }
0 commit comments