Description: add yarnpkg support as yarn is yarnpkg in debian
Author: Ananthu C V <weepingclown@disroot.org>
Last-Update: 2024-11-20
--- a/lib/install/helpers.rb
+++ b/lib/install/helpers.rb
@@ -2,11 +2,23 @@ require 'json'
 
 module Helpers
   def bundler_cmd
-    using_bun? ? "bun" : "yarn"
+    if using_bun?
+      "bun"
+    elsif tool_exists?('yarnpkg')
+      "yarnpkg"
+    else
+      "yarn"
+    end
   end
 
   def bundler_run_cmd
-    using_bun? ? "bun run" : "yarn"
+    if using_bun?
+      "bun"
+    elsif tool_exists?('yarnpkg')
+      "yarnpkg"
+    else
+      "yarn"
+    end
   end
 
   def bundler_x_cmd
@@ -35,11 +47,11 @@ module Helpers
       when 7.1...8.0
         say "Add #{name} script"
         run %(npm set-script #{name} "#{script}")
-        run %(yarn #{name}) if run_script
+        tool_exists?("yarnpkg") ? (run %(yarnpkg #{name}) if run_script): (run %(yarn #{name}) if run_script)
       when (8.0..)
         say "Add #{name} script"
         run %(npm pkg set scripts.#{name}="#{script}")
-        run %(yarn #{name}) if run_script
+        tool_exists?("yarnpkg") ? (run %(yarnpkg #{name}) if run_script): (run %(yarn #{name}) if run_script)
       else
         say %(Add "scripts": { "#{name}": "#{script}" } to your package.json), :green
       end
--- a/lib/tasks/cssbundling/build.rake
+++ b/lib/tasks/cssbundling/build.rake
@@ -23,7 +23,6 @@ module Cssbundling
 
     LOCK_FILES = {
       bun: %w[bun.lockb bun.lock yarn.lock],
-      yarn: %w[yarn.lock],
       pnpm: %w[pnpm-lock.yaml],
       npm: %w[package-lock.json]
     }
@@ -32,9 +31,11 @@ module Cssbundling
       case
       when using_tool?(:bun) then "bun install"
       when using_tool?(:yarn) then "yarn install"
+      when using_tool?(:yarnpkg) then "yarnpkg 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"
+      when :yarnpkg then "yarnpkg build:css"
       end
     end
 
@@ -42,6 +43,7 @@ module Cssbundling
       case
       when using_tool?(:bun) then "bun run build:css"
       when using_tool?(:yarn) then "yarn build:css"
+      when using_tool?(:yarnpkg) then "yarnpkg 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"
