diff --git a/lib/tapioca/helpers/sorbet_helper.rb b/lib/tapioca/helpers/sorbet_helper.rb index 362f31f37..2e1d1c634 100644 --- a/lib/tapioca/helpers/sorbet_helper.rb +++ b/lib/tapioca/helpers/sorbet_helper.rb @@ -39,16 +39,25 @@ def parse(content) end.to_h #: Hash[String, String | bool | nil] new( + # `--cache-dir=` disables the cache, modeled here with a `nil` value + cache_dir: if (value = options["--cache-dir"]).is_a?(String) + value.empty? ? nil : value + end, + parser: options["--parser"] == "prism" ? :prism : :original, ) end end - #: (parser: Symbol) -> void - def initialize(parser:) + #: (cache_dir: String?, parser: Symbol) -> void + def initialize(cache_dir:, parser:) + @cache_dir = cache_dir #: String? @parser = parser #: Symbol end + #: String? + attr_reader :cache_dir + #: Symbol attr_reader :parser @@ -64,6 +73,10 @@ def parse_with_prism? = @parser == :prism #: (*String sorbet_args) -> Spoom::ExecResult def sorbet(*sorbet_args) + if sorbet_config.cache_dir + sorbet_args << "--cache-dir=#{sorbet_config.cache_dir}" + end + if sorbet_config.parse_with_prism? sorbet_args << "--parser=prism" end diff --git a/spec/tapioca/helpers/sorbet_helper_spec.rb b/spec/tapioca/helpers/sorbet_helper_spec.rb index ca1893e5c..d1569f442 100644 --- a/spec/tapioca/helpers/sorbet_helper_spec.rb +++ b/spec/tapioca/helpers/sorbet_helper_spec.rb @@ -94,6 +94,32 @@ class Tapioca::SorbetHelperSpec < Minitest::Spec end end + describe "--cache-dir" do + it "detects --cache-dir" do + config = parse(<<~CONFIG) + . + --cache-dir=/tmp/sorbet-cache + CONFIG + assert_equal("/tmp/sorbet-cache", config.cache_dir) + end + + it "returns nil when not set" do + config = parse(<<~CONFIG) + . + --parser=prism + CONFIG + assert_nil(config.cache_dir) + end + + it "returns nil for empty value" do + config = parse(<<~CONFIG) + . + --cache-dir= + CONFIG + assert_nil(config.cache_dir) + end + end + private #: (String content) -> Tapioca::SorbetHelper::SorbetConfig