bun icon indicating copy to clipboard operation
bun copied to clipboard

Fix bun run folder

Open pfgithub opened this issue 1 year ago • 3 comments

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:

  1. Is there a script in package.json with the name? Execute it and exit.
  2. Try loading a module with that name. Can it be done? Execute it and exit.
  3. Is there a binary in node_modules/.bin with that name? Execute it and exit.
  4. (bun run only) Is there a binary in $PATH with that name? Execute it and exit.
  5. 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/run about 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] 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:main and run directly instead. bun:main is generated in entry_points.zig.

pfgithub avatar Nov 13 '24 00:11 pfgithub

Updated 9:46 PM PT - Jan 17th, 2025

:white_check_mark: @pfgithub, your commit d891e5d8f15611fdbe4f8d709600b7d6aa813aee has passed in #10003! :tada:


🧪   try this PR locally:

bunx bun-pr 15117

robobun avatar Nov 13 '24 00:11 robobun

I think you should also update the docs with this new order to be more explicit :) https://bun.sh/docs/cli/run

RiskyMH avatar Nov 13 '24 00:11 RiskyMH

very excited to see this land; of the top ~1000 packages, this affects 402

nektro avatar Dec 03 '24 04:12 nektro

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 avatar Jan 10 '25 11:01 Jarred-Sumner

@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

pfgithub avatar Jan 10 '25 23:01 pfgithub

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.

Jarred-Sumner avatar Jan 18 '25 06:01 Jarred-Sumner