Skip to content

Add language: bun support#1411

Merged
j178 merged 8 commits intoj178:v03from
shaanmajid:feat/bun-language-support
Jan 20, 2026
Merged

Add language: bun support#1411
j178 merged 8 commits intoj178:v03from
shaanmajid:feat/bun-language-support

Conversation

@shaanmajid
Copy link
Collaborator

@shaanmajid shaanmajid commented Jan 19, 2026

Adds language: bun support for running hooks with the Bun JavaScript runtime.

Mirrors the Node.js implementation:

  • Downloads from GitHub releases (oven-sh/bun)
  • Supports version constraints: bun@1.x, >=1.0, <2.0, paths
  • Isolated environments with BUN_INSTALL redirection
  • bun install -g for additional dependencies

Ref #619 (keeping issue open since this PR doesn't implement deno support)

@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 92.94404% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.21%. Comparing base (f1b110c) to head (ec9c1e6).
⚠️ Report is 11 commits behind head on v03.

Files with missing lines Patch % Lines
crates/prek/src/languages/bun/installer.rs 90.16% 18 Missing ⚠️
crates/prek/src/languages/bun/bun.rs 95.19% 5 Missing ⚠️
crates/prek/src/languages/bun/version.rs 95.68% 5 Missing ⚠️
crates/prek/src/languages/version.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              v03    #1411      +/-   ##
==========================================
- Coverage   90.66%   90.21%   -0.46%     
==========================================
  Files          82       86       +4     
  Lines       16698    17808    +1110     
