microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0ef10fee89118882890a01b2d4ff7fbae1405e11

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/launcher.ts

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