microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
70f7cae4a697f9868d22dfdd08089a2cd2076772

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/launcher.ts

53lines · modecode

1// 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 fs from "fs";
5import * as path from "path";
6
7import {MultipleLifetimesAppWorker} from "./appWorker";
8import {ErrorHelper} from "../common/error/errorHelper";
9import {InternalErrorCode} from "../common/error/internalErrorCode";
10import {ScriptImporter} from "./scriptImporter";
11import {TelemetryHelper} from "../common/telemetryHelper";
12import {Log} from "../common/log/log";
13import {RemoteExtension} from "../common/remoteExtension";
14import {EntryPointHandler, ProcessType} from "../common/entryPointHandler";
15
16export class Launcher {
17 private workspaceRootPath: string;
18 private projectRootPath: string;
19 private remoteExtension: RemoteExtension;
20
21 constructor(workspaceRootPath: string, projectRootPath: string) {
22 this.workspaceRootPath = workspaceRootPath;
23 this.projectRootPath = projectRootPath;
24 this.remoteExtension = RemoteExtension.atProjectRootPath(this.projectRootPath);
25 }
26
27 public launch(): void {
28 const debugAdapterPort = parseInt(process.argv[2], 10) || 9090;
29 // Enable telemetry
30 new EntryPointHandler(ProcessType.Debugee).runApp("react-native-debug-process", () => this.getAppVersion(),
31 ErrorHelper.getInternalError(InternalErrorCode.DebuggingFailed), this.projectRootPath, () => {
32 return TelemetryHelper.generate("launch", (generator) => {
33 const sourcesStoragePath = path.join(this.workspaceRootPath, ".vscode", ".react");
34 return this.remoteExtension.getPackagerPort().then(packagerPort => {
35 let scriptImporter = new ScriptImporter(packagerPort, sourcesStoragePath);
36 return scriptImporter.downloadDebuggerWorker(sourcesStoragePath).then(() => {
37 Log.logMessage("Downloaded debuggerWorker.js (Logic to run the React Native app) from the Packager.");
38 }).then(() => {
39 generator.step("Starting App Worker");
40 Log.logMessage("Starting debugger app worker.");
41 return new MultipleLifetimesAppWorker(packagerPort, sourcesStoragePath, debugAdapterPort).start();
42 }).then(() =>
43 Log.logMessage("Debugging session started successfully."));
44 });
45 });
46 }
47 );
48 }
49
50 private getAppVersion() {
51 return JSON.parse(fs.readFileSync(path.join(__dirname, "..", "..", "package.json"), "utf-8")).version;
52 }
53}
54