microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.5.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

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