@@ -61,17 +61,12 @@ namespace ts.server.typingsInstaller {
6161 return combinePaths ( normalizeSlashes ( globalTypingsCacheLocation ) , `node_modules/${ TypesRegistryPackageName } /index.json` ) ;
6262 }
6363
64-
65- type Exec = {
66- ( command : string , options : { cwd : string } , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : any
67- }
68-
6964 type ExecSync = {
70- ( command : string , options : { cwd : string , stdio : "ignore" } ) : any
65+ ( command : string , options : { cwd : string , stdio ? : "ignore" } ) : any
7166 }
7267
7368 export class NodeTypingsInstaller extends TypingsInstaller {
74- private readonly exec : Exec ;
69+ private readonly execSync : ExecSync ;
7570 private readonly npmPath : string ;
7671 readonly typesRegistry : Map < void > ;
7772
@@ -87,16 +82,15 @@ namespace ts.server.typingsInstaller {
8782 this . log . writeLine ( `Process id: ${ process . pid } ` ) ;
8883 }
8984 this . npmPath = getNPMLocation ( process . argv [ 0 ] ) ;
90- let execSync : ExecSync ;
91- ( { exec : this . exec , execSync } = require ( "child_process" ) ) ;
85+ ( { execSync : this . execSync } = require ( "child_process" ) ) ;
9286
9387 this . ensurePackageDirectoryExists ( globalTypingsCacheLocation ) ;
9488
9589 try {
9690 if ( this . log . isEnabled ( ) ) {
9791 this . log . writeLine ( `Updating ${ TypesRegistryPackageName } npm package...` ) ;
9892 }
99- execSync ( `${ this . npmPath } install ${ TypesRegistryPackageName } ` , { cwd : globalTypingsCacheLocation , stdio : "ignore" } ) ;
93+ this . execSync ( `${ this . npmPath } install ${ TypesRegistryPackageName } ` , { cwd : globalTypingsCacheLocation , stdio : "ignore" } ) ;
10094 }
10195 catch ( e ) {
10296 if ( this . log . isEnabled ( ) ) {
@@ -135,13 +129,21 @@ namespace ts.server.typingsInstaller {
135129 }
136130 const command = `${ this . npmPath } install ${ args . join ( " " ) } --save-dev` ;
137131 const start = Date . now ( ) ;
138- this . exec ( command , { cwd } , ( err , stdout , stderr ) => {
139- if ( this . log . isEnabled ( ) ) {
140- this . log . writeLine ( `npm install #${ requestId } took: ${ Date . now ( ) - start } ms${ sys . newLine } stdout: ${ stdout } ${ sys . newLine } stderr: ${ stderr } ` ) ;
141- }
142- // treat absence of error as success
143- onRequestCompleted ( ! err ) ;
144- } ) ;
132+ let stdout : Buffer ;
133+ let stderr : Buffer ;
134+ let hasError = false ;
135+ try {
136+ stdout = this . execSync ( command , { cwd } ) ;
137+ }
138+ catch ( e ) {
139+ stdout = e . stdout ;
140+ stderr = e . stderr ;
141+ hasError = true ;
142+ }
143+ if ( this . log . isEnabled ( ) ) {
144+ this . log . writeLine ( `npm install #${ requestId } took: ${ Date . now ( ) - start } ms${ sys . newLine } stdout: ${ stdout && stdout . toString ( ) } ${ sys . newLine } stderr: ${ stderr && stderr . toString ( ) } ` ) ;
145+ }
146+ onRequestCompleted ( ! hasError ) ;
145147 }
146148 }
147149
0 commit comments