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: add react-native doctor #532

Merged
merged 35 commits into from
Sep 3, 2019

Conversation

lucasbento
Copy link
Member

@lucasbento lucasbento commented Jul 15, 2019

Summary:

This PR fixes #51, it adds a doctor command to verify the softwares/libraries/tools that we depend on and make sure that they match the minimum requirements needed by react-native.

The version for Node.js is not correct as I put it there for testing purposes.


react-native doctor command

Test Plan:

  1. Uninstall cocoapods or ios-deploy (easiest ones to try);
  2. Run doctor command

TODOS:

  • List number of problems & warnings
  • Separate list of issues in a different file and each issue should have their own file to run the automatic fix
  • Add automatic fix for the softwares
  • For "no automatically fix" softwares there should be a link to download new versions;
  • Add prompt question to fix after it has been ran
  • Add --fix argument that should go directly to fixing it
  • Add --dry-run option
  • Add --contributor option to only show Android NDK if specified
  • Make sure that the version ranges are good to go
  • Add more softwares/tools/libs

@lucasbento lucasbento mentioned this pull request Jul 15, 2019
@patrickkempff
Copy link

Wow, this looks awesome!

@Inovassist-dev
Copy link

Oh my god, I must say, we need that!
Flutter has its own doctor command and it's really good. I wonder how many bugs and bad environment configs could be solved with an on-the-fly "doctor" command!

@lucasbento
Copy link
Member Author

@Inovassist-dev: thanks for the feedback on this, that's what we are aiming for!

This week I'm pretty busy, gonna get back to work on this by next week 🙂

@rickhanlonii
Copy link
Collaborator

Hey @lucasbento, this is amazing! I'd love to help you get this through, let me know what you need!

@sahrens
Copy link
Contributor

sahrens commented Aug 6, 2019

This would be great, thanks for getting it started!

Thoughts on building this in such a way that we can compose it with other tools and IDEs (e.g. support JSON output instead of logging direct to console). cc @thymikee

@cpojer
Copy link
Member

cpojer commented Aug 6, 2019

Can we call this react-native fix?

@Inovassist-dev
Copy link

Inovassist-dev commented Aug 6, 2019

@cpojer I don't think that the name "fix" would be a great idea.
Fluter already has the doctor command and, sincerely, it's a big deal.
As it's not going to necessarily fix React installation, we can call it doctor or repair, just to chase possible errors and, if found, fix them

@thymikee
Copy link
Member

thymikee commented Aug 6, 2019

@sahrens definitely open to that

@elicwhite
Copy link
Contributor

I'd love to see this landed and iterated upon. How many features do we need to wait for this to have before landing an MVP?

@lucasbento
Copy link
Member Author

Those are the installations that I would like to have in:

Platform agnostic
  • Current folder is a react-native project (check if react-native is installed)
  • yarn or npm are in a recent version (need to store the minimum version)
  • Minimum node version (need to store the minimum version)
  • Check watchman (need to store the minimum version)
Android
  • Check if ANDROID_HOME is defined
  • Android SDK
  • Android NDK (consider not showing every time as it's not needed for everyone)
iOS
  • Check Xcode
  • Check CocoaPods
  • Check if ios-deploy is installed (need to tell the user somehow that this is only needed with real devices)

Totally discussable though, I would like to have this on master as soon as possible so it's easier for people to add more stuff.

@rickhanlonii @sahrens: a review on the source would be very much appreciated, I'm trying to build something as modular as possible, the JSON output was already asked on #51 and I'm definitely on board with that.

The first thing that I need help with is a little review and adding more installation checks, if anyone of you want to help with that then let's do it!

@tabrindle
Copy link
Contributor

I realize that you are looking to add more functionality in the future, but right now this is exactly the feature set of Solidarity https://github.com/infinitered/solidarity Might we consider using this and combining efforts on the automatic fix part on the wishlist?

@rickhanlonii
Copy link
Collaborator

@tabrindle Aolidariy is great! Will support things like checking for IDE installations, android SDKs, xcode versions, vscode/intellij/android studio plugins?

@tabrindle
Copy link
Contributor

Solidarity can do anything envinfo does, as it uses it under the hood.

Copy link
Collaborator

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

Overall looks great, I really like the way the health checks are handled so that it's easy to add a new check. I think we can go with this and iterate 👍

};

