-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support react-native and expo doctor in command palette (#2116)
- Loading branch information
Showing
6 changed files
with
84 additions
and
4 deletions.
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
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
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,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); | ||
} | ||
} |
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 |
---|---|---|
@@ -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; | ||
} | ||
} |