@@ -61,17 +61,12 @@ namespace ts.server.typingsInstaller {
61
61
return combinePaths ( normalizeSlashes ( globalTypingsCacheLocation ) , `node_modules/${ TypesRegistryPackageName } /index.json` ) ;
62
62
}
63
63
64
-
65
- type Exec = {
66
- ( command : string , options : { cwd : string } , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : any
67
- } ;
68
-
69
64
type ExecSync = {
70
- ( command : string , options : { cwd : string , stdio : "ignore" } ) : any
71
- } ;
65
+ ( command : string , options : { cwd : string , stdio ? : "ignore" } ) : any
66
+ }
72
67
73
68
export class NodeTypingsInstaller extends TypingsInstaller {
74
- private readonly exec : Exec ;
69
+ private readonly execSync : ExecSync ;
75
70
private readonly npmPath : string ;
76
71
readonly typesRegistry : Map < void > ;
77
72
@@ -87,16 +82,15 @@ namespace ts.server.typingsInstaller {
87
82
this . log . writeLine ( `Process id: ${ process . pid } ` ) ;
88
83
}
89
84
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" ) ) ;
92
86
93
87
this . ensurePackageDirectoryExists ( globalTypingsCacheLocation ) ;
94
88
95
89
try {
96
90
if ( this . log . isEnabled ( ) ) {
97
91
this . log . writeLine ( `Updating ${ TypesRegistryPackageName } npm package...` ) ;
98
92
}
99
- execSync ( `${ this . npmPath } install ${ TypesRegistryPackageName } ` , { cwd : globalTypingsCacheLocation , stdio : "ignore" } ) ;
93
+ this . execSync ( `${ this . npmPath } install ${ TypesRegistryPackageName } ` , { cwd : globalTypingsCacheLocation , stdio : "ignore" } ) ;
100
94
}
101
95
catch ( e ) {
102
96
if ( this . log . isEnabled ( ) ) {
@@ -135,13 +129,21 @@ namespace ts.server.typingsInstaller {
135
129
}
136
130
const command = `${ this . npmPath } install ${ args . join ( " " ) } --save-dev` ;
137
131
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 ) ;
145
147
}
146
148
}
147
149
0 commit comments