88 * @format
99 */
1010
11- const { computeNightlyTarballURL , createLogger} = require ( './utils' ) ;
11+ const { createLogger} = require ( './utils' ) ;
1212const { execSync} = require ( 'child_process' ) ;
1313const fs = require ( 'fs' ) ;
1414const path = require ( 'path' ) ;
@@ -23,10 +23,15 @@ import type {BuildFlavor, Destination, Platform} from './types';
2323*/
2424
2525/**
26- * Downloads hermes artifacts from the specified version and build type. If you want to specify a specific
27- * version of hermes, use the HERMES_VERSION environment variable. The path to the artifacts will be inside
28- * the .build/artifacts/hermes folder, but this can be overridden by setting the HERMES_ENGINE_TARBALL_PATH
29- * environment variable. If this varuable is set, the script will use the local tarball instead of downloading it.
26+ * Downloads hermes artifacts from the specified version and build type.
27+ *
28+ * Version resolution (in order):
29+ * 1. `HERMES_ENGINE_TARBALL_PATH` env var → use that local file directly
30+ * 2. `HERMES_VERSION` env var:
31+ * - `"latest-v1"` (default) → resolve latest version from npm's `latest-v1` dist-tag
32+ * - any semver string → use that exact version from Maven Central
33+ * The resolved version is downloaded from Maven Central (stable) or from a
34+ * Maven snapshot repo as fallback.
3035 */
3136async function prepareHermesArtifactsAsync (
3237 reactNativeVersion /*:string*/ ,
@@ -57,12 +62,9 @@ async function prepareHermesArtifactsAsync(
5762 let resolvedVersion = process . env . HERMES_VERSION ?? 'latest-v1' ;
5863
5964 if ( resolvedVersion === 'latest-v1' ) {
65+ // TODO: rename 'latest-v1' to 'latest' once V1 is the only Hermes on npm
6066 hermesLog ( 'Using latest-v1 tarball' ) ;
61- const hermesVersion = await getLatestV1VersionFromNPM ( ) ;
62- resolvedVersion = hermesVersion ;
63- } else if ( resolvedVersion === 'nightly' ) {
64- hermesLog ( 'Using latest nightly tarball' ) ;
65- const hermesVersion = await getNightlyVersionFromNPM ( ) ;
67+ const hermesVersion = await getLatestHermesVersionFromNPM ( ) ;
6668 resolvedVersion = hermesVersion ;
6769 }
6870
@@ -106,7 +108,8 @@ async function prepareHermesArtifactsAsync(
106108 return artifactsPath ;
107109}
108110
109- async function getLatestV1VersionFromNPM ( ) /*: Promise<string> */ {
111+ async function getLatestHermesVersionFromNPM ( ) /*: Promise<string> */ {
112+ // TODO: rename 'latest-v1' to 'latest' once V1 is the only Hermes on npm
110113 const npmResponse /*: Response */ = await fetch (
111114 'https://registry.npmjs.org/hermes-compiler/latest-v1' ,
112115 ) ;
@@ -118,43 +121,23 @@ async function getLatestV1VersionFromNPM() /*: Promise<string> */ {
118121 }
119122
120123 const json = await npmResponse . json ( ) ;
121- const latestV1 = json . version ;
122- hermesLog ( `Using version ${ latestV1 } ` ) ;
123- return latestV1 ;
124- }
125-
126- async function getNightlyVersionFromNPM ( ) /*: Promise<string> */ {
127- const npmResponse /*: Response */ = await fetch (
128- 'https://registry.npmjs.org/hermes-compiler/nightly' ,
129- ) ;
130-
131- if ( ! npmResponse . ok ) {
132- throw new Error (
133- `Couldn't get a response from NPM: ${ npmResponse . status } ${ npmResponse . statusText } ` ,
134- ) ;
135- }
136-
137- const json = await npmResponse . json ( ) ;
138- const latestNightly = json . version ;
139- hermesLog ( `Using version ${ latestNightly } ` ) ;
140- return latestNightly ;
124+ const latestVersion = json . version ;
125+ hermesLog ( `Using version ${ latestVersion } ` ) ;
126+ return latestVersion ;
141127}
142128
143129/*::
144130type HermesEngineSourceType =
145131 | 'local_prebuilt_tarball'
146132 | 'download_prebuild_tarball'
147- | 'download_prebuilt_nightly_tarball'
148133*/
149134
150135const HermesEngineSourceTypes /*:{
151136 +DOWNLOAD_PREBUILD_TARBALL: "download_prebuild_tarball",
152- +DOWNLOAD_PREBUILT_NIGHTLY_TARBALL: "download_prebuilt_nightly_tarball",
153137 +LOCAL_PREBUILT_TARBALL: "local_prebuilt_tarball"
154138} */ = {
155139 LOCAL_PREBUILT_TARBALL : 'local_prebuilt_tarball' ,
156140 DOWNLOAD_PREBUILD_TARBALL : 'download_prebuild_tarball' ,
157- DOWNLOAD_PREBUILT_NIGHTLY_TARBALL : 'download_prebuilt_nightly_tarball' ,
158141} ;
159142
160143/**
@@ -216,21 +199,6 @@ function getTarballUrl(
216199 return `${ mavenRepoUrl } /${ namespace } /hermes-ios/${ version } /hermes-ios-${ version } -hermes-ios-${ buildType . toLowerCase ( ) } .tar.gz` ;
217200}
218201
219- async function getNightlyTarballUrl (
220- version /*: string */ ,
221- buildType /*: BuildFlavor */ ,
222- ) /*: Promise<string> */ {
223- const artifactCoordinate = 'hermes-ios' ;
224- const artifactName = `hermes-ios-${ buildType . toLowerCase ( ) } .tar.gz` ;
225- return await computeNightlyTarballURL (
226- version ,
227- buildType ,
228- 'hermes' ,
229- artifactCoordinate ,
230- artifactName ,
231- ) ;
232- }
233-
234202/**
235203 * Checks if a Hermes artifact exists at the given URL using fetch instead of curl
236204 */
@@ -266,17 +234,10 @@ async function hermesSourceType(
266234 return HermesEngineSourceTypes . DOWNLOAD_PREBUILD_TARBALL ;
267235 }
268236
269- // For nightly tarball, we need to resolve redirects first
270- const nightlyUrl = await getNightlyTarballUrl ( version , buildType ) ;
271- if ( await hermesArtifactExists ( nightlyUrl ) ) {
272- hermesLog ( 'Using download prebuild nightly tarball' ) ;
273- return HermesEngineSourceTypes . DOWNLOAD_PREBUILT_NIGHTLY_TARBALL ;
274- }
275-
276237 hermesLog (
277- 'Using download prebuild nightly tarball - this is a fallback and might not work.' ,
238+ `No prebuilt tarball found for version ${ version } . Falling back to DOWNLOAD_PREBUILD_TARBALL, which may fail.` ,
278239 ) ;
279- return HermesEngineSourceTypes . DOWNLOAD_PREBUILT_NIGHTLY_TARBALL ;
240+ return HermesEngineSourceTypes . DOWNLOAD_PREBUILD_TARBALL ;
280241}
281242
282243async function resolveSourceFromSourceType (
@@ -290,8 +251,6 @@ async function resolveSourceFromSourceType(
290251 return localPrebuiltTarball ( ) ;
291252 case HermesEngineSourceTypes . DOWNLOAD_PREBUILD_TARBALL :
292253 return downloadPrebuildTarball ( version , buildType , artifactsPath ) ;
293- case HermesEngineSourceTypes . DOWNLOAD_PREBUILT_NIGHTLY_TARBALL :
294- return downloadPrebuiltNightlyTarball ( version , buildType , artifactsPath ) ;
295254 default :
296255 abort (
297256 `[Hermes] Unsupported or invalid source type provided: ${ sourceType } ` ,
@@ -324,16 +283,6 @@ async function downloadPrebuildTarball(
324283 return downloadStableHermes ( version , buildType , artifactsPath ) ;
325284}
326285
327- async function downloadPrebuiltNightlyTarball (
328- version /*: string */ ,
329- buildType /*: BuildFlavor */ ,
330- artifactsPath /*: string*/ ,
331- ) /*: Promise<string> */ {
332- const url = await getNightlyTarballUrl ( version , buildType ) ;
333- hermesLog ( `Using nightly tarball from URL: ${ url } ` ) ;
334- return downloadHermesTarball ( url , version , buildType , artifactsPath ) ;
335- }
336-
337286async function downloadStableHermes (
338287 version /*: string */ ,
339288 buildType /*: BuildFlavor */ ,
0 commit comments