From 90b0713e32619dc6be70c9b5c91e3c254af39d4c Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Fri, 9 Jun 2017 14:00:03 -0700 Subject: [PATCH] =?UTF-8?q?refactor(compiler):=20don=E2=80=99t=20write=20s?= =?UTF-8?q?ummaries=20for=20jit=20by=20default?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default is false externally but true internally at Google. --- .../integrationtest/tsconfig-build.json | 3 +- packages/compiler-cli/src/codegen.ts | 1 + packages/compiler-cli/src/main.ts | 4 ++ packages/compiler-cli/src/ngtools_api.ts | 9 +++- .../test/diagnostics/check_types_spec.ts | 2 +- packages/compiler-cli/test/main_spec.ts | 47 +++++++++++++++++++ packages/compiler/src/aot/compiler.ts | 13 +++-- packages/compiler/src/aot/compiler_factory.ts | 3 +- packages/compiler/src/aot/compiler_options.ts | 1 + .../compiler/test/aot/jit_summaries_spec.ts | 4 +- tools/@angular/tsc-wrapped/src/options.ts | 4 ++ 11 files changed, 79 insertions(+), 12 deletions(-) diff --git a/packages/compiler-cli/integrationtest/tsconfig-build.json b/packages/compiler-cli/integrationtest/tsconfig-build.json index 9250ea6cc8..f46e5ba6ea 100644 --- a/packages/compiler-cli/integrationtest/tsconfig-build.json +++ b/packages/compiler-cli/integrationtest/tsconfig-build.json @@ -3,7 +3,8 @@ // For TypeScript 1.8, we have to lay out generated files // in the same source directory with your code. "genDir": ".", - "debug": true + "debug": true, + "enableSummariesForJit": true }, "compilerOptions": { diff --git a/packages/compiler-cli/src/codegen.ts b/packages/compiler-cli/src/codegen.ts index 47c0f96e49..675e6fbb3d 100644 --- a/packages/compiler-cli/src/codegen.ts +++ b/packages/compiler-cli/src/codegen.ts @@ -100,6 +100,7 @@ export class CodeGenerator { i18nFormat: cliOptions.i18nFormat, locale: cliOptions.locale, missingTranslation, enableLegacyTemplate: options.enableLegacyTemplate !== false, + enableSummariesForJit: options.enableSummariesForJit !== false, }); return new CodeGenerator(options, program, tsCompilerHost, aotCompiler, ngCompilerHost); } diff --git a/packages/compiler-cli/src/main.ts b/packages/compiler-cli/src/main.ts index db462e2db8..3dc68977d9 100644 --- a/packages/compiler-cli/src/main.ts +++ b/packages/compiler-cli/src/main.ts @@ -20,6 +20,10 @@ import {CodeGenerator} from './codegen'; function codegen( ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.NgcCliOptions, program: ts.Program, host: ts.CompilerHost) { + if (ngOptions.enableSummariesForJit === undefined) { + // default to false + ngOptions.enableSummariesForJit = false; + } return CodeGenerator.create(ngOptions, cliOptions, program, host).codegen(); } diff --git a/packages/compiler-cli/src/ngtools_api.ts b/packages/compiler-cli/src/ngtools_api.ts index 058b794838..766ce3394f 100644 --- a/packages/compiler-cli/src/ngtools_api.ts +++ b/packages/compiler-cli/src/ngtools_api.ts @@ -99,10 +99,15 @@ export class NgTools_InternalApi_NG_2 { missingTranslation: options.missingTranslation !, basePath: options.basePath }; + const ngOptions = options.angularCompilerOptions; + if (ngOptions.enableSummariesForJit === undefined) { + // default to false + ngOptions.enableSummariesForJit = false; + } // Create the Code Generator. - const codeGenerator = CodeGenerator.create( - options.angularCompilerOptions, cliOptions, options.program, options.host, hostContext); + const codeGenerator = + CodeGenerator.create(ngOptions, cliOptions, options.program, options.host, hostContext); return codeGenerator.codegen(); } diff --git a/packages/compiler-cli/test/diagnostics/check_types_spec.ts b/packages/compiler-cli/test/diagnostics/check_types_spec.ts index 6ad4e3f8bc..a2c52ee873 100644 --- a/packages/compiler-cli/test/diagnostics/check_types_spec.ts +++ b/packages/compiler-cli/test/diagnostics/check_types_spec.ts @@ -25,7 +25,7 @@ function compile( return ngChecker.getDiagnostics(); } -fdescribe('ng type checker', () => { +describe('ng type checker', () => { let angularFiles = setup(); function accept(...files: MockDirectory[]) { diff --git a/packages/compiler-cli/test/main_spec.ts b/packages/compiler-cli/test/main_spec.ts index a2f6e26832..5b6e822a67 100644 --- a/packages/compiler-cli/test/main_spec.ts +++ b/packages/compiler-cli/test/main_spec.ts @@ -261,5 +261,52 @@ describe('compiler-cli', () => { }) .catch(e => done.fail(e)); }); + + it('should not produce ngsummary files by default', (done) => { + writeConfig(`{ + "extends": "./tsconfig-base.json", + "files": ["mymodule.ts"] + }`); + write('mymodule.ts', ` + import {NgModule} from '@angular/core'; + + @NgModule() + export class MyModule {} + `); + + main({p: basePath}) + .then((exitCode) => { + expect(exitCode).toEqual(0); + expect(fs.existsSync(path.resolve(outDir, 'mymodule.ngsummary.js'))).toBe(false); + + done(); + }) + .catch(e => done.fail(e)); + }); + + it('should produce ngsummary files if configured', (done) => { + writeConfig(`{ + "extends": "./tsconfig-base.json", + "files": ["mymodule.ts"], + "angularCompilerOptions": { + "enableSummariesForJit": true + } + }`); + write('mymodule.ts', ` + import {NgModule} from '@angular/core'; + + @NgModule() + export class MyModule {} + `); + + main({p: basePath}) + .then((exitCode) => { + expect(exitCode).toEqual(0); + expect(fs.existsSync(path.resolve(outDir, 'mymodule.ngsummary.js'))).toBe(true); + + done(); + }) + .catch(e => done.fail(e)); + }); }); }); diff --git a/packages/compiler/src/aot/compiler.ts b/packages/compiler/src/aot/compiler.ts index ae23a5c3d3..f8e57b0d5d 100644 --- a/packages/compiler/src/aot/compiler.ts +++ b/packages/compiler/src/aot/compiler.ts @@ -35,7 +35,8 @@ export class AotCompiler { private _viewCompiler: ViewCompiler, private _ngModuleCompiler: NgModuleCompiler, private _outputEmitter: OutputEmitter, private _summaryResolver: SummaryResolver, private _localeId: string|null, - private _translationFormat: string|null, private _symbolResolver: StaticSymbolResolver) {} + private _translationFormat: string|null, private _enableSummariesForJit: boolean|null, + private _symbolResolver: StaticSymbolResolver) {} clearCache() { this._metadataResolver.clearCache(); } @@ -204,10 +205,12 @@ export class AotCompiler { o.StmtModifier.Exported ])); }); - return [ - new GeneratedFile(srcFileUrl, summaryFileName(srcFileUrl), json), - this._codegenSourceModule(srcFileUrl, forJitOutputCtx) - ]; + const summaryJson = new GeneratedFile(srcFileUrl, summaryFileName(srcFileUrl), json); + if (this._enableSummariesForJit) { + return [summaryJson, this._codegenSourceModule(srcFileUrl, forJitOutputCtx)]; + }; + + return [summaryJson]; } private _compileModule(outputCtx: OutputContext, ngModuleType: StaticSymbol): void { diff --git a/packages/compiler/src/aot/compiler_factory.ts b/packages/compiler/src/aot/compiler_factory.ts index ab44366458..7d911e4c81 100644 --- a/packages/compiler/src/aot/compiler_factory.ts +++ b/packages/compiler/src/aot/compiler_factory.ts @@ -70,6 +70,7 @@ export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCom const compiler = new AotCompiler( config, compilerHost, staticReflector, resolver, tmplParser, new StyleCompiler(urlResolver), viewCompiler, new NgModuleCompiler(staticReflector), new TypeScriptEmitter(), summaryResolver, - options.locale || null, options.i18nFormat || null, symbolResolver); + options.locale || null, options.i18nFormat || null, options.enableSummariesForJit || null, + symbolResolver); return {compiler, reflector: staticReflector}; } diff --git a/packages/compiler/src/aot/compiler_options.ts b/packages/compiler/src/aot/compiler_options.ts index 84b899fc11..772ce3ca12 100644 --- a/packages/compiler/src/aot/compiler_options.ts +++ b/packages/compiler/src/aot/compiler_options.ts @@ -14,4 +14,5 @@ export interface AotCompilerOptions { translations?: string; missingTranslation?: MissingTranslationStrategy; enableLegacyTemplate?: boolean; + enableSummariesForJit?: boolean } diff --git a/packages/compiler/test/aot/jit_summaries_spec.ts b/packages/compiler/test/aot/jit_summaries_spec.ts index 00033e4f00..0bf7643a61 100644 --- a/packages/compiler/test/aot/jit_summaries_spec.ts +++ b/packages/compiler/test/aot/jit_summaries_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {AotCompiler, AotCompilerHost, AotCompilerOptions, CompileSummaryKind, GeneratedFile, createAotCompiler, toTypeScript} from '@angular/compiler'; +import {AotCompiler, AotCompilerHost, AotCompilerOptions, CompileSummaryKind, GeneratedFile, toTypeScript} from '@angular/compiler'; import {MockDirectory, compile, setup} from './test_util'; @@ -15,7 +15,7 @@ describe('aot summaries for jit', () => { function compileApp(rootDir: MockDirectory, options: {useSummaries?: boolean} = {}): {genFiles: GeneratedFile[], outDir: MockDirectory} { - return compile([rootDir, angularFiles], options); + return compile([rootDir, angularFiles], {...options, enableSummariesForJit: true}); } it('should create @Injectable summaries', () => { diff --git a/tools/@angular/tsc-wrapped/src/options.ts b/tools/@angular/tsc-wrapped/src/options.ts index 4e3c7e9df3..fb24aa8b44 100644 --- a/tools/@angular/tsc-wrapped/src/options.ts +++ b/tools/@angular/tsc-wrapped/src/options.ts @@ -81,6 +81,10 @@ interface Options extends ts.CompilerOptions { // Whether to enable support for