Skip to content

Commit f408313

Browse files
authored
Improve package manager detection for Bun 1.2 compatibility (#165)
* Improve package manager detection for Bun compatibility - 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). * keep old name of tool_exists? * fix case statement in cssbundling/build.rake * Make using_bun? detect bun.lockb or bun.lock or yarn.lock
1 parent d39a8cc commit f408313

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

lib/install/helpers.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def bundler_x_cmd
1414
end
1515

1616
def using_bun?
17-
File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
17+
tool_exists?('bun') && (File.exist?('bun.lockb') ||
18+
File.exist?('bun.lock') ||
19+
File.exist?('yarn.lock'))
1820
end
1921

2022
def tool_exists?(tool)

lib/tasks/cssbundling/build.rake

+22-22
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,42 @@ module Cssbundling
2121
module Tasks
2222
extend self
2323

24+
LOCK_FILES = {
25+
bun: %w[bun.lockb bun.lock yarn.lock],
26+
yarn: %w[yarn.lock],
27+
pnpm: %w[pnpm-lock.yaml],
28+
npm: %w[package-lock.json]
29+
}
30+
2431
def install_command
25-
case tool
26-
when :bun then "bun install"
27-
when :yarn then "yarn install"
28-
when :pnpm then "pnpm install"
29-
when :npm then "npm install"
32+
case
33+
when using_tool?(:bun) then "bun install"
34+
when using_tool?(:yarn) then "yarn install"
35+
when using_tool?(:pnpm) then "pnpm install"
36+
when using_tool?(:npm) then "npm install"
3037
else raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies"
3138
end
3239
end
3340

3441
def build_command
35-
case tool
36-
when :bun then "bun run build:css"
37-
when :yarn then "yarn build:css"
38-
when :pnpm then "pnpm build:css"
39-
when :npm then "npm run build:css"
42+
case
43+
when using_tool?(:bun) then "bun run build:css"
44+
when using_tool?(:yarn) then "yarn build:css"
45+
when using_tool?(:pnpm) then "pnpm build:css"
46+
when using_tool?(:npm) then "npm run build:css"
4047
else raise "cssbundling-rails: No suitable tool found for building CSS"
4148
end
4249
end
4350

44-
def tool
45-
case
46-
when File.exist?('bun.lockb') then :bun
47-
when File.exist?('yarn.lock') then :yarn
48-
when File.exist?('pnpm-lock.yaml') then :pnpm
49-
when File.exist?('package-lock.json') then :npm
50-
when tool_exists?('bun') then :bun
51-
when tool_exists?('yarn') then :yarn
52-
when tool_exists?('pnpm') then :pnpm
53-
when tool_exists?('npm') then :npm
54-
end
55-
end
51+
private
5652

5753
def tool_exists?(tool)
5854
system "command -v #{tool} > /dev/null"
5955
end
56+
57+
def using_tool?(tool)
58+
tool_exists?(tool) && LOCK_FILES[tool].any? { |file| File.exist?(file) }
59+
end
6060
end
6161
end
6262

0 commit comments

Comments
 (0)