Fix bun run folder
This may be a breaking change, so it might wait for 1.2. When using bun <script> or bun run <script>, it now always checks in this order:
- Is there a script in package.json with the name? Execute it and exit.
- Try loading a module with that name. Can it be done? Execute it and exit.
- Is there a binary in
node_modules/.binwith that name? Execute it and exit. - (
bun runonly) Is there a binary in$PATHwith that name? Execute it and exit. - Error.
Previously, it would try guessing if it looked like a script name and sometimes it would execute before checking scripts in package.json.
Fixes #13819, Fixes #15743
TODO:
- [x] Docs in
cli/runabout resolution order- [x] Update the outdated line "Bun executes the script command in a subshell. It checks for the following shells in order, using the first one it finds: bash, sh, zsh."
- On windows, it uses bun shell rather than a system shell. This should be mentioned.
- [x] Add a new section at the bottom for resolution order
- [x] Update the outdated line "Bun executes the script command in a subshell. It checks for the following shells in order, using the first one it finds: bash, sh, zsh."
- [x] Remove entries added to launch.json
- [x] Remove irrelevant js_printer changes
- [x] Merge main
- [x] Pass tests:
- [x] prisma.test.ts
- [x] import-custom-condition.test.ts
- [x] if-present.test.ts
- [x] self-reference.test.ts
Consider:
- [ ] Make Run.boot skip generating
bun:mainand run directly instead.bun:mainis generated inentry_points.zig.
:white_check_mark: @pfgithub, your commit d891e5d8f15611fdbe4f8d709600b7d6aa813aee has passed in #10003! :tada:
🧪 try this PR locally:
bunx bun-pr 15117
I think you should also update the docs with this new order to be more explicit :) https://bun.sh/docs/cli/run
very excited to see this land; of the top ~1000 packages, this affects 402
is there a chance we could avoid doing this when a file path with an extension is passed? just so we don't read package.json files up to the root unnecessarily
@Jarred-Sumner I'm not seeing any performance impact from this PR with hyperfine "bun-45cbc92e81391b46a16c241043ea38c26310e931 run ./a.js" "bun-287f1628e78e2ecee0dfd937d78e3fe3e307187c run ./a.js" --shell=none --warmup=50, although bun-1.1.43 is ~0.2ms faster than latest main
This isn't really done, but I'm going to merge it.
Please add a follow-up PR that:
- [ ] Doesn't make entry-point-build and entry-point-run observable
- [ ] Avoids the use of std.fs for reading from stdin and instead uses bun.sys. Zig's use of unreachable will cause crashes for Bun.
There are 2 additional system calls to bun run from this PR. I think that's okay given the context.