From 7be06771b2023880ab1ec26bc873649f4c440e1e Mon Sep 17 00:00:00 2001 From: Roman K Date: Sun, 26 Jan 2025 10:27:19 +0000 Subject: [PATCH 1/4] 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). --- lib/tasks/cssbundling/build.rake | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/tasks/cssbundling/build.rake b/lib/tasks/cssbundling/build.rake index 8410147..aa13261 100644 --- a/lib/tasks/cssbundling/build.rake +++ b/lib/tasks/cssbundling/build.rake @@ -21,6 +21,13 @@ module Cssbundling module Tasks extend self + LOCK_FILES = { + bun: %w[bun.lockb bun.lock yarn.lock], + yarn: %w[yarn.lock], + pnpm: %w[pnpm-lock.yaml], + npm: %w[package-lock.json] + } + def install_command case tool when :bun then "bun install" @@ -33,29 +40,18 @@ module Cssbundling def build_command case tool - when :bun then "bun run build:css" - when :yarn then "yarn build:css" - when :pnpm then "pnpm build:css" - when :npm then "npm run build:css" + when using_tool?(:bun) then "bun run build:css" + when using_tool?(:yarn) then "yarn build:css" + when using_tool?(:pnpm) then "pnpm build:css" + when using_tool?(:npm) then "npm run build:css" else raise "cssbundling-rails: No suitable tool found for building CSS" end end - def tool - case - when File.exist?('bun.lockb') then :bun - when File.exist?('yarn.lock') then :yarn - when File.exist?('pnpm-lock.yaml') then :pnpm - when File.exist?('package-lock.json') then :npm - when tool_exists?('bun') then :bun - when tool_exists?('yarn') then :yarn - when tool_exists?('pnpm') then :pnpm - when tool_exists?('npm') then :npm - end - end + private - def tool_exists?(tool) - system "command -v #{tool} > /dev/null" + def using_tool?(tool) + system "command -v #{tool} > /dev/null" && LOCK_FILES[tool].any? { |file| File.exist?(file) } end end end From ae4227ec93d5fa9eb595634cfa023a002afda928 Mon Sep 17 00:00:00 2001 From: Roman K Date: Sun, 26 Jan 2025 10:44:39 +0000 Subject: [PATCH 2/4] keep old name of tool_exists? --- lib/tasks/cssbundling/build.rake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/tasks/cssbundling/build.rake b/lib/tasks/cssbundling/build.rake index aa13261..0b908eb 100644 --- a/lib/tasks/cssbundling/build.rake +++ b/lib/tasks/cssbundling/build.rake @@ -40,17 +40,17 @@ module Cssbundling def build_command case tool - when using_tool?(:bun) then "bun run build:css" - when using_tool?(:yarn) then "yarn build:css" - when using_tool?(:pnpm) then "pnpm build:css" - when using_tool?(:npm) then "npm run build:css" + when tool_exists?(:bun) then "bun run build:css" + when tool_exists?(:yarn) then "yarn build:css" + when tool_exists?(:pnpm) then "pnpm build:css" + when tool_exists?(:npm) then "npm run build:css" else raise "cssbundling-rails: No suitable tool found for building CSS" end end private - def using_tool?(tool) + def tool_exists?(tool) system "command -v #{tool} > /dev/null" && LOCK_FILES[tool].any? { |file| File.exist?(file) } end end From 8128b42c0df64c0c5a5c79d5ba8c4edf1b593b07 Mon Sep 17 00:00:00 2001 From: Roman K Date: Sun, 26 Jan 2025 11:19:55 +0000 Subject: [PATCH 3/4] fix case statement in cssbundling/build.rake --- lib/tasks/cssbundling/build.rake | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/tasks/cssbundling/build.rake b/lib/tasks/cssbundling/build.rake index 0b908eb..6bb5619 100644 --- a/lib/tasks/cssbundling/build.rake +++ b/lib/tasks/cssbundling/build.rake @@ -29,21 +29,21 @@ module Cssbundling } def install_command - case tool - when :bun then "bun install" - when :yarn then "yarn install" - when :pnpm then "pnpm install" - when :npm then "npm install" + case + when using_tool?(:bun) then "bun install" + when using_tool?(:yarn) then "yarn install" + when using_tool?(:pnpm) then "pnpm install" + when using_tool?(:npm) then "npm install" else raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies" end end def build_command - case tool - when tool_exists?(:bun) then "bun run build:css" - when tool_exists?(:yarn) then "yarn build:css" - when tool_exists?(:pnpm) then "pnpm build:css" - when tool_exists?(:npm) then "npm run build:css" + case + when using_tool?(:bun) then "bun run build:css" + when using_tool?(:yarn) then "yarn build:css" + when using_tool?(:pnpm) then "pnpm build:css" + when using_tool?(:npm) then "npm run build:css" else raise "cssbundling-rails: No suitable tool found for building CSS" end end @@ -51,7 +51,11 @@ module Cssbundling private def tool_exists?(tool) - system "command -v #{tool} > /dev/null" && LOCK_FILES[tool].any? { |file| File.exist?(file) } + system "command -v #{tool} > /dev/null" + end + + def using_tool?(tool) + tool_exists?(tool) && LOCK_FILES[tool].any? { |file| File.exist?(file) } end end end From c549b260391b4d66e26564f57d9819ca69b6ced5 Mon Sep 17 00:00:00 2001 From: Roman K Date: Sun, 26 Jan 2025 11:28:05 +0000 Subject: [PATCH 4/4] Make using_bun? detect bun.lockb or bun.lock or yarn.lock --- Gemfile.lock | 1 + lib/install/helpers.rb | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index bbda716..6704a8b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -199,6 +199,7 @@ PLATFORMS arm64-darwin-20 arm64-darwin-21 arm64-darwin-22 + arm64-darwin-24 x86_64-darwin-20 x86_64-darwin-21 x86_64-linux diff --git a/lib/install/helpers.rb b/lib/install/helpers.rb index dd4e974..710454a 100644 --- a/lib/install/helpers.rb +++ b/lib/install/helpers.rb @@ -10,7 +10,9 @@ def bundler_run_cmd end def using_bun? - 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')) end def tool_exists?(tool)