@@ -70,10 +70,10 @@ namespace ts.server.typingsInstaller {
70
70
cwd : string ;
71
71
encoding : "utf-8" ;
72
72
}
73
- type ExecFileSync = ( file : string , args : string [ ] , options : ExecSyncOptions ) => string ;
73
+ type ExecSync = ( command : string , options : ExecSyncOptions ) => string ;
74
74
75
75
export class NodeTypingsInstaller extends TypingsInstaller {
76
- private readonly nodeExecFileSync : ExecFileSync ;
76
+ private readonly nodeExecSync : ExecSync ;
77
77
private readonly npmPath : string ;
78
78
readonly typesRegistry : Map < MapLike < string > > ;
79
79
@@ -89,19 +89,23 @@ namespace ts.server.typingsInstaller {
89
89
log ) ;
90
90
this . npmPath = npmLocation !== undefined ? npmLocation : getDefaultNPMLocation ( process . argv [ 0 ] ) ;
91
91
92
+ // If the NPM path contains spaces and isn't wrapped in quotes, do so.
93
+ if ( stringContains ( this . npmPath , " " ) && this . npmPath [ 0 ] !== `"` ) {
94
+ this . npmPath = `"${ this . npmPath } "` ;
95
+ }
92
96
if ( this . log . isEnabled ( ) ) {
93
97
this . log . writeLine ( `Process id: ${ process . pid } ` ) ;
94
98
this . log . writeLine ( `NPM location: ${ this . npmPath } (explicit '${ Arguments . NpmLocation } ' ${ npmLocation === undefined ? "not " : "" } provided)` ) ;
95
99
}
96
- ( { execFileSync : this . nodeExecFileSync } = require ( "child_process" ) ) ;
100
+ ( { execSync : this . nodeExecSync } = require ( "child_process" ) ) ;
97
101
98
102
this . ensurePackageDirectoryExists ( globalTypingsCacheLocation ) ;
99
103
100
104
try {
101
105
if ( this . log . isEnabled ( ) ) {
102
106
this . log . writeLine ( `Updating ${ typesRegistryPackageName } npm package...` ) ;
103
107
}
104
- this . execFileSyncAndLog ( this . npmPath , [ " install" , " --ignore-scripts" , ` ${ typesRegistryPackageName } @${ this . latestDistTag } `] , { cwd : globalTypingsCacheLocation } ) ;
108
+ this . execSyncAndLog ( ` ${ this . npmPath } install --ignore-scripts ${ typesRegistryPackageName } @${ this . latestDistTag } `, { cwd : globalTypingsCacheLocation } ) ;
105
109
if ( this . log . isEnabled ( ) ) {
106
110
this . log . writeLine ( `Updated ${ typesRegistryPackageName } npm package` ) ;
107
111
}
@@ -185,20 +189,20 @@ namespace ts.server.typingsInstaller {
185
189
this . log . writeLine ( `#${ requestId } with arguments'${ JSON . stringify ( packageNames ) } '.` ) ;
186
190
}
187
191
const start = Date . now ( ) ;
188
- const hasError = installNpmPackages ( this . npmPath , version , packageNames , ( file , args ) => this . execFileSyncAndLog ( file , args , { cwd } ) ) ;
192
+ const hasError = installNpmPackages ( this . npmPath , version , packageNames , command => this . execSyncAndLog ( command , { cwd } ) ) ;
189
193
if ( this . log . isEnabled ( ) ) {
190
194
this . log . writeLine ( `npm install #${ requestId } took: ${ Date . now ( ) - start } ms` ) ;
191
195
}
192
196
onRequestCompleted ( ! hasError ) ;
193
197
}
194
198
195
199
/** Returns 'true' in case of error. */
196
- private execFileSyncAndLog ( file : string , args : string [ ] , options : Pick < ExecSyncOptions , "cwd" > ) : boolean {
200
+ private execSyncAndLog ( command : string , options : Pick < ExecSyncOptions , "cwd" > ) : boolean {
197
201
if ( this . log . isEnabled ( ) ) {
198
- this . log . writeLine ( `Exec: ${ file } ${ args . join ( " " ) } ` ) ;
202
+ this . log . writeLine ( `Exec: ${ command } ` ) ;
199
203
}
200
204
try {
201
- const stdout = this . nodeExecFileSync ( file , args , { ...options , encoding : "utf-8" } ) ;
205
+ const stdout = this . nodeExecSync ( command , { ...options , encoding : "utf-8" } ) ;
202
206
if ( this . log . isEnabled ( ) ) {
203
207
this . log . writeLine ( ` Succeeded. stdout:${ indent ( sys . newLine , stdout ) } ` ) ;
204
208
}
0 commit comments