Description
Is there a chance you would consider updating the plugin to function correctly when puma is run directly, without getting run via rails s
?
The Puma plugin is fantastic, and I would like to use it everywhere I use Puma, including with puma-dev. Unfortunately, the plugin uses constants and methods that are defined by libraries it does not require, like Tailwindcss::Commands
and Rails.root
. When run via rails s
it just happens to work because the Rails boot process is finished before Rails starts Puma.
It's easy to reproduce this issue, just choose any app with the Puma plugin and run bundle exec puma
. You'll see a backtrace like this one:
❯ bundle exec puma
Puma starting in single mode...
* Puma version: 6.5.0 ("Sky's Version")
* Ruby version: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [arm64-darwin24]
* Min threads: 3
* Max threads: 3
* Environment: development
* PID: 10335
.bundle/ruby/3.4.0/gems/tailwindcss-rails-3.2.0/lib/puma/plugin/tailwindcss.rb:14:in 'block in start': uninitialized constant Tailwindcss (NameError)
IO.popen(Tailwindcss::Commands.watch_command, 'r+') do |io|
^^^^^^^^^^^
from .bundle/ruby/3.4.0/gems/tailwindcss-rails-3.2.0/lib/puma/plugin/tailwindcss.rb:9:in 'Kernel#fork'
from .bundle/ruby/3.4.0/gems/tailwindcss-rails-3.2.0/lib/puma/plugin/tailwindcss.rb:9:in 'start'
To demonstrate that the issue is the plugin running code that it has not required, you can stop Puma from crashing by requiring the Rails app before the plugin runs, by adding this line directly before the call to plugin :tailwindcss
:
require_relative "application"
plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development"
Anyway, if possible, I would love for the plugin to not crash Puma when Puma is run directly. Thanks!