Load tap migration renames from the API

These would not get loaded from the API at all meaning these
were not loadable by the old names when the core formula or cask
tap was not installed. We assume that most users don't have those
core taps tapped which means this is broken for most everyone.
This commit is contained in:
apainintheneck 2024-06-30 10:18:03 -07:00
parent fda555d7e6
commit 10aa981209
2 changed files with 28 additions and 18 deletions

View File

@ -84,8 +84,8 @@ module Cask
# Loads a cask from a path.
class FromPathLoader < AbstractContentLoader
sig {
params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.attached_class))
overridable.params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.attached_class))
}
def self.try_new(ref, warn: false)
path = case ref
@ -152,8 +152,8 @@ module Cask
# Loads a cask from a URI.
class FromURILoader < FromPathLoader
sig {
params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.attached_class))
override.params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.attached_class))
}
def self.try_new(ref, warn: false)
# Cache compiled regex
@ -199,16 +199,22 @@ module Cask
attr_reader :tap
sig {
params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.attached_class))
override(allow_incompatible: true) # rubocop:todo Sorbet/AllowIncompatibleOverride
.params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.any(T.attached_class, FromAPILoader)))
}
def self.try_new(ref, warn: false)
ref = ref.to_s
return unless (token_tap_type = CaskLoader.tap_cask_token_type(ref, warn:))
token, tap, = token_tap_type
new("#{tap}/#{token}")
token, tap, type = token_tap_type
if type == :migration && tap.core_cask_tap? && (loader = FromAPILoader.try_new(token))
loader
else
new("#{tap}/#{token}")
end
end
sig { params(tapped_token: String).void }
@ -441,8 +447,8 @@ module Cask
# if the same token exists in multiple taps.
class FromNameLoader < FromTapLoader
sig {
params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.attached_class))
override.params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.any(T.attached_class, FromAPILoader)))
}
def self.try_new(ref, warn: false)
return unless ref.is_a?(String)
@ -452,7 +458,7 @@ module Cask
# If it exists in the default tap, never treat it as ambiguous with another tap.
if (core_cask_tap = CoreCaskTap.instance).installed? &&
(loader= super("#{core_cask_tap}/#{token}", warn:))&.path&.exist?
(loader = super("#{core_cask_tap}/#{token}", warn:))&.path&.exist?
return loader
end
@ -473,8 +479,8 @@ module Cask
# Loader which loads a cask from the installed cask file.
class FromInstalledPathLoader < FromPathLoader
sig {
params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.attached_class))
override.params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.attached_class))
}
def self.try_new(ref, warn: false)
return unless ref.is_a?(String)
@ -489,8 +495,8 @@ module Cask
# Pseudo-loader which raises an error when trying to load the corresponding cask.
class NullLoader < FromPathLoader
sig {
params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.attached_class))
override.params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
.returns(T.nilable(T.attached_class))
}
def self.try_new(ref, warn: false)
return if ref.is_a?(Cask)

View File

@ -759,7 +759,7 @@ module Formulary
sig {
params(ref: T.any(String, Pathname, URI::Generic), from: Symbol, warn: T::Boolean)
.returns(T.nilable(T.attached_class))
.returns(T.nilable(FormulaLoader))
}
def self.try_new(ref, from: T.unsafe(nil), warn: false)
ref = ref.to_s
@ -776,7 +776,11 @@ module Formulary
{}
end
new(name, path, tap:, **options)
if type == :migration && tap.core_tap? && (loader = FromAPILoader.try_new(name))
loader
else
new(name, path, tap:, **options)
end
end
sig { params(name: String, path: Pathname, tap: Tap, alias_name: String).void }
@ -811,7 +815,7 @@ module Formulary
class FromNameLoader < FromTapLoader
sig {
params(ref: T.any(String, Pathname, URI::Generic), from: Symbol, warn: T::Boolean)
.returns(T.nilable(T.attached_class))
.returns(T.nilable(FormulaLoader))
}
def self.try_new(ref, from: T.unsafe(nil), warn: false)
return unless ref.is_a?(String)