-
Notifications
You must be signed in to change notification settings - Fork 904
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
Migrate the rest of doctor command to TypeScript #722
Conversation
Unify type definitions for the command Remove Flow typings
); | ||
const healthchecksPerCategory = await iterateOverCategories(Object.values( | ||
getHealthchecks(options), | ||
).filter(category => category !== undefined) as HealthcheckCategory[]); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Remove useless arguments
packages/cli-types/src/index.ts
Outdated
@@ -13,14 +13,16 @@ import { | |||
|
|||
export type InquirerPrompt = any; | |||
|
|||
export type CommandFunction = ( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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?
const onKeyPress = async key => { | ||
// $FlowFixMe | ||
const onKeyPress = async (key: string) => { | ||
// @ts-ignore | ||
process.stdin.setRawMode(false); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
Co-Authored-By: Michał Pierzchała <thymikee@gmail.com>
All done @thymikee, thanks for the review! |
cc @lucasbento |
import chalk from 'chalk'; | ||
// @ts-ignore |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
|
||
export {AUTOMATIC_FIX_LEVELS}; | ||
export default async ({ | ||
interface RunAutomaticFixArgs { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks for replying!
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 😄 |
@thib92 thank you! ❤️ |
@lucasbento thanks a lot, will take a look! |
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.
Test Plan: