microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev/v-peq/add-expo-packager-command-tests

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/configurationProviders/debugConfigProvider.ts

135lines · 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 { MultiStepInput, InputStep } from "../multiStepInput";
5import {
6 DebugConfigurationState,
7 platformTypeDebugPickConfig,
8 DEBUG_TYPES,
9 DebugScenarioType,
10} from "../debugConfigTypesAndConstants";
11import { PlatformType } from "../../launchArgs";
12import { ILaunchRequestArgs } from "../../../debugger/debugSessionBase";
13import { BaseConfigProvider } from "./baseConfigProvider";
14
15export class DebugConfigProvider extends BaseConfigProvider {
16 constructor() {
17 super();
18 this.maxStepCount = 2;
19 }
20
21 public async buildConfiguration(
22 input: MultiStepInput<DebugConfigurationState>,
23 state: DebugConfigurationState,
24 ): Promise<InputStep<DebugConfigurationState> | void> {
25 state.config = {};
26 const config: Partial<ILaunchRequestArgs> = {
27 name: "Debug application",
28 request: "launch",
29 type: DEBUG_TYPES.REACT_NATIVE,
30 cwd: "${workspaceFolder}",
31 };
32
33 state.scenarioType = DebugScenarioType.DebugApp;
34
35 await this.configurationProviderHelper.selectPlatform(
36 input,
37 config,
38 platformTypeDebugPickConfig,
39 1,
40 this.maxStepCount,
41 );
42
43 Object.assign(state.config, config);
44
45 if (
46 state.config.platform !== PlatformType.Exponent &&
47 state.config.platform !== PlatformType.ExpoWeb
48 ) {
49 return async () => {
50 await this.configureApplicationType(input, state.config);
51 if (
52 state.config.platform === PlatformType.iOS &&
53 state.config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT
54 ) {
55 this.maxStepCount = 3;
56 await this.configureUseHermesEngine(input, state.config);
57 // Direct iOS debugging using ios-webkit-debug-proxy is supported
58 // only with applications running on the device
59 if (state.config.useHermesEngine === false) {
60 state.config.target = "device";
61 }
62 }
63 };
64 } else if (state.config.platform === PlatformType.Exponent) {
65 return async () => {
66 await this.configureApplicationType(input, state.config);
67 if (state.config.type === "reactnativedirect") {
68 await this.configureExpoPlatform(input, state.config);
69 }
70 await this.configureExpoHostType(input, state.config);
71 };
72 } else if (state.config.platform === PlatformType.ExpoWeb) {
73 return async () => {
74 await this.configureBrowserTarget(input, state.config);
75 await this.configureApplicationType(input, state.config);
76 state.config.url = "http://localhost:8081";
77 };
78 }
79 return;
80 }
81
82 private async configureApplicationType(
83 input: MultiStepInput<DebugConfigurationState>,
84 config: Partial<ILaunchRequestArgs>,
85 ): Promise<InputStep<DebugConfigurationState> | void> {
86 await this.configurationProviderHelper.selectApplicationType(
87 input,
88 config,
89 2,
90 this.maxStepCount,
91 );
92 }
93
94 private async configureExpoHostType(
95 input: MultiStepInput<DebugConfigurationState>,
96 config: Partial<ILaunchRequestArgs>,
97 ): Promise<InputStep<DebugConfigurationState> | void> {
98 await this.configurationProviderHelper.selectExpoHostType(input, config, 4, 4);
99 }
100
101 private async configureExpoPlatform(
102 input: MultiStepInput<DebugConfigurationState>,
103 config: Partial<ILaunchRequestArgs>,
104 ): Promise<InputStep<DebugConfigurationState> | void> {
105 await this.configurationProviderHelper.selectExpoPlatform(input, config, 3, 4);
106 }
107
108 private async configureUseHermesEngine(
109 input: MultiStepInput<DebugConfigurationState>,
110 config: Partial<ILaunchRequestArgs>,
111 ): Promise<InputStep<DebugConfigurationState> | void> {
112 delete config.useHermesEngine;
113 await this.configurationProviderHelper.shouldUseHermesEngine(
114 input,
115 config,
116 3,
117 this.maxStepCount,
118 );
119 if (config.useHermesEngine) {
120 delete config.useHermesEngine;
121 }
122 }
123
124 private async configureBrowserTarget(
125 input: MultiStepInput<DebugConfigurationState>,
126 config: Partial<ILaunchRequestArgs>,
127 ): Promise<InputStep<DebugConfigurationState> | void> {
128 await this.configurationProviderHelper.selectBrowserTarget(
129 input,
130 config,
131 4,
132 this.maxStepCount,
133 );
134 }
135}
136