Skip to content

Commit 27550d3

Browse files
authored
Merge pull request #23925 from rhysd/fix-npm-default-location-detection
Check detected default npm path is really existing
2 parents ccfd3bf + 1fda3a4 commit 27550d3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/server/typingsInstaller/nodeTypingsInstaller.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace ts.server.typingsInstaller {
44
const fs: {
5-
appendFileSync(file: string, content: string): void
5+
appendFileSync(file: string, content: string): void;
6+
existsSync(path: string): boolean;
67
} = require("fs");
78

89
const path: {
@@ -32,11 +33,12 @@ namespace ts.server.typingsInstaller {
3233
/** Used if `--npmLocation` is not passed. */
3334
function getDefaultNPMLocation(processName: string) {
3435
if (path.basename(processName).indexOf("node") === 0) {
35-
return `"${path.join(path.dirname(process.argv[0]), "npm")}"`;
36-
}
37-
else {
38-
return "npm";
36+
const npmPath = `"${path.join(path.dirname(process.argv[0]), "npm")}"`;
37+
if (fs.existsSync(npmPath)) {
38+
return npmPath;
39+
}
3940
}
41+
return "npm";
4042
}
4143

4244
interface TypesRegistryFile {

0 commit comments

Comments
 (0)