7
7
*/
8
8
9
9
import * as path from 'path' ;
10
- import * as webpack from 'webpack' ;
11
10
12
11
export interface EmittedFiles {
13
12
id ?: string ;
@@ -18,16 +17,20 @@ export interface EmittedFiles {
18
17
extension : string ;
19
18
}
20
19
21
- export function getEmittedFiles ( compilation : webpack . Compilation ) : EmittedFiles [ ] {
20
+ export function getEmittedFiles ( compilation : import ( ' webpack' ) . Compilation ) : EmittedFiles [ ] {
22
21
const files : EmittedFiles [ ] = [ ] ;
22
+ const chunkFileNames = new Set < string > ( ) ;
<
10000
code>23 23
24
24
// 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 ) {
26
26
for ( const file of chunk . files ) {
27
+ if ( chunkFileNames . has ( file ) ) {
28
+ continue ;
29
+ }
30
+
31
+ chunkFileNames . add ( file ) ;
27
32
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 ( ) ,
31
34
name : chunk . name ,
32
35
file,
33
36
extension : path . extname ( file ) ,
@@ -36,14 +39,15 @@ export function getEmittedFiles(compilation: webpack.Compilation): EmittedFiles[
36
39
}
37
40
}
38
41
39
- // other all files
42
+ // add all other files
40
43
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
+
41
49
files . push ( { file, extension : path . extname ( file ) , initial : false , asset : true } ) ;
42
50
}
43
51
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 ;
49
53
}
0 commit comments