From 47a55b0f2691dd9c1af6949a24be5ac86a210cc7 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Fri, 9 Aug 2019 06:50:45 -0700 Subject: [PATCH] Migrate BaseDevice from js to tsx Summary: As per the title Reviewed By: passy Differential Revision: D16687261 fbshipit-source-id: a9d85424fb0a08fada7edd0355c356907518d366 --- headless/index.js | 2 +- src/App.js | 2 +- src/Client.tsx | 2 +- src/PluginContainer.js | 2 +- src/chrome/DevicesButton.js | 2 +- src/chrome/LocationsButton.js | 2 +- src/chrome/MainSidebar.js | 2 +- src/chrome/ScreenCaptureButtons.js | 2 +- src/devices/AndroidDevice.js | 5 +- src/devices/ArchivedDevice.js | 4 +- src/devices/{BaseDevice.js => BaseDevice.tsx} | 47 +++++++++---------- src/devices/IOSDevice.js | 4 +- src/devices/MacDevice.js | 2 +- src/devices/WindowsDevice.js | 2 +- src/dispatcher/androidDevice.js | 2 +- src/dispatcher/iOSDevice.js | 2 +- src/index.js | 8 ++-- src/plugin.tsx | 6 +-- .../testCrashReporterPlugin.electron.js | 2 +- src/plugins/logs/index.js | 2 +- src/reducers/__tests__/connections.node.tsx | 2 +- src/utils/__tests__/exportData.electron.js | 2 +- src/utils/crashReporterUtility.js | 2 +- src/utils/exportData.js | 4 +- src/utils/listDevices.js | 2 +- src/utils/onRegisterDevice.js | 2 +- src/utils/pluginUtils.js | 2 +- src/utils/reduxDevToolsConfig.js | 2 +- tsconfig.json | 1 + 29 files changed, 60 insertions(+), 61 deletions(-) rename src/devices/{BaseDevice.js => BaseDevice.tsx} (82%) diff --git a/headless/index.js b/headless/index.js index 4e5999d6f..55a61a2dc 100644 --- a/headless/index.js +++ b/headless/index.js @@ -23,7 +23,7 @@ import setup from '../static/setup.js'; import type {Store} from '../src/reducers/index.tsx'; import {getPersistentPlugins} from '../src/utils/pluginUtils.js'; import {serialize} from '../src/utils/serialization'; -import type BaseDevice from '../src/devices/BaseDevice'; +import type BaseDevice from '../src/devices/BaseDevice.tsx'; import {getStringFromErrorLike} from '../src/utils/index'; diff --git a/src/App.js b/src/App.js index d217177d3..08856c4ef 100644 --- a/src/App.js +++ b/src/App.js @@ -34,7 +34,7 @@ import { } from './reducers/application.tsx'; import type {Logger} from './fb-interfaces/Logger.js'; import type BugReporter from './fb-stubs/BugReporter.tsx'; -import type BaseDevice from './devices/BaseDevice.js'; +import type BaseDevice from './devices/BaseDevice.tsx'; const version = remote.app.getVersion(); type OwnProps = {| diff --git a/src/Client.tsx b/src/Client.tsx index 62330f209..2c9b0e9c8 100644 --- a/src/Client.tsx +++ b/src/Client.tsx @@ -6,7 +6,7 @@ */ import {FlipperPlugin, FlipperDevicePlugin} from './plugin'; -import BaseDevice, {OS} from './devices/BaseDevice.js'; +import BaseDevice, {OS} from './devices/BaseDevice'; import {App} from './App.js'; import {Logger} from './fb-interfaces/Logger.js'; import {Store} from './reducers/index'; diff --git a/src/PluginContainer.js b/src/PluginContainer.js index db9276329..5ca93d566 100644 --- a/src/PluginContainer.js +++ b/src/PluginContainer.js @@ -6,10 +6,10 @@ */ import type {FlipperPlugin, FlipperDevicePlugin} from './plugin.tsx'; import type {Logger} from './fb-interfaces/Logger'; -import BaseDevice from './devices/BaseDevice.js'; import type {Props as PluginProps} from './plugin.tsx'; import {pluginKey as getPluginKey} from './reducers/pluginStates.tsx'; import Client from './Client.tsx'; +import BaseDevice from './devices/BaseDevice.tsx'; import { ErrorBoundary, PureComponent, diff --git a/src/chrome/DevicesButton.js b/src/chrome/DevicesButton.js index 24145995b..7f14d5256 100644 --- a/src/chrome/DevicesButton.js +++ b/src/chrome/DevicesButton.js @@ -14,7 +14,7 @@ import {default as which} from 'which'; import {promisify} from 'util'; import {showOpenDialog} from '../utils/exportData'; import PropTypes from 'prop-types'; -import type BaseDevice from '../devices/BaseDevice.js'; +import type BaseDevice from '../devices/BaseDevice.tsx'; const whichPromise = promisify(which); diff --git a/src/chrome/LocationsButton.js b/src/chrome/LocationsButton.js index 4834091df..3ce18a2b7 100644 --- a/src/chrome/LocationsButton.js +++ b/src/chrome/LocationsButton.js @@ -8,7 +8,7 @@ import {Button, Component, styled} from 'flipper'; import {connect} from 'react-redux'; -import type BaseDevice from '../devices/BaseDevice'; +import type BaseDevice from '../devices/BaseDevice.tsx'; import AndroidDevice from '../devices/AndroidDevice'; type OwnProps = {| diff --git a/src/chrome/MainSidebar.js b/src/chrome/MainSidebar.js index d52ae47f9..f32d1a682 100644 --- a/src/chrome/MainSidebar.js +++ b/src/chrome/MainSidebar.js @@ -7,7 +7,7 @@ import {FlipperBasePlugin} from '../plugin.tsx'; import config from '../fb-stubs/config.tsx'; -import type BaseDevice from '../devices/BaseDevice.js'; +import type BaseDevice from '../devices/BaseDevice.tsx'; import type Client from '../Client.tsx'; import type {UninitializedClient} from '../UninitializedClient.tsx'; import type {PluginNotification} from '../reducers/notifications.tsx'; diff --git a/src/chrome/ScreenCaptureButtons.js b/src/chrome/ScreenCaptureButtons.js index 68f5cd8d9..f1adc2c19 100644 --- a/src/chrome/ScreenCaptureButtons.js +++ b/src/chrome/ScreenCaptureButtons.js @@ -18,7 +18,7 @@ import {remote} from 'electron'; import path from 'path'; import {reportPlatformFailures} from '../utils/metrics'; import config from '../utils/processConfig'; -import type BaseDevice from '../devices/BaseDevice'; +import type BaseDevice from '../devices/BaseDevice.tsx'; const CAPTURE_LOCATION = expandTilde( config().screenCapturePath || remote.app.getPath('desktop'), diff --git a/src/devices/AndroidDevice.js b/src/devices/AndroidDevice.js index 9db48fedc..c562fe32c 100644 --- a/src/devices/AndroidDevice.js +++ b/src/devices/AndroidDevice.js @@ -5,12 +5,11 @@ * @format */ -import type {DeviceType, DeviceShell} from './BaseDevice.js'; - +import type {DeviceType, DeviceShell} from './BaseDevice.tsx'; +import BaseDevice from './BaseDevice.tsx'; import {Priority} from 'adbkit-logcat-fb'; import child_process from 'child_process'; import child_process_promise from 'child-process-es6-promise'; -import BaseDevice from './BaseDevice.js'; import ArchivedDevice from './ArchivedDevice.js'; type ADBClient = any; diff --git a/src/devices/ArchivedDevice.js b/src/devices/ArchivedDevice.js index 0c82316c4..44d6798a9 100644 --- a/src/devices/ArchivedDevice.js +++ b/src/devices/ArchivedDevice.js @@ -4,13 +4,13 @@ * LICENSE file in the root directory of this source tree. * @format */ -import BaseDevice from './BaseDevice.js'; +import BaseDevice from './BaseDevice.tsx'; import type { DeviceType, OS, DeviceShell, DeviceLogEntry, -} from './BaseDevice.js'; +} from './BaseDevice.tsx'; export default class ArchivedDevice extends BaseDevice { constructor( diff --git a/src/devices/BaseDevice.js b/src/devices/BaseDevice.tsx similarity index 82% rename from src/devices/BaseDevice.js rename to src/devices/BaseDevice.tsx index 928270611..40ecd7045 100644 --- a/src/devices/BaseDevice.js +++ b/src/devices/BaseDevice.tsx @@ -5,8 +5,7 @@ * @format */ -import type stream from 'stream'; -import type ArchivedDevice from './ArchivedDevice'; +import stream from 'stream'; export type LogLevel = | 'unknown' @@ -17,20 +16,20 @@ export type LogLevel = | 'error' | 'fatal'; -export type DeviceLogEntry = {| - date: Date, - pid: number, - tid: number, - app?: string, - type: LogLevel, - tag: string, - message: string, -|}; +export type DeviceLogEntry = { + date: Date; + pid: number; + tid: number; + app?: string; + type: LogLevel; + tag: string; + message: string; +}; export type DeviceShell = { - stdout: stream.Readable, - stderr: stream.Readable, - stdin: stream.Writable, + stdout: stream.Readable; + stderr: stream.Readable; + stdin: stream.Writable; }; export type DeviceLogListener = (entry: DeviceLogEntry) => void; @@ -41,13 +40,13 @@ export type DeviceType = | 'archivedEmulator' | 'archivedPhysical'; -export type DeviceExport = {| - os: string, - title: string, - deviceType: DeviceType, - serial: string, - logs: Array, -|}; +export type DeviceExport = { + os: string; + title: string; + deviceType: DeviceType; + serial: string; + logs: Array; +}; export type OS = 'iOS' | 'Android' | 'Windows' | 'MacOS'; @@ -71,7 +70,7 @@ export default class BaseDevice { serial: string; // possible src of icon to display next to the device title - icon: ?string; + icon: string | null | undefined; logListeners: Map = new Map(); logEntries: Array = []; @@ -135,7 +134,7 @@ export default class BaseDevice { this.logListeners.delete(id); } - spawnShell(): ?DeviceShell { + spawnShell(): DeviceShell | null | undefined { throw new Error('unimplemented'); } @@ -143,7 +142,7 @@ export default class BaseDevice { throw new Error('unimplemented'); } - archive(): ?ArchivedDevice { + archive(): any | null | undefined { return null; } } diff --git a/src/devices/IOSDevice.js b/src/devices/IOSDevice.js index c1fd86efb..34f21379c 100644 --- a/src/devices/IOSDevice.js +++ b/src/devices/IOSDevice.js @@ -5,9 +5,9 @@ * @format */ -import type {DeviceType, LogLevel, DeviceLogEntry} from './BaseDevice.js'; +import type {DeviceType, LogLevel, DeviceLogEntry} from './BaseDevice.tsx'; import child_process from 'child_process'; -import BaseDevice from './BaseDevice.js'; +import BaseDevice from './BaseDevice.tsx'; import JSONStream from 'JSONStream'; import {Transform} from 'stream'; diff --git a/src/devices/MacDevice.js b/src/devices/MacDevice.js index ba7e55200..dc8d4a8b4 100644 --- a/src/devices/MacDevice.js +++ b/src/devices/MacDevice.js @@ -5,7 +5,7 @@ * @format */ -import BaseDevice from './BaseDevice.js'; +import BaseDevice from './BaseDevice.tsx'; export default class MacDevice extends BaseDevice { os = 'MacOS'; diff --git a/src/devices/WindowsDevice.js b/src/devices/WindowsDevice.js index 1d9e20507..b909899da 100644 --- a/src/devices/WindowsDevice.js +++ b/src/devices/WindowsDevice.js @@ -5,7 +5,7 @@ * @format */ -import BaseDevice from './BaseDevice.js'; +import BaseDevice from './BaseDevice.tsx'; export default class WindowsDevice extends BaseDevice { os = 'Windows'; diff --git a/src/dispatcher/androidDevice.js b/src/dispatcher/androidDevice.js index bf4deb38f..74dfc4b59 100644 --- a/src/dispatcher/androidDevice.js +++ b/src/dispatcher/androidDevice.js @@ -8,7 +8,7 @@ import AndroidDevice from '../devices/AndroidDevice'; import child_process from 'child_process'; import type {Store} from '../reducers/index.tsx'; -import type BaseDevice from '../devices/BaseDevice'; +import type BaseDevice from '../devices/BaseDevice.tsx'; import type {Logger} from '../fb-interfaces/Logger.js'; import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice.js'; import {getAdbClient} from '../utils/adbClient'; diff --git a/src/dispatcher/iOSDevice.js b/src/dispatcher/iOSDevice.js index a52f81df9..b22a44b5f 100644 --- a/src/dispatcher/iOSDevice.js +++ b/src/dispatcher/iOSDevice.js @@ -8,7 +8,7 @@ import type {ChildProcess} from 'child_process'; import type {Store} from '../reducers/index.tsx'; import type {Logger} from '../fb-interfaces/Logger.js'; -import type {DeviceType} from '../devices/BaseDevice'; +import type {DeviceType} from '../devices/BaseDevice.tsx'; import {promisify} from 'util'; import path from 'path'; import child_process from 'child_process'; diff --git a/src/index.js b/src/index.js index 47b3be701..1c88cbf64 100644 --- a/src/index.js +++ b/src/index.js @@ -25,8 +25,8 @@ export {default as constants} from './fb-stubs/constants.tsx'; export {connect} from 'react-redux'; export {selectPlugin} from './reducers/connections.tsx'; export {getPluginKey, getPersistedState} from './utils/pluginUtils.js'; -export {default as BaseDevice} from './devices/BaseDevice.js'; export type {Store, MiddlewareAPI} from './reducers/index.tsx'; +export {default as BaseDevice} from './devices/BaseDevice.tsx'; export { default as SidebarExtensions, @@ -35,7 +35,7 @@ export { DeviceLogListener, DeviceLogEntry, LogLevel, -} from './devices/BaseDevice.js'; +} from './devices/BaseDevice.tsx'; export {shouldParseAndroidLog} from './utils/crashReporterUtility.js'; export {default as isProduction} from './utils/isProduction.js'; export {createTablePlugin} from './createTablePlugin.js'; @@ -43,6 +43,6 @@ export {default as DetailSidebar} from './chrome/DetailSidebar.js'; export {default as AndroidDevice} from './devices/AndroidDevice.js'; export {default as ArchivedDevice} from './devices/ArchivedDevice.js'; -export {default as Device} from './devices/BaseDevice.js'; +export {default as Device} from './devices/BaseDevice.tsx'; export {default as IOSDevice} from './devices/IOSDevice.js'; -export type {OS} from './devices/BaseDevice.js'; +export type {OS} from './devices/BaseDevice.tsx'; diff --git a/src/plugin.tsx b/src/plugin.tsx index 2997cdf0a..87c3099e9 100644 --- a/src/plugin.tsx +++ b/src/plugin.tsx @@ -12,7 +12,7 @@ import Client from './Client'; import {Store, MiddlewareAPI} from './reducers/index'; import {MetricType} from './utils/exportMetrics.js'; import {ReactNode, Component} from 'react'; -import BaseDevice from './devices/BaseDevice.js'; +import BaseDevice from './devices/BaseDevice'; // This function is intended to be called from outside of the plugin. // If you want to `call` from the plugin use, this.client.call @@ -163,7 +163,7 @@ export class FlipperDevicePlugin< constructor(props: Props

) { super(props); - // $FlowFixMe props.target will be instance of Device + // @ts-ignore props.target will be instance of Device this.device = props.target; } @@ -192,7 +192,7 @@ export class FlipperPlugin< super(props); const {id} = this.constructor; this.subscriptions = []; - // $FlowFixMe props.target will be instance of Client + // @ts-ignore props.target will be instance of Client this.realClient = props.target; this.client = { call: (method, params) => this.realClient.call(id, method, true, params), diff --git a/src/plugins/crash_reporter/__tests__/testCrashReporterPlugin.electron.js b/src/plugins/crash_reporter/__tests__/testCrashReporterPlugin.electron.js index bb1c6a9d2..2dc1016ef 100644 --- a/src/plugins/crash_reporter/__tests__/testCrashReporterPlugin.electron.js +++ b/src/plugins/crash_reporter/__tests__/testCrashReporterPlugin.electron.js @@ -4,7 +4,7 @@ * LICENSE file in the root directory of this source tree. * @format */ -import BaseDevice from '../../../devices/BaseDevice'; +import BaseDevice from '../../../devices/BaseDevice.tsx'; import CrashReporterPlugin from '../../crash_reporter'; import type {PersistedState, Crash} from '../../crash_reporter'; import { diff --git a/src/plugins/logs/index.js b/src/plugins/logs/index.js index 7d8ff9a66..4446d6e40 100644 --- a/src/plugins/logs/index.js +++ b/src/plugins/logs/index.js @@ -12,8 +12,8 @@ import type { TableColumns, } from 'flipper'; import type {Counter} from './LogWatcher.js'; -import type {DeviceLogEntry} from '../../devices/BaseDevice.js'; import type {Props as PluginProps} from '../../plugin.tsx'; +import type {DeviceLogEntry} from '../../devices/BaseDevice.tsx'; import { Text, diff --git a/src/reducers/__tests__/connections.node.tsx b/src/reducers/__tests__/connections.node.tsx index 1fcefbd6a..cc6048c56 100644 --- a/src/reducers/__tests__/connections.node.tsx +++ b/src/reducers/__tests__/connections.node.tsx @@ -6,8 +6,8 @@ */ import reducer from '../connections'; -import BaseDevice from '../../devices/BaseDevice'; import {State} from '../connections'; +import BaseDevice from '../../devices/BaseDevice'; test('REGISTER_DEVICE doesnt remove error', () => { const initialState: State = reducer(undefined, { diff --git a/src/utils/__tests__/exportData.electron.js b/src/utils/__tests__/exportData.electron.js index 72c1e335c..ff75a63eb 100644 --- a/src/utils/__tests__/exportData.electron.js +++ b/src/utils/__tests__/exportData.electron.js @@ -5,7 +5,7 @@ * @format */ -import {default as BaseDevice} from '../../devices/BaseDevice'; +import {default as BaseDevice} from '../../devices/BaseDevice.tsx'; import {default as ArchivedDevice} from '../../devices/ArchivedDevice'; import {processStore} from '../exportData'; import {FlipperDevicePlugin} from '../../plugin.tsx'; diff --git a/src/utils/crashReporterUtility.js b/src/utils/crashReporterUtility.js index 91ffb6de2..391449815 100644 --- a/src/utils/crashReporterUtility.js +++ b/src/utils/crashReporterUtility.js @@ -5,7 +5,7 @@ * @format * @flow */ -import type {DeviceLogEntry} from '../devices/BaseDevice.js'; +import type {DeviceLogEntry} from '../devices/BaseDevice.tsx'; export function shouldParseAndroidLog( entry: DeviceLogEntry, diff --git a/src/utils/exportData.js b/src/utils/exportData.js index 9d4acae0f..5310053d4 100644 --- a/src/utils/exportData.js +++ b/src/utils/exportData.js @@ -6,14 +6,14 @@ */ import {getInstance as getLogger} from '../fb-stubs/Logger'; import type {Store, MiddlewareAPI} from '../reducers.tsx'; -import type {DeviceExport} from '../devices/BaseDevice'; +import type {DeviceExport} from '../devices/BaseDevice.tsx'; import type {State as PluginStates} from '../reducers/pluginStates.tsx'; import type {PluginNotification} from '../reducers/notifications.tsx'; import type {ClientExport} from '../Client.tsx'; import type {State as PluginStatesState} from '../reducers/pluginStates.tsx'; import {pluginKey} from '../reducers/pluginStates.tsx'; import {FlipperDevicePlugin, FlipperPlugin, callClient} from '../plugin.tsx'; -import {default as BaseDevice} from '../devices/BaseDevice'; +import {default as BaseDevice} from '../devices/BaseDevice.tsx'; import {default as ArchivedDevice} from '../devices/ArchivedDevice'; import {default as Client} from '../Client.tsx'; import fs from 'fs'; diff --git a/src/utils/listDevices.js b/src/utils/listDevices.js index 0f3733138..5904436f9 100644 --- a/src/utils/listDevices.js +++ b/src/utils/listDevices.js @@ -6,7 +6,7 @@ */ import {getActiveAndroidDevices} from '../dispatcher/androidDevice'; import {getActiveDevicesAndSimulators} from '../dispatcher/iOSDevice'; -import type BaseDevice from '../devices/BaseDevice'; +import type BaseDevice from '../devices/BaseDevice.tsx'; export async function listDevices(): Promise> { const androidDevices = await getActiveAndroidDevices(); diff --git a/src/utils/onRegisterDevice.js b/src/utils/onRegisterDevice.js index 14b472806..f91a23b67 100644 --- a/src/utils/onRegisterDevice.js +++ b/src/utils/onRegisterDevice.js @@ -6,8 +6,8 @@ */ import type {Store} from '../reducers/index.tsx'; import {FlipperPlugin, FlipperDevicePlugin} from '../plugin.tsx'; -import type BaseDevice from '../devices/BaseDevice.js'; import {setPluginState} from '../reducers/pluginStates.tsx'; +import type BaseDevice from '../devices/BaseDevice.tsx'; import {getPersistedState} from '../utils/pluginUtils.js'; export function registerDeviceCallbackOnPlugins( diff --git a/src/utils/pluginUtils.js b/src/utils/pluginUtils.js index 4d50f9a6a..ecda70e5e 100644 --- a/src/utils/pluginUtils.js +++ b/src/utils/pluginUtils.js @@ -4,9 +4,9 @@ * LICENSE file in the root directory of this source tree. * @format */ -import type BaseDevice from '../devices/BaseDevice.js'; import {FlipperDevicePlugin, FlipperPlugin} from '../plugin.tsx'; import type {State as PluginStatesState} from '../reducers/pluginStates.tsx'; +import type BaseDevice from '../devices/BaseDevice.tsx'; import {pluginsClassMap} from './exportData.js'; import type {State as PluginsState} from '../reducers/plugins.tsx'; import type {PluginDefinition} from '../dispatcher/plugins'; diff --git a/src/utils/reduxDevToolsConfig.js b/src/utils/reduxDevToolsConfig.js index 7801565e0..22d612adf 100644 --- a/src/utils/reduxDevToolsConfig.js +++ b/src/utils/reduxDevToolsConfig.js @@ -5,7 +5,7 @@ * @format */ import {State} from '../reducers/index.tsx'; -import type {DeviceExport} from '../devices/BaseDevice'; +import type {DeviceExport} from '../devices/BaseDevice.tsx'; export const stateSanitizer = (state: State) => { if (state.connections && state.connections.devices) { diff --git a/tsconfig.json b/tsconfig.json index 310639730..6f515f360 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "moduleResolution": "node", "baseUrl": ".", "downlevelIteration": true, + "esModuleInterop": true, "paths": { "flipper": ["./src/index.js"] }