From 71c81741361d96864e533b6617397370434a2510 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 4 Jun 2025 11:40:27 -0400 Subject: [PATCH] Add undocumented `HOMEBREW_USE_INTERNAL_API` switch --- Library/Homebrew/api/cask.rb | 11 +++++++++-- Library/Homebrew/api/formula.rb | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/api/cask.rb b/Library/Homebrew/api/cask.rb index 03b94f848a..a06aa9b495 100644 --- a/Library/Homebrew/api/cask.rb +++ b/Library/Homebrew/api/cask.rb @@ -12,6 +12,13 @@ module Homebrew DEFAULT_API_FILENAME = "cask.jws.json" + sig { returns(String) } + def self.api_filename + return DEFAULT_API_FILENAME unless ENV.fetch("HOMEBREW_USE_INTERNAL_API", false) + + "cask.#{SimulateSystem.current_tag}.jws.json" + end + private_class_method :cache sig { params(token: String).returns(Hash) } @@ -41,12 +48,12 @@ module Homebrew end def self.cached_json_file_path - HOMEBREW_CACHE_API/DEFAULT_API_FILENAME + HOMEBREW_CACHE_API/api_filename end sig { returns(T::Boolean) } def self.download_and_cache_data! - json_casks, updated = Homebrew::API.fetch_json_api_file DEFAULT_API_FILENAME + json_casks, updated = Homebrew::API.fetch_json_api_file api_filename cache["renames"] = {} cache["casks"] = json_casks.to_h do |json_cask| diff --git a/Library/Homebrew/api/formula.rb b/Library/Homebrew/api/formula.rb index 1bcd622da4..fe02c4bc08 100644 --- a/Library/Homebrew/api/formula.rb +++ b/Library/Homebrew/api/formula.rb @@ -12,6 +12,13 @@ module Homebrew DEFAULT_API_FILENAME = "formula.jws.json" + sig { returns(String) } + def self.api_filename + return DEFAULT_API_FILENAME unless ENV.fetch("HOMEBREW_USE_INTERNAL_API", false) + + "internal/formula.#{SimulateSystem.current_tag}.jws.json" + end + private_class_method :cache sig { params(name: String).returns(T::Hash[String, T.untyped]) } @@ -42,12 +49,12 @@ module Homebrew sig { returns(Pathname) } def self.cached_json_file_path - HOMEBREW_CACHE_API/DEFAULT_API_FILENAME + HOMEBREW_CACHE_API/api_filename end sig { returns(T::Boolean) } def self.download_and_cache_data! - json_formulae, updated = Homebrew::API.fetch_json_api_file DEFAULT_API_FILENAME + json_formulae, updated = Homebrew::API.fetch_json_api_file api_filename cache["aliases"] = {} cache["renames"] = {}