microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
d55f3c22ee18a37c605867c8bf588451292bd24e

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

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