microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
improve-test-stability-with-safer-access

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/jsDebugConfigAdapter.ts

107lines · modeblame

1bdccb66RedMickey6 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
43fe950dlexie0111 years ago3import * as semver from "semver";
4import { ProjectVersionHelper } from "../common/projectVersionHelper";
c8ff508eEzio Li1 years ago5import { IAttachRequestArgs } from "./debugSessionBase";
1bdccb66RedMickey6 years ago6
7export class JsDebugConfigAdapter {
43fe950dlexie0111 years ago8private static RNVersion_Direct_Debug = "0.76.0";
34472878RedMickey5 years ago9public static createDebuggingConfigForPureRN(
10attachArgs: IAttachRequestArgs,
11cdpProxyPort: number,
12sessionId: string,
13): any {
1bdccb66RedMickey6 years ago14return Object.assign({}, JsDebugConfigAdapter.getExistingExtraArgs(attachArgs), {
15type: "pwa-node",
16request: "attach",
17name: "Attach",
18continueOnAttach: true,
19port: cdpProxyPort,
20// The unique identifier of the debug session. It is used to distinguish React Native extension's
21// debug sessions from other ones. So we can save and process only the extension's debug sessions
22// in vscode.debug API methods "onDidStartDebugSession" and "onDidTerminateDebugSession".
23rnDebugSessionId: sessionId,
a32e1e1fYuri Skorokhodov5 years ago24// Fixes https://github.com/microsoft/vscode/issues/102042
34472878RedMickey5 years ago25resolveSourceMapLocations: ["!**/debuggerWorker.js"],
1bdccb66RedMickey6 years ago26});
27}
28
43fe950dlexie0111 years ago29public static async createDebuggingConfigForRNHermes(
34472878RedMickey5 years ago30attachArgs: IAttachRequestArgs,
31cdpProxyPort: number,
32sessionId: string,
43fe950dlexie0111 years ago33) {
7ee7914dEzio Li1 years ago34const extraArgs: any = {};
43fe950dlexie0111 years ago35const versions = await ProjectVersionHelper.getReactNativeVersions(attachArgs.cwd);
7ee7914dEzio Li1 years ago36// Handle project file path from 0.76
43fe950dlexie0111 years ago37if (semver.gte(versions.reactNativeVersion, JsDebugConfigAdapter.RNVersion_Direct_Debug)) {
38extraArgs.sourceMapPathOverrides = {
39"/[metro-project]/*": `${attachArgs.cwd}/*`,
40};
41}
7ee7914dEzio Li1 years ago42
dd8d7777Ezio Li1 years ago43// Combine source map path between extra arguments and attach arguments
44if (attachArgs.sourceMapPathOverrides) {
45extraArgs.sourceMapPathOverrides = {
46...extraArgs.sourceMapPathOverrides,
47...attachArgs.sourceMapPathOverrides,
48};
49}
50
7ee7914dEzio Li1 years ago51return Object.assign({}, JsDebugConfigAdapter.getExistingExtraArgs(attachArgs), extraArgs, {
1bdccb66RedMickey6 years ago52type: "pwa-node",
53request: "attach",
54name: "Attach",
55continueOnAttach: true,
56port: cdpProxyPort,
57// The unique identifier of the debug session. It is used to distinguish React Native extension's
58// debug sessions from other ones. So we can save and process only the extension's debug sessions
59// in vscode.debug API methods "onDidStartDebugSession" and "onDidTerminateDebugSession".
60rnDebugSessionId: sessionId,
ccef4e60RedMickey4 years ago61// We need to provide js-debug with the "**" pattern, so that it can get source maps over a http URL.
62// We need to allow "**/node_modules/expo/**" path, since Expo source maps URL contains it.
63resolveSourceMapLocations: ["**", "!**/node_modules/!(expo)/**"],
1bdccb66RedMickey6 years ago64});
65}
66
9f8c460dEzio Li2 years ago67public static createChromeDebuggingConfig(
68attachArgs: IAttachRequestArgs,
69cdpProxyPort: number,
70pwaSessionName: string,
71sessionId: string,
72): any {
73const extraArgs: any = {};
74
75return Object.assign({}, this.getExistingExtraArgs(attachArgs), extraArgs, {
76type: pwaSessionName,
77request: "attach",
78name: "Attach",
79port: cdpProxyPort,
80webRoot: attachArgs.cwd,
81rnDebugSessionId: sessionId,
82});
83}
84
1bdccb66RedMickey6 years ago85private static getExistingExtraArgs(attachArgs: IAttachRequestArgs): any {
09f6024fHeniker4 years ago86const existingExtraArgs: any = {};
1bdccb66RedMickey6 years ago87if (attachArgs.env) {
88existingExtraArgs.env = attachArgs.env;
89}
90if (attachArgs.envFile) {
91existingExtraArgs.envFile = attachArgs.envFile;
92}
4dfc9ffdRedMickey5 years ago93existingExtraArgs.sourceMaps = attachArgs.sourceMaps;
81fc1822JiglioNero4 years ago94existingExtraArgs.sourceMapRenames = attachArgs.sourceMapRenames;
1bdccb66RedMickey6 years ago95if (attachArgs.sourceMapPathOverrides) {
96existingExtraArgs.sourceMapPathOverrides = attachArgs.sourceMapPathOverrides;
97}
98if (attachArgs.skipFiles) {
99existingExtraArgs.skipFiles = attachArgs.skipFiles;
100}
2d89fb47Ezio Li3 years ago101if (attachArgs.jsDebugTrace) {
102existingExtraArgs.trace = attachArgs.jsDebugTrace;
103}
1bdccb66RedMickey6 years ago104
105return existingExtraArgs;
106}
107}