| 1247 | var which = require_which(); |
| 1248 | var getPathKey = require_path_key(); |
| 1249 | function resolveCommandAttempt(parsed, withoutPathExt) { |
| 1250 | const env2 = parsed.options.env || process.env; |
| 1251 | const cwd = process.cwd(); |
| 1252 | const hasCustomCwd = parsed.options.cwd != null; |
| 1253 | const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled; |
| 1254 | if (shouldSwitchCwd) { |
| 1255 | try { |
| 1256 | process.chdir(parsed.options.cwd); |
| 1257 | } catch (err) { |
| 1258 | } |
| 1259 | } |
| 1260 | let resolved; |
| 1261 | try { |
| 1262 | resolved = which.sync(parsed.command, { |
| 1263 | path: env2[getPathKey({ env: env2 })], |
| 1264 | pathExt: withoutPathExt ? path5.delimiter : void 0 |
| 1265 | }); |
| 1266 | } catch (e3) { |
| 1267 | } finally { |
| 1268 | if (shouldSwitchCwd) { |
| 1269 | process.chdir(cwd); |
| 1270 | } |
| 1271 | } |
| 1272 | if (resolved) { |
| 1273 | resolved = path5.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved); |
| 1274 | } |
| 1275 | return resolved; |
| 1276 | } |
| 1277 | function resolveCommand(parsed) { |
| 1278 | return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true); |
| 1279 | } |