Skip to content

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

Closed
tido64 wants to merge 2 commits into
mainfrom
tido/return-null-pkgjson
Closed

RNGP - findPackageJsonFile should return null if package.json does not exist#35566
tido64 wants to merge 2 commits into
mainfrom
tido/return-null-pkgjson

Conversation

@tido64

Copy link
Copy Markdown
Collaborator

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-botfacebook-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
Copy Markdown
CollaboratorAuthor

cc @Titozzz

@analysis-bot

analysis-bot commented Dec 5, 2022

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
ios-universaln/a--

Base commit: 56b10a8
Branch: main

@cortinico

Copy link
Copy Markdown
Contributor

Thanks for doing this @tido64

  1. Can you write a test for it here?
    https://github.com/facebook/react-native/blob/032bed45a9e9c531d5243d39903a8f6f44d7d6e5/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/PathUtilsTest.kt#L225-L250

  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

analysis-bot commented Dec 5, 2022

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a7,104,305-41
androidhermesarmeabi-v7a6,473,067-40
androidhermesx867,522,581-40
androidhermesx86_647,381,008-37
androidjscarm64-v8a8,971,778-7
androidjscarmeabi-v7a7,703,208-5
androidjscx869,034,387-6
androidjscx86_649,511,779+3

Base commit: 56b10a8
Branch: main

@facebook-github-bot

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown

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

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

@github-actionsgithub-actionsBot 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
@cipolleschicipolleschi mentioned this pull request Oct 11, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BugCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.MergedThis PR has been merged.p: MicrosoftPartner: MicrosoftPartnerPlatform: AndroidAndroid applications.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@tido64@analysis-bot@cortinico@facebook-github-bot@react-native-bot