Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/util/resolveCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@ const path = require('path');
const which = require('which');
const pathKey = require('path-key')();

let isMainThread;

try {
isMainThread = require('worker_threads').isMainThread;
} catch (error) {
// Worker threads are not supported in the current node version
// because of this we're always in the main thread
isMainThread = true;
}

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;
// Worker threads do not have process.chdir() so we should only use it if
// we're running in the main thread
const shouldSwitchCwd = hasCustomCwd && isMainThread;

// 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
Expand Down