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