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

Migrate the rest of doctor command to TypeScript #722

Merged

Conversation

thib92
Copy link
Contributor

@thib92 thib92 commented Sep 14, 2019

Summary:

This is the last PR to move the doctor command to TypeScript. This one was quite a long one because I needed to unify the type definitions of all the functions manipulating the type checks, and it can be a little bit confusing (at least to me).

So I hope with this, all the functions and their roles in the healthchecks will be easier to read.

Feel free to comment if anything feels off.

  • Migrate the rest of doctor command to TypeScript
  • Unify type definitions for the command
  • Remove Flow typings

Test Plan:

  • CI is green ✅
  • Everything makes sense

Unify type definitions for the command
Remove Flow typings
);
const healthchecksPerCategory = await iterateOverCategories(Object.values(
getHealthchecks(options),
).filter(category => category !== undefined) as HealthcheckCategory[]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here, the as part is necessary, but could use type predicates.

const onKeyPress = async key => {
// $FlowFixMe
const onKeyPress = async (key: string) => {
// @ts-ignore
process.stdin.setRawMode(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does stdin.setRawMode really exist? It's not in the typings.

Copy link
Member

Choose a reason for hiding this comment

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

It exists in TTY, which is our primary use case, so yep: https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode
Please check if typeof process.stdin.setRawMode === "function" before accessing it. We should add it to every call of this method at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, it's optional. Thanks!

healthchecks,
automaticFixLevel,
stats,
loader,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw here that this function doesn't use its loader argument, but uses ora directly from the import. Is this intended?

Copy link
Member

Choose a reason for hiding this comment

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

if loader is unused, please remove it from the type def as well

@@ -13,14 +13,16 @@ import {

export type InquirerPrompt = any;

export type CommandFunction = (
Copy link
Member

Choose a reason for hiding this comment

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

We could make it a parametrized type and pass the param to args, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call!

ctx: ConfigT,
options: FlagsT,
) {
export default (async (_, __, options: FlagsT) => {
Copy link
Member

Choose a reason for hiding this comment

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

Use something like CommandFunction<FlagsT> maybe?

packages/cli/src/commands/doctor/doctor.ts Outdated Show resolved Hide resolved
const onKeyPress = async key => {
// $FlowFixMe
const onKeyPress = async (key: string) => {
// @ts-ignore
process.stdin.setRawMode(false);
Copy link
Member

Choose a reason for hiding this comment

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

It exists in TTY, which is our primary use case, so yep: https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode
Please check if typeof process.stdin.setRawMode === "function" before accessing it. We should add it to every call of this method at some point.

// Remove the fix options from screen
// $FlowFixMe
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

instead of ignore, please add if (process.stdout.isTTY) {} check, or make sure moveCursor and clearScreenDown exist

};

export type Healthchecks = {
common: HealthcheckCategory;
Copy link
Member

Choose a reason for hiding this comment

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

Please rename to HealthChecks and HealthCheckCategory to stay consistent consistency

thib92 and others added 2 commits September 16, 2019 11:10
Co-Authored-By: Michał Pierzchała <thymikee@gmail.com>
@thib92
Copy link
Contributor Author

thib92 commented Sep 16, 2019

All done @thymikee, thanks for the review!

@thymikee
Copy link
Member

cc @lucasbento

import chalk from 'chalk';
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

Noobie question: shouldn't we type these instead of just adding it to ignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep we should. I might give it a try, but there is a pending WIP PR on the repo. Would probably be worth being put on DefinitelyTyped

ERRORS: 'ERRORS',
WARNINGS: 'WARNINGS',
};
export enum AUTOMATIC_FIX_LEVELS {
Copy link
Member

Choose a reason for hiding this comment

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

so good

Copy link
Member

@lucasbento lucasbento left a comment

Choose a reason for hiding this comment

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

Looks awesome, thank you for this @thib92!

process.stdout.clearScreenDown();
if (process.stdout.isTTY) {
// @ts-ignore
process.stdout.moveCursor(0, -6);
Copy link
Member

Choose a reason for hiding this comment

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

Those should be part of readline as they are apparently not typed under process.stdout: DefinitelyTyped/DefinitelyTyped#31505.

I can change those later as there's no harm on ignoring this.

@thymikee thymikee merged commit 85198d2 into react-native-community:master Sep 16, 2019

export {AUTOMATIC_FIX_LEVELS};
export default async ({
interface RunAutomaticFixArgs {
Copy link
Member

Choose a reason for hiding this comment

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

@thib92: small question, when do you use type and interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a small difference between the two, but to be fair I usually use type because you can union them, type functions, etc. I'm not sure what the advantages of interface is though. I saw you used interface before so I used them where I could

Copy link
Member

Choose a reason for hiding this comment

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

Cool, thanks for replying!

@thib92 thib92 deleted the typescript-command-doctor branch September 16, 2019 09:55
@thib92
Copy link
Contributor Author

thib92 commented Sep 16, 2019

Thanks for the merge. @thymikee @lucasbento if you need help on other stuff, please send me a message! I'd love to contribute more on the project! I'll be looking at issues that I could take 😄

@thymikee
Copy link
Member

@thib92 thank you! ❤️

@lucasbento
Copy link
Member

@thib92: thanks for the contributions!

We have a good list of issues that we need to work on at #694 in order to get doctor out of experimental, if you are feeling adventurous you can take one and open a PR 🙂

@thib92
Copy link
Contributor Author

thib92 commented Sep 16, 2019

@lucasbento thanks a lot, will take a look!

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.

3 participants