microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

105lines · 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";
11
12/**
13 * Windows specific platform implementation for debugging RN applications.
14 */
15export class WindowsPlatform extends GeneralMobilePlatform {
16 protected static NO_PACKAGER_VERSION = "0.53.0";
17
18 private static SUCCESS_PATTERNS = ["Starting the app"];
19 private static FAILURE_PATTERNS: PatternToFailure[] = [
20 {
21 pattern: "Unrecognized command 'run-windows'",
22 errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled,
23 },
24 ];
25
26 constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
27 super(runOptions, platformDeps);
28 }
29
30 public runApp(enableDebug: boolean = true): Promise<void> {
31 let extProps = {
32 platform: {
33 value: PlatformType.Windows,
34 isPii: false,
35 },
36 };
37
38 extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
39 this.runOptions,
40 this.runOptions.reactNativeVersions,
41 extProps,
42 );
43
44 return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => {
45 const env = GeneralMobilePlatform.getEnvArgument(
46 process.env,
47 this.runOptions.env,
48 this.runOptions.envFile,
49 );
50
51 if (
52 semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0")
53 ) {
54 this.runArguments.push("--logging");
55 if (enableDebug) {
56 this.runArguments.push("--remote-debugging");
57 }
58 }
59
60 if (
61 !semver.valid(
62 this.runOptions.reactNativeVersions.reactNativeVersion,
63 ) /*Custom RN implementations should support this flag*/ ||
64 semver.gte(
65 this.runOptions.reactNativeVersions.reactNativeVersion,
66 WindowsPlatform.NO_PACKAGER_VERSION,
67 )
68 ) {
69 this.runArguments.push("--no-packager");
70 }
71
72 const runWindowsSpawn = new CommandExecutor(
73 this.projectPath,
74 this.logger,
75 ).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
76 return new OutputVerifier(
77 () => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS),
78 () => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS),
79 this.platformName,
80 ).process(runWindowsSpawn);
81 });
82 }
83
84 public prewarmBundleCache(): Promise<void> {
85 return this.packager.prewarmBundleCache(PlatformType.Windows);
86 }
87
88 public getRunArguments(): string[] {
89 let runArguments: string[] = [];
90
91 if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
92 runArguments.push(...this.runOptions.runArguments);
93 } else {
94 let target =
95 this.runOptions.target === WindowsPlatform.simulatorString
96 ? ""
97 : this.runOptions.target;
98 if (target) {
99 runArguments.push(`--${target}`);
100 }
101 }
102
103 return runArguments;
104 }
105}
106