| 72 | * A plugin for `tsc_wrapped` which allows Angular compilation from a plain `ts_library`. |
| 73 | */ |
| 74 | export class NgTscPlugin implements TscPlugin { |
| 75 | name = 'ngtsc'; |
| 76 | |
| 77 | private options: NgCompilerOptions | null = null; |
| 78 | private host: NgCompilerHost | null = null; |
| 79 | private _compiler: NgCompiler | null = null; |
| 80 | |
| 81 | get compiler(): NgCompiler { |
| 82 | if (this._compiler === null) { |
| 83 | throw new Error('Lifecycle error: setupCompilation() must be called first.'); |
| 84 | } |
| 85 | return this._compiler; |
| 86 | } |
| 87 | |
| 88 | constructor(private ngOptions: {}) { |
| 89 | setFileSystem(new NodeJSFileSystem()); |
| 90 | } |
| 91 | |
| 92 | wrapHost( |
| 93 | host: ts.CompilerHost & Partial<UnifiedModulesHost>, |
| 94 | inputFiles: readonly string[], |
| 95 | options: ts.CompilerOptions, |
| 96 | ): PluginCompilerHost { |
| 97 | // TODO(alxhub): Eventually the `wrapHost()` API will accept the old `ts.Program` (if one is |
| 98 | // available). When it does, its `ts.SourceFile`s need to be re-tagged to enable proper |
| 99 | // incremental compilation. |
| 100 | this.options = {...this.ngOptions, ...options} as NgCompilerOptions; |
| 101 | this.host = NgCompilerHost.wrap(host, inputFiles, this.options, /* oldProgram */ null); |
| 102 | return this.host; |
| 103 | } |
| 104 | |
| 105 | setupCompilation( |
| 106 | program: ts.Program, |
| 107 | oldProgram?: ts.Program, |
| 108 | ): { |
| 109 | ignoreForDiagnostics: Set<ts.SourceFile>; |
| 110 | ignoreForEmit: Set<ts.SourceFile>; |
| 111 | } { |
| 112 | // TODO(alxhub): we provide a `PerfRecorder` to the compiler, but because we're not driving the |
| 113 | // compilation, the information captured within it is incomplete, and may not include timings |
| 114 | // for phases such as emit. |
| 115 | // |
| 116 | // Additionally, nothing actually captures the perf results here, so recording stats at all is |
| 117 | // somewhat moot for now :) |
| 118 | const perfRecorder = ActivePerfRecorder.zeroedToNow(); |
| 119 | if (this.host === null || this.options === null) { |
| 120 | throw new Error('Lifecycle error: setupCompilation() before wrapHost().'); |
| 121 | } |
| 122 | this.host.postProgramCreationCleanup(); |
| 123 | const programDriver = new TsCreateProgramDriver( |
| 124 | program, |
| 125 | this.host, |
| 126 | this.options, |
| 127 | this.host.shimExtensionPrefixes, |
| 128 | ); |
| 129 | const strategy = new PatchedProgramIncrementalBuildStrategy(); |
| 130 | const oldState = oldProgram !== undefined ? strategy.getIncrementalState(oldProgram) : null; |
| 131 | let ticket: CompilationTicket; |
nothing calls this directly
no outgoing calls
no test coverage detected