Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,17 @@ def bundler_settings_as_env
Bundler::Settings.new
end

# List of Bundler settings that don't make sense for the composed bundle and are better controlled manually by the
# user
ignored_settings = ["bin", "cache_all", "cache_all_platforms"]

# Map all settings to their environment variable names with `key_for` and their values. For example, the if the
# setting name `e` is `path` with a value of `vendor/bundle`, then it will return `"BUNDLE_PATH" =>
# "vendor/bundle"`
settings.all.to_h do |e|
settings
.all
.reject { |setting| ignored_settings.include?(setting) }
.to_h do |e|
key = settings.key_for(e)
value = Array(settings[e]).join(":").tr(" ", ":")

Expand Down
45 changes: 45 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,51 @@ def test_only_returns_environment_if_bundle_was_composed_ahead_of_time
end
end

def test_ignores_bundle_bin
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "irb"
GEMFILE

capture_subprocess_io do
Bundler.with_unbundled_env do
system("bundle", "config", "set", "--local", "bin", "bin")
system("bundle", "install")

assert_path_exists(File.join(dir, "bin"))

env = RubyLsp::SetupBundler.new(dir, launcher: true).setup!
refute_includes(env.keys, "BUNDLE_BIN")
end
end
end
end
end

def test_ignores_bundle_package
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "irb"
GEMFILE

capture_subprocess_io do
Bundler.with_unbundled_env do
system("bundle", "install")
system("bundle", "package")

env = RubyLsp::SetupBundler.new(dir, launcher: true).setup!
refute_includes(env.keys, "BUNDLE_CACHE_ALL")
refute_includes(env.keys, "BUNDLE_CACHE_ALL_PLATFORMS")
end
end
end
end
end

private

def with_default_external_encoding(encoding, &block)
Expand Down