@@ -187,26 +187,20 @@ async function getLatestStableVersionFromNPM() /*: Promise<string> */ {
187187}
188188
189189/**
190- * Checks whether the upstream Hermes tarball (from Maven) already contains
191- * macOS slices. If it does, we can skip building Hermes from source entirely.
190+ * Downloads the upstream Hermes tarball from Maven or Sonatype.
191+ * The caller is responsible for extracting and recomposing the
192+ * xcframework (e.g. adding the macOS slice to the universal).
192193 *
193194 * Tries multiple version resolution strategies in order:
194195 * 1. Mapped version from peerDependencies (stable branches)
195196 * 2. Version at merge base with facebook/react-native (main branch)
196197 * 3. Latest stable version from npm (last resort)
197198 *
198- * Returns {hasMacSlice: boolean, tarballPath?: string, version?: string}.
199- * When hasMacSlice is true, tarballPath points to the downloaded tarball and
200- * version is the upstream version string used for the lookup.
201- *
202- * The check looks for a macOS platform entry inside the universal
203- * hermes.xcframework (via its Info.plist), not just for a standalone
204- * macosx/ directory. Upstream tarballs ship a standalone macosx/hermes.framework
205- * but don't include it in the universal xcframework yet.
199+ * Returns {tarballPath, version} on success, or null if no tarball is available.
206200 */
207- async function checkUpstreamHermesHasMacSlice (
201+ async function downloadUpstreamHermesTarball (
208202 buildType /*: BuildFlavor */ = 'Debug' ,
209- ) /*: Promise<{| hasMacSlice: boolean, tarballPath? : string, version? : string |}> */ {
203+ ) /*: Promise<? {| tarballPath: string, version: string |}> */ {
210204 const packageJsonPath = path . resolve ( __dirname , '..' , '..' , 'package.json' ) ;
211205
212206 // Build a list of candidate versions to try (in priority order)
@@ -232,8 +226,10 @@ async function checkUpstreamHermesHasMacSlice(
232226 }
233227
234228 if ( candidates . length === 0 ) {
235- macosLog ( 'Could not determine any upstream version to check Hermes tarball' ) ;
236- return { hasMacSlice : false } ;
229+ macosLog (
230+ 'Could not determine any upstream version to download Hermes tarball' ,
231+ ) ;
232+ return null ;
237233 }
238234
239235 const mavenRepoUrl = 'https://repo1.maven.org/maven2' ;
@@ -255,74 +251,29 @@ async function checkUpstreamHermesHasMacSlice(
255251
256252 for ( const tarballUrl of urlsToTry ) {
257253 macosLog (
258- `Checking upstream Hermes tarball (version: ${ version } , ${ buildType } ) at ${ tarballUrl } ...` ,
254+ `Trying upstream Hermes tarball (version: ${ version } , ${ buildType } ) at ${ tarballUrl } ...` ,
259255 ) ;
260256
261- // Check if the tarball exists
262- try {
263- const headResponse = await fetch ( tarballUrl , { method : 'HEAD' } ) ;
264- if ( headResponse . status !== 200 ) {
265- macosLog ( `Tarball not found, trying next URL...` ) ;
266- continue ;
267- }
268- } catch ( _ ) {
269- macosLog ( 'Failed to reach server, trying next URL...' ) ;
270- continue ;
271- }
272-
273- // Download the tarball to a temp directory
274- const tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'hermes-check-' ) ) ;
275- const tarballPath = path . join ( tmpDir , 'hermes-ios.tar.gz' ) ;
276-
277257 try {
278- macosLog ( `Downloading upstream tarball...` ) ;
279- const response = await fetch ( tarballUrl ) ;
258+ const response /*: Response */ = await fetch ( tarballUrl ) ;
280259 if ( ! response . ok ) {
281260 macosLog (
282- `Download failed : ${ response . status } ${ response . statusText } ` ,
261+ `Tarball not available : ${ response . status } ${ response . statusText } ` ,
283262 ) ;
284- fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
285263 continue ;
286264 }
287265
266+ const tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'hermes-' ) ) ;
267+ const tarballPath = path . join ( tmpDir , 'hermes-ios.tar.gz' ) ;
288268 const buffer = await response . arrayBuffer ( ) ;
289269 fs . writeFileSync ( tarballPath , Buffer . from ( buffer ) ) ;
290270
291- // Extract the xcframework's Info.plist and check for a macOS
292- // platform entry. We can't just look for a macosx/ directory in
293- // the tarball — upstream ships a standalone macosx/hermes.framework
294- // but doesn't include macOS in the universal xcframework yet.
295- let hasMacSlice = false ;
296- try {
297- const plist = execSync (
298- `tar -xzf "${ tarballPath } " -O --wildcards '*/universal/hermes.xcframework/Info.plist' 2>/dev/null` ,
299- { encoding : 'utf8' , maxBuffer : 1024 * 1024 } ,
300- ) ;
301- hasMacSlice = plist . includes ( 'macos' ) || plist . includes ( 'macOS' ) ;
302- } catch ( _ ) {
303- // Info.plist not found or extraction failed — no mac slice
304- macosLog ( 'Could not extract xcframework Info.plist from tarball.' ) ;
305- }
306-
307- if ( hasMacSlice ) {
308- macosLog (
309- `Upstream Hermes tarball (${ version } ) includes macOS in the universal xcframework — build from source can be skipped!` ,
310- ) ;
311- return { hasMacSlice : true , tarballPath, version} ;
312- } else {
313- macosLog (
314- `Upstream Hermes tarball (${ version } ) does NOT include macOS in the universal xcframework.` ,
315- ) ;
316- fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
317- // Don't try other versions — if the tarball exists but lacks
318- // the mac slice, older versions won't have it either.
319- return { hasMacSlice : false } ;
320- }
271+ macosLog (
272+ `Downloaded upstream Hermes tarball (${ version } ) to ${ tarballPath } ` ,
273+ ) ;
274+ return { tarballPath, version} ;
321275 } catch ( e ) {
322- macosLog ( `Error checking tarball for ${ version } : ${ e . message } ` ) ;
323- try {
324- fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
325- } catch ( _ ) { }
276+ macosLog ( `Error downloading tarball for ${ version } : ${ e . message } ` ) ;
326277 continue ;
327278 }
328279 }
@@ -331,7 +282,7 @@ async function checkUpstreamHermesHasMacSlice(
331282 macosLog (
332283 'No upstream Hermes tarball found for any candidate version — will build from source.' ,
333284 ) ;
334- return { hasMacSlice : false } ;
285+ return null ;
335286}
336287
337288function abort ( message /*: string */ ) {
@@ -344,5 +295,5 @@ module.exports = {
344295 hermesCommitAtMergeBase,
345296 findVersionAtMergeBase,
346297 getLatestStableVersionFromNPM,
347- checkUpstreamHermesHasMacSlice ,
298+ downloadUpstreamHermesTarball ,
348299} ;
0 commit comments