bun icon indicating copy to clipboard operation
bun copied to clipboard

`bun run` should prioritize running script over file/directory

Open PatrickMatthiesen opened this issue 1 year ago • 6 comments

What version of Bun is running?

1.0.18+1a2643520

What platform is your computer?

Linux 5.15.133.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

Simply have a script called build and try to run it with the --bun flag

What is the expected behavior?

The script should run like the following: image Note I removed the d in the script name to make it work

What do you see instead?

image

Additional information

I couldn't reproduce the issue with other flags but the --bun and -b flags.

PatrickMatthiesen avatar Dec 19 '23 14:12 PatrickMatthiesen

Interesting, tried on macOS arm64.

> bun run --bun build
$ echo Hi
Hi
{
  "dependencies": {
    "express": "^4.18.2"
  },
  "scripts": {
    "build": "echo Hi"
  }
}

Electroid avatar Dec 19 '23 23:12 Electroid

I did some more testing and figured out that it's because I have a directory that is named build. So it is an issue if a script and folder in the path have the same name. I would assume it's because Bun will prioritize the folder over the script name?

PatrickMatthiesen avatar Dec 20 '23 00:12 PatrickMatthiesen

Yep, looks like that's the issue. We should fix this so bun run [name] prioritizes running the script, before checking for a file/directory.

Electroid avatar Dec 20 '23 17:12 Electroid

ah, is it checking for an item named [name] and then finding the directory, then giving up?

actually no, we dont run the module resolver for script names

image

reminds me that i actually made this work if you run node as bun

image

I dont know if the logic can be copy pasted from this but it likely is possible.

paperclover avatar Dec 20 '23 21:12 paperclover

idk if this is a goodfirstissue but if someone wants to investigate the code, run command starts in run_command.zig line 1032 "pub fn exec("

paperclover avatar Dec 20 '23 21:12 paperclover

Debug logs:

Debug logs

aboqasem avatar Jan 22 '24 17:01 aboqasem

Is there any way to force bun to use script?

ryoppippi avatar Jun 07 '24 18:06 ryoppippi