Skip to content

Commit

Permalink
fix(core): support worker threads (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored and satazor committed Nov 18, 2024
1 parent 301187a commit f4af31c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/util/resolveCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ const pathKey = require('path-key')();
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) {
Expand All @@ -28,7 +30,9 @@ function resolveCommandAttempt(parsed, withoutPathExt) {
} catch (e) {
/* Empty */
} finally {
process.chdir(cwd);
if (shouldSwitchCwd) {
process.chdir(cwd);
}
}

// If we successfully resolved, ensure that an absolute path is returned
Expand Down

0 comments on commit f4af31c

Please sign in to comment.