microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev/v-peq/removeNode10TodoComments

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

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