77 */
88
99import * as path from 'path' ;
10- import * as webpack from 'webpack' ;
1110
1211export interface EmittedFiles {
1312 id ?: string ;
@@ -18,16 +17,20 @@ export interface EmittedFiles {
1817 extension : string ;
1918}
2019
21- export function getEmittedFiles ( compilation : webpack . Compilation ) : EmittedFiles [ ] {
20+ export function getEmittedFiles ( compilation : import ( ' webpack' ) . Compilation ) : EmittedFiles [ ] {
2221 const files : EmittedFiles [ ] = [ ] ;
22+ const chunkFileNames = new Set < string > ( ) ;
2323
2424 // adds all chunks to the list of emitted files such as lazy loaded modules
25- for ( const chunk of compilation . chunks as Iterable < webpack . Chunk > ) {
25+ for ( const chunk of compilation . chunks ) {
2626 for ( const file of chunk . files ) {
27+ if ( chunkFileNames . has ( file ) ) {
28+ continue ;
29+ }
30+
31+ chunkFileNames . add ( file ) ;
2732 files . push ( {
28- // The id is guaranteed to exist at this point in the compilation process
29- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
30- id : chunk . id ! . toString ( ) ,
33+ id : chunk . id ?. toString ( ) ,
3134 name : chunk . name ,
3235 file,
3336 extension : path . extname ( file ) ,
@@ -36,14 +39,15 @@ export function getEmittedFiles(compilation: webpack.Compilation): EmittedFiles[
3639 }
3740 }
3841
39- // other all files
42+ // add all other files
4043 for ( const file of Object . keys ( compilation . assets ) ) {
44+ // Chunk files have already been added to the files list above
45+ if ( chunkFileNames . has ( file ) ) {
46+ continue ;
47+ }
48+
4149 files . push ( { file, extension : path . extname ( file ) , initial : false , asset : true } ) ;
4250 }
4351
44- // dedupe
45- return files . filter (
46- ( { file, name } , index ) =>
47- files . findIndex ( ( f ) => f . file === file && ( ! name || name === f . name ) ) === index ,
48- ) ;
52+ return files ;
4953}
0 commit comments