Skip to content

Fix bun run folder - #15117

Merged
Jarred-Sumner merged 39 commits into
mainfrom
pfg/fix-bun-run-folder
Jan 18, 2025
Merged

Jarred-Sumner merged 39 commits into
mainfrom
pfg/fix-bun-run-folder

Conversation

@pfgithub

@pfgithub pfgithub commented Nov 13, 2024 •

Copy link
Copy Markdown
Contributor

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, Fixes #16169, Fixes #16482

New features: If there is a script called myscript.js you can now run it with bun myscript just like node allows

TODO:

  • Docs in cli/run about resolution order
    • 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.
    • Add a new section at the bottom for resolution order
  • Remove entries added to launch.json
  • Remove irrelevant js_printer changes
  • Merge main
  • Pass tests:
    • prisma.test.ts
    • import-custom-condition.test.ts
    • if-present.test.ts
    • self-reference.test.ts

Test failures:

  • bundler-plugin.test.ts (?)
  • 08757.test.ts (windows, absolute path override code)
  • if-present.test.ts (file not found -> module not found)
  • bun-run.test.ts
  • wasi.test.js (windows, absolute path override code)

Consider:

  • Make Run.boot skip generating bun:main and run directly instead. bun:main is generated in entry_points.zig.

Performance:
~0.5ms slower :/ even for ./ which is strange

@robobun

robobun commented Nov 13, 2024 •

Copy link
Copy Markdown
Collaborator
Updated 9:46 PM PT - Jan 17th, 2025

✅ @pfgithub, your commit d891e5d has passed in #10003! 🎉


🧪   try this PR locally:

bunx bun-pr 15117

@RiskyMH

RiskyMH commented Nov 13, 2024

Copy link
Copy Markdown
Contributor

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

@pfgithub
pfgithub marked this pull request as ready for review November 19, 2024 02:00
@nektro

nektro commented Dec 3, 2024

Copy link
Copy Markdown
Contributor

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

@Jarred-Sumner
Jarred-Sumner marked this pull request as ready for review January 18, 2025 06:06
@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

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
Jarred-Sumner merged commit 0d17843 into main Jan 18, 2025
@Jarred-Sumner
Jarred-Sumner deleted the pfg/fix-bun-run-folder branch January 18, 2025 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants