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 Oct 6, 2019
1 parent 0e7cd3d commit cfd49c9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/util/resolveCommand.js
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 cfd49c9

Please sign in to comment.