Sha256: bd4033b3667b93e224c2da1f16cb486cb77a62fdddfc1c0f089df5971c682bdd

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 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({
      }.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

4 entries across 4 versions & 1 rubygems

Version Path
tapioca-0.5.6 lib/tapioca/compilers/sorbet.rb
tapioca-0.5.5 lib/tapioca/compilers/sorbet.rb
tapioca-0.5.4 lib/tapioca/compilers/sorbet.rb
tapioca-0.5.3 lib/tapioca/compilers/sorbet.rb