| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,10 +7,12 @@ const pathKey = require('path-key')(); | |||
| 7 | 7 | function resolveCommandAttempt(parsed, withoutPathExt) { | |
| 8 | 8 | const cwd = process.cwd(); | |
| 9 | 9 | const hasCustomCwd = parsed.options.cwd != null; | |
| 10 | + // Worker threads do not have process.chdir() | ||
| 11 | + const shouldSwitchCwd = hasCustomCwd && process.chdir !== undefined; | ||
| 10 | 12 | ||
| 11 | 13 | // If a custom `cwd` was specified, we need to change the process cwd | |
| 12 | 14 | // because `which` will do stat calls but does not support a custom cwd | |
| 13 | - if (hasCustomCwd) { | ||
| 15 | + if (shouldSwitchCwd) { | ||
| 14 | 16 | try { | |
| 15 | 17 | process.chdir(parsed.options.cwd); | |
| 16 | 18 | } catch (err) { | |
@@ -28,7 +30,9 @@ function resolveCommandAttempt(parsed, withoutPathExt) { | |||
| 28 | 30 | } catch (e) { | |
| 29 | 31 | /* Empty */ | |
| 30 | 32 | } finally { | |
| 31 | - process.chdir(cwd); | ||
| 33 | + if (shouldSwitchCwd) { | ||
| 34 | + process.chdir(cwd); | ||
| 35 | + } | ||
| 32 | 36 | } | |
| 33 | 37 | ||
| 34 | 38 | // If we successfully resolved, ensure that an absolute path is returned | |
| Back | FazBrowse Home | New Git URL |
0 commit comments