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

Conversation

tido64
Copy link
Collaborator

@tido64 tido64 commented Dec 5, 2022

Summary

findPackageJsonFile always returns a path even though package.json does not exist. This causes issues in libraries whose repo setups look like:

react-native-webview
├── android
│   └── build.gradle
├── example  <-- Note the lack of `package.json` here
│   └── App.tsx
├── ios
│   └── RNCWebView.xcodeproj
├── macos
│   └── RNCWebView.xcodeproj
├── package.json
└── src

When newArchEnabled=true, running yarn android will fail with the following:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:generateCodegenArtifactsFromSchema'.
> Could not create task ':app:generateCodegenSchemaFromJavaScript'.
   > /~/react-native-webview/example/package.json (No such file or directory)

Changelog

[Android] [Fixed] - findPackageJsonFile should return null if package.json does not exist

Test Plan

git clone https://github.com/react-native-webview/react-native-webview.git
cd react-native-webview
git checkout new-arch-ios
yarn
cd example/android
./gradlew clean assembleDebug

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 5, 2022
@tido64
Copy link
Collaborator Author

tido64 commented Dec 5, 2022

cc @Titozzz

@analysis-bot
Copy link

analysis-bot commented Dec 5, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 56b10a8
Branch: main

@cortinico
Copy link
Contributor

Thanks for doing this @tido64

  1. Can you write a test for it here?

    @Test
    fun findPackageJsonFile_withFileInParentFolder_picksItUp() {
    tempFolder.newFile("package.json")
    val moduleFolder = tempFolder.newFolder("awesome-module")
    val project = ProjectBuilder.builder().withProjectDir(moduleFolder).build()
    project.plugins.apply("com.android.library")
    project.plugins.apply("com.facebook.react")
    val extension = project.extensions.getByType(ReactExtension::class.java)
    assertEquals(project.file("../package.json"), findPackageJsonFile(project, extension))
    }
    @Test
    fun findPackageJsonFile_withFileConfiguredInExtension_picksItUp() {
    val moduleFolder = tempFolder.newFolder("awesome-module")
    val localFile = File(moduleFolder, "package.json").apply { writeText("{}") }
    val project = ProjectBuilder.builder().withProjectDir(moduleFolder).build()
    project.plugins.apply("com.android.library")
    project.plugins.apply("com.facebook.react")
    val extension =
    project.extensions.getByType(ReactExtension::class.java).apply { root.set(moduleFolder) }
    assertEquals(localFile, findPackageJsonFile(project, extension))
    }

  2. I believe the problem here is that @Titozzz had root misconfigured inside the library. root should be placed to where the root of the package/library so in this folder setup:

react-native-webview <--- root should be here
├── android
│   └── build.gradle
├── example
│   └── App.tsx
├── ios
│   └── RNCWebView.xcodeproj
├── macos
│   └── RNCWebView.xcodeproj
├── package.json
└── src 

Making this function return null is correct, but the build will fail at a later stage as the package.json is not found.

@analysis-bot
Copy link

analysis-bot commented Dec 5, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,104,305 -41
android hermes armeabi-v7a 6,473,067 -40
android hermes x86 7,522,581 -40
android hermes x86_64 7,381,008 -37
android jsc arm64-v8a 8,971,778 -7
android jsc armeabi-v7a 7,703,208 -5
android jsc x86 9,034,387 -6
android jsc x86_64 9,511,779 +3

Base commit: 56b10a8
Branch: main

@facebook-github-bot
Copy link
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@github-actions
Copy link

github-actions bot commented Dec 6, 2022

This pull request was successfully merged by @tido64 in 913ebd2.

When will my fix make it into a release? | Upcoming Releases

@github-actions github-actions bot added the Merged This PR has been merged. label Dec 6, 2022
@tido64 tido64 deleted the tido/return-null-pkgjson branch December 6, 2022 10:21
kelset pushed a commit that referenced this pull request Dec 13, 2022
…oes not exist (#35566)

Summary:
`findPackageJsonFile` always returns a path even though `package.json` does not exist. This causes issues in libraries whose repo setups look like:

```
react-native-webview
├── android
│   └── build.gradle
├── example  <-- Note the lack of `package.json` here
│   └── App.tsx
├── ios
│   └── RNCWebView.xcodeproj
├── macos
│   └── RNCWebView.xcodeproj
├── package.json
└── src
```

When `newArchEnabled=true`, running `yarn android` will fail with the following:

```
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:generateCodegenArtifactsFromSchema'.
> Could not create task ':app:generateCodegenSchemaFromJavaScript'.
   > /~/react-native-webview/example/package.json (No such file or directory)
```

## Changelog

[Android] [Fixed] - `findPackageJsonFile` should return `null` if `package.json` does not exist

Pull Request resolved: #35566

Test Plan:
```
git clone https://github.com/react-native-webview/react-native-webview.git
cd react-native-webview
git checkout new-arch-ios
yarn
cd example/android
./gradlew clean assembleDebug
```

Reviewed By: NickGerleman

Differential Revision: D41739176

Pulled By: cortinico

fbshipit-source-id: cab0f1f717db160df244c9bb2769e345d6e19917
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…oes not exist (facebook#35566)

Summary:
`findPackageJsonFile` always returns a path even though `package.json` does not exist. This causes issues in libraries whose repo setups look like:

```
react-native-webview
├── android
│   └── build.gradle
├── example  <-- Note the lack of `package.json` here
│   └── App.tsx
├── ios
│   └── RNCWebView.xcodeproj
├── macos
│   └── RNCWebView.xcodeproj
├── package.json
└── src
```

When `newArchEnabled=true`, running `yarn android` will fail with the following:

```
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:generateCodegenArtifactsFromSchema'.
> Could not create task ':app:generateCodegenSchemaFromJavaScript'.
   > /~/react-native-webview/example/package.json (No such file or directory)
```

## Changelog

[Android] [Fixed] - `findPackageJsonFile` should return `null` if `package.json` does not exist

Pull Request resolved: facebook#35566

Test Plan:
```
git clone https://github.com/react-native-webview/react-native-webview.git
cd react-native-webview
git checkout new-arch-ios
yarn
cd example/android
./gradlew clean assembleDebug
```

Reviewed By: NickGerleman

Differential Revision: D41739176

Pulled By: cortinico

fbshipit-source-id: cab0f1f717db160df244c9bb2769e345d6e19917
@cipolleschi cipolleschi mentioned this pull request Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Microsoft Partner: Microsoft Partner Platform: Android Android applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants