rails / cssbundling-rails

Bundle and process CSS in Rails with Tailwind, PostCSS, and Sass via Node.js.
MIT License
563 stars 83 forks source link

Surprised by Bun default on new Rails project #140

Closed erikaxel closed 5 months ago

erikaxel commented 7 months ago

Hi,

I recently created a new project by running rails my_app --css=bootstrap I was then surprised that it choose bun as the javscript bundler. After some investigation I found out the reason it does is because of a recent PR #130 which checks for two things:

By a coincidence I had bun in the path, and there is no yarn.lock file since it is a new project. Btw, I also have yarn in my path, so it selected bun over yarn even though both are available. This caused some issues down the road because bun was not supported by my hosting solution, probably because bun is fairly new.

Was bun selected as a default on purpose in #130 or was it an unintended consequence? I also see that #138 suggests adding npm as well, what will be the ordering then?

If bun is the preferred default, I would suggest adding a paragraph to the readme about it to avoid surprises. Happy to create a documentation PR for this if this is the case.

It might also make sense to allow the user to select bundler in other ways than "touch yarn.lock" or fiddling with the PATH, especially when cssbundling is used through rails new

dhh commented 5 months ago

This is intentional. Here's the ordering:

    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

Feel free to open a PR to document 👍