@@ -131,17 +131,28 @@ function _sortPackages() {
131131function _build ( logger : logging . Logger ) {
132132 logger . info ( 'Building...' ) ;
133133 const tsConfigPath = path . relative ( process . cwd ( ) , path . join ( __dirname , '../tsconfig.json' ) ) ;
134- try {
135- // Load the Compiler Options.
136- const tsConfig = ts . readConfigFile ( tsConfigPath , ts . sys . readFile ) ;
137- const parsedTsConfig = ts . parseJsonConfigFileContent ( tsConfig . config , ts . sys , '.' ) ;
138-
139- // Create the program and emit.
140- const program = ts . createProgram ( parsedTsConfig . fileNames , parsedTsConfig . options ) ;
141- program . emit ( ) ;
142- } catch ( err ) {
143- const stdout = err . stdout . toString ( ) . split ( '\n' ) . join ( '\n ' ) ;
144- logger . error ( `TypeScript compiler failed:\n\nSTDOUT:\n ${ stdout } ` ) ;
134+ // Load the Compiler Options.
135+ const tsConfig = ts . readConfigFile ( tsConfigPath , ts . sys . readFile ) ;
136+ const parsedTsConfig = ts . parseJsonConfigFileContent ( tsConfig . config , ts . sys , '.' ) ;
137+
138+ // Create the program and emit.
139+ const program = ts . createProgram ( parsedTsConfig . fileNames , parsedTsConfig . options ) ;
140+ const result = program . emit ( ) ;
141+ if ( result . emitSkipped ) {
142+ logger . error ( `TypeScript compiler failed:` ) ;
143+ const diagLogger = logger . createChild ( 'diagnostics' ) ;
144+ result . diagnostics . forEach ( diagnostic => {
145+ const messageText = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ;
146+
147+ if ( diagnostic . file ) {
148+ const position = diagnostic . file . getLineAndCharacterOfPosition ( diagnostic . start || 0 ) ;
149+ const fileName = diagnostic . file . fileName ;
150+ const { line, character } = position ;
151+ diagLogger . error ( `${ fileName } (${ line + 1 } ,${ character + 1 } ): ${ messageText } ` ) ;
152+ } else {
153+ diagLogger . error ( messageText ) ;
154+ }
155+ } ) ;
145156 process . exit ( 1 ) ;
146157 }
147158}
0 commit comments