@@ -69,11 +69,11 @@ class Chunk {
6969 }
7070
7171 get initial ( ) {
72- throw new Error ( "Chunk.initial was removed. Use isInitial ()" ) ;
72+ throw new Error ( "Chunk.initial was removed. Use canBeInitial/isOnlyInitial ()" ) ;
7373 }
7474
7575 set initial ( data ) {
76- throw new Error ( "Chunk.initial was removed. Use isInitial ()" ) ;
76+ throw new Error ( "Chunk.initial was removed. Use canBeInitial/isOnlyInitial ()" ) ;
7777 }
7878
7979 hasRuntime ( ) {
@@ -84,14 +84,23 @@ class Chunk {
8484 return false ;
8585 }
8686
87- isInitial ( ) {
87+ canBeInitial ( ) {
8888 for ( const chunkGroup of this . _groups ) {
89- // We only need to check the first one
90- return chunkGroup . isInitial ( ) ;
89+ if ( chunkGroup . isInitial ( ) )
90+ return true ;
9191 }
9292 return false ;
9393 }
9494
95+ isOnlyInitial ( ) {
96+ if ( this . _groups . size <= 0 ) return false ;
97+ for ( const chunkGroup of this . _groups ) {
98+ if ( ! chunkGroup . isInitial ( ) )
99+ return false ;
100+ }
101+ return true ;
102+ }
103+
95104 hasEntryModule ( ) {
96105 return ! ! this . entryModule ;
97106 }
@@ -263,10 +272,10 @@ class Chunk {
263272 }
264273 return true ;
265274 } ;
266- if ( this . isInitial ( ) !== otherChunk . isInitial ( ) ) {
267- if ( this . isInitial ( ) ) {
275+ if ( this . hasRuntime ( ) !== otherChunk . hasRuntime ( ) ) {
276+ if ( this . hasRuntime ( ) ) {
268277 return isAvailable ( this , otherChunk ) ;
269- } else if ( otherChunk . isInitial ( ) ) {
278+ } else if ( otherChunk . hasRuntime ( ) ) {
270279 return isAvailable ( otherChunk , this ) ;
271280 } else {
272281 return false ;
@@ -279,7 +288,7 @@ class Chunk {
279288
280289 addMultiplierAndOverhead ( size , options ) {
281290 const overhead = typeof options . chunkOverhead === "number" ? options . chunkOverhead : 10000 ;
282- const multiplicator = this . isInitial ( ) ? ( options . entryChunkMultiplicator || 10 ) : 1 ;
291+ const multiplicator = this . canBeInitial ( ) ? ( options . entryChunkMultiplicator || 10 ) : 1 ;
283292
284293 return size * multiplicator + overhead ;
285294 }
@@ -317,22 +326,33 @@ class Chunk {
317326 this . sortModules ( ) ;
318327 }
319328
320- getChunkMaps ( includeInitial , realHash ) {
321- const chunkHashMap = Object . create ( null ) ;
322- const chunkNameMap = Object . create ( null ) ;
323-
329+ getAllAsyncChunks ( ) {
330+ const initialChunks = new Set ( ) ;
324331 const queue = new Set ( this . groupsIterable ) ;
325332 const chunks = new Set ( ) ;
326333
327334 for ( const chunkGroup of queue ) {
328- if ( includeInitial || ! chunkGroup . isInitial ( ) )
329- for ( const chunk of chunkGroup . chunks )
335+ for ( const chunk of chunkGroup . chunks )
336+ initialChunks . add ( chunk ) ;
337+ }
338+
339+ for ( const chunkGroup of queue ) {
340+ for ( const chunk of chunkGroup . chunks ) {
341+ if ( ! initialChunks . has ( chunk ) )
330342 chunks . add ( chunk ) ;
343+ }
331344 for ( const child of chunkGroup . childrenIterable )
332345 queue . add ( child ) ;
333346 }
334347
335- for ( const chunk of chunks ) {
348+ return chunks ;
349+ }
350+
351+ getChunkMaps ( realHash ) {
352+ const chunkHashMap = Object . create ( null ) ;
353+ const chunkNameMap = Object . create ( null ) ;
354+
355+ for ( const chunk of this . getAllAsyncChunks ( ) ) {
336356 chunkHashMap [ chunk . id ] = realHash ? chunk . hash : chunk . renderedHash ;
337357 if ( chunk . name )
338358 chunkNameMap [ chunk . id ] = chunk . name ;
@@ -344,22 +364,11 @@ class Chunk {
344364 } ;
345365 }
346366
347- getChunkModuleMaps ( includeInitial , filterFn ) {
367+ getChunkModuleMaps ( filterFn ) {
348368 const chunkModuleIdMap = Object . create ( null ) ;
349369 const chunkModuleHashMap = Object . create ( null ) ;
350370
351- const queue = new Set ( this . groupsIterable ) ;
352- const chunks = new Set ( ) ;
353-
354- for ( const chunkGroup of queue ) {
355- if ( includeInitial || ! chunkGroup . isInitial ( ) )
356- for ( const chunk of chunkGroup . chunks )
357- chunks . add ( chunk ) ;
358- for ( const child of chunkGroup . childrenIterable )
359- queue . add ( child ) ;
360- }
361-
362- for ( const chunk of chunks ) {
371+ for ( const chunk of this . getAllAsyncChunks ( ) ) {
363372 let array ;
364373 for ( const module of chunk . modulesIterable ) {
365374 if ( filterFn ( module ) ) {
0 commit comments