microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
connor/ts7-beta-compat-tracking

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/jsDebugConfigAdapter.ts

107lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3import * as semver from "semver";
4import { ProjectVersionHelper } from "../common/projectVersionHelper";
5import { IAttachRequestArgs } from "./debugSessionBase";
6
7export class JsDebugConfigAdapter {
8 private static RNVersion_Direct_Debug = "0.76.0";
9 public static createDebuggingConfigForPureRN(
10 attachArgs: IAttachRequestArgs,
11 cdpProxyPort: number,
12 sessionId: string,
13 ): any {
14 return Object.assign({}, JsDebugConfigAdapter.getExistingExtraArgs(attachArgs), {
15 type: "pwa-node",
16 request: "attach",
17 name: "Attach",
18 continueOnAttach: true,
19 port: 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".
23 rnDebugSessionId: sessionId,
24 // Fixes https://github.com/microsoft/vscode/issues/102042
25 resolveSourceMapLocations: ["!**/debuggerWorker.js"],
26 });
27 }
28
29 public static async createDebuggingConfigForRNHermes(
30 attachArgs: IAttachRequestArgs,
31 cdpProxyPort: number,
32 sessionId: string,
33 ) {
34 const extraArgs: any = {};
35 const versions = await ProjectVersionHelper.getReactNativeVersions(attachArgs.cwd);
36 // Handle project file path from 0.76
37 if (semver.gte(versions.reactNativeVersion, JsDebugConfigAdapter.RNVersion_Direct_Debug)) {
38 extraArgs.sourceMapPathOverrides = {
39 "/[metro-project]/*": `${attachArgs.cwd}/*`,
40 };
41 }
42
43 // Combine source map path between extra arguments and attach arguments
44 if (attachArgs.sourceMapPathOverrides) {
45 extraArgs.sourceMapPathOverrides = {
46 ...extraArgs.sourceMapPathOverrides,
47 ...attachArgs.sourceMapPathOverrides,
48 };
49 }
50
51 return Object.assign({}, JsDebugConfigAdapter.getExistingExtraArgs(attachArgs), extraArgs, {
52 type: "pwa-node",
53 request: "attach",
54 name: "Attach",
55 continueOnAttach: true,
56 port: 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".
60 rnDebugSessionId: sessionId,
61 // 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.
63 resolveSourceMapLocations: ["**", "!**/node_modules/!(expo)/**"],
64 });
65 }
66
67 public static createChromeDebuggingConfig(
68 attachArgs: IAttachRequestArgs,
69 cdpProxyPort: number,
70 pwaSessionName: string,
71 sessionId: string,
72 ): any {
73 const extraArgs: any = {};
74
75 return Object.assign({}, this.getExistingExtraArgs(attachArgs), extraArgs, {
76 type: pwaSessionName,
77 request: "attach",
78 name: "Attach",
79 port: cdpProxyPort,
80 webRoot: attachArgs.cwd,
81 rnDebugSessionId: sessionId,
82 });
83 }
84
85 private static getExistingExtraArgs(attachArgs: IAttachRequestArgs): any {
86 const existingExtraArgs: any = {};
87 if (attachArgs.env) {
88 existingExtraArgs.env = attachArgs.env;
89 }
90 if (attachArgs.envFile) {
91 existingExtraArgs.envFile = attachArgs.envFile;
92 }
93 existingExtraArgs.sourceMaps = attachArgs.sourceMaps;
94 existingExtraArgs.sourceMapRenames = attachArgs.sourceMapRenames;
95 if (attachArgs.sourceMapPathOverrides) {
96 existingExtraArgs.sourceMapPathOverrides = attachArgs.sourceMapPathOverrides;
97 }
98 if (attachArgs.skipFiles) {
99 existingExtraArgs.skipFiles = attachArgs.skipFiles;
100 }
101 if (attachArgs.jsDebugTrace) {
102 existingExtraArgs.trace = attachArgs.jsDebugTrace;
103 }
104
105 return existingExtraArgs;
106 }
107}
108