From 09c7279d7196e23bca18533e26a0095c205faa0e Mon Sep 17 00:00:00 2001 From: Kevin Sylvestre Date: Fri, 5 Jan 2024 13:13:59 -0800 Subject: [PATCH 1/3] Simplify build tool selection for bun / yarn Simplifying ahead of introducing NPM as a build tool. --- lib/tasks/cssbundling/build.rake | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/tasks/cssbundling/build.rake b/lib/tasks/cssbundling/build.rake index dcdd429..d657f4a 100644 --- a/lib/tasks/cssbundling/build.rake +++ b/lib/tasks/cssbundling/build.rake @@ -22,15 +22,28 @@ module Cssbundling extend self def install_command - return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock')) - return "yarn install" if File.exist?('yarn.lock') || tool_exists?('yarn') - raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies" + case tool + when :bun then "bun install" + when :yarn then "yarn install" + else raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies" + end end def build_command - return "bun run build:css" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock')) - return "yarn build:css" if File.exist?('yarn.lock') || tool_exists?('yarn') - raise "cssbundling-rails: No suitable tool found for building CSS" + case tool + when :bun then "bun run build:css" + when :yarn then "yarn 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 tool_exists?('bun') then :bun + when tool_exists?('yarn') then :yarn + end end def tool_exists?(tool) From 46305c8de32f698e7f46304e8c2695fc98fffaa7 Mon Sep 17 00:00:00 2001 From: Kevin Sylvestre Date: Fri, 5 Jan 2024 13:15:24 -0800 Subject: [PATCH 2/3] Support for NPM --- lib/tasks/cssbundling/build.rake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tasks/cssbundling/build.rake b/lib/tasks/cssbundling/build.rake index d657f4a..2682b23 100644 --- a/lib/tasks/cssbundling/build.rake +++ b/lib/tasks/cssbundling/build.rake @@ -25,6 +25,7 @@ module Cssbundling case tool when :bun then "bun install" when :yarn then "yarn install" + when :npm then "npm install" else raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies" end end @@ -33,6 +34,7 @@ module Cssbundling case tool when :bun then "bun run build:css" when :yarn then "yarn build:css" + when :npm then "npm run build:css" else raise "cssbundling-rails: No suitable tool found for building CSS" end end @@ -41,8 +43,10 @@ module Cssbundling case when File.exist?('bun.lockb') then :bun when File.exist?('yarn.lock') then :yarn + when File.exist?('package-lock.json') then :npm when tool_exists?('bun') then :bun when tool_exists?('yarn') then :yarn + when tool_exists?('npm') then :npm end end From 4ac5bc6a0fa696cd77c76bc556bd3d9b47db1b73 Mon Sep 17 00:00:00 2001 From: Kevin Sylvestre Date: Fri, 5 Jan 2024 13:32:53 -0800 Subject: [PATCH 3/3] Support PNPM --- lib/tasks/cssbundling/build.rake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tasks/cssbundling/build.rake b/lib/tasks/cssbundling/build.rake index 2682b23..8410147 100644 --- a/lib/tasks/cssbundling/build.rake +++ b/lib/tasks/cssbundling/build.rake @@ -25,6 +25,7 @@ module Cssbundling case tool when :bun then "bun install" when :yarn then "yarn install" + when :pnpm then "pnpm install" when :npm then "npm install" else raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies" end @@ -34,6 +35,7 @@ module Cssbundling 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" else raise "cssbundling-rails: No suitable tool found for building CSS" end @@ -43,9 +45,11 @@ module Cssbundling 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