8000 refactor(@angular-devkit/build-webpack): reduce complexity of get emi… · danielsogl/angular-cli@0780e63 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0780e63

Browse files
committed
refactor(@angular-devkit/build-webpack): reduce complexity of get emitted files helper function
The deduplication logic is now inline with the chunk and asset iteration and is checked via a Set instead of a follow-up step.
1 parent f44cb90 commit 0780e63

File tree

2 files changed

+17
-13
lines changed
  • goldens/public-api/angular_devkit/build_webpack/src
  • packages/angular_devkit/build_webpack/src

2 files changed

+17
-13
lines changed

goldens/public-api/angular_devkit/build_webpack/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type DevServerBuildOutput = BuildResult & {
2424
address: string;
2525
};
2626

27-
// @public (undocumented)
27+
// @public
2828
export interface EmittedFiles {
2929
// (undocumented)
3030
asset?: boolean;

packages/angular_devkit/build_webpack/src/utils.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import * as path from 'path';
10-
import * as webpack from 'webpack';
1110

1211
export 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>();
< 10000 code>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

Comments
 (0)
0