Sha256: 7612743373ab1d4559d5ef63ad19f0d5134e2fbd4c1ff0b9962c0e503529bb46

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

# typed: true
# frozen_string_literal: true

require "sorbet-runtime"

begin
  T::Configuration.default_checked_level = :never

  T.singleton_class.prepend(
    Module.new do
      def cast(value, type, checked: true)
        value
      end

      def let(value, type, checked: true)
        value
      end

      def must(arg)
        arg
      end

      def absurd(value)
        value
      end

      def bind(value, type, checked: true)
        value
      end
    end
  )
rescue RuntimeError => error
  # From https://github.com/sorbet/sorbet/blob/dcf1b069cfb0d6624c027e45e59f4c6ca33de970/gems/sorbet-runtime/lib/types/private/runtime_levels.rb#L54
  # Sorbet has already evaluated a method call somewhere, so we can't disable it.
  # In this case, we want to log a warning so Packwerk can still be used (but will be slower).
  if /Set the default checked level earlier./.match?(error.message)
    warn("Packwerk couldn't disable Sorbet. Please ensure it isn't being used before Packwerk is loaded.")
  else
    raise error
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
packwerk-3.2.2 lib/packwerk/disable_sorbet.rb
packwerk-3.2.1 lib/packwerk/disable_sorbet.rb
packwerk-3.2.0 lib/packwerk/disable_sorbet.rb
packwerk-3.1.0 lib/packwerk/disable_sorbet.rb
packwerk-3.0.1 lib/packwerk/disable_sorbet.rb
packwerk-3.0.0 lib/packwerk/disable_sorbet.rb