Skip to content

Commit f8d8764

Browse files
cortinicofacebook-github-bot
authored andcommitted
RNGP - Fix defaults for PrivateReactExtension
Summary: When building from source, the PrivateReactExtension is getting no defaults (or missing defaults). Specifically root should point to ../../ (as the build from source will originate from `./node_modules/react-native`). Without that root specified, all the subsequent paths are broken, specifically, the default being `../` causes the codegen to be searched inside: ``` project/node_modules/node_modules/react-native/codegen ``` which is broken Changelog: [Internal] [Changed] - RNGP - Fix defaults for PrivateReactExtension Reviewed By: cipolleschi Differential Revision: D43435590 fbshipit-source-id: 2ed5e26c1d63fd808fc2d559ea83d6d39d106ff6
1 parent 421df9f commit f8d8764

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,32 @@ abstract class PrivateReactExtension @Inject constructor(project: Project) {
2525

2626
private val objects = project.objects
2727

28-
val root: DirectoryProperty = objects.directoryProperty()
29-
30-
val reactNativeDir: DirectoryProperty = objects.directoryProperty()
31-
32-
val nodeExecutableAndArgs: ListProperty<String> = objects.listProperty(String::class.java)
33-
34-
val codegenDir: DirectoryProperty = objects.directoryProperty()
28+
val root: DirectoryProperty =
29+
objects
30+
.directoryProperty()
31+
.convention(
32+
// This is the default for the project root if the users hasn't specified anything.
33+
// If the project is called "react-native-github"
34+
// - We're inside the Github Repo -> root is defined by RN Tester (so no default
35+
// needed)
36+
// - We're inside an includedBuild as we're performing a build from source
37+
// (then we're inside `node_modules/react-native`, so default should be ../../)
38+
// If the project is called in any other name
39+
// - We're inside a user project, so inside the ./android folder. Default should be
40+
// ../
41+
// User can always override this default by setting a `root =` inside the template.
42+
if (project.rootProject.name == "react-native-github") {
43+
project.rootProject.layout.projectDirectory.dir("../../")
44+
} else {
45+
project.rootProject.layout.projectDirectory.dir("../")
46+
})
47+
48+
val reactNativeDir: DirectoryProperty =
49+
objects.directoryProperty().convention(root.dir("node_modules/react-native"))
50+
51+
val nodeExecutableAndArgs: ListProperty<String> =
52+
objects.listProperty(String::class.java).convention(listOf("node"))
53+
54+
val codegenDir: DirectoryProperty =
55+
objects.directoryProperty().convention(root.dir("node_modules/@react-native/codegen"))
3556
}

0 commit comments

Comments
 (0)