-
Notifications
You must be signed in to change notification settings - Fork 905
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
Allow platforms and community packages to provide additional health checks #1231
Merged
grabbou
merged 10 commits into
react-native-community:master
from
acoates-ms:pluggabledoctor
Sep 21, 2020
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ddd4e2d
Allow platforms and community packages to provide additional health c…
acoates-ms 4a8ea76
Adding some documentation
acoates-ms 15013e8
Update tests
acoates-ms 5e9e602
remove todo
9b21966
Merge remote-tracking branch 'upstream/master' into pluggabledoctor
6471154
Add a couple of examples for RunAutomaticFix implementations
27b1976
update config snapshot
e3c1d78
Use real ora project for types
acoates-ms a01c12c
Merge remote-tracking branch 'upstream/master' into pluggabledoctor
acoates-ms aa0b672
lint fix
acoates-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# Health Check Plugins | ||
|
||
Plugins can be used to extend the health checks that `react-native doctor` runs. This can be used to add additional checks for out of tree platforms, or other checks that are specific to a community module. | ||
|
||
See [`Plugins`](./plugins.md) for information about how plugins work. | ||
|
||
|
||
## How does it work? | ||
|
||
To provide additional health checks, a package needs to have a `react-native.config.js` at the root folder in order to be discovered by the CLI as a plugin. | ||
|
||
```js | ||
module.exports = { | ||
healthChecks: [ | ||
{ | ||
label: 'Foo', | ||
healthchecks: [ | ||
label: 'bar-installed', | ||
getDiagnostics: async () => ({ | ||
needsToBeFixed: !isBarInstalled() | ||
}), | ||
runAutomaticFix: async ({loader}) => { | ||
await installBar(); | ||
loader.succeed(); | ||
}, | ||
} | ||
], | ||
}; | ||
``` | ||
|
||
> Above is an example of a plugin that extends the healthChecks performed by `react-native doctor` to check if `bar` is installed. | ||
|
||
At the startup, React Native CLI reads configuration from all dependencies listed in `package.json` and reduces them into a single configuration. | ||
|
||
At the end, an array of health check categories is concatenated to be checked when `react-native doctor` is run. | ||
|
||
|
||
## HealthCheckCategory interface | ||
|
||
```ts | ||
type HealthCheckCategory = { | ||
label: string; | ||
healthchecks: HealthCheckInterface[]; | ||
}; | ||
``` | ||
|
||
##### `label` | ||
|
||
Name of the category for this health check. This will be used to group health checks in doctor. | ||
|
||
##### `healthChecks` | ||
|
||
Array of health checks to perorm in this category | ||
|
||
|
||
## HealthCheckInterface interface | ||
|
||
```ts | ||
type HealthCheckInterface = { | ||
label: string; | ||
visible?: boolean | void; | ||
isRequired?: boolean; | ||
description?: string; | ||
getDiagnostics: ( | ||
environmentInfo: EnvironmentInfo, | ||
) => Promise<{ | ||
version?: string; | ||
versions?: [string]; | ||
versionRange?: string; | ||
needsToBeFixed: boolean | string; | ||
}>; | ||
win32AutomaticFix?: RunAutomaticFix; | ||
darwinAutomaticFix?: RunAutomaticFix; | ||
linuxAutomaticFix?: RunAutomaticFix; | ||
runAutomaticFix: RunAutomaticFix; | ||
}; | ||
``` | ||
|
||
##### `label` | ||
|
||
Name of this health check | ||
|
||
##### `visible` | ||
|
||
If set to false, doctor will ignore this health check | ||
|
||
##### `isRequired` | ||
|
||
Is this health check required or optional? | ||
|
||
##### `description` | ||
|
||
Longer description of this health check | ||
|
||
|
||
##### `getDiagnostics` | ||
|
||
Functions which performs the actual check. Simple checks can just return `needsToBeFixed`. Checks which are looking at versions of an installed components (such as the version of node), can also return `version`, `versions` and `versionRange` to provide better information to be displayed in `react-native doctor` when running the check | ||
|
||
##### `win32AutomaticFix` | ||
|
||
This function will be used to try to fix the issue when `react-native doctor` is run on a windows machine. If this is not specified, `runAutomaticFix` will be run instead. | ||
|
||
##### `darwinAutomaticFix` | ||
|
||
This function will be used to try to fix the issue when `react-native doctor` is run on a macOS machine. If this is not specified, `runAutomaticFix` will be run instead. | ||
|
||
##### `linuxAutomaticFix` | ||
|
||
This function will be used to try to fix the issue when `react-native doctor` is run on a linux machine. If this is not specified, `runAutomaticFix` will be run instead. | ||
|
||
##### `runAutomaticFix` | ||
|
||
This function will be used to try to fix the issue when `react-native doctor` is run and no more platform specific automatic fix function was provided. | ||
|
||
|
||
## RunAutomaticFix interface | ||
|
||
```ts | ||
type RunAutomaticFix = (args: { | ||
loader: Ora; | ||
logManualInstallation: ({ | ||
healthcheck, | ||
url, | ||
command, | ||
message, | ||
}: { | ||
healthcheck?: string; | ||
url?: string; | ||
command?: string; | ||
message?: string; | ||
}) => void; | ||
environmentInfo: EnvironmentInfo; | ||
}) => Promise<void> | void; | ||
``` | ||
|
||
##### `loader` | ||
|
||
A reference to a [`ora`](https://www.npmjs.com/package/ora) instance which should be used to report success / failure, and progress of the fix. The fix function should always call either `loader.succeed()` or `loader.fail()` before returning. | ||
|
||
##### `logManualInstallation` | ||
|
||
If an automated fix cannot be performed, this function should be used to provide instructions to the user on how to manually fix the issue. | ||
|
||
##### `environmentInfo` | ||
|
||
Provides information about the current system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ import { | |
AndroidDependencyConfig, | ||
AndroidDependencyParams, | ||
} from './android'; | ||
import {Ora} from './ora'; | ||
export {Ora} from './ora'; | ||
|
||
export type InquirerPrompt = any; | ||
|
||
|
@@ -120,6 +122,100 @@ export type ProjectConfig = { | |
[key: string]: any; | ||
}; | ||
|
||
export type NotFound = 'Not Found'; | ||
type AvailableInformation = { | ||
version: string; | ||
path: string; | ||
}; | ||
|
||
type Information = AvailableInformation | NotFound; | ||
|
||
export type EnvironmentInfo = { | ||
System: { | ||
OS: string; | ||
CPU: string; | ||
Memory: string; | ||
Shell: AvailableInformation; | ||
}; | ||
Binaries: { | ||
Node: AvailableInformation; | ||
Yarn: AvailableInformation; | ||
npm: AvailableInformation; | ||
Watchman: AvailableInformation; | ||
}; | ||
SDKs: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the idea that this is what will get asked of envinfo? if so, please make sure that info continues to report the windows properties we care about: Windows SDKs, VS installs, dev mode reg keys. |
||
'iOS SDK': { | ||
Platforms: string[]; | ||
}; | ||
'Android SDK': | ||
| { | ||
'API Levels': string[] | NotFound; | ||
'Build Tools': string[] | NotFound; | ||
'System Images': string[] | NotFound; | ||
'Android NDK': string | NotFound; | ||
} | ||
| NotFound; | ||
}; | ||
IDEs: { | ||
'Android Studio': AvailableInformation | NotFound; | ||
Emacs: AvailableInformation; | ||
Nano: AvailableInformation; | ||
VSCode: AvailableInformation; | ||
Vim: AvailableInformation; | ||
Xcode: AvailableInformation; | ||
}; | ||
Languages: { | ||
Java: Information; | ||
Python: Information; | ||
}; | ||
}; | ||
|
||
export type HealthCheckCategory = { | ||
label: string; | ||
healthchecks: HealthCheckInterface[]; | ||
}; | ||
|
||
export type Healthchecks = { | ||
common: HealthCheckCategory; | ||
android: HealthCheckCategory; | ||
ios?: HealthCheckCategory; | ||
}; | ||
|
||
export type RunAutomaticFix = (args: { | ||
loader: Ora; | ||
logManualInstallation: ({ | ||
healthcheck, | ||
url, | ||
command, | ||
message, | ||
}: { | ||
healthcheck?: string; | ||
url?: string; | ||
command?: string; | ||
message?: string; | ||
}) => void; | ||
environmentInfo: EnvironmentInfo; | ||
}) => Promise<void> | void; | ||
|
||
export type HealthCheckInterface = { | ||
label: string; | ||
visible?: boolean | void; | ||
isRequired?: boolean; | ||
description?: string; | ||
getDiagnostics: ( | ||
environmentInfo: EnvironmentInfo, | ||
) => Promise<{ | ||
version?: string; | ||
versions?: [string]; | ||
versionRange?: string; | ||
needsToBeFixed: boolean | string; | ||
}>; | ||
win32AutomaticFix?: RunAutomaticFix; | ||
darwinAutomaticFix?: RunAutomaticFix; | ||
linuxAutomaticFix?: RunAutomaticFix; | ||
runAutomaticFix: RunAutomaticFix; | ||
}; | ||
|
||
/** | ||
* @property root - Root where the configuration has been resolved from | ||
* @property reactNativePath - Path to React Native source | ||
|
@@ -128,6 +224,7 @@ export type ProjectConfig = { | |
* @property dependencies - Map of the dependencies that are present in the project | ||
* @property platforms - Map of available platforms (build-ins and dynamically loaded) | ||
* @property commands - An array of commands that are present in 3rd party packages | ||
* @property healthChecks - An array of health check categories to add to doctor command | ||
*/ | ||
export interface Config extends IOSNativeModulesConfig { | ||
root: string; | ||
|
@@ -151,6 +248,7 @@ export interface Config extends IOSNativeModulesConfig { | |
[name: string]: PlatformConfig<any, any, any, any>; | ||
}; | ||
commands: Command[]; | ||
healthChecks: HealthCheckCategory[]; | ||
} | ||
|
||
/** | ||
|
@@ -175,6 +273,8 @@ export type UserDependencyConfig = { | |
commands: Command[]; | ||
// An array of extra platforms to load | ||
platforms: Config['platforms']; | ||
// Additional health checks | ||
healthChecks: HealthCheckCategory[]; | ||
}; | ||
|
||
export { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is so awesome.