Skip to content

Commit a3b0804

Browse files
Esemesekfacebook-github-bot
authored andcommitted
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: #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
1 parent 928f443 commit a3b0804

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

RNTester/android/app/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ plugins {
6565
*/
6666

6767
project.ext.react = [
68-
cliPath: "$rootDir/cli.js",
6968
bundleAssetName: "RNTesterApp.android.bundle",
7069
entryFile: file("../../js/RNTesterApp.android.js"),
7170
root: "$rootDir",

react.gradle

+17-9
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ afterEvaluate {
9999
// Additional node and packager commandline arguments
100100
def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"]
101101
def extraPackagerArgs = config.extraPackagerArgs ?: []
102+
def npx = Os.isFamily(Os.FAMILY_WINDOWS) ? "npx.cmd" : "npx"
103+
104+
def execCommand = []
105+
106+
if (config.cliPath || config.nodeExecutableAndArgs) {
107+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
108+
execCommand.addAll(["cmd", "/c", *nodeExecutableAndArgs, cliPath])
109+
} else {
110+
execCommand.addAll([*nodeExecutableAndArgs, cliPath])
111+
}
112+
} else {
113+
execCommand.addAll([npx, "react-native"])
114+
}
102115

103116
def enableHermes = enableHermesForVariant(variant)
104117

@@ -140,15 +153,10 @@ afterEvaluate {
140153
extraArgs.add(bundleConfig);
141154
}
142155

143-
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
144-
commandLine("cmd", "/c", *nodeExecutableAndArgs, cliPath, bundleCommand, "--platform", "android", "--dev", "${devEnabled}",
145-
"--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir,
146-
"--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs)
147-
} else {
148-
commandLine(*nodeExecutableAndArgs, cliPath, bundleCommand, "--platform", "android", "--dev", "${devEnabled}",
149-
"--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir,
150-
"--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs)
151-
}
156+
commandLine(*execCommand, bundleCommand, "--platform", "android", "--dev", "${devEnabled}",
157+
"--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir,
158+
"--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs)
159+
152160

153161
if (enableHermes) {
154162
doLast {

0 commit comments

Comments
 (0)