-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathutils.ts
47 lines (41 loc) · 1.36 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as path from 'path';
import * as webpack from 'webpack';
export interface EmittedFiles {
id?: string;
name?: string;
file: string;
initial: boolean;
asset?: boolean;
extension: string;
}
export function getEmittedFiles(compilation: webpack.compilation.Compilation): EmittedFiles[] {
const files: EmittedFiles[] = [];
// adds all chunks to the list of emitted files such as lazy loaded modules
for (const chunk of compilation.chunks as Iterable<webpack.compilation.Chunk>) {
for (const file of chunk.files) {
files.push({
// The id is guaranteed to exist at this point in the compilation process
// tslint:disable-next-line: no-non-null-assertion
id: chunk.id!.toString(),
name: chunk.name,
file,
extension: path.extname(file),
initial: chunk.isOnlyInitial(),
});
}
}
// other all files
for (const file of Object.keys(compilation.assets)) {
files.push({ file, extension: path.extname(file), initial: false, asset: true });
}
// dedupe
return files.filter(({ file, name }, index) =>
files.findIndex(f => f.file === file && (!name || name === f.name)) === index);
}