Ignore types when loading CaskStruct from installed caskfiles

This commit is contained in:
Rylan Polster
2026-01-08 21:45:58 -05:00
parent 64f62f694d
commit 94c1347800
3 changed files with 18 additions and 11 deletions
+3 -3
View File
@@ -147,8 +147,8 @@ module Homebrew
end
# NOTE: this will be used to load installed cask JSON files, so it must never fail with older JSON API versions)
sig { params(hash: T::Hash[String, T.untyped]).returns(CaskStruct) }
def self.generate_cask_struct_hash(hash)
sig { params(hash: T::Hash[String, T.untyped], ignore_types: T::Boolean).returns(CaskStruct) }
def self.generate_cask_struct_hash(hash, ignore_types: false)
hash = Homebrew::API.merge_variations(hash).dup.deep_symbolize_keys.transform_keys(&:to_s)
hash["conflicts_with_args"] = hash["conflicts_with"]
@@ -254,7 +254,7 @@ module Homebrew
hash["desc_present"] = hash["desc"].present?
hash["disable_present"] = hash["disable_args"].present?
CaskStruct.from_hash(hash)
CaskStruct.from_hash(hash, ignore_types:)
end
end
end
+4 -2
View File
@@ -4,8 +4,10 @@
module Homebrew
module API
class CaskStruct < T::Struct
sig { params(cask_hash: T::Hash[String, T.untyped]).returns(CaskStruct) }
def self.from_hash(cask_hash)
sig { params(cask_hash: T::Hash[String, T.untyped], ignore_types: T::Boolean).returns(CaskStruct) }
def self.from_hash(cask_hash, ignore_types: false)
return super(cask_hash) if ignore_types
cask_hash = cask_hash.transform_keys(&:to_sym)
.slice(*decorator.all_props)
.compact_blank
+11 -6
View File
@@ -137,6 +137,7 @@ module Cask
@token = path.basename(path.extname).to_s
@path = path
@tap = Tap.from_path(path) || Homebrew::API.tap_from_source_download(path)
@from_installed_caskfile = false
end
sig { override.params(config: T.nilable(Config)).returns(Cask) }
@@ -151,7 +152,8 @@ module Cask
if !self.class.invalid_path?(path, valid_extnames: %w[.json]) &&
(from_json = JSON.parse(@content).presence) &&
from_json.is_a?(Hash)
return FromAPILoader.new(token, from_json:, path:).load(config:)
return FromAPILoader.new(token, from_json:, path:,
from_installed_caskfile: @from_installed_caskfile).load(config:)
end
begin
@@ -323,16 +325,18 @@ module Cask
sig {
params(
token: String,
from_json: T.nilable(T::Hash[String, T.untyped]),
path: T.nilable(Pathname),
token: String,
from_json: T.nilable(T::Hash[String, T.untyped]),
path: T.nilable(Pathname),
from_installed_caskfile: T::Boolean,
).void
}
def initialize(token, from_json: T.unsafe(nil), path: nil)
def initialize(token, from_json: T.unsafe(nil), path: nil, from_installed_caskfile: false)
@token = token.sub(%r{^homebrew/(?:homebrew-)?cask/}i, "")
@sourcefile_path = path || Homebrew::API.cached_cask_json_file_path
@path = path || CaskLoader.default_path(@token)
@from_json = from_json
@from_installed_caskfile = from_installed_caskfile
end
def load(config:)
@@ -343,7 +347,7 @@ module Cask
Homebrew::API::Cask.all_casks.fetch(token)
end
cask_struct = Homebrew::API::Cask.generate_cask_struct_hash(json_cask)
cask_struct = Homebrew::API::Cask.generate_cask_struct_hash(json_cask, ignore_types: @from_installed_caskfile)
cask_options = {
loaded_from_api: true,
@@ -458,6 +462,7 @@ module Cask
installed_tap = Cask.new(@token).tab.tap
@tap = installed_tap if installed_tap
@from_installed_caskfile = true
end
end