bridgetownrb / bridgetown

A next-generation progressive site generator & fullstack framework, powered by Ruby
https://www.bridgetownrb.com
MIT License
1.16k stars 112 forks source link

Using direnv for a Ruby environment, Bundler fails to load rake #608

Closed sandstrom closed 1 year ago

sandstrom commented 2 years ago

Bridgetown Version: 1.1.0

To Reproduce

I've added a repo which should be sufficient to reproduce this error: https://github.com/sandstrom/bridgetown-bug-repro1

But basically the steps are:

  1. Install direnv and configure it for ruby (see .envrc file in repro repo).
  2. Install bridgetown.
  3. Run bin/bridgetown start.

Current behavior

% bin/bridgetown start
[Bridgetown]           Starting: Bridgetown v1.1.0 (codename "Belmont")
[Server] * Puma version: 5.6.4 (ruby 2.7.1-p83) ("Birdie's Version")
[Server] * PID: 72181
[Server] * Listening on http://0.0.0.0:4000
[Server] Use Ctrl-C to stop
[Frontend] bundler: failed to load command: bridgetown (/Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/bin/bridgetown)
[Frontend] LoadError: cannot load such file -- rake
[Frontend]   /Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/gems/bridgetown-core-1.1.0/lib/bridgetown-core/commands/base.rb:48:in `require'
[Frontend]   /Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/gems/bridgetown-core-1.1.0/lib/bridgetown-core/commands/base.rb:48:in `handle_no_command_error'
[Frontend]   /Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/gems/thor-1.2.1/lib/thor/command.rb:31:in `run'
[Frontend]   /Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/gems/thor-1.2.1/lib/thor/command.rb:135:in `run'
[Frontend]   /Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
[Frontend]   /Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
[Frontend]   /Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
[Frontend]   /Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/gems/bridgetown-core-1.1.0/bin/bridgetown:38:in `<top (required)>'
[Frontend]   /Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/bin/bridgetown:23:in `load'
[Frontend]   /Users/my-user/repos/my-org/bridgetown-bug-repro1/.direnv/ruby/bin/bridgetown:23:in `<top (required)>'
[Bridgetown]        Environment: development
[Bridgetown]             Source: /Users/my-user/repos/my-org/bridgetown-bug-repro1/src
[Bridgetown]        Destination: /Users/my-user/repos/my-org/bridgetown-bug-repro1/output
[Bridgetown]     Custom Plugins: /Users/my-user/repos/my-org/bridgetown-bug-repro1/plugins
[Bridgetown]         Generating… 
[Bridgetown]         Pagination: disabled. Enable in site config with pagination:\n enabled: true
[Bridgetown]            esbuild: There was an error parsing your esbuild manifest file. Please check your esbuild manifest file for any errors.
[Bridgetown]             Done! 🎉 Completed in less than 0.18 seconds.
[Bridgetown]                     
[Bridgetown]     Now serving at: http://localhost:4000
[Bridgetown]                     http://192.168.65.2:4000
[Bridgetown]                     

Expected behavior

Frontend should run.

Workaround fix

It works if I remove the characters bundle exec from this line:

https://github.com/bridgetownrb/bridgetown/blob/main/bridgetown-core/lib/bridgetown-core/tasks/bridgetown_tasks.rake#L15

Thoughts

Is the bundle exec prefix really needed here? For us it's fine to omit it, but not sure if that goes for everyone.

Computing environment (please complete the following information):

jaredcwhite commented 2 years ago

I'll try to dig into this soon…hadn't heard of direnv to be honest, and I should mention our recommended installation approach is to use rbenv.

sandstrom commented 2 years ago

Sounds great!

As mentioned above, maybe we can just skip the bundle exec prefix?

But if some scenarios need it, then a command line flag or config value may be better. For example it could be frontend-runner-prefix or similar. Which one could then set to nothing to clear it. Or replace with something other than bundle exec, if needed.

sandstrom commented 2 years ago

@jaredcwhite Sorry for persistent asking, but just wanted to see if you have any thoughts on this?

We're closing in on our middleman -> bridgetown migration, and this is one of the blockers (we have a manual hack in place now, via a private fork).

As mentioned above, to me it seems like it should be fine to simply drop the bundle exec prefix. Since the outer invocation would already be running via bundle exec, any inner child-process invocation should inherit env etc from the parent process.

zealot128 commented 2 years ago

Had the same issue (but using asdf version manager), but just updating to Ruby 3.0.x seemed to have fixed the issue with my environment .

sandstrom commented 2 years ago

@zealot128 Thanks, we'll try it out and see if that solves it under our scenario too.

sandstrom commented 2 years ago

@zealot128 I've checked, and 3.0 doesn't solve this for us. To be honest, I don't really see how this would be a ruby version concern. I think it's occurring at the shell-level.

@jaredcwhite Would you be open to a PR where we remove bundle exec from this file: https://github.com/bridgetownrb/bridgetown/blob/v1.1.0/bridgetown-core/lib/bridgetown-core/tasks/bridgetown_tasks.rake#L15

I don't understand why bundle exec is called here. In my view, it's better to apply bundle exec to the outer call, for example bundle exec bridgetown start.

jaredcwhite commented 2 years ago

@sandstrom That does seem to be the right idea…I went ahead and created a PR so I can test across a few different environments. Should work to get released as part of v1.2.

sandstrom commented 2 years ago

Sounds great!

sandstrom commented 1 year ago

Fixed in https://github.com/bridgetownrb/bridgetown/pull/641