Skip to content

Commit

Permalink
Support react-native and expo doctor in command palette (#2116)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexie011 committed Mar 7, 2024
1 parent f81a4c8 commit 76faa50
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ If you want to debug Expo app using [expo-dev-client](https://docs.expo.dev/deve
```json
"configurations": [
{
"name": "Attach to packager",
"name": "Attach to Hermes application",
"request": "attach",
"type": "reactnative",
"type": "reactnativedirect",
"cwd": "${workspaceFolder}"
}
]
Expand Down
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,18 @@
"category": "React Native",
"enablement": "!config.security.workspace.trust.enabled && !inDebugMode || isWorkspaceTrusted && !inDebugMode",
"icon": "$(play)"
},
{
"command": "reactNative.doctor",
"title": "Run Doctor",
"category": "React Native",
"enablement": "!config.security.workspace.trust.enabled || isWorkspaceTrusted"
},
{
"command": "reactNative.ExpoDoctor",
"title": "Expo Run Doctor",
"category": "React Native",
"enablement": "!config.security.workspace.trust.enabled || isWorkspaceTrusted"
}
],
"menus": {
Expand Down
3 changes: 2 additions & 1 deletion src/common/error/internalErrorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export enum InternalErrorCode {
FailedToOpenRNUpgradeHelper = 122,
FailedToInstallExpoGo = 123,
FailedToLaunchExpoWeb = 124,

FailedToRunRNDoctor = 125,
FailedToRunExpoDoctor = 126,
// Device Deployer errors
IOSDeployNotFound = 201,

Expand Down
25 changes: 25 additions & 0 deletions src/extension/commands/expoDoctor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as assert from "assert";
import { ReactNativeCommand } from "./util/reactNativeCommand";
import { ErrorHelper } from "../../common/error/errorHelper";
import { InternalErrorCode } from "../../common/error/internalErrorCode";
import { ChildProcess } from "../../common/node/childProcess";
import { OutputChannelLogger } from "../log/OutputChannelLogger";

const logger = OutputChannelLogger.getMainChannel();
export class expoDoctor extends ReactNativeCommand {
codeName = "ExpoDoctor";
label = "Expo Doctor";
error = ErrorHelper.getInternalError(InternalErrorCode.FailedToRunExpoDoctor);

async baseFn(): Promise<void> {
assert(this.project);
const projectRootPath = this.project.getPackager().getProjectPath();
const res = await new ChildProcess().exec("npx expo-doctor", { cwd: projectRootPath });
logger.info("Running diagnostics...");
const outcome = await res.outcome;
logger.info(outcome);
}
}
3 changes: 2 additions & 1 deletion src/extension/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

export * from "./rnDoctor";
export * from "./expoDoctor";
export * from "./debugScenario";
export * from "./elementInspector";
export * from "./launchAndroidEmulator";
Expand Down
41 changes: 41 additions & 0 deletions src/extension/commands/rnDoctor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as assert from "assert";
import { ReactNativeCommand } from "./util/reactNativeCommand";
import { ErrorHelper } from "../../common/error/errorHelper";
import { InternalErrorCode } from "../../common/error/internalErrorCode";
import { CommandExecutor } from "../../common/commandExecutor";
import { OutputChannelLogger } from "../log/OutputChannelLogger";
import { OutputVerifier, PatternToFailure } from "../../common/outputVerifier";
import { AppLauncher } from "../../extension/appLauncher";

export class rnDoctor extends ReactNativeCommand {
private static RUN_DOCTOR_SUCCESS_PATTERNS: string[] = ["run doctor succeeded"];
private static RUN_DOCTOR_FAILURE_PATTERNS: PatternToFailure[] = [
{
pattern: "Failed to run doctor",
errorCode: InternalErrorCode.FailedToRunRNDoctor,
},
];
codeName = "doctor";
label = "React Native Doctor";
nodeModulesRoot: string;
error = ErrorHelper.getInternalError(InternalErrorCode.FailedToRunRNDoctor);
async baseFn(): Promise<void> {
assert(this.project);
const projectRootPath = this.project.getPackager().getProjectPath();
const logger = OutputChannelLogger.getChannel("ReactNativeRunDoctor", true);
const nodeModulesRoot: string =
AppLauncher.getNodeModulesRootByProjectPath(projectRootPath);
const commandExecutor = new CommandExecutor(nodeModulesRoot, projectRootPath, logger);
const res = commandExecutor.spawnReactCommand("doctor");

const output = new OutputVerifier(
() => Promise.resolve(rnDoctor.RUN_DOCTOR_SUCCESS_PATTERNS),
() => Promise.resolve(rnDoctor.RUN_DOCTOR_FAILURE_PATTERNS),
"run doctor",
).process(res);
await output;
}
}

0 comments on commit 76faa50

Please sign in to comment.