diff --git a/gem/lib/rbi-central/static/context.rb b/gem/lib/rbi-central/static/context.rb index f61db1f0..5e4206a0 100644 --- a/gem/lib/rbi-central/static/context.rb +++ b/gem/lib/rbi-central/static/context.rb @@ -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 " \ @@ -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