@@ -52,6 +52,8 @@ class BroccoliTypeScriptCompiler extends Plugin {
52
52
var entries = this . listEntries ( ) ;
53
53
const inputPath = this . inputPaths [ 0 ] ;
54
54
55
+ const pathsToEmit = [ ] ;
56
+
55
57
entries . forEach ( entry => {
56
58
const tsFilePath = path . join ( inputPath , entry . relativePath ) ;
57
59
if ( ! tsFilePath . match ( / \. t s $ / ) || ! fs . existsSync ( tsFilePath ) ) {
@@ -66,13 +68,11 @@ class BroccoliTypeScriptCompiler extends Plugin {
66
68
// not get compiled. It needs to be referenced at some point, and unless we
67
69
// add the spec files first (which we don't know the order), it won't.
68
70
// So make every new files an entry point instead.
69
- // TODO(hansl): We should rather build a list and recreate the program only once.
70
- // We need to investigate if we should emit files that are not
71
+ // TODO(hansl): We need to investigate if we should emit files that are not
71
72
// referenced. This doesn't take that into account.
72
73
this . _tsServiceHost . fileNames . push ( tsFilePath ) ;
73
74
74
- // Force the TS Service to recreate the program (ie. call synchronizeHostData).
75
- this . _tsServiceHost . projectVersion ++ ;
75
+ pathsToEmit . push ( tsFilePath ) ;
76
76
} else if ( this . _fileRegistry [ tsFilePath ] . version >= entry . mtime ) {
77
77
// Nothing to do for this file. Just link the cached outputs.
78
78
this . _fileRegistry [ tsFilePath ] . outputs . forEach ( absoluteFilePath => {
@@ -83,21 +83,29 @@ class BroccoliTypeScriptCompiler extends Plugin {
83
83
return ;
84
84
} else {
85
85
this . _fileRegistry [ tsFilePath ] . version = entry . mtime ;
86
+ pathsToEmit . push ( tsFilePath ) ;
86
87
}
88
+ } ) ;
87
89
88
- var output = this . _tsService . getEmitOutput ( tsFilePath ) ;
89
- if ( output . emitSkipped ) {
90
- var errorFound = this . collectErrors ( tsFilePath ) ;
91
- if ( errorFound ) {
92
- pathsWithErrors . push ( tsFilePath ) ;
93
- errorMessages . push ( errorFound ) ;
90
+ if ( pathsToEmit . length > 0 ) {
91
+ // Force the TS Service to recreate the program (ie. call synchronizeHostData).
92
+ this . _tsServiceHost . projectVersion ++ ;
93
+
94
+ pathsToEmit . forEach ( tsFilePath => {
95
+ var output = this . _tsService . getEmitOutput ( tsFilePath ) ;
96
+ if ( output . emitSkipped ) {
97
+ var errorFound = this . collectErrors ( tsFilePath ) ;
98
+ if ( errorFound ) {
99
+ pathsWithErrors . push ( tsFilePath ) ;
100
+ errorMessages . push ( errorFound ) ;
101
+ }
102
+ } else {
103
+ output . outputFiles . forEach ( o => {
104
+ this . _outputFile ( o . name , o . text , this . _fileRegistry [ tsFilePath ] ) ;
105
+ } ) ;
94
106
}
95
- } else {
96
- output . outputFiles . forEach ( o => {
97
- this . _outputFile ( o . name , o . text , this . _fileRegistry [ tsFilePath ] ) ;
98
- } ) ;
99
- }
100
- } ) ;
107
+ } ) ;
108
+ }
101
109
102
110
if ( pathsWithErrors . length ) {
103
111
this . previousRunFailed = true ;
@@ -254,6 +262,7 @@ class CustomLanguageServiceHost {
254
262
}
255
263
256
264
getScriptVersion ( fileName ) {
265
+ fileName = path . resolve ( this . treeInputPath , fileName ) ;
257
266
return this . fileRegistry [ fileName ] && this . fileRegistry [ fileName ] . version . toString ( ) ;
258
267
}
259
268
0 commit comments