Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 73a744b

Browse files
committed
refactor(AOT): use ng-tools public api instead of ngc private apis
use ng-tools public api instead of ngc private apis
1 parent f933223 commit 73a744b

File tree

5 files changed

+21
-55
lines changed

5 files changed

+21
-55
lines changed

src/aot/aot-compiler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class AotCompiler {
4343
this.program = createProgram(this.tsConfig.parsed.fileNames, this.tsConfig.parsed.options, this.compilerHost);
4444
}
4545

46-
compile(): Promise<void> {
46+
compile(): Promise<any> {
4747
return Promise.resolve().then(() => {
4848
}).then(() => {
4949
clearDiagnostics(this.context, DiagnosticsType.TypeScript);
@@ -59,7 +59,8 @@ export class AotCompiler {
5959
angularCompilerOptions: this.angularCompilerOptions,
6060
cliOptions: i18nOptions,
6161
program: this.program,
62-
compilerHost: this.compilerHost
62+
compilerHost: this.compilerHost,
63+
compilerOptions: this.tsConfig.parsed.options
6364
});
6465
}).then(() => {
6566
Logger.debug('[AotCompiler] compile: starting codegen ... DONE');

src/aot/codegen.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
import { CodegenOptions } from '../util/interfaces';
2-
import { runCodegen, isAngular22 } from './codegen/codegen-ng22';
3-
import { runCodegen as runCodegen23 } from './codegen/codegen-ng23plus';
1+
import { __NGTOOLS_PRIVATE_API_2 } from '@angular/compiler-cli';
42

3+
import { readFileAsync } from '../util/helpers';
4+
import { CodegenOptions } from '../util/interfaces';
55

66
export function doCodegen(options: CodegenOptions) {
7-
if (isAngular22()) {
8-
return runCodegen(options);
9-
}
10-
return runCodegen23(options);
7+
return __NGTOOLS_PRIVATE_API_2.codeGen({
8+
angularCompilerOptions: options.angularCompilerOptions,
9+
basePath: options.cliOptions.basePath,
10+
program: options.program,
11+
host: options.compilerHost,
12+
compilerOptions: options.compilerOptions,
13+
i18nFile: options.cliOptions.i18nFile,
14+
i18nFormat: options.cliOptions.i18nFormat,
15+
locale: options.cliOptions.locale,
16+
readResource: (fileName: string) => {
17+
return readFileAsync(fileName);
18+
}
19+
});
1120
}
1221

1322

src/aot/codegen/codegen-ng22.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/aot/codegen/codegen-ng23plus.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/util/interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as CompilerCLI from '@angular/compiler-cli';
22
import AngularCompilerOptions from '@angular/tsc-wrapped/src/options';
3-
import { CompilerHost, Program } from 'typescript';
3+
import { CompilerHost, CompilerOptions, Program } from 'typescript';
44

55
import { FileCache } from './file-cache';
66
import { VirtualDirStats, VirtualFileStats } from './virtual-file-utils';
@@ -179,6 +179,7 @@ export interface CodegenOptions {
179179
cliOptions: CompilerCLI.NgcCliOptions;
180180
program: Program;
181181
compilerHost: CompilerHost;
182+
compilerOptions: CompilerOptions;
182183
};
183184

184185
export interface TreeShakeCalcResults {

0 commit comments

Comments
 (0)