@@ -19,6 +19,7 @@ const pipeline = promisify(stream.pipeline);
1919const hermesLog = createLogger ( 'Hermes' ) ;
2020const MAVEN_CENTRAL_REPOSITORY = 'https://repo1.maven.org/maven2' ;
2121const REACT_NATIVE_MAVEN_CACHE_REPOSITORY = 'https://rnmaven.swmtest.xyz' ;
22+ const artifactExistenceCache = new Map ( ) ;
2223
2324/*::
2425import type {BuildFlavor, Destination, Platform} from './types';
@@ -193,16 +194,25 @@ async function getTarballUrl(
193194 version /*: string */ ,
194195 buildType /*: BuildFlavor */ ,
195196) /*: Promise<string> */ {
197+ const existingUrl = await findExistingTarballUrl ( version , buildType ) ;
198+ if ( existingUrl != null ) {
199+ return existingUrl ;
200+ }
201+
202+ return getTarballUrls ( version , buildType ) [ 0 ] ;
203+ }
204+
205+ async function findExistingTarballUrl (
206+ version /*: string */ ,
207+ buildType /*: BuildFlavor */ ,
208+ ) /*: Promise<?string> */ {
196209 const candidates = getTarballUrls ( version , buildType ) ;
197210 for ( const url of candidates ) {
198- console . log ( `Checking if Hermes artifact exists at URL: ${ url } ` ) ;
199211 if ( await hermesArtifactExists ( url ) ) {
200- console . log ( `Found Hermes artifact at URL: ${ url } ` ) ;
201212 return url ;
202213 }
203- console . log ( `Hermes artifact not found at URL: ${ url } ` ) ;
204214 }
205- return candidates [ 0 ] ;
215+ return null ;
206216}
207217
208218function getTarballUrls (
@@ -233,13 +243,20 @@ function getMavenRepositoryUrls() /*: Array<string> */ {
233243async function hermesArtifactExists (
234244 tarballUrl /*: string */ ,
235245) /*: Promise<boolean> */ {
246+ if ( artifactExistenceCache . has ( tarballUrl ) ) {
247+ return artifactExistenceCache . get ( tarballUrl ) ;
248+ }
249+
236250 try {
237251 const response /*: Response */ = await fetch ( tarballUrl , {
238252 method : 'HEAD' ,
239253 } ) ;
240254
241- return response . status === 200 ;
255+ const exists = response . status === 200 ;
256+ artifactExistenceCache . set ( tarballUrl , exists ) ;
257+ return exists ;
242258 } catch ( e ) {
259+ artifactExistenceCache . set ( tarballUrl , false ) ;
243260 return false ;
244261 }
245262}
@@ -256,8 +273,7 @@ async function hermesSourceType(
256273 return HermesEngineSourceTypes . LOCAL_PREBUILT_TARBALL ;
257274 }
258275
259- const tarballUrl = await getTarballUrl ( version , buildType ) ;
260- if ( await hermesArtifactExists ( tarballUrl ) ) {
276+ if ( ( await findExistingTarballUrl ( version , buildType ) ) != null ) {
261277 hermesLog ( `Using download prebuild ${ buildType } tarball` ) ;
262278 return HermesEngineSourceTypes . DOWNLOAD_PREBUILD_TARBALL ;
263279 }
0 commit comments