Skip to content

Commit

Permalink
Make bin/setup work with bun
Browse files Browse the repository at this point in the history
  • Loading branch information
duduribeiro committed Sep 12, 2023
1 parent 1b97206 commit 9a98235
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
6 changes: 6 additions & 0 deletions railties/CHANGELOG.md
@@ -1,3 +1,9 @@
* bin/setup uses `bun` instead of `yarn` when generated an app with bun

Use `bun install` on `bin/setup` when using `bun`.

*Cadu Ribeiro*

* `config/application.rb` now includes

```ruby
Expand Down
22 changes: 14 additions & 8 deletions railties/lib/rails/generators/app_base.rb
Expand Up @@ -467,10 +467,16 @@ def hotwire_gemfile_entry
end

def using_node?
return if using_bun?

(options[:javascript] && !%w[importmap].include?(options[:javascript])) ||
(options[:css] && !%w[tailwind sass].include?(options[:css]))
end

def using_bun?
options[:javascript] == "bun"
end

def node_version
if using_node?
ENV.fetch("NODE_VERSION") do
Expand Down Expand Up @@ -569,12 +575,12 @@ def dockerfile_deploy_packages
def css_gemfile_entry
return unless options[:css]

if !using_node? && options[:css] == "tailwind"
if using_node? || using_bun?
GemfileEntry.floats "cssbundling-rails", "Bundle and process CSS [https://github.com/rails/cssbundling-rails]"
elsif options[:css] == "tailwind"
GemfileEntry.floats "tailwindcss-rails", "Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]"
elsif !using_node? && options[:css] == "sass"
elsif options[:css] == "sass"
GemfileEntry.floats "dartsass-rails", "Use Dart SASS [https://github.com/rails/dartsass-rails]"
else
GemfileEntry.floats "cssbundling-rails", "Bundle and process CSS [https://github.com/rails/cssbundling-rails]"
end
end

Expand Down Expand Up @@ -684,12 +690,12 @@ def run_hotwire
def run_css
return if !options[:css] || !bundle_install?

if !using_node? && options[:css] == "tailwind"
if using_bun? || using_node?
rails_command "css:install:#{options[:css]}"
elsif options[:css] == "tailwind"
rails_command "tailwindcss:install"
elsif !using_node? && options[:css] == "sass"
elsif options[:css] == "sass"
rails_command "dartsass:install"
else
rails_command "css:install:#{options[:css]}"
end
end

Expand Down
Expand Up @@ -19,6 +19,10 @@ FileUtils.chdir APP_ROOT do

# Install JavaScript dependencies
system("yarn check --check-files") || system!("yarn install")
<% elsif using_bun? %>
# Install JavaScript dependencies

system("bun install")
<% end -%>
<% unless options.skip_active_record? -%>

Expand Down

0 comments on commit 9a98235

Please sign in to comment.