Skip to content

Commit eacf1b7

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
fix(@ngtools/webpack): display unused file warning once per file
1 parent d8652a2 commit eacf1b7

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/angular_compiler_plugin.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class AngularCompilerPlugin {
111111
// This is needed because if the first build fails we need to do a full emit
112112
// even whe only a single file gets updated.
113113
private _hadFullJitEmit: boolean | undefined;
114+
private _unusedFiles = new Set<string>();
114115
private _changedFileExtensions = new Set(['ts', 'tsx', 'html', 'css', 'js', 'json']);
115116

116117
// Webpack plugin.
@@ -626,12 +627,18 @@ export class AngularCompilerPlugin {
626627
}
627628
}
628629

629-
const unusedFilesWarning = program.getSourceFiles()
630-
.filter(({ fileName }) => !fileExcludeRegExp.test(fileName) && !usedFiles.has(fileName))
631-
.map(({ fileName }) => `${fileName} is part of the TypeScript compilation but it's unused.`);
630+
const sourceFiles = program.getSourceFiles();
631+
for (const { fileName } of sourceFiles) {
632+
if (
633+
fileExcludeRegExp.test(fileName)
634+
|| usedFiles.has(fileName)
635+
|| this._unusedFiles.has(fileName)
636+
) {
637+
continue;
638+
}
632639

633-
if (unusedFilesWarning.length) {
634-
compilation.warnings.push(...unusedFilesWarning);
640+
compilation.warnings.push(`${fileName} is part of the TypeScript compilation but it's unused.`);
641+
this._unusedFiles.add(fileName);
635642
}
636643
}
637644

0 commit comments

Comments
 (0)