@@ -11,7 +11,9 @@ import * as ts from 'typescript';
11
11
12
12
import { SyntheticFilesCompilerHost } from './synthetic_files_compiler_host' ;
13
13
14
- // Copied from tsc_wrapped/plugin_api.ts to avoid a runtime dependency on that package
14
+ // Copied from tsc_wrapped/plugin_api.ts to avoid a runtime dependency on the
15
+ // @bazel /typescript package - it would be strange for non-Bazel users of
16
+ // Angular to fetch that package.
15
17
function createProxy < T > ( delegate : T ) : T {
16
18
const proxy = Object . create ( null ) ;
17
19
for ( const k of Object . keys ( delegate ) ) {
@@ -23,6 +25,20 @@ function createProxy<T>(delegate: T): T {
23
25
export class NgTscPlugin implements TscPlugin {
24
26
constructor ( private angularCompilerOptions : unknown ) { }
25
27
28
+ wrapHost ( inputFiles : string [ ] , compilerHost : ts . CompilerHost ) {
29
+ return new SyntheticFilesCompilerHost ( inputFiles , compilerHost , ( rootFiles : string [ ] ) => {
30
+ // For demo purposes, assume that the first .ts rootFile is the only
31
+ // one that needs ngfactory.js/d.ts back-compat files produced.
32
+ const tsInputs = rootFiles . filter ( f => f . endsWith ( '.ts' ) && ! f . endsWith ( '.d.ts' ) ) ;
33
+ const factoryPath : string = tsInputs [ 0 ] . replace ( / \. t s / , '.ngfactory.ts' ) ;
34
+
35
+ return {
36
+ factoryPath : ( host : ts . CompilerHost ) =>
37
+ ts . createSourceFile ( factoryPath , 'contents' , ts . ScriptTarget . ES5 ) ,
38
+ } ;
39
+ } ) ;
40
+ }
41
+
26
42
wrap ( program : ts . Program , config : { } , host : ts . CompilerHost ) {
27
43
const proxy = createProxy ( program ) ;
28
44
proxy . getSemanticDiagnostics = ( sourceFile : ts . SourceFile ) => {
@@ -38,7 +54,7 @@ export class NgTscPlugin implements TscPlugin {
38
54
category : ts . DiagnosticCategory . Error ,
39
55
code : 12345 ,
40
56
// source is the name of the plugin.
41
- source : 'Angular ' ,
57
+ source : 'ngtsc ' ,
42
58
} ;
43
59
result . push ( fake ) ;
44
60
}
@@ -64,15 +80,4 @@ export class NgTscPlugin implements TscPlugin {
64
80
} ] ;
65
81
return { afterDeclarations} ;
66
82
}
67
-
68
- wrapHost ( inputFiles : string [ ] , compilerHost : ts . CompilerHost ) {
69
- return new SyntheticFilesCompilerHost ( inputFiles , compilerHost , this . generatedFiles ) ;
70
- }
71
-
72
- generatedFiles ( rootFiles : string [ ] ) {
73
- return {
74
- 'file-1.ts' : ( host : ts . CompilerHost ) =>
75
- ts . createSourceFile ( 'file-1.ts' , 'contents' , ts . ScriptTarget . ES5 ) ,
76
- } ;
77
- }
78
83
}
0 commit comments