Skip to content

Improve package manager detection for Bun 1.2 compatibility - #165

Merged
dhh merged 4 commits into
rails:mainfrom
r3cha:propper-detect-tool
Mar 3, 2025
Merged

Improve package manager detection for Bun 1.2 compatibility#165
dhh merged 4 commits into
rails:mainfrom
r3cha:propper-detect-tool

Conversation

@r3cha

@r3cha r3cha commented Jan 26, 2025

Copy link
Copy Markdown
Contributor

I'm using bun and install packages with bun install --yarn and its generate a yarn.lock file, same time new version of bun 1.2 generates bun.lock file instead of bun.lockb.
Some users may have bun with yarn.lock file or bun with bun.lock

My assets recompilation failed with:

RAILS_ENV=production rails assets:precompile
bin/rails aborted!
cssbundling-rails: Command install failed, ensure yarn is installed

Tasks: TOP => assets:precompile => css:build => css:install
(See full trace by running task with --trace)

Here is a proposal to handle this, idk what best way to do this. If this way looks ok I can fix test as well. Also we have using_bun? method at Helpers module that dose not check for bun.lock and return false if bun exists and yarn.lock present

  • Add support for both old bun.lockb and new bun.lock Bun lock files
  • Handle Bun with Yarn compatibility mode yarn.lock
  • Combine command existence and lock file checks into single method

r3cha added 2 commits January 26, 2025 10:27
- Add support for both old (bun.lockb) and new (bun.lock) Bun lock files
- Handle Bun with Yarn compatibility mode (yarn.lock)
- Simplify tool detection by introducing LOCK_FILES mapping
- Combine command existence and lock file checks into single method

This change ensures proper detection of Bun when using different versions
or when running in Yarn compatibility mode (bun install --yarn).
@r3cha
r3cha marked this pull request as ready for review January 26, 2025 10:45
@r3cha r3cha mentioned this pull request Jan 26, 2025
@dhh
dhh merged commit f408313 into rails:main Mar 3, 2025
@dhh

dhh commented Mar 3, 2025

Copy link
Copy Markdown
Member

Looks good to me. Please do add a PR with tests.

@nikitug

nikitug commented Mar 4, 2025

Copy link
Copy Markdown

It looks like this update changes the detection logic. Now, if I have bun installed on my system but use Yarn for installing packages, version 1.4.3 assumes I'm using Bun instead. That's because the logic now states: if both the bun command and yarn.lock exist, it must be Bun. So I'm getting bun.lock next to my yarn.lock every time I run rake css:build.

@dhh

dhh commented Mar 4, 2025

Copy link
Copy Markdown
Member

Ah. Please do investigate a PR to flip that back. Thanks for catching!

Comment thread lib/install/helpers.rb
File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
tool_exists?('bun') && (File.exist?('bun.lockb') ||
File.exist?('bun.lock') ||
File.exist?('yarn.lock'))

@navidemad navidemad Mar 4, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When a system has both bun installed alongside a project that uses Yarn (presence of a yarn.lock file)

We should remove any conditional checks for yarn.lock from bun related lines.

Even though Bun can technically manage yarn.lock file.

Keeping these existence checks may lead to use of bun when you were using yarn before this PR has been merged and want to keep using yarn for the project.

extend self

LOCK_FILES = {
bun: %w[bun.lockb bun.lock yarn.lock],

@navidemad navidemad Mar 4, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as : #165 (comment)

@r3cha

r3cha commented Mar 12, 2025

Copy link
Copy Markdown
Contributor Author

@navidemad @nikitug @dhh
Agree that using bun with --yarn flag its edge case, I did another PR-172 to remove yarn from bun detection a you recommended

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants