Skip to content

Conversation

@Gerkinfeltser
Copy link

Problem

Shell commands configured in hooks fail to execute on Windows with error:

bun: command not found: sh

This happens because the plugin uses sh -c ${command} to execute commands, but Bun on Windows doesn't have sh in PATH.

Solution

Use Bun's native cross-platform shell with the ${{ raw: command }} syntax. Bun Shell is a Zig-based interpreter that works natively on Windows, Linux, and macOS without requiring /bin/sh.

Changes

  • src/execution/shell.ts: Replace sh -c ${command} with ${{ raw: command }}
  • tests/execution.shell.test.ts: Update 4 tests to use cross-platform shell syntax:
    • stderr test: printf 'error' 1>&2 instead of sh -c 'echo >&2'
    • env var test: VAR=val && echo $VAR instead of sh -c
    • quiet mode test: printf 'error' 1>&2 instead of echo 'error' >&2
    • syntax error test: (invalid instead of sh -c 'invalid'

Testing

  • ✅ All 24 shell execution tests pass on Windows (Bun 1.3.3)
  • ✅ Build succeeds
  • ✅ Manual testing on Windows - hooks execute with exitCode=0 and captured output
  • ⚠️ Not locally tested on Linux/macOS - However, Bun Shell is explicitly designed to be cross-platform, and all commands used (printf, env var assignment, redirection) are Bun shell builtins that should work identically on all platforms. CI would catch any platform-specific issues.

Known Limitations

During testing, discovered that Bun shell's built-in echo doesn't properly support fd redirection (>&2), but printf does. This is a Bun shell limitation, not specific to this plugin. Users needing to redirect echo output to stderr should use printf instead.

Replace `sh -c ${command}` with `${{ raw: command }}` to fix shell
execution on Windows where `sh` is not available.
Bun's native shell is cross-platform (Windows/Linux/macOS) and doesn't
require external `sh`. Previously, all hook commands failed on Windows
with "bun: command not found: sh".
Changes:
- src/execution/shell.ts: Use `${{ raw: command }}` syntax
- tests: Update 4 tests to use cross-platform shell syntax
Testing:
- All 24 shell tests pass on Windows (Bun 1.3.3)
- Manual testing confirms hooks execute successfully
Note: Bun's `echo` builtin doesn't support `>&2` redirection; use `printf`
instead for stderr redirection.
@Gerkinfeltser Gerkinfeltser marked this pull request as ready for review January 21, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant