microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.6.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

128lines · 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
cfbe5cc9etatanova5 years ago31public reloadApp(appLauncher: AppLauncher): Promise<void> {
32const worker = appLauncher.getAppWorker();
33if (worker) {
34worker.reloadAppCommand();
35}
36return Promise.resolve();
37}
38
299883f9Artem Egorov8 years ago39constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
40super(runOptions, platformDeps);
41}
42
ce5e88eeYuri Skorokhodov6 years ago43public runApp(enableDebug: boolean = true): Promise<void> {
008d88e5RedMickey5 years ago44let extProps: any = {
031832ffArtem Egorov8 years ago45platform: {
259c018fYuri Skorokhodov5 years ago46value: PlatformType.Windows,
031832ffArtem Egorov8 years ago47isPii: false,
48},
49};
50
008d88e5RedMickey5 years ago51if (this.runOptions.isDirect) {
52extProps.isDirect = {
53value: true,
54isPii: false,
55};
56}
57
34472878RedMickey5 years ago58extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
59this.runOptions,
60this.runOptions.reactNativeVersions,
61extProps,
62);
ba953e9fRedMickey6 years ago63
031832ffArtem Egorov8 years ago64return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => {
34472878RedMickey5 years ago65const env = GeneralMobilePlatform.getEnvArgument(
66process.env,
67this.runOptions.env,
68this.runOptions.envFile,
69);
299883f9Artem Egorov8 years ago70
34472878RedMickey5 years ago71if (
72semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0")
73) {
4dfc9ffdRedMickey5 years ago74this.runArguments.push("--logging");
75if (enableDebug) {
008d88e5RedMickey5 years ago76this.runOptions.isDirect
77? this.runArguments.push("--direct-debugging")
78: this.runArguments.push("--remote-debugging");
4dfc9ffdRedMickey5 years ago79}
299883f9Artem Egorov8 years ago80}
81
34472878RedMickey5 years ago82if (
83!semver.valid(
84this.runOptions.reactNativeVersions.reactNativeVersion,
85) /*Custom RN implementations should support this flag*/ ||
86semver.gte(
87this.runOptions.reactNativeVersions.reactNativeVersion,
88WindowsPlatform.NO_PACKAGER_VERSION,
89)
90) {
7fa90b3bRedMickey6 years ago91this.runArguments.push("--no-packager");
92}
299883f9Artem Egorov8 years ago93
34472878RedMickey5 years ago94const runWindowsSpawn = new CommandExecutor(
4dfb1c4cetatanova5 years ago95this.runOptions.nodeModulesRoot,
34472878RedMickey5 years ago96this.projectPath,
97this.logger,
98).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
99return new OutputVerifier(
100() => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS),
101() => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS),
102this.platformName,
103).process(runWindowsSpawn);
299883f9Artem Egorov8 years ago104});
105}
106
ce5e88eeYuri Skorokhodov6 years ago107public prewarmBundleCache(): Promise<void> {
259c018fYuri Skorokhodov5 years ago108return this.packager.prewarmBundleCache(PlatformType.Windows);
299883f9Artem Egorov8 years ago109}
110
cbc7ac5bArtem Egorov7 years ago111public getRunArguments(): string[] {
299883f9Artem Egorov8 years ago112let runArguments: string[] = [];
113
4dfc9ffdRedMickey5 years ago114if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
299883f9Artem Egorov8 years ago115runArguments.push(...this.runOptions.runArguments);
116} else {
34472878RedMickey5 years ago117let target =
118this.runOptions.target === WindowsPlatform.simulatorString
119? ""
120: this.runOptions.target;
dd90a856Artem Egorov8 years ago121if (target) {
122runArguments.push(`--${target}`);
299883f9Artem Egorov8 years ago123}
124}
125
126return runArguments;
127}
128}