diff --git a/packages/platform-ios/native_modules.rb b/packages/platform-ios/native_modules.rb index 48481e55f7..9f59f85cfe 100644 --- a/packages/platform-ios/native_modules.rb +++ b/packages/platform-ios/native_modules.rb @@ -5,14 +5,35 @@ # require 'pathname' -def use_native_modules!(config = nil) +# Since CLI is a React Native dependency, we start looking for its +# executable from React Native `node_modules`. +def get_cli_path() + script = ' + const path = require("path"); + + const rnPath = path.dirname(require.resolve("react-native/package.json")); + + console.log( + require.resolve("@react-native-community/cli/build/index.js", { + paths: [rnPath] + }) + ); + '; + + Pod::Executable.execute_command("node", ["-e", script], true).strip +end + +def use_native_modules!(root = "..", config = nil) if (!config) json = [] - # @todo: Do not use Yarn here, but find path dynamically - IO.popen("yarn run --silent react-native config") do |data| - while line = data.gets - json << line + # Make sure `react-native config` is ran from the project root + # @todo: deprecate `root` and switch to Yarn once `--silent` flag works + Dir.chdir(root) do + IO.popen("node #{get_cli_path} config") do |data| + while line = data.gets + json << line + end end end