Skip to content

Commit

Permalink
Filter versions while testing
Browse files Browse the repository at this point in the history
  • Loading branch information
KaanOzkan committed Sep 27, 2024
1 parent 077e9ab commit 538b616
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions gem/lib/rbi-central/static/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ def run!
errors = super
return errors if errors.any?

filtered_rbi = filter_versions_from_annotation(@gem.name, @annotations_file)

# Write the filtered annotation to the context folder
write!(@annotations_file, filtered_rbi)

res = bundle_exec("tapioca gem --no-doc --post requires.rb")
unless res.status
errors << Error.new(T.must(res.err).lstrip)
return errors
end

# Copy annotations file inside the context so path look relative
FileUtils.mkdir_p("#{absolute_path}/rbi/annotations")
FileUtils.cp(@annotations_file, "#{absolute_path}/#{@annotations_file}")

res = bundle_exec("tapioca check-shims --no-payload " \
"--gem-rbi-dir=sorbet/rbi/gems " \
"--shim-rbi-dir=rbi/annotations " \
Expand Down Expand Up @@ -78,6 +79,17 @@ def add_require(name)
require "#{name}"
RB
end

private

sig { params(gem_name: String, annotations_file: String).returns(String) }
def filter_versions_from_annotation(gem_name, annotations_file)
gem_version = ::Gem::Version.new(gem_version_from_gemfile_lock(gem_name))
rbi = RBI::Parser.parse_file(annotations_file)
rbi.filter_versions!(gem_version)

rbi.string
end
end
end
end

0 comments on commit 538b616

Please sign in to comment.