@@ -114,22 +114,10 @@ function getHermesCommand(): string {
114114 return false ;
115115 }
116116 } ;
117- const reactNativePath = getReactNativePackagePath ( ) ;
118- const hermesCompilerPath = getHermesCompilerPackagePath ( ) ;
119-
120- // Since react-native 0.83, Hermes compiler in 'hermes-compiler' package
121- if ( hermesCompilerPath ) {
122- const engine = path . join ( hermesCompilerPath , 'hermesc' , getHermesOSBin ( ) , getHermesOSExe ( ) ) ;
123- if ( fileExists ( engine ) ) {
124- return engine ;
125- }
126- }
127117
128- // Hermes is bundled with react-native since 0.69
129- const bundledHermesEngine = path . join ( reactNativePath , 'sdks' , 'hermesc' , getHermesOSBin ( ) , getHermesOSExe ( ) ) ;
130- // Hermes is bundled with react-native since 0.69
131- if ( fileExists ( bundledHermesEngine ) ) {
132- return bundledHermesEngine ;
118+ const hermescExecutable = path . join ( getHermesCompilerPath ( ) , getHermesOSBin ( ) , getHermesOSExe ( ) ) ;
119+ if ( fileExists ( hermescExecutable ) ) {
120+ return hermescExecutable ;
133121 }
134122 throw new Error ( 'Hermes engine binary not found. Please upgrade to react-native 0.69 or later' ) ;
135123}
@@ -180,19 +168,26 @@ function getReactNativePackagePath(): string {
180168 return path . join ( 'node_modules' , 'react-native' ) ;
181169}
182170
183- function getHermesCompilerPackagePath ( ) {
184- try {
185- const result = childProcess . spawnSync ( 'node' , [
186- '--print' ,
187- "require.resolve('hermes-compiler/package.json')" ,
188- ] ) ;
189- const packagePath = path . dirname ( result . stdout . toString ( ) ) ;
190- if ( result . status === 0 && directoryExistsSync ( packagePath ) ) {
191- return packagePath ;
192- }
193- return path . join ( 'node_modules' , 'hermes-compiler' ) ;
194- } catch {
195- return null ;
171+ function getHermescDirPathInHermesCompilerPackage ( ) {
172+ const result = childProcess . spawnSync ( 'node' , [
173+ '--print' ,
174+ "require.resolve('hermes-compiler/package.json')" ,
175+ ] ) ;
176+ const packagePath = path . dirname ( result . stdout . toString ( ) ) ;
177+ const hermescDirPath = path . join ( packagePath , 'hermesc' ) ;
178+ if ( result . status === 0 && directoryExistsSync ( hermescDirPath ) ) {
179+ return hermescDirPath ;
180+ }
181+ return null ;
182+ }
183+
184+ function getHermesCompilerPath ( ) {
185+ const hermescDirPath = getHermescDirPathInHermesCompilerPackage ( ) ;
186+ if ( hermescDirPath ) {
187+ // Since react-native 0.83, Hermes compiler executables are in 'hermes-compiler' package
188+ return hermescDirPath
189+ } else {
190+ return path . join ( getReactNativePackagePath ( ) , 'sdks' , 'hermesc' ) ;
196191 }
197192}
198193
0 commit comments