oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.09k stars 2.47k forks source link

Bun doesn't find binaries in PATH variable #10865

Open thewh1teagle opened 1 week ago

thewh1teagle commented 1 week ago

What version of Bun is running?

1.1.6+e58d67b46

What platform is your computer?

Windows / macOS

What steps can reproduce the bug?

Create two files:

hello

#!/bin/bash
echo "Hello"

main.js

import { $ } from 'bun'
process.env.PATH = `${__dirname}:${process.env.PATH}`
console.log(process.env.PATH.split(':')[0])
await $`hello`

Add permission to hello

chmod +x hello

Run main.js

bun run main.js # Command not found error

Run again and see that it works with correct path

PATH=$(pwd):$PATH bun run main.js

What is the expected behavior?

When modifying process.env.PATH it should run binaries / scripts which are in the PATH.

What do you see instead?

Error, it doesn't find those scripts / binaries

Additional information

➜  bun-issue pwd       
/Users/user/Documents/bun-issue
➜  bun-issue cat hello      
#!/bin/bash

echo "Hello"%                                                                                                                                                                                                                          
➜  bun-issue cat main.js
import { $ } from 'bun'
process.env.PATH = `${__dirname}:${process.env.PATH}`
console.log(process.env.PATH.split(':')[0])
await $`hello`
➜  bun-issue bun run main.js
/Users/user/Documents/bun-issue
bun: command not found: hello
1 | import { $ } from 'bun'
2 | process.env.PATH = `${__dirname}:${process.env.PATH}`
3 | console.log(process.env.PATH.split(':')[0])
4 | await $`hello`
                                  ^
ShellError: Failed with exit code 1
 info: {
  "exitCode": 1,
  "stderr": "bun: command not found: hello\n",
  "stdout": ""
}

      at new ShellError (:12:31)
      at new ShellPromise (:64:31)
      at BunShell (:184:69)
      at /Users/user/Documents/bun-issue/main.js:4:7
➜  bun-issue PATH=$(pwd):$PATH bun run main.js
/Users/user/Documents/bun-issue
Hello