Skip to content

Commit 022789a

Browse files
authored
Improve tool selection
1 parent 567144f commit 022789a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/tasks/jsbundling/build.rake

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,23 @@ module Jsbundling
4242
end
4343
end
4444

45-
def tool_exists?(tool)
46-
system "command -v #{tool} > /dev/null"
45+
def tool
46+
tool_determined_by_config_file || tool_determined_by_executable
4747
end
4848

49-
def tool
49+
def tool_determined_by_config_file
5050
case
51-
when File.exist?("bun.lockb") then :bun
52-
when File.exist?("bun.lock") then :bun
53-
when File.exist?("yarn.lock") then :yarn
54-
when File.exist?("pnpm-lock.yaml") then :pnpm
51+
when File.exist?("bun.lockb") then :bun
52+
when File.exist?("bun.lock") then :bun
53+
when File.exist?("yarn.lock") then :yarn
54+
when File.exist?("pnpm-lock.yaml") then :pnpm
5555
when File.exist?("package-lock.json") then :npm
56-
when tool_exists?("bun") then :bun
57-
when tool_exists?("yarn") then :yarn
58-
when tool_exists?("pnpm") then :pnpm
59-
when tool_exists?("npm") then :npm
56+
end
57+
end
58+
59+
def tool_determined_by_executable
60+
%i[ bun yarn pnpm npm ].each do |exe|
61+
return exe if system "command -v #{exe} > /dev/null"
6062
end
6163
end
6264
end

0 commit comments

Comments
 (0)