@@ -29,13 +29,17 @@ namespace ts.server.typingsInstaller {
29
29
}
30
30
31
31
/** Used if `--npmLocation` is not passed. */
32
- function getDefaultNPMLocation ( processName : string ) {
32
+ function getDefaultNPMLocation ( processName : string , validateDefaultNpmLocation : boolean , host : InstallTypingHost ) : string {
33
33
if ( path . basename ( processName ) . indexOf ( "node" ) === 0 ) {
34
- return `"${ path . join ( path . dirname ( process . argv [ 0 ] ) , "npm" ) } "` ;
35
- }
36
- else {
37
- return "npm" ;
34
+ const npmPath = path . join ( path . dirname ( process . argv [ 0 ] ) , "npm" ) ;
35
+ if ( ! validateDefaultNpmLocation ) {
36
+ return npmPath ;
37
+ }
38
+ if ( host . fileExists ( npmPath ) ) {
39
+ return `"${ npmPath } "` ;
40
+ }
38
41
}
42
+ return "npm" ;
39
43
}
40
44
41
45
interface TypesRegistryFile {
@@ -79,15 +83,15 @@ namespace ts.server.typingsInstaller {
79
83
80
84
private delayedInitializationError : InitializationFailedResponse | undefined ;
81
85
82
- constructor ( globalTypingsCacheLocation : string , typingSafeListLocation : string , typesMapLocation : string , npmLocation : string | undefined , throttleLimit : number , log : Log ) {
86
+ constructor ( globalTypingsCacheLocation : string , typingSafeListLocation : string , typesMapLocation : string , npmLocation : string | undefined , validateDefaultNpmLocation : boolean , throttleLimit : number , log : Log ) {
83
87
super (
84
88
sys ,
85
89
globalTypingsCacheLocation ,
86
90
typingSafeListLocation ? toPath ( typingSafeListLocation , "" , createGetCanonicalFileName ( sys . useCaseSensitiveFileNames ) ) : toPath ( "typingSafeList.json" , __dirname , createGetCanonicalFileName ( sys . useCaseSensitiveFileNames ) ) ,
87
91
typesMapLocation ? toPath ( typesMapLocation , "" , createGetCanonicalFileName ( sys . useCaseSensitiveFileNames ) ) : toPath ( "typesMap.json" , __dirname , createGetCanonicalFileName ( sys . useCaseSensitiveFileNames ) ) ,
88
92
throttleLimit ,
89
93
log ) ;
90
- this . npmPath = npmLocation !== undefined ? npmLocation : getDefaultNPMLocation ( process . argv [ 0 ] ) ;
94
+ this . npmPath = npmLocation !== undefined ? npmLocation : getDefaultNPMLocation ( process . argv [ 0 ] , validateDefaultNpmLocation , this . installTypingHost ) ;
91
95
92
96
// If the NPM path contains spaces and isn't wrapped in quotes, do so.
93
97
if ( stringContains ( this . npmPath , " " ) && this . npmPath [ 0 ] !== `"` ) {
@@ -96,6 +100,7 @@ namespace ts.server.typingsInstaller {
96
100
if ( this . log . isEnabled ( ) ) {
97
101
this . log . writeLine ( `Process id: ${ process . pid } ` ) ;
98
102
this . log . writeLine ( `NPM location: ${ this . npmPath } (explicit '${ Arguments . NpmLocation } ' ${ npmLocation === undefined ? "not " : "" } provided)` ) ;
103
+ this . log . writeLine ( `validateDefaultNpmLocation: ${ validateDefaultNpmLocation } ` ) ;
99
104
}
100
105
( { execSync : this . nodeExecSync } = require ( "child_process" ) ) ;
101
106
@@ -229,6 +234,7 @@ namespace ts.server.typingsInstaller {
229
234
const typingSafeListLocation = findArgument ( Arguments . TypingSafeListLocation ) ;
230
235
const typesMapLocation = findArgument ( Arguments . TypesMapLocation ) ;
231
236
const npmLocation = findArgument ( Arguments . NpmLocation ) ;
237
+ const validateDefaultNpmLocation = hasArgument ( Arguments . ValidateDefaultNpmLocation ) ;
232
238
233
239
const log = new FileLog ( logFilePath ) ;
234
240
if ( log . isEnabled ( ) ) {
@@ -242,7 +248,7 @@ namespace ts.server.typingsInstaller {
242
248
}
243
249
process . exit ( 0 ) ;
244
250
} ) ;
245
- const installer = new NodeTypingsInstaller ( globalTypingsCacheLocation ! , typingSafeListLocation ! , typesMapLocation ! , npmLocation , /*throttleLimit*/ 5 , log ) ; // TODO: GH#18217
251
+ const installer = new NodeTypingsInstaller ( globalTypingsCacheLocation ! , typingSafeListLocation ! , typesMapLocation ! , npmLocation , validateDefaultNpmLocation , /*throttleLimit*/ 5 , log ) ; // TODO: GH#18217
246
252
installer . listen ( ) ;
247
253
248
254
function indent ( newline : string , str : string ) : string {
0 commit comments