Description
I have spring
in development group in my Gemfile. I install dependencies for production using bundle install --without development test
. When I run bin/rails
in production (and it seems that even if I run bundle exec rails
bin/rails
with spring is still invoked) it fails:
/usr/local/lib/ruby/3.0.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'spring' (= 2.1.1) among 141 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/api/vendor/bundle/ruby/3.0.0:/home/api/.local/share/gem/ruby/3.0.0:/usr/local/lib/ruby/gems/3.0.0:/usr/local/bundle' , execute `gem env` for more information
from /usr/local/lib/ruby/3.0.0/rubygems/dependency.rb:323:in `to_spec'
from /usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_gem.rb:62:in `gem'
from /api/bin/spring:14:in `<top (required)>'
from bin/rails:7:in `load'
from bin/rails:7:in `<main>'
I expected spring is bypassed. But it seems it is not.
I don't understand how bypassing technically should occure. Here's the bin/spring
:
#!/usr/bin/env ruby
# This file loads Spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.
unless defined?(Spring)
require 'rubygems'
require 'bundler'
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
spring = lockfile.specs.detect { |spec| spec.name == 'spring' }
if spring
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
gem 'spring', spring.version
require 'spring/binstub'
end
end
/api/bin/spring:14:
gem 'spring', spring.version
From what I understand, spring is always present in lockfile therefore bin/spring
finds it and tries to load but fails since it is not installed because I excluded the "development" group during bundle install
.
Maybe rubygem's behavior was changed in recent versions so gem 'spring', spring.version
fails now and we need to amend binstub's code accordingly?
Without knowing too much about rubygems I would fix it with catching the Gem::MissingSpecError
exception and just ignoring it. What do you think?