From c7a874dd2f0719dec207f4d054a27102fa3e8950 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 23 Aug 2016 16:26:35 -0700 Subject: [PATCH] feature(ngc): allow codegen to skip over .d.ts inputs (#11021) --- modules/@angular/compiler-cli/src/codegen.ts | 11 ++++++++--- tools/@angular/tsc-wrapped/src/options.ts | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/@angular/compiler-cli/src/codegen.ts b/modules/@angular/compiler-cli/src/codegen.ts index 1ac0e26f62..4a34f86224 100644 --- a/modules/@angular/compiler-cli/src/codegen.ts +++ b/modules/@angular/compiler-cli/src/codegen.ts @@ -26,6 +26,7 @@ import {StaticReflector, StaticSymbol} from './static_reflector'; const nodeFs = require('fs'); const GENERATED_FILES = /\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/; +const GENERATED_OR_DTS_FILES = /\.d\.ts$|\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/; const PREAMBLE = `/** * This file is generated by the Angular 2 template compiler. @@ -94,9 +95,13 @@ export class CodeGenerator { } codegen(): Promise { - const filePaths = this.program.getSourceFiles() - .map(sf => this.reflectorHost.getCanonicalFileName(sf.fileName)) - .filter(f => !GENERATED_FILES.test(f)); + // Compare with false since the default should be true + const skipFileNames = (this.options.generateCodeForLibraries === false) ? + GENERATED_OR_DTS_FILES : + GENERATED_FILES; + let filePaths = this.program.getSourceFiles() + .filter(sf => !skipFileNames.test(sf.fileName)) + .map(sf => this.reflectorHost.getCanonicalFileName(sf.fileName)); const fileMetas = filePaths.map((filePath) => this.readFileMetadata(filePath)); const ngModules = fileMetas.reduce((ngModules, fileMeta) => { ngModules.push(...fileMeta.ngModules); diff --git a/tools/@angular/tsc-wrapped/src/options.ts b/tools/@angular/tsc-wrapped/src/options.ts index c4f32d3d26..db6f7bee41 100644 --- a/tools/@angular/tsc-wrapped/src/options.ts +++ b/tools/@angular/tsc-wrapped/src/options.ts @@ -16,6 +16,11 @@ interface Options extends ts.CompilerOptions { // Don't produce .ngfactory.ts or .css.shim.ts files skipTemplateCodegen: boolean; + // Whether to generate code for library code. + // If true, produce .ngfactory.ts and .css.shim.ts files for .d.ts inputs. + // Default is true. + generateCodeForLibraries?: boolean; + // Print extra information while running the compiler trace: boolean;