microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1ca47c7c2d73a604d8f110cdbad1aad4bbdddce6

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/reactNativeDebugEntryPoint.ts

86lines · modeblame

40e4b177Patricio Beltran10 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 fs from "fs";
5import * as path from "path";
6
b8999098Dmitry Zinovyev9 years ago7import { TelemetryHelper } from "../common/telemetryHelper";
8import { EntryPointHandler, ProcessType } from "../common/entryPointHandler";
9import { ErrorHelper } from "../common/error/errorHelper";
10import { InternalErrorCode } from "../common/error/internalErrorCode";
11import { NullTelemetryReporter, ReassignableTelemetryReporter } from "../common/telemetryReporters";
e45838cbVladimir Kotikov9 years ago12import { makeAdapter, makeSession } from "./nodeDebugWrapper";
40e4b177Patricio Beltran10 years ago13
14const version = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "..", "package.json"), "utf-8")).version;
15const telemetryReporter = new ReassignableTelemetryReporter(new NullTelemetryReporter());
e45838cbVladimir Kotikov9 years ago16const extensionName = "react-native-debug-adapter";
40e4b177Patricio Beltran10 years ago17
18function bailOut(reason: string): void {
19// Things have gone wrong in initialization: Report the error to telemetry and exit
20TelemetryHelper.sendSimpleEvent(reason);
21process.exit(1);
22}
23
b8999098Dmitry Zinovyev9 years ago24function codeToRun() {
25
26/**
27* For debugging React Native we basically want to debug node plus some other stuff.
28* There is no need to create a new adapter for node because ther already exists one.
29* We look for node debug adapter on client's computer so we can jump of on top of that.
30*/
31let nodeDebugFolder: string;
32let VSCodeDebugAdapter: typeof VSCodeDebugAdapterPackage;
33let Node2DebugAdapter: typeof Node2DebugAdapterPackage.Node2DebugAdapter;
34let ChromeDebuggerPackage: typeof ChromeDebuggerCorePackage;
40e4b177Patricio Beltran10 years ago35
b8999098Dmitry Zinovyev9 years ago36// nodeDebugLocation.json is dynamically generated on extension activation.
37// If it fails, we must not have been in a react native project
38try {
39/* tslint:disable:no-var-requires */
40nodeDebugFolder = require("./nodeDebugLocation.json").nodeDebugPath;
41VSCodeDebugAdapter = require(path.join(nodeDebugFolder, "node_modules/vscode-debugadapter"));
42ChromeDebuggerPackage = require(path.join(nodeDebugFolder, "node_modules/vscode-chrome-debug-core"));
43Node2DebugAdapter = require(path.join(nodeDebugFolder, "out/src/nodeDebugAdapter")).NodeDebugAdapter;
44/* tslint:enable:no-var-requires */
40e4b177Patricio Beltran10 years ago45
5c8365a6Artem Egorov8 years ago46/**
47* We did find chrome debugger package and node2 debug adapter. Lets create debug
48* session and adapter with our customizations.
49*/
50let session: typeof ChromeDebuggerCorePackage.ChromeDebugSession;
51let adapter: typeof Node2DebugAdapterPackage.Node2DebugAdapter;
40e4b177Patricio Beltran10 years ago52
5c8365a6Artem Egorov8 years ago53try {
54/* Create customised react-native debug adapter based on Node-debug2 adapter */
55adapter = makeAdapter(Node2DebugAdapter);
56// Create a debug session class based on ChromeDebugSession
57session = makeSession(ChromeDebuggerPackage.ChromeDebugSession,
58{ adapter, extensionName }, VSCodeDebugAdapter, telemetryReporter, extensionName, version);
59
60// Run the debug session for the node debug adapter with our modified requests
61ChromeDebuggerPackage.ChromeDebugSession.run(session);
62} catch (e) {
63const debugSession = new VSCodeDebugAdapter.DebugSession();
64// Start session before sending any events otherwise the client wouldn't receive them
65debugSession.start(process.stdin, process.stdout);
66debugSession.sendEvent(new VSCodeDebugAdapter.OutputEvent("Unable to start debug adapter: " + e.toString(), "stderr"));
67debugSession.sendEvent(new VSCodeDebugAdapter.TerminatedEvent());
68bailOut(e.toString());
69}
b8999098Dmitry Zinovyev9 years ago70} catch (e) {
5c8365a6Artem Egorov8 years ago71// Nothing we can do here: can't even communicate back because we don't know how to speak debug adapter
72bailOut("cannotFindDebugAdapter");
b8999098Dmitry Zinovyev9 years ago73}
40e4b177Patricio Beltran10 years ago74
b8999098Dmitry Zinovyev9 years ago75}
40e4b177Patricio Beltran10 years ago76
b8999098Dmitry Zinovyev9 years ago77// Enable telemetry
78const entryPointHandler = new EntryPointHandler(ProcessType.Debugger);
79entryPointHandler.runApp(
80extensionName,
81() => version,
82ErrorHelper.getInternalError(InternalErrorCode.DebuggingFailed),
83telemetryReporter,
84codeToRun
85);
e45838cbVladimir Kotikov9 years ago86