Skip to content

Commit

Permalink
Avoid excluding transitive dependencies of default dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Nov 29, 2024
1 parent c611340 commit 29c1e07
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/ruby_indexer/lib/ruby_indexer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ def initial_excluded_gems
end

others.concat(this_gem.to_spec.dependencies) if this_gem
others.concat(others.filter_map { |d| d.to_spec&.dependencies }.flatten)
others.uniq!
others.map!(&:name)

excluded.each do |dependency|
next unless dependency.runtime?
Expand All @@ -281,12 +284,7 @@ def initial_excluded_gems
next unless spec

spec.dependencies.each do |transitive_dependency|
# If the transitive dependency is included in other groups, skip it
next if others.any? { |d| d.name == transitive_dependency.name }

# If the transitive dependency is included as a transitive dependency of a gem outside of the development
# group, skip it
next if others.any? { |d| d.to_spec&.dependencies&.include?(transitive_dependency) }
next if others.include?(transitive_dependency.name)

excluded << transitive_dependency
end
Expand Down
32 changes: 32 additions & 0 deletions lib/ruby_indexer/test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,37 @@ def test_includes_top_level_files
assert(uris.find { |u| File.basename(u.full_path) == "find_me.rb" })
end
end

def test_transitive_dependencies_for_non_dev_gems_are_not_excluded
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
# Both IRB and debug depend on reline. Since IRB is in the default group, reline should not be excluded
File.write(File.join(dir, "Gemfile"), <<~RUBY)
source "https://rubygems.org"
gem "irb"
gem "ruby-lsp", path: "#{Bundler.root}"
group :development do
gem "debug"
end
RUBY

Bundler.with_unbundled_env do
system("bundle install")

stdout, _stderr = capture_subprocess_io do
script = "puts RubyIndexer::Configuration.new.send(:initial_excluded_gems).join(\",\")"

system("bundle exec ruby -rruby_lsp/internal -e '#{script}'")
end

excluded_gems = stdout.split(",")
assert_includes(excluded_gems, "debug")
refute_includes(excluded_gems, "reline")
refute_includes(excluded_gems, "irb")
end
end
end
end
end
end

0 comments on commit 29c1e07

Please sign in to comment.