diff --git a/integration/hello_world__closure/tsconfig.json b/integration/hello_world__closure/tsconfig.json index 68f4fd9397..34cc0b9fb2 100644 --- a/integration/hello_world__closure/tsconfig.json +++ b/integration/hello_world__closure/tsconfig.json @@ -1,7 +1,8 @@ { "angularCompilerOptions": { "annotationsAs": "static fields", - "annotateForClosureCompiler": true + "annotateForClosureCompiler": true, + "alwaysCompileGeneratedCode": true }, "compilerOptions": { diff --git a/packages/compiler-cli/integrationtest/tsconfig-build.json b/packages/compiler-cli/integrationtest/tsconfig-build.json index f46e5ba6ea..2928fa0a65 100644 --- a/packages/compiler-cli/integrationtest/tsconfig-build.json +++ b/packages/compiler-cli/integrationtest/tsconfig-build.json @@ -4,7 +4,8 @@ // in the same source directory with your code. "genDir": ".", "debug": true, - "enableSummariesForJit": true + "enableSummariesForJit": true, + "alwaysCompileGeneratedCode": true }, "compilerOptions": { diff --git a/packages/compiler-cli/test/main_spec.ts b/packages/compiler-cli/test/main_spec.ts index 5b6e822a67..a69e50c1b7 100644 --- a/packages/compiler-cli/test/main_spec.ts +++ b/packages/compiler-cli/test/main_spec.ts @@ -199,10 +199,40 @@ describe('compiler-cli', () => { }); describe('compile ngfactory files', () => { + it('should only compile ngfactory files that are referenced by root files by default', + (done) => { + writeConfig(`{ + "extends": "./tsconfig-base.json", + "files": ["mymodule.ts"] + }`); + write('mymodule.ts', ` + import {CommonModule} from '@angular/common'; + import {NgModule} from '@angular/core'; + + @NgModule({ + imports: [CommonModule] + }) + export class MyModule {} + `); + + main({p: basePath}) + .then((exitCode) => { + expect(exitCode).toEqual(0); + + expect(fs.existsSync(path.resolve(outDir, 'mymodule.ngfactory.js'))).toBe(false); + + done(); + }) + .catch(e => done.fail(e)); + }); + it('should report errors for ngfactory files that are not referenced by root files', (done) => { writeConfig(`{ "extends": "./tsconfig-base.json", - "files": ["mymodule.ts"] + "files": ["mymodule.ts"], + "angularCompilerOptions": { + "alwaysCompileGeneratedCode": true + } }`); write('mymodule.ts', ` import {NgModule, Component} from '@angular/core'; @@ -235,7 +265,10 @@ describe('compiler-cli', () => { it('should compile ngfactory files that are not referenced by root files', (done) => { writeConfig(`{ "extends": "./tsconfig-base.json", - "files": ["mymodule.ts"] + "files": ["mymodule.ts"], + "angularCompilerOptions": { + "alwaysCompileGeneratedCode": true + } }`); write('mymodule.ts', ` import {CommonModule} from '@angular/common'; @@ -289,7 +322,8 @@ describe('compiler-cli', () => { "extends": "./tsconfig-base.json", "files": ["mymodule.ts"], "angularCompilerOptions": { - "enableSummariesForJit": true + "enableSummariesForJit": true, + "alwaysCompileGeneratedCode": true } }`); write('mymodule.ts', ` diff --git a/tools/@angular/tsc-wrapped/src/main.ts b/tools/@angular/tsc-wrapped/src/main.ts index 220e883a1c..3405cdf9f6 100644 --- a/tools/@angular/tsc-wrapped/src/main.ts +++ b/tools/@angular/tsc-wrapped/src/main.ts @@ -124,8 +124,11 @@ export function main( if (diagnostics) console.time('NG codegen'); return codegen(ngOptions, cliOptions, program, host).then((genFiles) => { if (diagnostics) console.timeEnd('NG codegen'); + // Add the generated files to the configuration so they will become part of the program. - genFiles.forEach(genFileName => addGeneratedFileName(genFileName)); + if (ngOptions.alwaysCompileGeneratedCode) { + genFiles.forEach(genFileName => addGeneratedFileName(genFileName)); + } let definitionsHost: ts.CompilerHost = tsickleCompilerHost; if (!ngOptions.skipMetadataEmit) { // if tsickle is not not used for emitting, but we do use the MetadataWriterHost, diff --git a/tools/@angular/tsc-wrapped/src/options.ts b/tools/@angular/tsc-wrapped/src/options.ts index fb24aa8b44..f9ad2bde23 100644 --- a/tools/@angular/tsc-wrapped/src/options.ts +++ b/tools/@angular/tsc-wrapped/src/options.ts @@ -83,8 +83,13 @@ interface Options extends ts.CompilerOptions { enableLegacyTemplate?: boolean; // Whether to generate .ngsummary.ts files that allow to use AOTed artifacts - // in JIT mode. + // in JIT mode. This is off by default. enableSummariesForJit?: boolean; + + // Whether to compile generated .ngfacgtory.ts files, even when they are no + // matched by the `files` / `includes` in the `tsconfig.json`. + // This is off by default. + alwaysCompileGeneratedCode?: boolean; } export default Options;