microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
test-microbuild1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

138lines · 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";
4cd25962JiglioNero4 years ago5import { GeneralPlatform, MobilePlatformDeps, TargetType } from "../generalPlatform";
4dfc9ffdRedMickey5 years ago6import { 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";
47927908RedMickey4 years ago12import { ProjectVersionHelper } from "../../common/projectVersionHelper";
299883f9Artem Egorov8 years ago13
14/**
15* Windows specific platform implementation for debugging RN applications.
16*/
4cd25962JiglioNero4 years ago17export class WindowsPlatform extends GeneralPlatform {
7bc455e9Artem Egorov8 years ago18protected static NO_PACKAGER_VERSION = "0.53.0";
299883f9Artem Egorov8 years ago19
47927908RedMickey4 years ago20private static readonly RNW_CLI_EXISTS_VERSION = "0.63.0";
34472878RedMickey5 years ago21private static SUCCESS_PATTERNS = ["Starting the app"];
299883f9Artem Egorov8 years ago22private static FAILURE_PATTERNS: PatternToFailure[] = [
23{
24pattern: "Unrecognized command 'run-windows'",
d7d405aeYuri Skorokhodov7 years ago25errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled,
299883f9Artem Egorov8 years ago26},
60ad4ec0JiglioNero5 years ago27{
28pattern: /×.+$/gm,
29errorCode: InternalErrorCode.WinRunCommandFailed,
30},
299883f9Artem Egorov8 years ago31];
32
0d77292aJiglioNero4 years ago33public async reloadApp(appLauncher: AppLauncher): Promise<void> {
cfbe5cc9etatanova5 years ago34const worker = appLauncher.getAppWorker();
35if (worker) {
36worker.reloadAppCommand();
37}
38}
39
299883f9Artem Egorov8 years ago40constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
41super(runOptions, platformDeps);
42}
43
0d77292aJiglioNero4 years ago44public async runApp(enableDebug: boolean = true): Promise<void> {
008d88e5RedMickey4 years ago45let extProps: any = {
031832ffArtem Egorov8 years ago46platform: {
259c018fYuri Skorokhodov5 years ago47value: PlatformType.Windows,
031832ffArtem Egorov8 years ago48isPii: false,
49},
50};
51
e7a2c40dRedMickey4 years ago52this.projectObserver?.updateRNWindowsProjectState(true);
008d88e5RedMickey4 years ago53if (this.runOptions.isDirect) {
54extProps.isDirect = {
55value: true,
56isPii: false,
57};
e7a2c40dRedMickey4 years ago58this.projectObserver?.updateRNWindowsHermesProjectState(true);
008d88e5RedMickey4 years ago59}
60
34472878RedMickey5 years ago61extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
62this.runOptions,
63this.runOptions.reactNativeVersions,
64extProps,
65);
ba953e9fRedMickey6 years ago66
0d77292aJiglioNero4 years ago67await TelemetryHelper.generate("WindowsPlatform.runApp", extProps, async () => {
4cd25962JiglioNero4 years ago68const env = GeneralPlatform.getEnvArgument(
34472878RedMickey5 years ago69process.env,
70this.runOptions.env,
71this.runOptions.envFile,
72);
299883f9Artem Egorov8 years ago73
34472878RedMickey5 years ago74if (
47927908RedMickey4 years ago75semver.gte(
76this.runOptions.reactNativeVersions.reactNativeWindowsVersion,
77WindowsPlatform.RNW_CLI_EXISTS_VERSION,
78) ||
79ProjectVersionHelper.isCanaryVersion(
80this.runOptions.reactNativeVersions.reactNativeWindowsVersion,
81)
34472878RedMickey5 years ago82) {
4dfc9ffdRedMickey5 years ago83this.runArguments.push("--logging");
84if (enableDebug) {
008d88e5RedMickey4 years ago85this.runOptions.isDirect
86? this.runArguments.push("--direct-debugging")
87: this.runArguments.push("--remote-debugging");
4dfc9ffdRedMickey5 years ago88}
299883f9Artem Egorov8 years ago89}
90
34472878RedMickey5 years ago91if (
92!semver.valid(
93this.runOptions.reactNativeVersions.reactNativeVersion,
09f6024fHeniker4 years ago94) /* Custom RN implementations should support this flag*/ ||
34472878RedMickey5 years ago95semver.gte(
96this.runOptions.reactNativeVersions.reactNativeVersion,
97WindowsPlatform.NO_PACKAGER_VERSION,
47927908RedMickey4 years ago98) ||
99ProjectVersionHelper.isCanaryVersion(
100this.runOptions.reactNativeVersions.reactNativeVersion,
34472878RedMickey5 years ago101)
102) {
7fa90b3bRedMickey6 years ago103this.runArguments.push("--no-packager");
104}
299883f9Artem Egorov8 years ago105
34472878RedMickey5 years ago106const runWindowsSpawn = new CommandExecutor(
4dfb1c4cetatanova5 years ago107this.runOptions.nodeModulesRoot,
34472878RedMickey5 years ago108this.projectPath,
109this.logger,
110).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
0d77292aJiglioNero4 years ago111await new OutputVerifier(
34472878RedMickey5 years ago112() => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS),
113() => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS),
114this.platformName,
115).process(runWindowsSpawn);
299883f9Artem Egorov8 years ago116});
117}
118
ce5e88eeYuri Skorokhodov5 years ago119public prewarmBundleCache(): Promise<void> {
259c018fYuri Skorokhodov5 years ago120return this.packager.prewarmBundleCache(PlatformType.Windows);
299883f9Artem Egorov8 years ago121}
122
cbc7ac5bArtem Egorov7 years ago123public getRunArguments(): string[] {
09f6024fHeniker4 years ago124const runArguments: string[] = [];
299883f9Artem Egorov8 years ago125
4dfc9ffdRedMickey5 years ago126if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
299883f9Artem Egorov8 years ago127runArguments.push(...this.runOptions.runArguments);
128} else {
09f6024fHeniker4 years ago129const target =
4cd25962JiglioNero4 years ago130this.runOptions.target === TargetType.Simulator ? "" : this.runOptions.target;
dd90a856Artem Egorov8 years ago131if (target) {
132runArguments.push(`--${target}`);
299883f9Artem Egorov8 years ago133}
134}
135
136return runArguments;
137}
138}