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