Skip to content

Commit

Permalink
[react-native] Fix Hermes version mismatch (facebook#2014)
Browse files Browse the repository at this point in the history
* [react-native] Fix Hermes version mismatch

* Address PR comments

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

Co-authored-by: Saad Najmi <[email protected]>

---------

Co-authored-by: Saad Najmi <[email protected]>
  • Loading branch information
gabrieldonadel and Saadnajmi committed Jan 19, 2024
1 parent d0d4c8d commit 1c30ac4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ react_native_path = File.join(__dir__, "..", "..")

# package.json
package = JSON.parse(File.read(File.join(react_native_path, "package.json")))
version = package['version']
# [macOS
rn_version = package['version']
version = findLastestVersionWithArtifact(rn_version) || rn_version
# macOS]

source_type = hermes_source_type(version, react_native_path)
source = podspec_source(source_type, version, react_native_path)
Expand Down
23 changes: 23 additions & 0 deletions packages/react-native/sdks/hermes-engine/hermes-utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require 'net/http'
require 'rexml/document'
require 'open3' # [macOS]

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

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

# [macOS react-native-macos does not publish macos specific hermes artifacts
# so we attempt to find the latest patch version of the iOS artifacts and use that
def findLastestVersionWithArtifact(version)
versionWithoutPatch = version.match(/^(\d+\.\d+)/)
xml_data, = Open3.capture3("curl -s https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/maven-metadata.xml")

metadata = REXML::Document.new(xml_data)
versions = metadata.elements.to_a('//metadata/versioning/versions/version')

# Extract version numbers and sort them
filtered_versions = versions.select { |version| version.text.match?(/^#{versionWithoutPatch}\.\d+$/) }
if filtered_versions.empty?
return
end

version_numbers = filtered_versions.map { |version| version.text }
sorted_versions = version_numbers.sort_by { |v| Gem::Version.new(v) }

return sorted_versions.last
end
# macOS]

# This function checks that Hermes artifact exists.
# As of now it should check it on the Maven repo.
#
Expand Down

0 comments on commit 1c30ac4

Please sign in to comment.