@@ -12,6 +12,7 @@ const plist = require("plist");
1212const g2js = require ( "gradle-to-js/lib/parser" ) ;
1313const properties = require ( "properties" ) ;
1414import * as childProcess from "child_process" ;
15+ import { directoryExistsSync } from "../../../util/misc/fs-helper" ;
1516
1617export interface VersionSearchParams {
1718 os : string ; // ios or android
@@ -541,7 +542,7 @@ async function getHermesCommand(gradleFile: string): Promise<string> {
541542 }
542543 } ;
543544 // Hermes is bundled with react-native since 0.69
544- const bundledHermesEngine = path . join ( "node_modules" , "react-native" , "sdks" , "hermesc" , getHermesOSBin ( ) , getHermesOSExe ( ) ) ;
545+ const bundledHermesEngine = path . join ( getReactNativePackagePath ( ) , "sdks" , "hermesc" , getHermesOSBin ( ) , getHermesOSExe ( ) ) ;
545546 if ( fileExists ( bundledHermesEngine ) ) {
546547 return bundledHermesEngine ;
547548 }
@@ -561,7 +562,7 @@ async function getHermesCommand(gradleFile: string): Promise<string> {
561562
562563function getComposeSourceMapsPath ( ) : string {
563564 // detect if compose-source-maps.js script exists
564- const composeSourceMaps = path . join ( "node_modules" , "react-native" , "scripts" , "compose-source-maps.js" ) ;
565+ const composeSourceMaps = path . join ( getReactNativePackagePath ( ) , "scripts" , "compose-source-maps.js" ) ;
565566 if ( fs . existsSync ( composeSourceMaps ) ) {
566567 return composeSourceMaps ;
567568 }
@@ -570,12 +571,22 @@ function getComposeSourceMapsPath(): string {
570571
571572function getCliPath ( ) : string {
572573 if ( process . platform === "win32" ) {
573- return path . join ( "node_modules" , "react-native" , "local-cli" , "cli.js" ) ;
574+ return path . join ( getReactNativePackagePath ( ) , "local-cli" , "cli.js" ) ;
574575 }
575576
576577 return path . join ( "node_modules" , ".bin" , "react-native" ) ;
577578}
578579
580+ function getReactNativePackagePath ( ) : string {
581+ const result = childProcess . spawnSync ( "node" , [ "--print" , "require.resolve('react-native/package.json')" ] ) ;
582+ const packagePath = path . dirname ( result . stdout . toString ( ) ) ;
583+ if ( directoryExistsSync ( packagePath ) ) {
584+ return packagePath ;
585+ }
586+
587+ return path . join ( "node_modules" , "react-native" ) ;
588+ }
589+
579590export function isValidOS ( os : string ) : boolean {
580591 switch ( os . toLowerCase ( ) ) {
581592 case "android" :
0 commit comments