Skip to content

Commit

Permalink
Merge pull request #2096 from rzane/rzane/exclude-should-ignore-trans…
Browse files Browse the repository at this point in the history
…itive-dependencies

`--exclude` should also exclude transitive dependencies
  • Loading branch information
KaanOzkan authored Nov 28, 2024
2 parents ebb0cc2 + 29bed6e commit a14f396
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/tapioca/commands/abstract_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def initialize(
def gems_to_generate(gem_names)
return @bundle.dependencies if gem_names.empty?

gem_names.each_with_object([]) do |gem_name, gems|
(gem_names - @exclude).each_with_object([]) do |gem_name, gems|
gem = @bundle.gem(gem_name)

if gem.nil?
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def load_dependencies

sig { returns([T::Enumerable[Spec], T::Array[String]]) }
def materialize_deps
deps = definition.locked_gems.dependencies.values
deps = definition.locked_gems.dependencies.except(*@excluded_gems).values
materialized_dependencies = definition.resolve.materialize(deps)
missing_spec_names = materialized_dependencies.missing_specs.map(&:name).to_set
missing_specs = materialized_dependencies.missing_specs.map do |spec|
Expand Down
9 changes: 8 additions & 1 deletion spec/spec_with_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def assert_project_file_exist(path)
# `Path` can include patterns such as `*`, useful for testing RBIs for real gems
sig { params(path: String).void }
def assert_project_file_match(path)
assert(Dir[path].any?)
assert(@project.glob(path).any?)
end

# Refute that `path` exists inside `@project`
Expand All @@ -117,6 +117,13 @@ def refute_project_file_exist(path)
refute(@project.file?(path))
end

# Refute that `path` exists inside `@project`
# `Path` can include patterns such as `*`, useful for testing RBIs for real gems
sig { params(path: String).void }
def refute_project_file_match(path)
refute(@project.glob(path).any?)
end

sig { params(strictness: String, file: String).void }
def assert_file_strictness(strictness, file)
assert_equal(strictness, Spoom::Sorbet::Sigils.file_strictness(@project.absolute_path_to(file)))
Expand Down
8 changes: 6 additions & 2 deletions spec/tapioca/cli/gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -780,19 +780,23 @@ class Secret; end

it "must respect exclude option" do
@project.require_mock_gem(mock_gem("foo", "0.0.1"))
@project.require_mock_gem(mock_gem("bar", "0.3.0"))
@project.require_mock_gem(mock_gem("baz", "0.0.2"))
@project.require_mock_gem(mock_gem("bar", "0.3.0", dependencies: ["activemodel", "actionpack"]))
@project.require_mock_gem(mock_gem("baz", "0.0.2", dependencies: ["activemodel"]))
@project.bundle_install!

result = @project.tapioca("gem --all --exclude foo bar")

refute_includes(result.out, "Compiled bar")
refute_includes(result.out, "Compiled actionpack")
assert_stdout_includes(result, "Compiled baz")
assert_stdout_includes(result, "Compiled activemodel")
refute_includes(result.out, "Compiled foo")

refute_project_file_exist("sorbet/rbi/gems/[email protected]")
refute_project_file_exist("sorbet/rbi/gems/[email protected]")
refute_project_file_match("sorbet/rbi/gems/actionpack@*.rbi")
assert_project_file_exist("sorbet/rbi/gems/[email protected]")
assert_project_file_match("sorbet/rbi/gems/activemodel@*.rbi")

assert_empty_stderr(result)
assert_success_status(result)
Expand Down

0 comments on commit a14f396

Please sign in to comment.