Skip to content

Commit

Permalink
PNPM Support (#145)
Browse files Browse the repository at this point in the history
* Simplify build tool selection for bun / yarn

Simplifying ahead of introducing NPM as a build tool.

* Support for NPM

* Support PNPM
  • Loading branch information
ksylvest authored Jan 21, 2024
1 parent 3e768cd commit e650c9a
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions lib/tasks/cssbundling/build.rake
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,36 @@ 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"
when :pnpm then "pnpm install"
when :npm then "npm 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"
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
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

def tool_exists?(tool)
Expand Down

0 comments on commit e650c9a

Please sign in to comment.