Skip to content

Commit 76faa50

Browse files
authored
Support react-native and expo doctor in command palette (#2116)
1 parent f81a4c8 commit 76faa50

File tree

6 files changed

+84
-4
lines changed

6 files changed

+84
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ If you want to debug Expo app using [expo-dev-client](https://docs.expo.dev/deve
372372
```json
373373
"configurations": [
374374
{
375-
"name": "Attach to packager",
375+
"name": "Attach to Hermes application",
376376
"request": "attach",
377-
"type": "reactnative",
377+
"type": "reactnativedirect",
378378
"cwd": "${workspaceFolder}"
379379
}
380380
]

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,18 @@
423423
"category": "React Native",
424424
"enablement": "!config.security.workspace.trust.enabled && !inDebugMode || isWorkspaceTrusted && !inDebugMode",
425425
"icon": "$(play)"
426+
},
427+
{
428+
"command": "reactNative.doctor",
429+
"title": "Run Doctor",
430+
"category": "React Native",
431+
"enablement": "!config.security.workspace.trust.enabled || isWorkspaceTrusted"
432+
},
433+
{
434+
"command": "reactNative.ExpoDoctor",
435+
"title": "Expo Run Doctor",
436+
"category": "React Native",
437+
"enablement": "!config.security.workspace.trust.enabled || isWorkspaceTrusted"
426438
}
427439
],
428440
"menus": {

src/common/error/internalErrorCode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export enum InternalErrorCode {
2727
FailedToOpenRNUpgradeHelper = 122,
2828
FailedToInstallExpoGo = 123,
2929
FailedToLaunchExpoWeb = 124,
30-
30+
FailedToRunRNDoctor = 125,
31+
FailedToRunExpoDoctor = 126,
3132
// Device Deployer errors
3233
IOSDeployNotFound = 201,
3334

src/extension/commands/expoDoctor.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
import * as assert from "assert";
5+
import { ReactNativeCommand } from "./util/reactNativeCommand";
6+
import { ErrorHelper } from "../../common/error/errorHelper";
7+
import { InternalErrorCode } from "../../common/error/internalErrorCode";
8+
import { ChildProcess } from "../../common/node/childProcess";
9+
import { OutputChannelLogger } from "../log/OutputChannelLogger";
10+
11+
const logger = OutputChannelLogger.getMainChannel();
12+
export class expoDoctor extends ReactNativeCommand {
13+
codeName = "ExpoDoctor";
14+
label = "Expo Doctor";
15+
error = ErrorHelper.getInternalError(InternalErrorCode.FailedToRunExpoDoctor);
16+
17+
async baseFn(): Promise<void> {
18+
assert(this.project);
19+
const projectRootPath = this.project.getPackager().getProjectPath();
20+
const res = await new ChildProcess().exec("npx expo-doctor", { cwd: projectRootPath });
21+
logger.info("Running diagnostics...");
22+
const outcome = await res.outcome;
23+
logger.info(outcome);
24+
}
25+
}

src/extension/commands/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for details.
3-
3+
export * from "./rnDoctor";
4+
export * from "./expoDoctor";
45
export * from "./debugScenario";
56
export * from "./elementInspector";
67
export * from "./launchAndroidEmulator";

src/extension/commands/rnDoctor.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
import * as assert from "assert";
5+
import { ReactNativeCommand } from "./util/reactNativeCommand";
6+
import { ErrorHelper } from "../../common/error/errorHelper";
7+
import { InternalErrorCode } from "../../common/error/internalErrorCode";
8+
import { CommandExecutor } from "../../common/commandExecutor";
9+
import { OutputChannelLogger } from "../log/OutputChannelLogger";
10+
import { OutputVerifier, PatternToFailure } from "../../common/outputVerifier";
11+
import { AppLauncher } from "../../extension/appLauncher";
12+
13+
export class rnDoctor extends ReactNativeCommand {
14+
private static RUN_DOCTOR_SUCCESS_PATTERNS: string[] = ["run doctor succeeded"];
15+
private static RUN_DOCTOR_FAILURE_PATTERNS: PatternToFailure[] = [
16+
{
17+
pattern: "Failed to run doctor",
18+
errorCode: InternalErrorCode.FailedToRunRNDoctor,
19+
},
20+
];
21+
codeName = "doctor";
22+
label = "React Native Doctor";
23+
nodeModulesRoot: string;
24+
error = ErrorHelper.getInternalError(InternalErrorCode.FailedToRunRNDoctor);
25+
async baseFn(): Promise<void> {
26+
assert(this.project);
27+
const projectRootPath = this.project.getPackager().getProjectPath();
28+
const logger = OutputChannelLogger.getChannel("ReactNativeRunDoctor", true);
29+
const nodeModulesRoot: string =
30+
AppLauncher.getNodeModulesRootByProjectPath(projectRootPath);
31+
const commandExecutor = new CommandExecutor(nodeModulesRoot, projectRootPath, logger);
32+
const res = commandExecutor.spawnReactCommand("doctor");
33+
34+
const output = new OutputVerifier(
35+
() => Promise.resolve(rnDoctor.RUN_DOCTOR_SUCCESS_PATTERNS),
36+
() => Promise.resolve(rnDoctor.RUN_DOCTOR_FAILURE_PATTERNS),
37+
"run doctor",
38+
).process(res);
39+
await output;
40+
}
41+
}

0 commit comments

Comments
 (0)