hotwired / stimulus-rails

Use Stimulus in your Ruby on Rails app
https://stimulus.hotwired.dev
MIT License
638 stars 92 forks source link

Use bun for installation if applicable #125

Closed terracatta closed 1 year ago

terracatta commented 1 year ago

This PR is part of an overall effort to allow Rails developers to completely use the Bun JS runtime and bundler without needing to use Node.JS and Yarn.

This gem is automatically invoked when a new rails projects is created and before this PR would always use Yarn. After this PR this gem will detect which JS bundler is being used and use the correct one so that Yarn doesn't accidentally slip into your Rails project.

I have opened a companion PR to the turbo-rails repo as well.

Example run of javascript:install:bun and bin/rails stimulus:install

☁  test_app [main] ./bin/rails javascript:install:bun
Compile into app/assets/builds
      create  app/assets/builds
      create  app/assets/builds/.keep
      append  app/assets/config/manifest.js
      append  .gitignore
      append  .gitignore
Add JavaScript include tag in application layout
      insert  app/views/layouts/application.html.erb
Create default entrypoint in app/javascript/application.js
      create  app/javascript
      create  app/javascript/application.js
Add default package.json
      create  package.json
Add bin/dev to start foreman
      create  bin/dev
Add default Procfile.dev
      create  Procfile.dev
Ensure foreman is installed
         run  gem install foreman from "."
Successfully installed foreman-0.87.2
Parsing documentation for foreman-0.87.2
Done installing documentation for foreman after 0 seconds
1 gem installed
Add default bun.config.js
      create  bun.config.js
Add build script to package.json
☁  test_app [main] ⚡  bin/rails stimulus:install
Create controllers directory
      create  app/javascript/controllers
      create  app/javascript/controllers/index.js
      create  app/javascript/controllers/application.js
      create  app/javascript/controllers/hello_controller.js
Import Stimulus controllers
      append  app/javascript/application.js
Install Stimulus
         run  bun add @hotwired/stimulus from "."
bun add v1.0.0 (822a00c4)

 installed @hotwired/stimulus@3.2.2

 1 packages installed [931.00ms]
1st8 commented 1 year ago

Can confirm that this works.

This must be released to allow rails new --js bun to work without --skip-hotwire in Rails 7.1.0

See https://github.com/hotwired/turbo-rails/pull/494#issuecomment-1737185656 for details.