microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.1.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

80lines · 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.addPlatformPropertiesToTelemetryProperties(this.runOptions, this.runOptions.reactNativeVersions, extProps);
41
42 return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => {
43 const env = GeneralMobilePlatform.getEnvArgument(process.env, this.runOptions.env, this.runOptions.envFile);
44
45 if (semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0")) {
46 this.runArguments.push("--logging");
47 if (enableDebug) {
48 this.runArguments.push("--remote-debugging");
49 }
50 }
51
52 if (!semver.valid(this.runOptions.reactNativeVersions.reactNativeVersion) /*Custom RN implementations should support this flag*/ || semver.gte(this.runOptions.reactNativeVersions.reactNativeVersion, WindowsPlatform.NO_PACKAGER_VERSION)) {
53 this.runArguments.push("--no-packager");
54 }
55
56 const runWindowsSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
57 return new OutputVerifier(() => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS), () => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS), this.platformName)
58 .process(runWindowsSpawn);
59 });
60 }
61
62 public prewarmBundleCache(): Promise<void> {
63 return this.packager.prewarmBundleCache(PlatformType.Windows);
64 }
65
66 public getRunArguments(): string[] {
67 let runArguments: string[] = [];
68
69 if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
70 runArguments.push(...this.runOptions.runArguments);
71 } else {
72 let target = this.runOptions.target === WindowsPlatform.simulatorString ? "" : this.runOptions.target;
73 if (target) {
74 runArguments.push(`--${target}`);
75 }
76 }
77
78 return runArguments;
79 }
80}
81