Skip to content

Commit ce68f92

Browse files
authored
fix: fix build failure with older versions and Hermes (#2500)
## Summary: `findLastestVersionWithArtifact` fails to find older versions of Hermes prebuilds because the Maven endpoint it uses does not return all versions. Resolves #2499 ## Test Plan: `pod install` output from RNTA with RN 0.78.2 and RNM 0.78.3 ![image](https://github.com/user-attachments/assets/a6984ba0-87c0-4304-95d1-4a5b054b44fa)
1 parent 5d1be36 commit ce68f92

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

packages/react-native/sdks/hermes-engine/hermes-utils.rb

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'net/http'
77
require 'rexml/document'
88
require 'open3' # [macOS]
9+
require 'json' # [macOS]
910

1011
HERMES_GITHUB_URL = "https://github.com/facebook/hermes.git"
1112
ENV_BUILD_FROM_SOURCE = "RCT_BUILD_HERMES_FROM_SOURCE"
@@ -242,22 +243,12 @@ def resolve_url_redirects(url)
242243
# [macOS react-native-macos does not publish macos specific hermes artifacts
243244
# so we attempt to find the latest patch version of the iOS artifacts and use that
244245
def findLastestVersionWithArtifact(version)
245-
versionWithoutPatch = version.match(/^(\d+\.\d+)/)
246-
xml_data, = Open3.capture3("curl -s https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/maven-metadata.xml")
247-
248-
metadata = REXML::Document.new(xml_data)
249-
versions = metadata.elements.to_a('//metadata/versioning/versions/version')
250-
251-
# Extract version numbers and sort them
252-
filtered_versions = versions.select { |version| version.text.match?(/^#{versionWithoutPatch}\.\d+$/) }
253-
if filtered_versions.empty?
254-
return
255-
end
256-
257-
version_numbers = filtered_versions.map { |version| version.text }
258-
sorted_versions = version_numbers.sort_by { |v| Gem::Version.new(v) }
259-
260-
return sorted_versions.last
246+
# See https://central.sonatype.org/search/rest-api-guide/ for details on query params
247+
versionWithoutPatch = "#{version.match(/^(\d+\.\d+)/)}"
248+
res, = Open3.capture3("curl -s https://search.maven.org/solrsearch/select?q=g:com.facebook.react+AND+a:react-native-artifacts+AND+v:#{versionWithoutPatch}.*&core=gav&rows=1&wt=json")
249+
wt = JSON.parse(res)
250+
response = wt['response']
251+
return response['docs'][0]['v'] unless response['numFound'] == 0
261252
end
262253
# macOS]
263254

0 commit comments

Comments
 (0)