microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
10136ee86a53d80ade52ebf07175f4acbed01d7f

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

84lines · 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 Q from "q";
5import * as semver from "semver";
6
7import {GeneralMobilePlatform, MobilePlatformDeps} from "../generalMobilePlatform";
8import {IWindowsRunOptions} from "../launchArgs";
9import {OutputVerifier, PatternToFailure} from "../../common/outputVerifier";
10import {TelemetryHelper} from "../../common/telemetryHelper";
11import {CommandExecutor} from "../../common/commandExecutor";
12import {ReactNativeProjectHelper} from "../../common/reactNativeProjectHelper";
13import { InternalErrorCode } from "../../common/error/internalErrorCode";
14
15/**
16 * Windows specific platform implementation for debugging RN applications.
17 */
18export class WindowsPlatform extends GeneralMobilePlatform {
19 protected static NO_PACKAGER_VERSION = "0.53.0";
20
21 private static SUCCESS_PATTERNS = [
22 "Installing new version of the app",
23 "Starting the app",
24 ];
25 private static FAILURE_PATTERNS: PatternToFailure[] = [
26 {
27 pattern: "Unrecognized command 'run-windows'",
28 errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled,
29 },
30 ];
31
32 constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
33 super(runOptions, platformDeps);
34 }
35
36 public runApp(enableDebug: boolean = true): Q.Promise<void> {
37 let extProps = {
38 platform: {
39 value: "windows",
40 isPii: false,
41 },
42 };
43
44 extProps = TelemetryHelper.addReactNativeVersionToEventProperties(this.runOptions.reactNativeVersion, extProps);
45
46 return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => {
47 const env = this.getEnvArgument();
48
49 if (enableDebug) {
50 this.runArguments.push("--proxy");
51 }
52
53 return ReactNativeProjectHelper.getReactNativeVersion(this.runOptions.projectRoot)
54 .then(version => {
55 if (!semver.valid(version) /*Custom RN implementations should support this flag*/ || semver.gte(version, WindowsPlatform.NO_PACKAGER_VERSION)) {
56 this.runArguments.push("--no-packager");
57 }
58
59 const runWindowsSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env});
60 return new OutputVerifier(() => Q(WindowsPlatform.SUCCESS_PATTERNS), () => Q(WindowsPlatform.FAILURE_PATTERNS), this.platformName)
61 .process(runWindowsSpawn);
62 });
63 });
64 }
65
66 public prewarmBundleCache(): Q.Promise<void> {
67 return this.packager.prewarmBundleCache("windows");
68 }
69
70 public getRunArguments(): string[] {
71 let runArguments: string[] = [];
72
73 if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
74 runArguments.push(...this.runOptions.runArguments);
75 } else {
76 let target = this.runOptions.target === WindowsPlatform.simulatorString ? "" : this.runOptions.target;
77 if (target) {
78 runArguments.push(`--${target}`);
79 }
80 }
81
82 return runArguments;
83 }
84}
85