diff --git a/packages/react-native-builder-bob/src/utils/runRNCCli.ts b/packages/react-native-builder-bob/src/utils/runRNCCli.ts index c6b29598d..3d4e1dc03 100644 --- a/packages/react-native-builder-bob/src/utils/runRNCCli.ts +++ b/packages/react-native-builder-bob/src/utils/runRNCCli.ts @@ -1,13 +1,8 @@ import { type SpawnOptions } from 'node:child_process'; import { spawn } from './spawn'; import path from 'node:path'; - -const RNC_CLI_BINARY_PATH = path.resolve( - process.cwd(), // We are always expected to run in the library - 'node_modules', - '.bin', - 'rnc-cli' -); +import fs from 'fs-extra' +import assert from 'node:assert' // This is a special case for calling bob from the XCode scripts // XCode scripts don't have the node binary properly set @@ -23,5 +18,27 @@ export async function runRNCCli( stdio: 'ignore', } ) { + const rncCliBinaryName = await getCliBinaryName() + + const RNC_CLI_BINARY_PATH = path.resolve( + process.cwd(), // We are always expected to run in the library + 'node_modules', + '.bin', + rncCliBinaryName + ); + return await spawn(NODE_BINARY, [RNC_CLI_BINARY_PATH, ...args], options); } + +async function getCliBinaryName(): Promise { + const rncCliPackagePath = await spawn(NODE_BINARY, [ + '-e', + `console.log(require.resolve('@react-native-community/cli/package.json'))` + ]) + + const rncCliPackage = await fs.readJson(rncCliPackagePath) + const binaries = rncCliPackage.bin as Record + assert(typeof (binaries) === 'object', 'React Native CLI doesn\'t specify proper binaries') + + return Object.keys(binaries)[0] +}