Module: Jets::Bundle

Extended by:
Bundle
Included in:
Bundle
Defined in:
lib/jets/bundle.rb

Overview

Named Bundle vs Bundler to avoid having to fully qualify ::Bundler

Instance Method Summary collapse

Instance Method Details

#bundler_enabled?Boolean

Also check for Afterburner mode since in that mode jets is a standalone tool.

Returns:

  • (Boolean)


45
46
47
# File 'lib/jets/bundle.rb', line 45

def bundler_enabled?
  !Jets::Turbo.afterburner? && gemfile?
end

#bundler_groupsObject



53
54
55
# File 'lib/jets/bundle.rb', line 53

def bundler_groups
  [:default, Jets.env.to_sym]
end

#gemfile?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/jets/bundle.rb', line 49

def gemfile?
  ENV['BUNDLE_GEMFILE'] || File.exist?("Gemfile")
end

#requireObject

Bundler.require called when environment boots up via Jets.boot. This will eagerly require all gems in the Gemfile. This means the user will not have to explictly require dependencies.

It also useful for when to loading Rake tasks in Jets::Commands::RakeTasks.load! For example, some gems like webpacker that load rake tasks are specified with a git based source:

gem "webpacker", git: "https://github.com/tongueroo/webpacker.git"

This results in the user having to specific bundle exec in front of jets for those rake tasks to show up in jets help. Instead, when the user is within the project folder, jets automatically requires bundler for the user. So the rake tasks show up when calling jets help.

When the user calls jets help from outside the project folder, bundler is not used and the load errors get rescued gracefully. This is done in Jets::Commands::RakeTasks.load! In the case when user is in another project with another Gemfile, the load errors will also be rescued.



38
39
40
41
42
# File 'lib/jets/bundle.rb', line 38

def require
  return unless bundler_enabled?
  Kernel.require "bundler/setup"
  Bundler.require(*bundler_groups)
end

#setupObject

Looks like for zeitwerk module autovivification to work ‘bundle exec` must be called. This allows zeitwork module autovivification to work even if the user has not called jets with `bundle exec jets`. Bundler.setup is essentially the same as `bundle exec` Reference: www.justinweiss.com/articles/what-are-the-differences-between-irb/

The Bundler.setup is only necessary because we use Bundler.require after require “zeitwerk” is called.

Note, this is called super early right before require “zeitwerk” The initially Bundler.setup does not include the Jets.env group. Later in Jets::Booter, Bundle.require is called and includes the Jets.env group.



17
18
19
20
21
# File 'lib/jets/bundle.rb', line 17

def setup
  return unless bundler_enabled?
  Kernel.require "bundler/setup"
  Bundler.setup # Same as Bundler.setup(:default)
end