microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
transitive-dependency-serialize-javascript

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/commands/elementInspector.ts

91lines · modeblame

36a21645Heniker4 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as child_process from "child_process";
5import * as nls from "vscode-nls";
6import { ErrorHelper } from "../../common/error/errorHelper";
7import { InternalErrorCode } from "../../common/error/internalErrorCode";
8import { TipNotificationService } from "../services/tipsNotificationsService/tipsNotificationService";
9import { HostPlatform } from "../../common/hostPlatform";
10import { OutputChannelLogger } from "../log/OutputChannelLogger";
11import { Command } from "./util/command";
12
13nls.config({
14messageFormat: nls.MessageFormat.bundle,
15bundleFormat: nls.BundleFormat.standalone,
16})();
17const localize = nls.loadMessageBundle();
18
19// #todo!> commands should not maintain state
20let elementInspector: child_process.ChildProcess | undefined;
21
22export class RunElementInspector extends Command {
23codeName = "runInspector";
24label = "Run Element Inspector";
25requiresTrust = false;
26requiresProject = false;
27
28error = ErrorHelper.getInternalError(
29InternalErrorCode.CommandFailed,
21e2e2f0Ezio Li1 years ago30"ReactNativeRunElementInspector",
31"React Native: Run Element Inspector",
36a21645Heniker4 years ago32);
33
34async baseFn(): Promise<void> {
35const logger = OutputChannelLogger.getMainChannel();
36
37void TipNotificationService.getInstance().setKnownDateForFeatureById("elementInspector");
38
39if (elementInspector) {
40logger.info(
41localize(
42"AnotherElementInspectorAlreadyRun",
43"Another element inspector already run",
44),
45);
46
47return;
48}
49// Remove the following env variables to prevent running electron app in node mode.
50// https://github.com/microsoft/vscode/issues/3011#issuecomment-184577502
51// eslint-disable-next-line @typescript-eslint/no-unused-vars
52const { ATOM_SHELL_INTERNAL_RUN_AS_NODE, ELECTRON_RUN_AS_NODE, ...env } = process.env;
53const command = HostPlatform.getNpmCliCommand("react-devtools");
54
55elementInspector = child_process.spawn(command, [], {
56env,
77e86943lexie0111 years ago57shell: true,
36a21645Heniker4 years ago58});
59
60if (!elementInspector.pid) {
61elementInspector = undefined;
62throw ErrorHelper.getInternalError(InternalErrorCode.ReactDevtoolsIsNotInstalled);
63}
64
65elementInspector.stdout.on("data", (data: string) => {
66logger.info(data);
67});
68elementInspector.stderr.on("data", (data: string) => {
69logger.error(data);
70});
71elementInspector.once("exit", () => {
72elementInspector = undefined;
73});
74}
75}
76
77export class StopElementInspector extends Command {
78codeName = "stopInspector";
79label = "Stop Element Inspector";
80requiresTrust = false;
81requiresProject = false;
82
83error = ErrorHelper.getInternalError(
84InternalErrorCode.CommandFailed,
21e2e2f0Ezio Li1 years ago85"React Native: Stop Element Inspector",
36a21645Heniker4 years ago86);
87
88async baseFn(): Promise<void> {
89elementInspector?.kill();
90}
91}