diff --git a/packages/angular_devkit/build_angular/test/browser/unused-files-warning_spec_large.ts b/packages/angular_devkit/build_angular/test/browser/unused-files-warning_spec_large.ts index eb0cae8fb2e8..a8079e9b4f30 100644 --- a/packages/angular_devkit/build_angular/test/browser/unused-files-warning_spec_large.ts +++ b/packages/angular_devkit/build_angular/test/browser/unused-files-warning_spec_large.ts @@ -66,6 +66,40 @@ describe('Browser Builder unused files warnings', () => { await run.stop(); }); + it('should not show warning when excluded files are unused', async () => { + if (veEnabled) { + // TODO: https://github.com/angular/angular-cli/issues/15056 + pending('Only supported in Ivy.'); + + return; + } + + const ignoredFiles = { + 'src/file.d.ts': 'export type MyType = number;', + 'src/file.ngsummary.ts': 'export const hello = 42;', + 'src/file.ngfactory.ts': 'export const hello = 42;', + 'src/file.ngstyle.ts': 'export const hello = 42;', + 'src/file.ng_typecheck__.ts': 'export const hello = 42;', + }; + + host.writeMultipleFiles(ignoredFiles); + + host.replaceInFile( + 'src/tsconfig.app.json', + '"main.ts"', + `"main.ts", ${Object.keys(ignoredFiles).map(f => `"${f.replace('src/', '')}"`).join(',')}`, + ); + + const logger = new TestLogger('unused-files-warnings'); + const run = await architect.scheduleTarget(targetSpec, undefined, { logger }); + const output = await run.result as BrowserBuilderOutput; + expect(output.success).toBe(true); + expect(logger.includes(warningMessageSuffix)).toBe(false); + logger.clear(); + + await run.stop(); + }); + it('should not show warning when type files are used', async () => { if (veEnabled) { // TODO: https://github.com/angular/angular-cli/issues/15056 diff --git a/packages/ngtools/webpack/src/angular_compiler_plugin.ts b/packages/ngtools/webpack/src/angular_compiler_plugin.ts index 398421f27c59..46cbc70418d4 100644 --- a/packages/ngtools/webpack/src/angular_compiler_plugin.ts +++ b/packages/ngtools/webpack/src/angular_compiler_plugin.ts @@ -611,7 +611,7 @@ export class AngularCompilerPlugin { // JS file example `@angular/core/core.ngfactory.ts`. // - .d.ts files might not have a correspondent JS file due to bundling. // - __ng_typecheck__.ts will never be requested. - const fileExcludeRegExp = /(\.(d|ngfactory|ngstyle)\.ts|ng_typecheck__\.ts)$/; + const fileExcludeRegExp = /(\.(d|ngfactory|ngstyle|ngsummary)\.ts|ng_typecheck__\.ts)$/; // Start with a set of all the source file names we care about. const unusedSourceFileNames = new Set(