Skip to content

Commit e383d81

Browse files
vinistockparacycle
authored andcommitted
Remove stale gem RBIs on generate (#616)
1 parent 9ca7942 commit e383d81

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

lib/tapioca/generators/gem.rb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,27 @@ def initialize(
5151
def generate
5252
require_gem_file
5353

54-
gems_to_generate(@gem_names)
55-
.reject { |gem| @gem_excludes.include?(gem.name) }
56-
.each do |gem|
57-
say("Processing '#{gem.name}' gem:", :green)
58-
shell.indent do
59-
compile_gem_rbi(gem)
60-
puts
61-
end
54+
gems_to_process = gems_to_generate(@gem_names).reject { |gem| @gem_excludes.include?(gem.name) }
55+
56+
anything_done = [
57+
perform_removals,
58+
gems_to_process.any?,
59+
].any?
60+
61+
gems_to_process.each do |gem|
62+
say("Processing '#{gem.name}' gem:", :green)
63+
shell.indent do
64+
compile_gem_rbi(gem)
65+
puts
6266
end
67+
end
6368

64-
say("All operations performed in working directory.", [:green, :bold])
65-
say("Please review changes and commit them.", [:green, :bold])
69+
if anything_done
70+
say("All operations performed in working directory.", [:green, :bold])
71+
say("Please review changes and commit them.", [:green, :bold])
72+
else
73+
say("No operations performed, all RBIs are up-to-date.", [:green, :bold])
74+
end
6675
end
6776

6877
sig { params(should_verify: T::Boolean).void }

spec/tapioca/cli/gem_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,22 @@ def fizz; end
185185
refute_path_exists("#{repo_path}/sorbet/rbi/gems/baz@0.0.2.rbi")
186186
end
187187

188+
it "must remove outdated RBIs" do
189+
FileUtils.touch("#{outdir}/outdated@5.0.0.rbi")
190+
191+
output = tapioca("gem foo")
192+
193+
assert_includes(output, <<~OUTPUT)
194+
Processing 'foo' gem:
195+
Compiling foo, this may take a few seconds... Done
196+
OUTPUT
197+
198+
assert_includes(output, "-- Removing: #{outdir}/outdated@5.0.0.rbi\n")
199+
200+
assert_path_exists("#{outdir}/foo@0.0.1.rbi")
201+
refute_path_exists("#{outdir}/outdated@5.0.0.rbi")
202+
end
203+
188204
it "must perform postrequire properly" do
189205
output = tapioca("gem foo --postrequire #{repo_path / "postrequire.rb"}")
190206

0 commit comments

Comments
 (0)