Skip to content

Commit

Permalink
RNGP - Fix defaults for PrivateReactExtension
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cortinico authored and kelset committed Mar 6, 2023
1 parent f2bfe91 commit cbaf4c8
Showing 1 changed file with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,32 @@ abstract class PrivateReactExtension @Inject constructor(project: Project) {

private val objects = project.objects

val root: DirectoryProperty = objects.directoryProperty()

val reactNativeDir: DirectoryProperty = objects.directoryProperty()

val nodeExecutableAndArgs: ListProperty<String> = objects.listProperty(String::class.java)

val codegenDir: DirectoryProperty = objects.directoryProperty()
val root: DirectoryProperty =
objects
.directoryProperty()
.convention(
// This is the default for the project root if the users hasn't specified anything.
// If the project is called "react-native-github"
// - We're inside the Github Repo -> root is defined by RN Tester (so no default
// needed)
// - We're inside an includedBuild as we're performing a build from source
// (then we're inside `node_modules/react-native`, so default should be ../../)
// If the project is called in any other name
// - We're inside a user project, so inside the ./android folder. Default should be
// ../
// User can always override this default by setting a `root =` inside the template.
if (project.rootProject.name == "react-native-github") {
project.rootProject.layout.projectDirectory.dir("../../")
} else {
project.rootProject.layout.projectDirectory.dir("../")
})

val reactNativeDir: DirectoryProperty =
objects.directoryProperty().convention(root.dir("node_modules/react-native"))

val nodeExecutableAndArgs: ListProperty<String> =
objects.listProperty(String::class.java).convention(listOf("node"))

val codegenDir: DirectoryProperty =
objects.directoryProperty().convention(root.dir("node_modules/@react-native/codegen"))

This comment has been minimized.

Copy link
@zxcpoiu

zxcpoiu Mar 11, 2023

Contributor

Seems the path node_modules/@react-native/codegen are only for 0.72+, below 0.71 should use node_modules/react-native-codegen

This comment has been minimized.

Copy link
@kelset

kelset Mar 13, 2023

Contributor

good shout - @cortinico I guess we need to fix this locally in 0.71 and release a new RNGP version?

This comment has been minimized.

Copy link
@cortinico

cortinico Mar 13, 2023

Author Contributor

Oh thanks for the heads up. You're right. This needs a different path for 0.71. I'll take care of this

}

0 comments on commit cbaf4c8

Please sign in to comment.