microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
f6dca75c1463707cce152dc4b8529e9e2072720e

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/launcher.ts

68lines · 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 path from "path";
5import {MultipleLifetimesAppWorker} from "./appWorker";
6import {Packager} from "../common/packager";
7import {Log} from "../common/log";
8import {PlatformResolver} from "./platformResolver";
9import {TelemetryHelper} from "../common/telemetryHelper";
10import {IRunOptions} from "./launchArgs";
11
12export class Launcher {
13 private projectRootPath: string;
14
15 constructor(projectRootPath: string) {
16 this.projectRootPath = projectRootPath;
17 }
18
19 public launch() {
20 let resolver = new PlatformResolver();
21 let runOptions = this.parseRunOptions();
22 let mobilePlatform = resolver.resolveMobilePlatform(runOptions.platform);
23 if (!mobilePlatform) {
24 Log.logError("The target platform could not be read. Did you forget to add it to the launch.json configuration arguments?");
25 } else {
26 TelemetryHelper.generate("launch", (generator) => {
27 let sourcesStoragePath = path.join(this.projectRootPath, ".vscode", ".react");
28 let packager = new Packager(this.projectRootPath, sourcesStoragePath);
29 return packager.start()
30 // We've seen that if we don't prewarm the bundle cache, the app fails on the first attempt to connect to the debugger logic
31 // and the user needs to Reload JS manually. We prewarm it to prevent that issue
32 .then(() => {
33 generator.step("prewarmBundleCache");
34 packager.prewarmBundleCache(runOptions.platform);
35 })
36 .then(() => {
37 generator.step("mobilePlatform.runApp");
38 mobilePlatform.runApp(runOptions);
39 })
40 .then(() => {
41 generator.step("Starting App Worker");
42 new MultipleLifetimesAppWorker(sourcesStoragePath, runOptions.debugAdapterPort).start();
43 }) // Start the app worker
44 .then(() => {
45 generator.step("mobilePlatform.enableJSDebuggingMode");
46 mobilePlatform.enableJSDebuggingMode(runOptions);
47 });
48 }).done(() => { }, reason => {
49 Log.logError("Cannot debug application.", reason);
50 });
51 }
52 }
53
54 /**
55 * Parses the launch arguments set in the launch configuration.
56 */
57 private parseRunOptions(): IRunOptions {
58 let result: IRunOptions = { projectRoot: this.projectRootPath };
59 // We expect our debugAdapter to pass in arguments as [platform, debugAdapterPort, target?];
60
61 result.platform = process.argv[2].toLowerCase();
62 result.debugAdapterPort = parseInt(process.argv[3], 10) || 9090;
63 result.target = process.argv[4];
64
65 return result;
66 }
67}
68
69