const doesSoftwareNeedToBeFixed = ({version, versionRange}) =>
version === 'Not Found' || !semver.satisfies(version, versionRange);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that semver can throw here if for some reason one of the versions are invalid. e.g. for me, I'm getting the string "Using globally installed version of Yarn"

Screenshot 2019-08-07 11 33 17

We'll at least need to try/catch here, but in the catch we may want to log a quality error and consider crashing because if we don't get a semver by this point that the individual issue needs to diagnose why they don't have a semver

Copy link
Member Author

Choose a reason for hiding this comment

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

How did you install yarn? I want to reproduce that locally.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably npm install -g yarn

packages/cli/src/commands/doctor/doctor.js Outdated Show resolved Hide resolved

export default (async function runDoctor() {
const Loader = getLoader();
const loader = new Loader();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: naming this a "loader" when it's not really showing a loading message and is mostly only a logger is hard to read (I recognize that this is called a loader elsewhere so we should either change all usages or stay consistent)

packages/cli/src/commands/doctor/doctor.js Outdated Show resolved Hide resolved
packages/cli/src/commands/doctor/doctor.js Outdated Show resolved Hide resolved
packages/cli/src/commands/doctor/doctor.js Outdated Show resolved Hide resolved
try {
await issueToFix.runAutomaticFix({loader: issueSpinner});
} catch (error) {
// TODO: log the error in a meaningful way
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would console.error be better than nothing for now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't pay much attention to this part yet, it's hard to log an error right now as the loader is on top of everything, so first it needs to stop the loader, log an error and then continue to the next automatic fix.

packages/cli/src/commands/doctor/doctor.js Show resolved Hide resolved
@Inovassist-dev
Copy link

@tabrindle, I think it would be nice to have something like Solidarity already integrated with React Native, dont you think?

@lucasbento
Copy link
Member Author

@rickhanlonii: thank you so much for the review! gonna check it out.

I realize that you are looking to add more functionality in the future, but right now this is exactly the feature set of Solidarity infinitered/solidarity Might we consider using this and combining efforts on the automatic fix part on the wishlist?

@tabrindle: I checked solidarity before starting this and I struggled to understand how it would be used on the core of the CLI, perhaps we should discuss its possibilities somewhere else?

@rickhanlonii
Copy link
Collaborator

@lucasbento do you want to get this in an start iterating?

@thymikee thymikee marked this pull request as ready for review September 3, 2019 09:15
@thymikee
Copy link
Member

thymikee commented Sep 3, 2019

I like the direction where it's going. Let's make sure to mark it as experimental (e.g. in the description and the docs, or add docs later) and it doesn't break stable commands. And ship it :shipit:

runAutomaticFix: async ({loader}) => {
try {
// First attempt to install `cocoapods`
await execa('gem', ['install', 'cocoapods']);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we rely on Homebrew/MacPorts to avoid having to invoke sudo? Or at least use them if they are installed.

Copy link
Member

Choose a reason for hiding this comment

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


process.exit(0);
} catch (err) {
// TODO: log error
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this going to be done now or in a separate PR?

// or if we can't identify that the user uses yarn or npm
visible:
packageManager === PACKAGE_MANAGERS.YARN || packageManager === undefined,
runAutomaticFix: () => console.log('should fix node'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intentional? Isn't Yarn installed separately?

versionRange: versionRanges.WATCHMAN,
}),
}),
runAutomaticFix: () => console.log('should fix watchman'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this placeholder text?


const label = 'ANDROID_HOME';

const iosDeploy = {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename

import versionRanges from '../versionRanges';
import {doesSoftwareNeedToBeFixed} from '../checkInstallation';

const iosDeploy = {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename

import versionRanges from '../versionRanges';
import {doesSoftwareNeedToBeFixed} from '../checkInstallation';

const iosDeploy = {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename


// List of answers on how to set `ANDROID_HOME` for each platform
const URLS = {
darwin: 'https://stackoverflow.com/a/28296325/4252781',
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be smart to inline these answers

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Let's fix the remaining stuff in followup PRs 👍

@thymikee thymikee merged commit 9139af0 into react-native-community:master Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Health check command