rails / jsbundling-rails

Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.
MIT License
831 stars 143 forks source link

bun install fails without .gitattributes file in project root #175

Closed Petercopter closed 1 month ago

Petercopter commented 11 months ago

I was trying to replace esbuild with bun by running the installer:

./bin/rails javascript:install:bun

but I got this error:

Add ability to diff lockb to .gitattributes
rails aborted!
Thor::Error: Could not find "/Users/peter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jsbundling-rails-1.2.1/lib/install/bun/.gitattributes" in any of your source paths. Your current source paths are: 
/Users/peter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.8/lib/rails/generators/rails/app/templates

So I tested in a different project, and that one worked because it had a .gitattributes file in the root.

It looks like adding a .gitattributes file is a new-ish thing in Rails, that's why the first project didn't have one, it's about 3 years old. https://github.com/platformsh-templates/rails/commits/master/.gitattributes

So it seems like the jsbundling-rails installer just needs to check and see if that file already exists or not.

sronsiek commented 8 months ago

After creating an empty .gitattributes in the project root dir, the bun install command works and outputs:

Run 'git config diff.lockb.textconv bun && git config diff.lockb.binary true' to enable pretty diffs for Bun's .lockb file

Why is it assumed git is in use? I my case it is not, and git is not installed!

dhh commented 7 months ago

Feel free to open a PR fixing this.

pokonski commented 4 months ago

Actually the problem lies elsewhere. When the gem is built, the .gitattributes file is not properly bundled with it which is what the error is implying.

PR with a fix here: https://github.com/rails/jsbundling-rails/pull/193