microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.7.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

127lines · modeblame

299883f9Artem Egorov8 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
7bc455e9Artem Egorov8 years ago4import * as semver from "semver";
4dfc9ffdRedMickey5 years ago5import { 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";
d7d405aeYuri Skorokhodov7 years ago10import { InternalErrorCode } from "../../common/error/internalErrorCode";
cfbe5cc9etatanova5 years ago11import { AppLauncher } from "../appLauncher";
299883f9Artem Egorov8 years ago12
13/**
14* Windows specific platform implementation for debugging RN applications.
15*/
16export class WindowsPlatform extends GeneralMobilePlatform {
7bc455e9Artem Egorov8 years ago17protected static NO_PACKAGER_VERSION = "0.53.0";
299883f9Artem Egorov8 years ago18
34472878RedMickey5 years ago19private static SUCCESS_PATTERNS = ["Starting the app"];
299883f9Artem Egorov8 years ago20private static FAILURE_PATTERNS: PatternToFailure[] = [
21{
22pattern: "Unrecognized command 'run-windows'",
d7d405aeYuri Skorokhodov7 years ago23errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled,
299883f9Artem Egorov8 years ago24},
60ad4ec0JiglioNero5 years ago25{
26pattern: /×.+$/gm,
27errorCode: InternalErrorCode.WinRunCommandFailed,
28},
299883f9Artem Egorov8 years ago29];
30
0d77292aJiglioNero4 years ago31public async reloadApp(appLauncher: AppLauncher): Promise<void> {
cfbe5cc9etatanova5 years ago32const worker = appLauncher.getAppWorker();
33if (worker) {
34worker.reloadAppCommand();
35}
36}
37
299883f9Artem Egorov8 years ago38constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
39super(runOptions, platformDeps);
40}
41
0d77292aJiglioNero4 years ago42public async runApp(enableDebug: boolean = true): Promise<void> {
008d88e5RedMickey4 years ago43let extProps: any = {
031832ffArtem Egorov8 years ago44platform: {
259c018fYuri Skorokhodov5 years ago45value: PlatformType.Windows,
031832ffArtem Egorov8 years ago46isPii: false,
47},
48};
49
008d88e5RedMickey4 years ago50if (this.runOptions.isDirect) {
51extProps.isDirect = {
52value: true,
53isPii: false,
54};
55}
56
34472878RedMickey5 years ago57extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
58this.runOptions,
59this.runOptions.reactNativeVersions,
60extProps,
61);
ba953e9fRedMickey6 years ago62
0d77292aJiglioNero4 years ago63await TelemetryHelper.generate("WindowsPlatform.runApp", extProps, async () => {
34472878RedMickey5 years ago64const env = GeneralMobilePlatform.getEnvArgument(
65process.env,
66this.runOptions.env,
67this.runOptions.envFile,
68);
299883f9Artem Egorov8 years ago69
34472878RedMickey5 years ago70if (
71semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0")
72) {
4dfc9ffdRedMickey5 years ago73this.runArguments.push("--logging");
74if (enableDebug) {
008d88e5RedMickey4 years ago75this.runOptions.isDirect
76? this.runArguments.push("--direct-debugging")
77: this.runArguments.push("--remote-debugging");
4dfc9ffdRedMickey5 years ago78}
299883f9Artem Egorov8 years ago79}
80
34472878RedMickey5 years ago81if (
82!semver.valid(
83this.runOptions.reactNativeVersions.reactNativeVersion,
84) /*Custom RN implementations should support this flag*/ ||
85semver.gte(
86this.runOptions.reactNativeVersions.reactNativeVersion,
87WindowsPlatform.NO_PACKAGER_VERSION,
88)
89) {
7fa90b3bRedMickey6 years ago90this.runArguments.push("--no-packager");
91}
299883f9Artem Egorov8 years ago92
34472878RedMickey5 years ago93const runWindowsSpawn = new CommandExecutor(
4dfb1c4cetatanova5 years ago94this.runOptions.nodeModulesRoot,
34472878RedMickey5 years ago95this.projectPath,
96this.logger,
97).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
0d77292aJiglioNero4 years ago98await new OutputVerifier(
34472878RedMickey5 years ago99() => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS),
100() => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS),
101this.platformName,
102).process(runWindowsSpawn);
299883f9Artem Egorov8 years ago103});
104}
105
ce5e88eeYuri Skorokhodov5 years ago106public prewarmBundleCache(): Promise<void> {
259c018fYuri Skorokhodov5 years ago107return this.packager.prewarmBundleCache(PlatformType.Windows);
299883f9Artem Egorov8 years ago108}
109
cbc7ac5bArtem Egorov7 years ago110public getRunArguments(): string[] {
299883f9Artem Egorov8 years ago111let runArguments: string[] = [];
112
4dfc9ffdRedMickey5 years ago113if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
299883f9Artem Egorov8 years ago114runArguments.push(...this.runOptions.runArguments);
115} else {
34472878RedMickey5 years ago116let target =
117this.runOptions.target === WindowsPlatform.simulatorString
118? ""
119: this.runOptions.target;
dd90a856Artem Egorov8 years ago120if (target) {
121runArguments.push(`--${target}`);
299883f9Artem Egorov8 years ago122}
123}
124
125return runArguments;
126}
127}