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

feat(doctor): detect wrong dependencies #1983

Conversation

tarunrajput
Copy link
Contributor

@tarunrajput tarunrajput commented Jun 23, 2023

Summary:

Detect wrong/incompatible dependencies/devDependencies inside package.json
Resolves: #1848

Test Plan:

  1. Build cli codebase using : node ./scripts/build.js && yarn build:debugger
  2. Link the cli-doctor using : yarn link
  3. In the example React Native app(Awesome Project), run yarn link "@react-native-community/cli-doctor"
  4. Run the CLI Doctor using : npx @react-native-community/cli doctor

Failure:

⠏ Running diagnostics...
Common
 ● Dependencies - There are some issues with your project dependencies
   - warn @react-native/codegen is part of React Native and should not be a dependency in your package.json
   - error @react-native/gradle-plugin: "0.72.1" is not compatible with react-native: "0.71.11"
 ✓ Node.js - Required to execute JavaScript code
 ✓ yarn - Required to install NPM dependencies
 ● Metro - Metro Bundler is not running
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✖ Adb - No devices and/or emulators connected. Please create emulator with Android Studio or connect Android device.
 ✓ JDK - Required to compile Java code
 ✓ Android Studio - Required for building and installing your app on Android
 ✖ Android SDK - Required for building and installing your app on Android
   - Versions found: N/A
   - Version supported: 33.0.0
 ✖ ANDROID_HOME - Environment variable that points to your Android SDK installation

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ Ruby - Required for installing iOS dependencies
 ✓ CocoaPods - Required for installing iOS dependencies
 ● ios-deploy - Required for installing your app on a physical device with the CLI
 ✓ .xcode.env - File to customize Xcode environment

Errors:   3
Warnings: 3


Attempting to fix 6 issues...

Common
 ✖ Dependencies
   Please check your package.json and make sure the dependencies are correct
 ✖ Metro
 ✔ Metro

Android
 ✖ Adb
? Select the device / emulator you want to use › - Use arrow-keys. Return to submit.
{
  "name": "jackeye",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.71.11"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.2.1",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.10",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4",
    "@react-native/gradle-plugin": "0.72.1",
    "@react-native/codegen": "0.71.11"
  "jest": {
    "preset": "react-native"
  }
}

Success:

⠏ Running diagnostics...
Common
 ✓ Dependencies - NPM dependencies needed for the project to work correctly
 ✓ Node.js - Required to execute JavaScript code
 ✓ yarn - Required to install NPM dependencies
 ● Metro - Metro Bundler is not running
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✖ Adb - No devices and/or emulators connected. Please create emulator with Android Studio or connect Android device.
 ✖ JDK - Required to compile Java code
   - Version found: 20.0.1
   - Version supported: >= 11 < 19
 ✓ Android Studio - Required for building and installing your app on Android
 ✖ Android SDK - Required for building and installing your app on Android
   - Versions found: N/A
   - Version supported: 33.0.0
 ✖ ANDROID_HOME - Environment variable that points to your Android SDK installation

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ Ruby - Required for installing iOS dependencies
 ✓ CocoaPods - Required for installing iOS dependencies
 ● ios-deploy - Required for installing your app on a physical device with the CLI
 ✖ .xcode.env - File to customize Xcode environment

Errors:   5
Warnings: 2

Usage
 › Press f to try to fix issues.
 › Press e to try to fix errors.
 › Press w to try to fix warnings.
 › Press Enter to exit.

@tarunrajput
Copy link
Contributor Author

tarunrajput commented Jun 23, 2023

@adamTrz @cortinico , mind taking a look?

@tarunrajput tarunrajput marked this pull request as ready for review June 28, 2023 05:49
Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adds some tests inside src/tools/healthchecks/__tests__/

@tarunrajput tarunrajput force-pushed the tarunrajput/doctor-detect-wrong-dependencies branch from ce0ae4c to a7ee439 Compare July 10, 2023 06:21
@tarunrajput
Copy link
Contributor Author

@cortinico, I've added a few unit tests

Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, let's wait for someone else from the CLI team to review this one 👍

Copy link
Collaborator

@szymonrybczak szymonrybczak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🎉 I left few small comments.

@szymonrybczak
Copy link
Collaborator

Hey @tarunrajput, sorry that I'm writing this right now, but might you adding check for internal @react-native-community/cli packages? It would be perfect if we check for react-native-cli and all packages that we have in our repo. I think we should add other warning / error message that we show when we detect internal React Native packages. My proposal is that:

  • if we detect react-native-cli -> we should give an error
  • if we detect @react-native-community/cli -> (at correct corresponding version to RN - print a warning, if there's version mismatch give an error - same as we do with RN's internal packages). Mind adding missing logic? 🙏

cc. @cortinico

@tarunrajput
Copy link
Contributor Author

Hi @szymonrybczak, Thanks for the suggestion! Could you please guide me on how to check if the CLI version is compatible with the React Native version, considering they have independent release cycles? 😅

@szymonrybczak
Copy link
Collaborator

considering they have independent release cycles

See here, every CLI release corresponds to relevant React Native version - that is the source of truth.

@tarunrajput tarunrajput force-pushed the tarunrajput/doctor-detect-wrong-dependencies branch from 770f0c6 to d308daa Compare July 25, 2023 19:26
@arushikesarwani94
Copy link
Contributor

LGTM ! For CLI review cc: @szymonrybczak

Copy link
Collaborator

@szymonrybczak szymonrybczak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing this! Left few small nits 🙌

@tarunrajput tarunrajput force-pushed the tarunrajput/doctor-detect-wrong-dependencies branch from d308daa to 26f59e5 Compare August 17, 2023 15:24
@tarunrajput
Copy link
Contributor Author

@szymonrybczak, Thanks! Just updated the PR with the changes.

@szymonrybczak
Copy link
Collaborator

@thymikee mind giving final review on this PR?

Comment on lines +85 to +87
` - ${chalk.red(
'error',
)} ${pkg}: "${packageVersion}" is not compatible with react-native: "${reactNativeVersion}"`,
);
Copy link
Member

@thymikee thymikee Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use logger.error (and logger.warn where applicable) instead? They handle coloring the warn/error/info words, so we don't have to reimplement it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the suggestion! I chose not to use logger in this case because it would print the error/warning immediately outside of the issue category like this

⠸ Running diagnostics...
warn  @react-native-community/cli comes included with React Native and should not be listed as a dependency in your package.json
Common
 ● Dependencies - There are some issues with your project dependencies

@tarunrajput tarunrajput force-pushed the tarunrajput/doctor-detect-wrong-dependencies branch from 26f59e5 to 8571afa Compare September 20, 2023 08:44
@szymonrybczak szymonrybczak force-pushed the tarunrajput/doctor-detect-wrong-dependencies branch from 8571afa to 1f6940e Compare October 30, 2023 16:21
@szymonrybczak szymonrybczak mentioned this pull request Nov 1, 2023
2 tasks
Copy link

There hasn't been any activity on this pull request in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions bot added the stale label Jan 29, 2024
@github-actions github-actions bot closed this Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

doctor: detect wrong app dependencies
6 participants