@@ -30,6 +30,7 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
3030 private tsServiceHost : ts . LanguageServiceHost ;
3131 private tsService : ts . LanguageService ;
3232 private firstRun : boolean = true ;
33+ private previousRunFailed : boolean = false ;
3334
3435 static includeExtensions = [ '.ts' ] ;
3536 static excludeExtensions = [ '.d.ts' ] ;
@@ -79,27 +80,7 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
7980
8081 if ( this . firstRun ) {
8182 this . firstRun = false ;
82- let program = this . tsService . getProgram ( ) ;
83- let emitResult = program . emit ( undefined , function ( absoluteFilePath , fileContent ) {
84- fse . mkdirsSync ( path . dirname ( absoluteFilePath ) ) ;
85- fs . writeFileSync ( absoluteFilePath , fileContent , FS_OPTS ) ;
86- } ) ;
87-
88- if ( emitResult . emitSkipped ) {
89- let allDiagnostics = ts . getPreEmitDiagnostics ( program ) . concat ( emitResult . diagnostics ) ;
90- let errorMessages = [ ] ;
91-
92- allDiagnostics . forEach ( diagnostic => {
93- var { line, character } = diagnostic . file . getLineAndCharacterOfPosition ( diagnostic . start ) ;
94- var message = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ;
95- errorMessages . push ( ` ${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } ` ) ;
96- } ) ;
97-
98- if ( errorMessages . length ) {
99- console . log ( errorMessages . join ( '\n' ) ) ;
100- throw new Error ( 'Typescript found errors listed above...' ) ;
101- }
102- }
83+ this . doFullBuild ( ) ;
10384 } else {
10485 pathsToEmit . forEach ( ( tsFilePath ) => {
10586 let output = this . tsService . getEmitOutput ( tsFilePath ) ;
@@ -119,7 +100,10 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
119100 } ) ;
120101
121102 if ( pathsWithErrors . length ) {
103+ this . previousRunFailed = true ;
122104 throw new Error ( 'Typescript found errors listed above...' ) ;
105+ } else if ( this . previousRunFailed ) {
106+ this . doFullBuild ( ) ;
123107 }
124108 }
125109 }
@@ -143,6 +127,34 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
143127
144128 return ! ! allDiagnostics . length ;
145129 }
130+
131+
132+ private doFullBuild ( ) {
133+ let program = this . tsService . getProgram ( ) ;
134+ let emitResult = program . emit ( undefined , function ( absoluteFilePath , fileContent ) {
135+ fse . mkdirsSync ( path . dirname ( absoluteFilePath ) ) ;
136+ fs . writeFileSync ( absoluteFilePath , fileContent , FS_OPTS ) ;
137+ } ) ;
138+
139+ if ( emitResult . emitSkipped ) {
140+ let allDiagnostics = ts . getPreEmitDiagnostics ( program ) . concat ( emitResult . diagnostics ) ;
141+ let errorMessages = [ ] ;
142+
143+ allDiagnostics . forEach ( diagnostic => {
144+ var { line, character } = diagnostic . file . getLineAndCharacterOfPosition ( diagnostic . start ) ;
145+ var message = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ;
146+ errorMessages . push ( ` ${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } ` ) ;
147+ } ) ;
148+
149+ if ( errorMessages . length ) {
150+ this . previousRunFailed = true ;
151+ console . log ( errorMessages . join ( '\n' ) ) ;
152+ throw new Error ( 'Typescript found errors listed above...' ) ;
153+ } else {
154+ this . previousRunFailed = false ;
155+ }
156+ }
157+ }
146158}
147159
148160
0 commit comments