Sha256: 866c4461fc648dc7176e9f88d9e983cf7b674f3e46a88ad869da0ba04bd10047

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

# typed: strict
# frozen_string_literal: true

require "pathname"
require "shellwords"

module Tapioca
  module Compilers
    module Sorbet
      SORBET_GEM_SPEC = T.let(
        Gem::Specification.find_by_name("sorbet-static"),
        Gem::Specification
      )
      SORBET = T.let(
        Pathname.new(SORBET_GEM_SPEC.full_gem_path) / "libexec" / "sorbet",
        Pathname
      )
      EXE_PATH_ENV_VAR = "TAPIOCA_SORBET_EXE"

      FEATURE_REQUIREMENTS = T.let({
        mixes_in_class_methods_multiple_args: Gem::Requirement.new("> 0.5.6200"),
      }.freeze, T::Hash[Symbol, Gem::Requirement])

      class << self
        extend(T::Sig)

        sig { params(args: String).returns(String) }
        def run(*args)
          IO.popen(
            [
              sorbet_path,
              "--quiet",
              *args,
            ].join(" "),
            err: "/dev/null"
          ).read
        end

        sig { returns(String) }
        def sorbet_path
          sorbet_path = ENV.fetch(EXE_PATH_ENV_VAR, SORBET)
          sorbet_path = SORBET if sorbet_path.empty?
          sorbet_path.to_s.shellescape
        end

        sig { params(feature: Symbol, version: T.nilable(Gem::Version)).returns(T::Boolean) }
        def supports?(feature, version: nil)
          version = SORBET_GEM_SPEC.version unless version
          requirement = FEATURE_REQUIREMENTS[feature]

          raise "Invalid Sorbet feature #{feature}" unless requirement

          requirement.satisfied_by?(version)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tapioca-0.5.2 lib/tapioca/compilers/sorbet.rb
tapioca-0.5.1 lib/tapioca/compilers/sorbet.rb
tapioca-0.5.0 lib/tapioca/compilers/sorbet.rb