Skip to content

Commit

Permalink
RNGP - Properly set the jsRootDir default value
Browse files Browse the repository at this point in the history
Summary:
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

Differential Revision: D42806411

fbshipit-source-id: 44371edec593aba5a5115d05e6f8d2e86ec6dc11
  • Loading branch information
cortinico authored and facebook-github-bot committed Jan 27, 2023
1 parent a00cea4 commit a2555e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ class ReactPlugin : Plugin<Project> {
// 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)
Expand Down

0 comments on commit a2555e9

Please sign in to comment.