Skip to content

Commit 44919fe

Browse files
authored
Merge pull request #180 from ksylvest/ksylvest/npm-build-tool-selection-fix
Simplify build / install tool (bun / yarn / npm) logic
2 parents ff78e2b + 092ef9f commit 44919fe

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

lib/tasks/jsbundling/build.rake

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,37 @@ module Jsbundling
2323
extend self
2424

2525
def install_command
26-
return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
27-
return "yarn install" if File.exist?('yarn.lock') || (tool_exists?('yarn') && !File.exist?('package-lock.json'))
28-
return "npm install" if File.exist?('package-lock.json') || tool_exists?('npm')
29-
raise "jsbundling-rails: No suitable tool found for installing JavaScript dependencies"
26+
case tool
27+
when :bun then "bun install"
28+
when :yarn then "yarn install"
29+
when :npm then "npm install"
30+
else raise "jsbundling-rails: No suitable tool found for installing JavaScript dependencies"
31+
end
3032
end
3133

3234
def build_command
33-
return "bun run build" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
34-
return "yarn build" if File.exist?('yarn.lock') || (tool_exists?('yarn') && !File.exist?('package-lock.json'))
35-
return "npm run build" if File.exist?('package-lock.json') || tool_exists?('npm')
36-
raise "jsbundling-rails: No suitable tool found for building JavaScript"
35+
case tool
36+
when :bun then "bun run build"
37+
when :yarn then "yarn build"
38+
when :npm then "npm run build"
39+
else raise "jsbundling-rails: No suitable tool found for building JavaScript"
40+
end
3741
end
3842

3943
def tool_exists?(tool)
4044
system "command -v #{tool} > /dev/null"
4145
end
46+
47+
def tool
48+
case
49+
when File.exist?('bun.lockb') then :bun
50+
when File.exist?('yarn.lock') then :yarn
51+
when File.exist?('package-lock.json') then :npm
52+
when tool_exists?('bun') then :bun
53+
when tool_exists?('yarn') then :yarn
54+
when tool_exists?('npm') then :npm
55+
end
56+
end
4257
end
4358
end
4459

0 commit comments

Comments
 (0)