(
command: string,
{
platform = process.platform,
env = process.env,
cwd = process.cwd(),
}: {
platform?: NodeJS.Platform;
env?: NodeJS.ProcessEnv;
cwd?: string;
} = {},
)
| 481 | } |
| 482 | |
| 483 | function resolveCommand( |
| 484 | command: string, |
| 485 | { |
| 486 | platform = process.platform, |
| 487 | env = process.env, |
| 488 | cwd = process.cwd(), |
| 489 | }: { |
| 490 | platform?: NodeJS.Platform; |
| 491 | env?: NodeJS.ProcessEnv; |
| 492 | cwd?: string; |
| 493 | } = {}, |
| 494 | ): string | null { |
| 495 | const normalizedCommand = normalizeOptionalString(command); |
| 496 | if (!normalizedCommand) { |
| 497 | return null; |
| 498 | } |
| 499 | const explicit = resolveExplicitCommandPath(normalizedCommand, { |
| 500 | platform, |
| 501 | env, |
| 502 | cwd, |
| 503 | }); |
| 504 | if (explicit) { |
| 505 | return explicit; |
| 506 | } |
| 507 | if (hasPathSeparator(normalizedCommand)) { |
| 508 | return null; |
| 509 | } |
| 510 | const pathEntries = splitPathEntries(env.PATH ?? ''); |
| 511 | const suffixes = resolveCommandSuffixes(platform, env, normalizedCommand); |
| 512 | for (const entry of pathEntries) { |
| 513 | for (const suffix of suffixes) { |
| 514 | const candidate = path.join(entry, `${normalizedCommand}${suffix}`); |
| 515 | if (isCommandFile(candidate)) { |
| 516 | return candidate; |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | return null; |
| 521 | } |
| 522 | |
| 523 | function resolveExplicitCommandPath( |
| 524 | command: string, |
no test coverage detected