refactor(compiler): don’t write summaries for jit by default
The default is false externally but true internally at Google.
This commit is contained in:
parent
d56b7ed96d
commit
90b0713e32
|
@ -3,7 +3,8 @@
|
||||||
// For TypeScript 1.8, we have to lay out generated files
|
// For TypeScript 1.8, we have to lay out generated files
|
||||||
// in the same source directory with your code.
|
// in the same source directory with your code.
|
||||||
"genDir": ".",
|
"genDir": ".",
|
||||||
"debug": true
|
"debug": true,
|
||||||
|
"enableSummariesForJit": true
|
||||||
},
|
},
|
||||||
|
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
|
|
@ -100,6 +100,7 @@ export class CodeGenerator {
|
||||||
i18nFormat: cliOptions.i18nFormat,
|
i18nFormat: cliOptions.i18nFormat,
|
||||||
locale: cliOptions.locale, missingTranslation,
|
locale: cliOptions.locale, missingTranslation,
|
||||||
enableLegacyTemplate: options.enableLegacyTemplate !== false,
|
enableLegacyTemplate: options.enableLegacyTemplate !== false,
|
||||||
|
enableSummariesForJit: options.enableSummariesForJit !== false,
|
||||||
});
|
});
|
||||||
return new CodeGenerator(options, program, tsCompilerHost, aotCompiler, ngCompilerHost);
|
return new CodeGenerator(options, program, tsCompilerHost, aotCompiler, ngCompilerHost);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,10 @@ import {CodeGenerator} from './codegen';
|
||||||
function codegen(
|
function codegen(
|
||||||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.NgcCliOptions, program: ts.Program,
|
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.NgcCliOptions, program: ts.Program,
|
||||||
host: ts.CompilerHost) {
|
host: ts.CompilerHost) {
|
||||||
|
if (ngOptions.enableSummariesForJit === undefined) {
|
||||||
|
// default to false
|
||||||
|
ngOptions.enableSummariesForJit = false;
|
||||||
|
}
|
||||||
return CodeGenerator.create(ngOptions, cliOptions, program, host).codegen();
|
return CodeGenerator.create(ngOptions, cliOptions, program, host).codegen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,10 +99,15 @@ export class NgTools_InternalApi_NG_2 {
|
||||||
missingTranslation: options.missingTranslation !,
|
missingTranslation: options.missingTranslation !,
|
||||||
basePath: options.basePath
|
basePath: options.basePath
|
||||||
};
|
};
|
||||||
|
const ngOptions = options.angularCompilerOptions;
|
||||||
|
if (ngOptions.enableSummariesForJit === undefined) {
|
||||||
|
// default to false
|
||||||
|
ngOptions.enableSummariesForJit = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Create the Code Generator.
|
// Create the Code Generator.
|
||||||
const codeGenerator = CodeGenerator.create(
|
const codeGenerator =
|
||||||
options.angularCompilerOptions, cliOptions, options.program, options.host, hostContext);
|
CodeGenerator.create(ngOptions, cliOptions, options.program, options.host, hostContext);
|
||||||
|
|
||||||
return codeGenerator.codegen();
|
return codeGenerator.codegen();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ function compile(
|
||||||
return ngChecker.getDiagnostics();
|
return ngChecker.getDiagnostics();
|
||||||
}
|
}
|
||||||
|
|
||||||
fdescribe('ng type checker', () => {
|
describe('ng type checker', () => {
|
||||||
let angularFiles = setup();
|
let angularFiles = setup();
|
||||||
|
|
||||||
function accept(...files: MockDirectory[]) {
|
function accept(...files: MockDirectory[]) {
|
||||||
|
|
|
@ -261,5 +261,52 @@ describe('compiler-cli', () => {
|
||||||
})
|
})
|
||||||
.catch(e => done.fail(e));
|
.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));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -35,7 +35,8 @@ export class AotCompiler {
|
||||||
private _viewCompiler: ViewCompiler, private _ngModuleCompiler: NgModuleCompiler,
|
private _viewCompiler: ViewCompiler, private _ngModuleCompiler: NgModuleCompiler,
|
||||||
private _outputEmitter: OutputEmitter,
|
private _outputEmitter: OutputEmitter,
|
||||||
private _summaryResolver: SummaryResolver<StaticSymbol>, private _localeId: string|null,
|
private _summaryResolver: SummaryResolver<StaticSymbol>, 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(); }
|
clearCache() { this._metadataResolver.clearCache(); }
|
||||||
|
|
||||||
|
@ -204,10 +205,12 @@ export class AotCompiler {
|
||||||
o.StmtModifier.Exported
|
o.StmtModifier.Exported
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
return [
|
const summaryJson = new GeneratedFile(srcFileUrl, summaryFileName(srcFileUrl), json);
|
||||||
new GeneratedFile(srcFileUrl, summaryFileName(srcFileUrl), json),
|
if (this._enableSummariesForJit) {
|
||||||
this._codegenSourceModule(srcFileUrl, forJitOutputCtx)
|
return [summaryJson, this._codegenSourceModule(srcFileUrl, forJitOutputCtx)];
|
||||||
];
|
};
|
||||||
|
|
||||||
|
return [summaryJson];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _compileModule(outputCtx: OutputContext, ngModuleType: StaticSymbol): void {
|
private _compileModule(outputCtx: OutputContext, ngModuleType: StaticSymbol): void {
|
||||||
|
|
|
@ -70,6 +70,7 @@ export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCom
|
||||||
const compiler = new AotCompiler(
|
const compiler = new AotCompiler(
|
||||||
config, compilerHost, staticReflector, resolver, tmplParser, new StyleCompiler(urlResolver),
|
config, compilerHost, staticReflector, resolver, tmplParser, new StyleCompiler(urlResolver),
|
||||||
viewCompiler, new NgModuleCompiler(staticReflector), new TypeScriptEmitter(), summaryResolver,
|
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};
|
return {compiler, reflector: staticReflector};
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,4 +14,5 @@ export interface AotCompilerOptions {
|
||||||
translations?: string;
|
translations?: string;
|
||||||
missingTranslation?: MissingTranslationStrategy;
|
missingTranslation?: MissingTranslationStrategy;
|
||||||
enableLegacyTemplate?: boolean;
|
enableLegacyTemplate?: boolean;
|
||||||
|
enableSummariesForJit?: boolean
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* 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';
|
import {MockDirectory, compile, setup} from './test_util';
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ describe('aot summaries for jit', () => {
|
||||||
|
|
||||||
function compileApp(rootDir: MockDirectory, options: {useSummaries?: boolean} = {}):
|
function compileApp(rootDir: MockDirectory, options: {useSummaries?: boolean} = {}):
|
||||||
{genFiles: GeneratedFile[], outDir: MockDirectory} {
|
{genFiles: GeneratedFile[], outDir: MockDirectory} {
|
||||||
return compile([rootDir, angularFiles], options);
|
return compile([rootDir, angularFiles], {...options, enableSummariesForJit: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should create @Injectable summaries', () => {
|
it('should create @Injectable summaries', () => {
|
||||||
|
|
|
@ -81,6 +81,10 @@ interface Options extends ts.CompilerOptions {
|
||||||
|
|
||||||
// Whether to enable support for <template> and the template attribute (true by default)
|
// Whether to enable support for <template> and the template attribute (true by default)
|
||||||
enableLegacyTemplate?: boolean;
|
enableLegacyTemplate?: boolean;
|
||||||
|
|
||||||
|
// Whether to generate .ngsummary.ts files that allow to use AOTed artifacts
|
||||||
|
// in JIT mode.
|
||||||
|
enableSummariesForJit?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Options;
|
export default Options;
|
||||||
|
|
Loading…
Reference in New Issue