From b9252077463f16ba61b4fedd3fba2a21a3784f8f Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Mon, 11 Nov 2019 13:03:08 +0000 Subject: [PATCH] fix(@ngtools/webpack): don't warn on unused ngsummary Fix https://github.com/angular/angular-cli/issues/15626#issuecomment-551632356 (cherry picked from commit 9b91163c52248651b03ae2f1a145b1907c509b56) --- .../unused-files-warning_spec_large.ts | 34 +++++++++++++++++++ .../webpack/src/angular_compiler_plugin.ts | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) 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(