jsbundling-rails
jsbundling-rails copied to clipboard
bun install fails without .gitattributes file in project root
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.
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!
Feel free to open a PR fixing this.
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