Skip to content

Built-in 'which' command returns non-zero exit code for existing commands #7

@konard

Description

@konard

Description

The built-in which command in command-stream returns a non-zero exit code even when the command exists in the system PATH.

Steps to Reproduce

  1. Install gh CLI tool (GitHub CLI) on macOS via Homebrew
  2. Verify gh is available by running gh --version in terminal (works)
  3. Use command-stream's built-in which command:
import { $ } from 'command-stream';

const result = await $`which gh`;
console.log(result.code); // Returns non-zero even though gh exists

Expected Behavior

The built-in which command should return exit code 0 when the command is found in PATH.

Actual Behavior

Returns non-zero exit code, incorrectly indicating the command doesn't exist.

Environment

  • OS: macOS (Darwin 24.5.0)
  • command-stream version: latest
  • Node.js/Bun version: Bun

Workaround

Using the system's which command or checking with --version flag works:

// This works correctly
await sh('gh --version', { mirror: false });

Additional Context

The gh command is installed at /opt/homebrew/bin/gh and is accessible from the terminal. Other built-in commands may have similar issues with PATH resolution on macOS systems with Homebrew.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions