microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
ffdf159274093d12e32a09aafae6d0de3099bb4a

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

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