microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
892f0aa6d2f90a4b52e551b6b4c8270ed6b96e83

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

128lines · 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 { GeneralMobilePlatform, MobilePlatformDeps } from "../generalMobilePlatform";
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 GeneralMobilePlatform {
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 reloadApp(appLauncher: AppLauncher): Promise<void> {
32 const worker = appLauncher.getAppWorker();
33 if (worker) {
34 worker.reloadAppCommand();
35 }
36 return Promise.resolve();
37 }
38
39 constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
40 super(runOptions, platformDeps);
41 }
42
43 public runApp(enableDebug: boolean = true): Promise<void> {
44 let extProps: any = {
45 platform: {
46 value: PlatformType.Windows,
47 isPii: false,
48 },
49 };
50
51 if (this.runOptions.isDirect) {
52 extProps.isDirect = {
53 value: true,
54 isPii: false,
55 };
56 }
57
58 extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
59 this.runOptions,
60 this.runOptions.reactNativeVersions,
61 extProps,
62 );
63
64 return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => {
65 const env = GeneralMobilePlatform.getEnvArgument(
66 process.env,
67 this.runOptions.env,
68 this.runOptions.envFile,
69 );
70
71 if (
72 semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0")
73 ) {
74 this.runArguments.push("--logging");
75 if (enableDebug) {
76 this.runOptions.isDirect
77 ? this.runArguments.push("--direct-debugging")
78 : this.runArguments.push("--remote-debugging");
79 }
80 }
81
82 if (
83 !semver.valid(
84 this.runOptions.reactNativeVersions.reactNativeVersion,
85 ) /*Custom RN implementations should support this flag*/ ||
86 semver.gte(
87 this.runOptions.reactNativeVersions.reactNativeVersion,
88 WindowsPlatform.NO_PACKAGER_VERSION,
89 )
90 ) {
91 this.runArguments.push("--no-packager");
92 }
93
94 const runWindowsSpawn = new CommandExecutor(
95 this.runOptions.nodeModulesRoot,
96 this.projectPath,
97 this.logger,
98 ).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
99 return new OutputVerifier(
100 () => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS),
101 () => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS),
102 this.platformName,
103 ).process(runWindowsSpawn);
104 });
105 }
106
107 public prewarmBundleCache(): Promise<void> {
108 return this.packager.prewarmBundleCache(PlatformType.Windows);
109 }
110
111 public getRunArguments(): string[] {
112 let runArguments: string[] = [];
113
114 if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
115 runArguments.push(...this.runOptions.runArguments);
116 } else {
117 let target =
118 this.runOptions.target === WindowsPlatform.simulatorString
119 ? ""
120 : this.runOptions.target;
121 if (target) {
122 runArguments.push(`--${target}`);
123 }
124 }
125
126 return runArguments;
127 }
128}
129