Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RNGP - findPackageJsonFile should return null if package.json does not exist #35566

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,19 @@ internal fun projectPathToLibraryName(projectPath: String): String =
* Gradle module (generally the case for library projects) or we fallback to looking into the `root`
* folder of a React Native project (generally the case for app projects).
*/
internal fun findPackageJsonFile(project: Project, extension: ReactExtension): File? =
if (project.file("../package.json").exists()) {
project.file("../package.json")
} else {
extension.root.file("package.json").orNull?.asFile
}
internal fun findPackageJsonFile(project: Project, extension: ReactExtension): File? {
val inParent = project.file("../package.json")
if (inParent.exists()) {
return inParent
}

val fromExtension = extension.root.file("package.json").orNull?.asFile
if (fromExtension?.exists() == true) {
return fromExtension
}

return null
}

/**
* Function to look for the `package.json` and parse it. It returns a [ModelPackageJson] if found or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class PathUtilsTest {
assertEquals(localFile, findPackageJsonFile(project, extension))
}

@Test(expected = FileNotFoundException::class)
@Test
fun readPackageJsonFile_withMissingFile_returnsNull() {
val moduleFolder = tempFolder.newFolder("awesome-module")
val project = ProjectBuilder.builder().withProjectDir(moduleFolder).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,12 @@ class ProjectUtilsTest {

assertFalse(project.needsCodegenFromPackageJson(model))
}

@Test
fun needsCodegenFromPackageJson_withMissingPackageJson_returnsFalse() {
val project = createProject()
val extension = TestReactExtension(project)

assertFalse(project.needsCodegenFromPackageJson(extension))
}
}