cross-spawn
6.0.56.0.6
lib/util/resolveCommand.jslib/util/resolveCommand.js+6−2
Index: package/lib/util/resolveCommand.js
===================================================================
--- package/lib/util/resolveCommand.js
+++ package/lib/util/resolveCommand.js
@@ -6,12 +6,14 @@
function resolveCommandAttempt(parsed, withoutPathExt) {
const cwd = process.cwd();
const hasCustomCwd = parsed.options.cwd != null;
+ // Worker threads do not have process.chdir()
+ const shouldSwitchCwd = hasCustomCwd && process.chdir !== undefined;
// If a custom `cwd` was specified, we need to change the process cwd
// because `which` will do stat calls but does not support a custom cwd
- if (hasCustomCwd) {
+ if (shouldSwitchCwd) {
try {
process.chdir(parsed.options.cwd);
} catch (err) {
/* Empty */
@@ -27,9 +29,11 @@
});
} catch (e) {
/* Empty */
} finally {
- process.chdir(cwd);
+ if (shouldSwitchCwd) {
+ process.chdir(cwd);
+ }
}
// If we successfully resolved, ensure that an absolute path is returned
// Note that when a custom `cwd` was used, we need to resolve to an absolute path based on it