Skip to content

Commit

Permalink
Handle missing specs when listing transitive dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jan 6, 2025
1 parent ee86730 commit 394fbf1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ruby_indexer/lib/ruby_indexer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,13 @@ 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.concat(
others.filter_map do |d|
d.to_spec&.dependencies
rescue Gem::MissingSpecError
false
end.flatten,
)
others.uniq!
others.map!(&:name)

Expand Down
31 changes: 31 additions & 0 deletions lib/ruby_indexer/test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,36 @@ def test_transitive_dependencies_for_non_dev_gems_are_not_excluded
end
end
end

def test_does_not_fail_if_there_are_missing_specs_due_to_platform_constraints
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
File.write(File.join(dir, "Gemfile"), <<~RUBY)
source "https://rubygems.org"
gem "ruby-lsp", path: "#{Bundler.root}"
platforms :windows do
gem "tzinfo"
gem "tzinfo-data"
end
RUBY

Bundler.with_unbundled_env do
capture_subprocess_io { system("bundle install") }

_stdout, stderr = capture_subprocess_io do
script = [
"require \"ruby_lsp/internal\"",
"RubyIndexer::Configuration.new.indexable_uris",
].join(";")

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

assert_empty(stderr)
end
end
end
end
end
end

0 comments on commit 394fbf1

Please sign in to comment.