From 76ca8e2dc921887e9a9c1afa1588b207458eda62 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Mon, 30 Jan 2023 06:50:24 -0800 Subject: [PATCH] RNGP - Properly set the `jsRootDir` default value (#35992) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35992 Fixes https://github.com/software-mansion/react-native-gesture-handler/issues/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 --- .../src/main/kotlin/com/facebook/react/ReactExtension.kt | 4 ++-- .../src/main/kotlin/com/facebook/react/ReactPlugin.kt | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt index 5dfb3737ee9d3e..9738124c79461a 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt @@ -129,9 +129,9 @@ abstract class ReactExtension @Inject constructor(project: Project) { /** * The root directory for all JS files for the app. * - * Default: [root] (i.e. ${rootProject.dir}/../) + * Default: the parent folder of the `/android` folder. */ - val jsRootDir: DirectoryProperty = objects.directoryProperty().convention(root.get()) + val jsRootDir: DirectoryProperty = objects.directoryProperty() /** * The library name that will be used for the codegen artifacts. diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 8fd0a54dbd3932..48fff59c790a38 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -110,6 +110,15 @@ class ReactPlugin : Plugin { // First, we set up the output dir for the codegen. val generatedSrcDir = File(project.buildDir, "generated/source/codegen") + // We specify the default value (convention) for jsRootDir. + // It's the root folder for apps (so ../../ from the Gradle project) + // and the package folder for library (so ../ from the Gradle project) + if (isLibrary) { + extension.jsRootDir.convention(project.layout.projectDirectory.dir("../")) + } else { + extension.jsRootDir.convention(extension.root) + } + val buildCodegenTask = project.tasks.register("buildCodegenCLI", BuildCodegenCLITask::class.java) { it.codegenDir.set(extension.codegenDir)