microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/debugger/jsDebugConfigAdapter.ts
107lines · modeblame
1bdccb66RedMickey6 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
43fe950dlexie0111 years ago | 3 | import * as semver from "semver"; |
| 4 | import { ProjectVersionHelper } from "../common/projectVersionHelper"; | |
c8ff508eEzio Li1 years ago | 5 | import { IAttachRequestArgs } from "./debugSessionBase"; |
1bdccb66RedMickey6 years ago | 6 | |
| 7 | export class JsDebugConfigAdapter { | |
43fe950dlexie0111 years ago | 8 | private static RNVersion_Direct_Debug = "0.76.0"; |
34472878RedMickey5 years ago | 9 | public static createDebuggingConfigForPureRN( |
| 10 | attachArgs: IAttachRequestArgs, | |
| 11 | cdpProxyPort: number, | |
| 12 | sessionId: string, | |
| 13 | ): any { | |
1bdccb66RedMickey6 years ago | 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, | |
a32e1e1fYuri Skorokhodov5 years ago | 24 | // Fixes https://github.com/microsoft/vscode/issues/102042 |
34472878RedMickey5 years ago | 25 | resolveSourceMapLocations: ["!**/debuggerWorker.js"], |
1bdccb66RedMickey6 years ago | 26 | }); |
| 27 | } | |
| 28 | | |
43fe950dlexie0111 years ago | 29 | public static async createDebuggingConfigForRNHermes( |
34472878RedMickey5 years ago | 30 | attachArgs: IAttachRequestArgs, |
| 31 | cdpProxyPort: number, | |
| 32 | sessionId: string, | |
43fe950dlexie0111 years ago | 33 | ) { |
7ee7914dEzio Li1 years ago | 34 | const extraArgs: any = {}; |
43fe950dlexie0111 years ago | 35 | const versions = await ProjectVersionHelper.getReactNativeVersions(attachArgs.cwd); |
7ee7914dEzio Li1 years ago | 36 | // Handle project file path from 0.76 |
43fe950dlexie0111 years ago | 37 | if (semver.gte(versions.reactNativeVersion, JsDebugConfigAdapter.RNVersion_Direct_Debug)) { |
| 38 | extraArgs.sourceMapPathOverrides = { | |
| 39 | "/[metro-project]/*": `${attachArgs.cwd}/*`, | |
| 40 | }; | |
| 41 | } | |
7ee7914dEzio Li1 years ago | 42 | |
dd8d7777Ezio Li1 years ago | 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 | | |
7ee7914dEzio Li1 years ago | 51 | return Object.assign({}, JsDebugConfigAdapter.getExistingExtraArgs(attachArgs), extraArgs, { |
1bdccb66RedMickey6 years ago | 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, | |
ccef4e60RedMickey4 years ago | 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)/**"], | |
1bdccb66RedMickey6 years ago | 64 | }); |
| 65 | } | |
| 66 | | |
9f8c460dEzio Li2 years ago | 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 | | |
1bdccb66RedMickey6 years ago | 85 | private static getExistingExtraArgs(attachArgs: IAttachRequestArgs): any { |
09f6024fHeniker4 years ago | 86 | const existingExtraArgs: any = {}; |
1bdccb66RedMickey6 years ago | 87 | if (attachArgs.env) { |
| 88 | existingExtraArgs.env = attachArgs.env; | |
| 89 | } | |
| 90 | if (attachArgs.envFile) { | |
| 91 | existingExtraArgs.envFile = attachArgs.envFile; | |
| 92 | } | |
4dfc9ffdRedMickey5 years ago | 93 | existingExtraArgs.sourceMaps = attachArgs.sourceMaps; |
81fc1822JiglioNero4 years ago | 94 | existingExtraArgs.sourceMapRenames = attachArgs.sourceMapRenames; |
1bdccb66RedMickey6 years ago | 95 | if (attachArgs.sourceMapPathOverrides) { |
| 96 | existingExtraArgs.sourceMapPathOverrides = attachArgs.sourceMapPathOverrides; | |
| 97 | } | |
| 98 | if (attachArgs.skipFiles) { | |
| 99 | existingExtraArgs.skipFiles = attachArgs.skipFiles; | |
| 100 | } | |
2d89fb47Ezio Li3 years ago | 101 | if (attachArgs.jsDebugTrace) { |
| 102 | existingExtraArgs.trace = attachArgs.jsDebugTrace; | |
| 103 | } | |
1bdccb66RedMickey6 years ago | 104 | |
| 105 | return existingExtraArgs; | |
| 106 | } | |
| 107 | } |