Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions lib/tapioca/commands/abstract_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def initialize(
@include_doc = include_doc #: bool
@include_loc = include_loc #: bool
@include_exported_rbis = include_exported_rbis
@skipped_gems = [] #: Array[String]
@halt_upon_load_error = halt_upon_load_error
end

Expand Down
32 changes: 27 additions & 5 deletions lib/tapioca/commands/gem_generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def execute
halt_upon_load_error: @halt_upon_load_error,
)

gem_queue = gems_to_generate(@gem_names).reject { |gem| @exclude.include?(gem.name) }
gem_queue = gems_to_generate(@gem_names)
user_excluded_gems = user_excluded_gem_names(gem_queue)
gem_queue.reject! { |gem| @exclude.include?(gem.name) }
Comment thread
written-fresh marked this conversation as resolved.
anything_done = [
perform_removals,
gem_queue.any?,
Expand All @@ -44,6 +46,14 @@ def execute
else
say("No operations performed, all RBIs are up-to-date.", [:green, :bold])
Comment thread
written-fresh marked this conversation as resolved.
end
unless @skipped_gems.empty?
say("\nNote: Tapioca is skipping gem rbi generation for following gems due to the built-in configuration:", [:yellow, :bold])
Comment thread
written-fresh marked this conversation as resolved.
Outdated
say(@skipped_gems.join(", "), [:yellow, :bold])
end
unless user_excluded_gems.empty?
say("\nNote: Tapioca is skipping gem rbi generation for following gems due to user configuration:", [:yellow, :bold])
Comment thread
written-fresh marked this conversation as resolved.
Outdated
say(user_excluded_gems.join(", "), [:yellow, :bold])
end
ensure
GitAttributes.create_generated_attribute_file(@outpath)
end
Expand All @@ -56,16 +66,28 @@ def gems_to_generate(gem_names)
gem = @bundle.gem(gem_name)

if gem.nil?
next if @lsp_addon

raise Tapioca::Error, set_color("Error: Cannot find gem '#{gem_name}'", :red)
if @lsp_addon
next
elsif Gemfile::GemSpec::IGNORED_GEMS.include?(gem_name)
@skipped_gems << gem_name
next
else
raise Tapioca::Error, set_color("Error: Cannot find gem '#{gem_name}'", :red)
end
end

gems.concat(gem_dependencies(gem)) if @include_dependencies
gems << gem
end
end

#: (Array[Gemfile::GemSpec] gem_queue) -> Array[String]
def user_excluded_gem_names(gem_queue)
@exclude.uniq.select do |gem_name|
@bundle.gem(gem_name) &&
(@gem_names.include?(gem_name) || gem_queue.any? { |gem| gem.name == gem_name })
end
end
Comment thread
written-fresh marked this conversation as resolved.
Outdated

#: (Gemfile::GemSpec gem, ?Array[Gemfile::GemSpec] dependencies) -> Array[Gemfile::GemSpec]
def gem_dependencies(gem, dependencies = [])
direct_dependencies = gem.dependencies.filter_map { |dependency| @bundle.gem(dependency.name) }
Expand Down
43 changes: 43 additions & 0 deletions spec/tapioca/cli/gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,49 @@ class Secret; end
assert_success_status(result)
end

it "reports explicitly requested ignored gems" do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test for not reporting excluded gems when we only run gem and gem --all?

result = @project.tapioca("gem sorbet", exclude: [])

assert_stdout_includes(result, <<~OUT)
Note: Tapioca is skipping gem rbi generation for following gems due to the built-in configuration:
sorbet
OUT
refute_includes(result.out, "Compiled sorbet")

assert_empty_stderr(result)
assert_success_status(result)
end

it "reports gems excluded by built-in and user configuration" do
result = @project.tapioca("gem sorbet rbi --exclude rbi")

assert_stdout_includes(result, <<~OUT)
Note: Tapioca is skipping gem rbi generation for following gems due to the built-in configuration:
sorbet
OUT
assert_stdout_includes(result, <<~OUT)
Note: Tapioca is skipping gem rbi generation for following gems due to user configuration:
rbi
OUT
refute_includes(result.out, "Compiled rbi")

assert_empty_stderr(result)
assert_success_status(result)
end

it "reports gems excluded by user configuration" do
result = @project.tapioca("gem rbi --exclude rbi")

assert_stdout_includes(result, <<~OUT)
Note: Tapioca is skipping gem rbi generation for following gems due to user configuration:
rbi
OUT
refute_includes(result.out, "Compiled rbi")

assert_empty_stderr(result)
assert_success_status(result)
end

it "fails with error when gem cannot be found" do
result = @project.tapioca("gem non_existent_gem")

Expand Down
Loading