microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.8.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

127lines · 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 * as semver from "semver";
5import { GeneralPlatform, MobilePlatformDeps, TargetType } from "../generalPlatform";
6import { IWindowsRunOptions, PlatformType } from "../launchArgs";
7import { OutputVerifier, PatternToFailure } from "../../common/outputVerifier";
8import { TelemetryHelper } from "../../common/telemetryHelper";
9import { CommandExecutor } from "../../common/commandExecutor";
10import { InternalErrorCode } from "../../common/error/internalErrorCode";
11import { AppLauncher } from "../appLauncher";
12
13/**
14 * Windows specific platform implementation for debugging RN applications.
15 */
16export class WindowsPlatform extends GeneralPlatform {
17 protected static NO_PACKAGER_VERSION = "0.53.0";
18
19 private static SUCCESS_PATTERNS = ["Starting the app"];
20 private static FAILURE_PATTERNS: PatternToFailure[] = [
21 {
22 pattern: "Unrecognized command 'run-windows'",
23 errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled,
24 },
25 {
26 pattern: /×.+$/gm,
27 errorCode: InternalErrorCode.WinRunCommandFailed,
28 },
29 ];
30
31 public async reloadApp(appLauncher: AppLauncher): Promise<void> {
32 const worker = appLauncher.getAppWorker();
33 if (worker) {
34 worker.reloadAppCommand();
35 }
36 }
37
38 constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
39 super(runOptions, platformDeps);
40 }
41
42 public async runApp(enableDebug: boolean = true): Promise<void> {
43 let extProps: any = {
44 platform: {
45 value: PlatformType.Windows,
46 isPii: false,
47 },
48 };
49
50 this.projectObserver?.updateRNWindowsProjectState(true);
51 if (this.runOptions.isDirect) {
52 extProps.isDirect = {
53 value: true,
54 isPii: false,
55 };
56 this.projectObserver?.updateRNWindowsHermesProjectState(true);
57 }
58
59 extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
60 this.runOptions,
61 this.runOptions.reactNativeVersions,
62 extProps,
63 );
64
65 await TelemetryHelper.generate("WindowsPlatform.runApp", extProps, async () => {
66 const env = GeneralPlatform.getEnvArgument(
67 process.env,
68 this.runOptions.env,
69 this.runOptions.envFile,
70 );
71
72 if (
73 semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0")
74 ) {
75 this.runArguments.push("--logging");
76 if (enableDebug) {
77 this.runOptions.isDirect
78 ? this.runArguments.push("--direct-debugging")
79 : this.runArguments.push("--remote-debugging");
80 }
81 }
82
83 if (
84 !semver.valid(
85 this.runOptions.reactNativeVersions.reactNativeVersion,
86 ) /*Custom RN implementations should support this flag*/ ||
87 semver.gte(
88 this.runOptions.reactNativeVersions.reactNativeVersion,
89 WindowsPlatform.NO_PACKAGER_VERSION,
90 )
91 ) {
92 this.runArguments.push("--no-packager");
93 }
94
95 const runWindowsSpawn = new CommandExecutor(
96 this.runOptions.nodeModulesRoot,
97 this.projectPath,
98 this.logger,
99 ).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
100 await new OutputVerifier(
101 () => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS),
102 () => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS),
103 this.platformName,
104 ).process(runWindowsSpawn);
105 });
106 }
107
108 public prewarmBundleCache(): Promise<void> {
109 return this.packager.prewarmBundleCache(PlatformType.Windows);
110 }
111
112 public getRunArguments(): string[] {
113 let runArguments: string[] = [];
114
115 if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
116 runArguments.push(...this.runOptions.runArguments);
117 } else {
118 let target =
119 this.runOptions.target === TargetType.Simulator ? "" : this.runOptions.target;
120 if (target) {
121 runArguments.push(`--${target}`);
122 }
123 }
124
125 return runArguments;
126 }
127}
128