Skip to content

Commit c000409

Browse files
cortinicofacebook-github-bot
authored andcommitted
RNGP - Properly set the jsRootDir default value (#35992)
Summary: Pull Request resolved: #35992 Fixes software-mansion/react-native-gesture-handler#2382 I've just realized that the default value fo `jsRootDir` is not entirely correct. That's the root of the folder where the codegen should run. For apps, it should be defaulted to `root` (i.e. ../../) For libraries, it should be defaulted to `../` (currently is root). This causes a problem where libraries without either a `codegenConfig` or a `react{ jsRootDir = ... }` specified in the build.gradle will be invoking the codegen and generating duplicated symbols. Changelog: [Android] [Fixed] - RNGP - Properly set the `jsRootDir` default value Reviewed By: cipolleschi Differential Revision: D42806411 fbshipit-source-id: ffe45f9684a22494cc2e4d0a19de9077cb341365
1 parent 112c89e commit c000409

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ abstract class ReactExtension @Inject constructor(project: Project) {
129129
/**
130130
* The root directory for all JS files for the app.
131131
*
132-
* Default: [root] (i.e. ${rootProject.dir}/../)
132+
* Default: the parent folder of the `/android` folder.
133133
*/
134-
val jsRootDir: DirectoryProperty = objects.directoryProperty().convention(root.get())
134+
val jsRootDir: DirectoryProperty = objects.directoryProperty()
135135

136136
/**
137137
* The library name that will be used for the codegen artifacts.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ class ReactPlugin : Plugin<Project> {
110110
// First, we set up the output dir for the codegen.
111111
val generatedSrcDir = File(project.buildDir, "generated/source/codegen")
112112

113+
// We specify the default value (convention) for jsRootDir.
114+
// It's the root folder for apps (so ../../ from the Gradle project)
115+
// and the package folder for library (so ../ from the Gradle project)
116+
if (isLibrary) {
117+
extension.jsRootDir.convention(project.layout.projectDirectory.dir("../"))
118+
} else {
119+
extension.jsRootDir.convention(extension.root)
120+
}
121+
113122
val buildCodegenTask =
114123
project.tasks.register("buildCodegenCLI", BuildCodegenCLITask::class.java) {
115124
it.codegenDir.set(extension.codegenDir)

0 commit comments

Comments
 (0)