From 6ebac9f72ac133e5679f08dc9f463412742478b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sun, 12 May 2019 10:09:43 +0200 Subject: [PATCH 1/4] fix: run "config" from react-native binary --- packages/platform-android/native_modules.gradle | 3 +-- packages/platform-ios/native_modules.rb | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/platform-android/native_modules.gradle b/packages/platform-android/native_modules.gradle index 3e925a62e..6805ebbfa 100644 --- a/packages/platform-android/native_modules.gradle +++ b/packages/platform-android/native_modules.gradle @@ -54,8 +54,7 @@ class ReactNativeModules { private ArrayList> reactNativeModules private static String LOG_PREFIX = ":ReactNative:" - private static String REACT_NATIVE_CLI_BIN = "node_modules${File.separator}@react-native-community${File.separator}cli${File.separator}build${File.separator}index.js" - private static String REACT_NATIVE_CONFIG_CMD = "node ${REACT_NATIVE_CLI_BIN} config" + private static String REACT_NATIVE_CONFIG_CMD = "node ./node_modules/.bin/react-native config" ReactNativeModules(Logger logger) { this.logger = logger diff --git a/packages/platform-ios/native_modules.rb b/packages/platform-ios/native_modules.rb index 63d8c296e..b52397965 100644 --- a/packages/platform-ios/native_modules.rb +++ b/packages/platform-ios/native_modules.rb @@ -5,12 +5,10 @@ # def use_native_modules!(root = "..", packages = nil) if (!packages) - # Resolve the CLI's main index file - cli_bin = Pod::Executable.execute_command("node", ["-e", "console.log(require.resolve('@react-native-community/cli/build/index.js'))"], true).strip output = "" # Make sure `react-native config` is ran from your project root Dir.chdir(root) do - output = Pod::Executable.execute_command("node", [cli_bin, "config"], true) + output = Pod::Executable.execute_command("node", ["./node_modules/.bin/react-native", "config"], true) end json = [] From 709da7c01b43817811ddc93bd94f5c7f561c3e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 13 May 2019 10:19:05 +0200 Subject: [PATCH 2/4] use yarn run when necessary and fallback to accessing binary with Node --- packages/platform-android/native_modules.gradle | 14 ++++++++++++-- packages/platform-ios/native_modules.rb | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/platform-android/native_modules.gradle b/packages/platform-android/native_modules.gradle index 6805ebbfa..03db83e1f 100644 --- a/packages/platform-android/native_modules.gradle +++ b/packages/platform-android/native_modules.gradle @@ -54,7 +54,8 @@ class ReactNativeModules { private ArrayList> reactNativeModules private static String LOG_PREFIX = ":ReactNative:" - private static String REACT_NATIVE_CONFIG_CMD = "node ./node_modules/.bin/react-native config" + private static String REACT_NATIVE_CONFIG_CMD = "yarn run react-native config" + private static String REACT_NATIVE_CONFIG_CMD_FALLBACK = "node ./node_modules/.bin/react-native config" ReactNativeModules(Logger logger) { this.logger = logger @@ -172,9 +173,17 @@ class ReactNativeModules { ArrayList> reactNativeModules = new ArrayList>() def cmdProcess + def root = getReactNativeProjectRoot() + def command = REACT_NATIVE_CONFIG_CMD_FALLBACK try { - cmdProcess = Runtime.getRuntime().exec(REACT_NATIVE_CONFIG_CMD, null, getReactNativeProjectRoot()) + try { + // Check if project uses Yarn + def isYarnProject = Runtime.getRuntime().exec("node -e console.log(require.resolve('./yarn.lock'))", null, root) + isYarnProject.waitFor() + command = REACT_NATIVE_CONFIG_CMD + } catch(Exception exception) {} + cmdProcess = Runtime.getRuntime().exec(command, null, root) cmdProcess.waitFor() } catch (Exception exception) { this.logger.warn("${LOG_PREFIX}${exception.message}") @@ -183,6 +192,7 @@ class ReactNativeModules { } def reactNativeConfigOutput = cmdProcess.in.text + // TODO: filter out "warn ...", "yarn run ..." "$ ..." "Done in ..." from reactNativeConfigOutput that are output by Yarn def json = new JsonSlurper().parseText(reactNativeConfigOutput) def dependencies = json["dependencies"] diff --git a/packages/platform-ios/native_modules.rb b/packages/platform-ios/native_modules.rb index b52397965..a93b9eb31 100644 --- a/packages/platform-ios/native_modules.rb +++ b/packages/platform-ios/native_modules.rb @@ -5,15 +5,28 @@ # def use_native_modules!(root = "..", packages = nil) if (!packages) + command = "node" + args = ["./node_modules/.bin/react-native", "config"] + begin + # Check if project uses Yarn + Pod::Executable.execute_command("node", ["-e", "console.log(require.resolve('#{root}/yarn.lock'))"], true) + command = "yarn" + args = ["run", "react-native", "config"] + rescue + end + output = "" # Make sure `react-native config` is ran from your project root Dir.chdir(root) do - output = Pod::Executable.execute_command("node", ["./node_modules/.bin/react-native", "config"], true) + output = Pod::Executable.execute_command(command, args, true) end json = [] output.each_line do |line| case line + when /^yarn run/ + when /^\$/ + when /^Done/ when /^warn\s(.+)/ Pod::UI.warn($1) when /^(success|info|error|debug)\s(.+)/ From 082ff03d7ae1598398f4a1684d98f9300dafdcf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 13 May 2019 11:34:57 +0200 Subject: [PATCH 3/4] filter out non-json stuff in gradle implementation --- .../platform-android/native_modules.gradle | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/platform-android/native_modules.gradle b/packages/platform-android/native_modules.gradle index 03db83e1f..482ce65a3 100644 --- a/packages/platform-android/native_modules.gradle +++ b/packages/platform-android/native_modules.gradle @@ -163,6 +163,23 @@ class ReactNativeModules { } } + /** + * Given a command string output, filter out non-json parts that may + * come from the package manager running the command. + * + * @param commandOutput + * @return string + */ + String getCommandJsonOutput(String commandOutput) { + def output = [] + commandOutput.readLines().forEach { line -> + if (line.startsWith("{") || line.startsWith("}") || line.startsWith(" ")) { + output.add(line) + } + } + return String.join("\n", output) + } + /** * Runs a process to call the React Native CLI Config command and parses the output * @@ -191,8 +208,7 @@ class ReactNativeModules { return reactNativeModules } - def reactNativeConfigOutput = cmdProcess.in.text - // TODO: filter out "warn ...", "yarn run ..." "$ ..." "Done in ..." from reactNativeConfigOutput that are output by Yarn + def reactNativeConfigOutput = getCommandJsonOutput(cmdProcess.in.text) def json = new JsonSlurper().parseText(reactNativeConfigOutput) def dependencies = json["dependencies"] From bc8a5b5d2fcd70c84132f0fc67cc5788d572196c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 13 May 2019 12:04:49 +0200 Subject: [PATCH 4/4] use yarn --silent --- .../platform-android/native_modules.gradle | 21 ++----------------- packages/platform-ios/native_modules.rb | 5 +---- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/packages/platform-android/native_modules.gradle b/packages/platform-android/native_modules.gradle index 482ce65a3..e7e00e20a 100644 --- a/packages/platform-android/native_modules.gradle +++ b/packages/platform-android/native_modules.gradle @@ -54,7 +54,7 @@ class ReactNativeModules { private ArrayList> reactNativeModules private static String LOG_PREFIX = ":ReactNative:" - private static String REACT_NATIVE_CONFIG_CMD = "yarn run react-native config" + private static String REACT_NATIVE_CONFIG_CMD = "yarn run --silent react-native config" private static String REACT_NATIVE_CONFIG_CMD_FALLBACK = "node ./node_modules/.bin/react-native config" ReactNativeModules(Logger logger) { @@ -163,23 +163,6 @@ class ReactNativeModules { } } - /** - * Given a command string output, filter out non-json parts that may - * come from the package manager running the command. - * - * @param commandOutput - * @return string - */ - String getCommandJsonOutput(String commandOutput) { - def output = [] - commandOutput.readLines().forEach { line -> - if (line.startsWith("{") || line.startsWith("}") || line.startsWith(" ")) { - output.add(line) - } - } - return String.join("\n", output) - } - /** * Runs a process to call the React Native CLI Config command and parses the output * @@ -208,7 +191,7 @@ class ReactNativeModules { return reactNativeModules } - def reactNativeConfigOutput = getCommandJsonOutput(cmdProcess.in.text) + def reactNativeConfigOutput = cmdProcess.in.text def json = new JsonSlurper().parseText(reactNativeConfigOutput) def dependencies = json["dependencies"] diff --git a/packages/platform-ios/native_modules.rb b/packages/platform-ios/native_modules.rb index a93b9eb31..0df725e74 100644 --- a/packages/platform-ios/native_modules.rb +++ b/packages/platform-ios/native_modules.rb @@ -11,7 +11,7 @@ def use_native_modules!(root = "..", packages = nil) # Check if project uses Yarn Pod::Executable.execute_command("node", ["-e", "console.log(require.resolve('#{root}/yarn.lock'))"], true) command = "yarn" - args = ["run", "react-native", "config"] + args = ["run", "--silent", "react-native", "config"] rescue end @@ -24,9 +24,6 @@ def use_native_modules!(root = "..", packages = nil) json = [] output.each_line do |line| case line - when /^yarn run/ - when /^\$/ - when /^Done/ when /^warn\s(.+)/ Pod::UI.warn($1) when /^(success|info|error|debug)\s(.+)/