Skip to content

Commit 626c8cc

Browse files
amgleitmanAdam Gleitman
andauthored
feat: Use peerDependencies to get Hermes version on stable branches (#2531)
## Summary: This is a follow-up to #2524 where we expect the RNCore version to be explicitly specified as a peer dependency in our stable branches. #2530 brings this in for 0.74-stable; this brings it into the main branch for cherry-picking into other branches. ## Test Plan: If CIs pass, we're good. This shouldn't do anything on the main branch anyway, since we don't run through any of the peer dependency logic. Either way, a quick run of RNTester validates that we're still getting our Hermes version via the same `git merge-base` approach. --------- Co-authored-by: Adam Gleitman <[email protected]>
1 parent 169e7f9 commit 626c8cc

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ end
2121

2222
# package.json
2323
package = JSON.parse(File.read(File.join(react_native_path, "package.json")))
24-
# [macOS
25-
rn_version = package['version']
26-
version = findLatestVersionWithArtifact(rn_version) || rn_version
27-
# macOS]
24+
version = findMatchingHermesVersion(package) # [macOS] Use special logic instead of just package['version']
2825

2926
source_type = hermes_source_type(version, react_native_path)
3027
source = podspec_source(source_type, version, react_native_path)
3128

29+
version = version || package['version'] # [macOS] If version is nil, fall back to package version so CocoaPods doesn't fail
30+
3231
Pod::Spec.new do |spec|
3332
spec.name = "hermes-engine"
3433
spec.version = version

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,20 @@ def resolve_url_redirects(url)
296296
return (`curl -Ls -o /dev/null -w %{url_effective} \"#{url}\"`)
297297
end
298298

299-
# [macOS react-native-macos does not publish macos specific hermes artifacts
300-
# so we attempt to find the latest patch version of the iOS artifacts and use that
301-
def findLatestVersionWithArtifact(version)
302-
if version == "1000.0.0"
303-
# The main branch builds from source, so skip the artifact check
299+
# [macOS
300+
# Tries to find a suitable Hermes version for a given react-native-macos package.
301+
# For stable branches, we prefer this to be specified as a peer dependency.
302+
def findMatchingHermesVersion(package)
303+
if package['version'] == "1000.0.0"
304+
# The main branch builds from source, so skip this check
304305
return nil
305306
end
306307

307-
# See https://central.sonatype.org/search/rest-api-guide/ for details on query params
308-
versionWithoutPatch = "#{version.match(/^(\d+\.\d+)/)}"
309-
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")
310-
wt = JSON.parse(res)
311-
response = wt['response']
312-
return response['docs'][0]['v'] unless response['numFound'] == 0
308+
if packages['peerDependencies']
309+
return package['peerDependencies']['react-native']
310+
end
311+
312+
hermes_log("No matching Hermes version found. Defaulting to main branch, which may be unreliable.")
313313
end
314314
# macOS]
315315

0 commit comments

Comments
 (0)