Skip to content

Commit a7894ac

Browse files
[react-native] Fix Hermes version mismatch (#2014) (#2041)
* [react-native] Fix Hermes version mismatch * Address PR comments * Update packages/react-native/sdks/hermes-engine/hermes-utils.rb --------- Co-authored-by: Saad Najmi <sanajmi@microsoft.com>
1 parent d0d4c8d commit a7894ac

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

packages/react-native/sdks/hermes-engine/hermes-engine.podspec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ react_native_path = File.join(__dir__, "..", "..")
1010

1111
# package.json
1212
package = JSON.parse(File.read(File.join(react_native_path, "package.json")))
13-
version = package['version']
13+
# [macOS
14+
rn_version = package['version']
15+
version = findLastestVersionWithArtifact(rn_version) || rn_version
16+
# macOS]
1417

1518
source_type = hermes_source_type(version, react_native_path)
1619
source = podspec_source(source_type, version, react_native_path)

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
require 'net/http'
77
require 'rexml/document'
8+
require 'open3' # [macOS]
89

910
HERMES_GITHUB_URL = "https://github.com/facebook/hermes.git"
1011

@@ -233,6 +234,28 @@ def resolve_url_redirects(url)
233234
return (`curl -Ls -o /dev/null -w %{url_effective} \"#{url}\"`)
234235
end
235236

237+
# [macOS react-native-macos does not publish macos specific hermes artifacts
238+
# so we attempt to find the latest patch version of the iOS artifacts and use that
239+
def findLastestVersionWithArtifact(version)
240+
versionWithoutPatch = version.match(/^(\d+\.\d+)/)
241+
xml_data, = Open3.capture3("curl -s https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/maven-metadata.xml")
242+
243+
metadata = REXML::Document.new(xml_data)
244+
versions = metadata.elements.to_a('//metadata/versioning/versions/version')
245+
246+
# Extract version numbers and sort them
247+
filtered_versions = versions.select { |version| version.text.match?(/^#{versionWithoutPatch}\.\d+$/) }
248+
if filtered_versions.empty?
249+
return
250+
end
251+
252+
version_numbers = filtered_versions.map { |version| version.text }
253+
sorted_versions = version_numbers.sort_by { |v| Gem::Version.new(v) }
254+
255+
return sorted_versions.last
256+
end
257+
# macOS]
258+
236259
# This function checks that Hermes artifact exists.
237260
# As of now it should check it on the Maven repo.
238261
#

0 commit comments

Comments
 (0)