==========================================
+ Hits        15140    16066     +926     
- Misses       1558     1742     +184     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Jan 19, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.44% (22.6 MiB → 22.7 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 77.4KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.2%   0.6% 58.0KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 53.0KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.3KiB         prek prek::run::{{closure}}
 0.2%   0.5% 43.6KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 36.5KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 31.8KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 30.0KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.2% 22.3KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 22.0KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.6KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.5KiB        prek? <prek::cli::Cli as clap_builder::derive::FromArgMatches>::from_arg_matches_mut
 0.1%   0.2% 19.7KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.2KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
36.9%  91.6%  8.4MiB              And 20026 smaller methods. Use -n N to show more.
40.3% 100.0%  9.2MiB              .text section size, the file size is 22.7MiB

Base Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 74.9KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.2%   0.6% 53.8KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 49.8KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.3KiB         prek prek::run::{{closure}}
 0.2%   0.5% 43.6KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 35.1KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 31.8KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 30.0KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.2% 22.2KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 22.0KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.5KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.3KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
 0.1%   0.2% 17.7KiB         prek prek::languages::python::uv::InstallSource::install::{{closure}}
36.8%  91.7%  8.3MiB              And 19982 smaller methods. Use -n N to show more.
40.2% 100.0%  9.1MiB              .text section size, the file size is 22.6MiB

@shaanmajid shaanmajid force-pushed the feat/bun-language-support branch from 0166c8c to 582a2cb Compare January 19, 2026 15:23
@j178
Copy link
Owner

j178 commented Jan 19, 2026

This looks really good. I went through all the code in one go without any confusion! I’ll take a closer look tomorrow, thank you!

@j178 j178 self-assigned this Jan 19, 2026
@j178 j178 added the enhancement New feature or request label Jan 19, 2026

/// List all versions of Bun available on GitHub releases.
async fn list_remote_versions(&self) -> Result<Vec<BunVersion>> {
let url = "https://api.github.com/repos/oven-sh/bun/releases?per_page=100";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might want to pull the GitHub token from the GH_TOKEN or GITHUB_TOKEN env vars (and document it in configuration.md) so we can avoid hitting the API rate limit.

Copy link
Collaborator Author

@shaanmajid shaanmajid Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now respects GITHUB_TOKEN (automatically set in GitHub actions) for authentication if set.

I did not yet implement support for GH_TOKEN, which is set by the GitHub CLI:

  1. The prek CLI looks like it only uses GITHUB_TOKEN so far
  2. This codepath should not run so frequently in real-world use to trigger the rate limit; this is primarily a CI concern

Happy to change if you feel otherwise :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For someone like me living in a country with heavy internet censorship, I have to use a proxy to access GitHub. That means I’m sharing the same busy IP with tons of other people, so hitting the GitHub API rate limit is basically an everyday thing :(

Copy link
Collaborator Author

@shaanmajid shaanmajid Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great point -- and sorry for the situation :(

To be clear though, I did add support for GITHUB_TOKEN in f05643f. I'm not sure if I see how supporting GH_TOKEN as well may be different than just supporting GITHUB_TOKEN. Since this isn't being called by the gh CLI in anyway, the user still needs to manually set the environment variable (in e.g. ~/.zshrc). Am I missing something?

Happy again to add GH_TOKEN support as well if you'd prefer it; just want to make sure I fully understand the impact of supporting it.

@shaanmajid shaanmajid force-pushed the feat/bun-language-support branch from 582a2cb to d1b97ca Compare January 19, 2026 15:34
Add three integration tests covering the key functionality:
- basic_bun: simple hook execution using bun -e
- additional_dependencies: verify deps installed via bunx cowsay
- language_version: test version specification with language_version: "1"

The additional_dependencies test runs twice to verify health_check and
cache reuse works correctly.
- Add Bun to toolchain list in README features section
- Add Bun to managed toolchain downloads list in languages.md
- Add full Bun language section with version format documentation
@shaanmajid shaanmajid force-pushed the feat/bun-language-support branch from d1b97ca to 223114a Compare January 19, 2026 15:35
@j178 j178 added this to the v0.3.0 milestone Jan 19, 2026
When listing Bun versions from GitHub releases, use the GITHUB_TOKEN
environment variable if available to authenticate requests. This
increases the rate limit from 60 to 5,000 requests/hour.

GITHUB_TOKEN is automatically set in GitHub Actions workflows.
Bun installs global packages to $BUN_INSTALL/bin/ on all platforms,
so bin_dir should always return prefix/bin. The Windows special case
was incorrectly copied from Node (which uses npm's different install
structure).
@j178 j178 changed the base branch from master to v03 January 20, 2026 10:33
@j178 j178 force-pushed the feat/bun-language-support branch from 0a5fd90 to 467f1a5 Compare January 20, 2026 11:25
@j178 j178 force-pushed the feat/bun-language-support branch from 467f1a5 to ec9c1e6 Compare January 20, 2026 11:33
@j178
Copy link
Owner

j178 commented Jan 20, 2026

Thanks!

@j178 j178 merged commit 794d0a6 into j178:v03 Jan 20, 2026
38 of 39 checks passed
j178 added a commit that referenced this pull request Jan 21, 2026
* feat(bun): add Bun language support

* test(bun): add integration tests for Bun language support

Add three integration tests covering the key functionality:
- basic_bun: simple hook execution using bun -e
- additional_dependencies: verify deps installed via bunx cowsay
- language_version: test version specification with language_version: "1"

The additional_dependencies test runs twice to verify health_check and
cache reuse works correctly.

* docs: add Bun to supported languages documentation

- Add Bun to toolchain list in README features section
- Add Bun to managed toolchain downloads list in languages.md
- Add full Bun language section with version format documentation

* ci: add Bun setup to test jobs

* feat(bun): use GITHUB_TOKEN to avoid API rate limits

When listing Bun versions from GitHub releases, use the GITHUB_TOKEN
environment variable if available to authenticate requests. This
increases the rate limit from 60 to 5,000 requests/hour.

GITHUB_TOKEN is automatically set in GitHub Actions workflows.

* fix(bun): use consistent bin_dir path on all platforms

Bun installs global packages to $BUN_INSTALL/bin/ on all platforms,
so bin_dir should always return prefix/bin. The Windows special case
was incorrectly copied from Node (which uses npm's different install
structure).

* Add toolchain download test

* Add tests

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
j178 added a commit that referenced this pull request Jan 22, 2026
* feat(bun): add Bun language support

* test(bun): add integration tests for Bun language support

Add three integration tests covering the key functionality:
- basic_bun: simple hook execution using bun -e
- additional_dependencies: verify deps installed via bunx cowsay
- language_version: test version specification with language_version: "1"

The additional_dependencies test runs twice to verify health_check and
cache reuse works correctly.

* docs: add Bun to supported languages documentation

- Add Bun to toolchain list in README features section
- Add Bun to managed toolchain downloads list in languages.md
- Add full Bun language section with version format documentation

* ci: add Bun setup to test jobs

* feat(bun): use GITHUB_TOKEN to avoid API rate limits

When listing Bun versions from GitHub releases, use the GITHUB_TOKEN
environment variable if available to authenticate requests. This
increases the rate limit from 60 to 5,000 requests/hour.

GITHUB_TOKEN is automatically set in GitHub Actions workflows.

* fix(bun): use consistent bin_dir path on all platforms

Bun installs global packages to $BUN_INSTALL/bin/ on all platforms,
so bin_dir should always return prefix/bin. The Windows special case
was incorrectly copied from Node (which uses npm's different install
structure).

* Add toolchain download test

* Add tests

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
@shaanmajid shaanmajid deleted the feat/bun-language-support branch January 22, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants