From a3b08048674e324dbe1f0ca816f35607e9e06a2f Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Tue, 5 Nov 2019 03:03:04 -0800 Subject: [PATCH] fix: Bundle assets in monorepo (#26940) Summary: In monorepo environment, `metro` isn't able to resolve `react-native` because the path to it is hardcoded. I've also added `packagingOptions` to RNTester to make Android builds work for me. Let me know if this is something that is only specific to my setup, and shouldn't be added. ## Changelog [Android] [Fixed] - Fix `bundleReleaseJsAndAssets` in monorepo env Pull Request resolved: https://github.com/facebook/react-native/pull/26940 Test Plan: - [x] - Works in monorepo setup on MacOS - [x] - Works with RNTester app Differential Revision: D18323703 Pulled By: cpojer fbshipit-source-id: b8eb15dfd8a32ae11fd862fc725af9cffea2cf96 --- RNTester/android/app/build.gradle | 1 - react.gradle | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/RNTester/android/app/build.gradle b/RNTester/android/app/build.gradle index db4a066d383fba..edac8893b3c390 100644 --- a/RNTester/android/app/build.gradle +++ b/RNTester/android/app/build.gradle @@ -65,7 +65,6 @@ plugins { */ project.ext.react = [ - cliPath: "$rootDir/cli.js", bundleAssetName: "RNTesterApp.android.bundle", entryFile: file("../../js/RNTesterApp.android.js"), root: "$rootDir", diff --git a/react.gradle b/react.gradle index 2672b23ad5d7a2..d886a9b986b468 100644 --- a/react.gradle +++ b/react.gradle @@ -99,6 +99,19 @@ afterEvaluate { // Additional node and packager commandline arguments def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"] def extraPackagerArgs = config.extraPackagerArgs ?: [] + def npx = Os.isFamily(Os.FAMILY_WINDOWS) ? "npx.cmd" : "npx" + + def execCommand = [] + + if (config.cliPath || config.nodeExecutableAndArgs) { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + execCommand.addAll(["cmd", "/c", *nodeExecutableAndArgs, cliPath]) + } else { + execCommand.addAll([*nodeExecutableAndArgs, cliPath]) + } + } else { + execCommand.addAll([npx, "react-native"]) + } def enableHermes = enableHermesForVariant(variant) @@ -140,15 +153,10 @@ afterEvaluate { extraArgs.add(bundleConfig); } - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine("cmd", "/c", *nodeExecutableAndArgs, cliPath, bundleCommand, "--platform", "android", "--dev", "${devEnabled}", - "--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, - "--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs) - } else { - commandLine(*nodeExecutableAndArgs, cliPath, bundleCommand, "--platform", "android", "--dev", "${devEnabled}", - "--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, - "--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs) - } + commandLine(*execCommand, bundleCommand, "--platform", "android", "--dev", "${devEnabled}", + "--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, + "--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs) + if (enableHermes) { doLast {