From 3bfb7faf0a5f6ff7485dc6205cda9372f4ef0341 Mon Sep 17 00:00:00 2001 From: John Knox Date: Thu, 8 Aug 2019 11:50:09 -0700 Subject: [PATCH] Convert plugin.js to plugin.tsx Summary: * Deletes plugin.js * Adds plugin.tsx * Adds plugin flow-typed module that has the old flow types Reviewed By: passy Differential Revision: D16668067 fbshipit-source-id: b2f0ce47c4cf7125b4e352821e921b97675d12a9 --- .flowconfig | 2 + flow-typed/plugin.js | 175 +++++++++++++++ src/Client.tsx | 10 +- src/MenuBar.js | 2 +- src/PluginContainer.js | 4 +- src/__tests__/createTablePlugin.node.js | 2 +- src/chrome/BugReporterDialog.js | 2 +- src/chrome/MainSidebar.js | 2 +- src/chrome/PluginDebugger.js | 2 +- src/createTablePlugin.js | 2 +- src/dispatcher/__tests__/TestPlugin.js | 2 +- src/dispatcher/__tests__/plugins.electron.js | 2 +- src/dispatcher/notifications.js | 2 +- src/dispatcher/plugins.js | 4 +- src/index.js | 4 +- src/{plugin.js => plugin.tsx} | 209 +++++++++--------- src/plugins/TableNativePlugin.js | 2 +- src/plugins/crash_reporter/index.js | 2 +- src/plugins/databases/ClientProtocol.js | 2 +- src/plugins/example/index.js | 2 +- src/plugins/fresco/__tests__/index.node.js | 2 +- src/plugins/fresco/index.js | 2 +- src/plugins/logs/index.js | 2 +- src/plugins/network/index.js | 2 +- src/reducers/__tests__/notifications.node.tsx | 4 +- src/reducers/__tests__/plugins.node.tsx | 31 +-- src/reducers/plugins.tsx | 6 +- src/ui/components/console.js | 2 +- .../components/elements-inspector/sidebar.js | 2 +- src/utils/__tests__/exportData.electron.js | 4 +- src/utils/exportData.js | 2 +- src/utils/onRegisterDevice.js | 2 +- src/utils/pluginUtils.js | 2 +- 33 files changed, 324 insertions(+), 173 deletions(-) create mode 100644 flow-typed/plugin.js rename src/{plugin.js => plugin.tsx} (52%) diff --git a/.flowconfig b/.flowconfig index 7f23fa53e..a3a0024a2 100644 --- a/.flowconfig +++ b/.flowconfig @@ -20,6 +20,8 @@ module.use_strict=true emoji=true all=true include_warnings=true +module.name_mapper='^.*plugin\.flow\.js$' -> 'plugin' +module.name_mapper='^.*plugin\.tsx$' -> 'plugin' module.name_mapper='^\(.*\)\.tsx$' -> 'TsStub' module.name_mapper='flipper' -> '/src/index.js' suppress_type=$FlowFixMe diff --git a/flow-typed/plugin.js b/flow-typed/plugin.js new file mode 100644 index 000000000..7b465ff77 --- /dev/null +++ b/flow-typed/plugin.js @@ -0,0 +1,175 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +// This has been taken from the old plugin.js and manually stripped of +// implementation so only the types remain. +// It's not generated using flowgen because the typescript def is slightly weaker +// than the original flow one. (Persisted State generic param being used +// in reducers etc. + +declare module plugin { + import type {KeyboardActions} from './MenuBar.js'; + import type {App} from './App.js'; + import type {Logger} from './fb-interfaces/Logger.js'; + import type Client from './Client.js'; + import type {Store, MiddlewareAPI} from './reducers/index.js'; + import type {MetricType} from './utils/exportMetrics.js'; + import type {Node} from 'react'; + import type BaseDevice from './devices/BaseDevice.js'; + import type AndroidDevice from './devices/AndroidDevice'; + import type IOSDevice from './devices/IOSDevice'; + + // This function is intended to be called from outside of the plugin. + // If you want to `call` from the plugin use, this.client.call + declare function callClient( + client: Client, + id: string, + ): (string, ?Object) => Promise; + + declare interface PluginClient { + // eslint-disable-next-line + send(method: string, params?: Object): void; + // eslint-disable-next-line + call(method: string, params?: Object): Promise; + // eslint-disable-next-line + subscribe(method: string, callback: (params: any) => void): void; + // eslint-disable-next-line + supportsMethod(method: string): Promise; + } + + declare type PluginTarget = BaseDevice | Client; + + declare type Notification = {| + id: string, + title: string, + message: string | Node, + severity: 'warning' | 'error', + timestamp?: number, + category?: string, + action?: string, + |}; + + declare type Props = { + logger: Logger, + persistedState: T, + setPersistedState: (state: $Shape) => void, + target: PluginTarget, + deepLinkPayload: ?string, + selectPlugin: (pluginID: string, deepLinkPayload: ?string) => boolean, + isArchivedDevice: boolean, + selectedApp: ?string, + }; + + declare class FlipperBasePlugin< + State = *, + Actions = *, + PersistedState = *, + > extends React.Component, State> { + static title: ?string; + static id: string; + static icon: ?string; + static gatekeeper: ?string; + static entry: ?string; + static bugs: ?{ + email?: string, + url?: string, + }; + static keyboardActions: ?KeyboardActions; + static screenshot: ?string; + static defaultPersistedState: PersistedState; + static persistedStateReducer: ?( + persistedState: PersistedState, + method: string, + data: Object, + ) => $Shape; + static metricsReducer: ?( + persistedState: PersistedState, + ) => Promise; + static exportPersistedState: ?( + callClient: (string, ?Object) => Promise, + persistedState: ?PersistedState, + store: ?MiddlewareAPI, + ) => Promise; + static getActiveNotifications: ?( + persistedState: PersistedState, + ) => Array; + static onRegisterDevice: ?( + store: Store, + baseDevice: BaseDevice, + setPersistedState: ( + pluginKey: string, + newPluginState: ?PersistedState, + ) => void, + ) => void; + // forbid instance properties that should be static + title: empty; + id: empty; + persist: empty; + icon: empty; + keyboardActions: empty; + screenshot: empty; + + reducers: { + [actionName: string]: (state: State, actionData: Object) => $Shape, + }; + app: App; + onKeyboardAction: ?(action: string) => void; + + toJSON(): string; + + init(): void; + teardown(): void; + computeNotifications(props: Props<*>, state: State): Array; + // methods to be overridden by subclasses + _init(): void; + _teardown(): void; + + dispatchAction(actionData: Actions): void; + } + + declare class FlipperDevicePlugin< + S = *, + A = *, + P = *, + > extends FlipperBasePlugin { + device: BaseDevice; + + constructor(props: Props

): void; + + _init(): void; + + _teardown(): void; + + static supportsDevice(device: BaseDevice): boolean; + } + + declare class FlipperPlugin extends FlipperBasePlugin< + S, + A, + P, + > { + constructor(props: Props

): void; + + subscriptions: Array<{ + method: string, + callback: Function, + }>; + + client: PluginClient; + realClient: Client; + + getDevice(): Promise; + + getAndroidDevice(): AndroidDevice; + + getIOSDevice(): IOSDevice; + + _teardown(): void; + + _init(): void; + } +} diff --git a/src/Client.tsx b/src/Client.tsx index 278627d5d..62330f209 100644 --- a/src/Client.tsx +++ b/src/Client.tsx @@ -5,11 +5,7 @@ * @format */ -import { - FlipperPlugin, - FlipperBasePlugin, - FlipperDevicePlugin, -} from './plugin.js'; +import {FlipperPlugin, FlipperDevicePlugin} from './plugin'; import BaseDevice, {OS} from './devices/BaseDevice.js'; import {App} from './App.js'; import {Logger} from './fb-interfaces/Logger.js'; @@ -315,7 +311,9 @@ export default class Client extends EventEmitter { const params = data.params; invariant(params, 'expected params'); - const persistingPlugin: typeof FlipperBasePlugin | null = + const persistingPlugin: + | typeof FlipperPlugin + | typeof FlipperDevicePlugin = this.store.getState().plugins.clientPlugins.get(params.api) || this.store.getState().plugins.devicePlugins.get(params.api); if (persistingPlugin && persistingPlugin.persistedStateReducer) { diff --git a/src/MenuBar.js b/src/MenuBar.js index 5477c248f..60004b851 100644 --- a/src/MenuBar.js +++ b/src/MenuBar.js @@ -5,7 +5,7 @@ * @format */ -import type {FlipperPlugin, FlipperDevicePlugin} from './plugin.js'; +import type {FlipperPlugin, FlipperDevicePlugin} from './plugin.tsx'; import {showOpenDialog} from './utils/exportData.js'; import { setExportDataToFileActiveSheet, diff --git a/src/PluginContainer.js b/src/PluginContainer.js index 2c99f2cae..db9276329 100644 --- a/src/PluginContainer.js +++ b/src/PluginContainer.js @@ -4,10 +4,10 @@ * LICENSE file in the root directory of this source tree. * @format */ -import type {FlipperPlugin, FlipperDevicePlugin} from './plugin.js'; +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'; +import type {Props as PluginProps} from './plugin.tsx'; import {pluginKey as getPluginKey} from './reducers/pluginStates.tsx'; import Client from './Client.tsx'; import { diff --git a/src/__tests__/createTablePlugin.node.js b/src/__tests__/createTablePlugin.node.js index 85e8b133a..70a9fd737 100644 --- a/src/__tests__/createTablePlugin.node.js +++ b/src/__tests__/createTablePlugin.node.js @@ -10,7 +10,7 @@ import {createTablePlugin} from '../createTablePlugin.js'; import type {TableRows_immutable} from 'flipper'; //import type {PersistedState, RowData} from '../createTablePlugin.js'; -import {FlipperPlugin} from '../plugin.js'; +import {FlipperPlugin} from '../plugin.tsx'; import {List, Map as ImmutableMap} from 'immutable'; diff --git a/src/chrome/BugReporterDialog.js b/src/chrome/BugReporterDialog.js index 20ac04940..6d6192dcd 100644 --- a/src/chrome/BugReporterDialog.js +++ b/src/chrome/BugReporterDialog.js @@ -6,7 +6,7 @@ */ import type BugReporter from '../fb-stubs/BugReporter.js'; -import type {FlipperDevicePlugin, FlipperPlugin} from '../plugin'; +import type {FlipperDevicePlugin, FlipperPlugin} from '../plugin.tsx'; import {Fragment, Component} from 'react'; import {connect} from 'react-redux'; import { diff --git a/src/chrome/MainSidebar.js b/src/chrome/MainSidebar.js index 010aeecf4..a9f7110cf 100644 --- a/src/chrome/MainSidebar.js +++ b/src/chrome/MainSidebar.js @@ -5,7 +5,7 @@ * @format */ -import {FlipperBasePlugin} from '../plugin.js'; +import {FlipperBasePlugin} from '../plugin.tsx'; import config from '../fb-stubs/config'; import type BaseDevice from '../devices/BaseDevice.js'; import type Client from '../Client.tsx'; diff --git a/src/chrome/PluginDebugger.js b/src/chrome/PluginDebugger.js index 4882a605d..fc5fb858b 100644 --- a/src/chrome/PluginDebugger.js +++ b/src/chrome/PluginDebugger.js @@ -5,7 +5,7 @@ * @format */ -import type {FlipperDevicePlugin, FlipperPlugin} from '../plugin'; +import type {FlipperDevicePlugin, FlipperPlugin} from '../plugin.tsx'; import type {PluginDefinition} from '../dispatcher/plugins'; import type Client from '../Client.tsx'; import type {TableBodyRow} from '../ui/components/table/types'; diff --git a/src/createTablePlugin.js b/src/createTablePlugin.js index 60aa08f5e..d6c619c61 100644 --- a/src/createTablePlugin.js +++ b/src/createTablePlugin.js @@ -15,7 +15,7 @@ import type { import FlexColumn from './ui/components/FlexColumn'; import Button from './ui/components/Button'; import DetailSidebar from './chrome/DetailSidebar'; -import {FlipperPlugin} from './plugin'; +import {FlipperPlugin} from './plugin.tsx'; import SearchableTable_immutable from './ui/components/searchable/SearchableTable_immutable'; import textContent from './utils/textContent.js'; import createPaste from './fb-stubs/createPaste.js'; diff --git a/src/dispatcher/__tests__/TestPlugin.js b/src/dispatcher/__tests__/TestPlugin.js index efe567cbd..a3e8fb448 100644 --- a/src/dispatcher/__tests__/TestPlugin.js +++ b/src/dispatcher/__tests__/TestPlugin.js @@ -5,7 +5,7 @@ * @format */ -import {FlipperPlugin} from '../../plugin.js'; +import {FlipperPlugin} from '../../plugin.tsx'; export default class extends FlipperPlugin { static id = 'Static ID'; diff --git a/src/dispatcher/__tests__/plugins.electron.js b/src/dispatcher/__tests__/plugins.electron.js index b21845910..c0a68e695 100644 --- a/src/dispatcher/__tests__/plugins.electron.js +++ b/src/dispatcher/__tests__/plugins.electron.js @@ -13,7 +13,7 @@ import dispatcher, { } from '../plugins'; import path from 'path'; import {remote} from 'electron'; -import {FlipperPlugin} from '../../plugin'; +import {FlipperPlugin} from '../../plugin.tsx'; import reducers from '../../reducers/index.tsx'; import {init as initLogger} from '../../fb-stubs/Logger.js'; import configureStore from 'redux-mock-store'; diff --git a/src/dispatcher/notifications.js b/src/dispatcher/notifications.js index c686efaee..58b87ccb6 100644 --- a/src/dispatcher/notifications.js +++ b/src/dispatcher/notifications.js @@ -8,7 +8,7 @@ import type {Store} from '../reducers/index.tsx'; import type {Logger} from '../fb-interfaces/Logger.js'; import type {PluginNotification} from '../reducers/notifications.tsx'; -import type {FlipperPlugin, FlipperDevicePlugin} from '../plugin.js'; +import type {FlipperPlugin, FlipperDevicePlugin} from '../plugin.tsx'; import isHeadless from '../utils/isHeadless.js'; import {ipcRenderer} from 'electron'; import {selectPlugin} from '../reducers/connections.tsx'; diff --git a/src/dispatcher/plugins.js b/src/dispatcher/plugins.js index f3bbf2639..29c87e6e0 100644 --- a/src/dispatcher/plugins.js +++ b/src/dispatcher/plugins.js @@ -7,7 +7,7 @@ import type {Store} from '../reducers/index.tsx'; import type {Logger} from '../fb-interfaces/Logger.js'; -import type {FlipperPlugin, FlipperDevicePlugin} from '../plugin.js'; +import type {FlipperPlugin, FlipperDevicePlugin} from '../plugin.tsx'; import type {State} from '../reducers/plugins.tsx'; import React from 'react'; @@ -21,7 +21,7 @@ import { } from '../reducers/plugins.tsx'; import {remote} from 'electron'; import GK from '../fb-stubs/GK'; -import {FlipperBasePlugin} from '../plugin.js'; +import {FlipperBasePlugin} from '../plugin.tsx'; import {setupMenuBar} from '../MenuBar.js'; import path from 'path'; import {default as config} from '../utils/processConfig.js'; diff --git a/src/index.js b/src/index.js index 6fad38721..1c1f19789 100644 --- a/src/index.js +++ b/src/index.js @@ -16,8 +16,8 @@ export { FlipperPlugin, FlipperDevicePlugin, callClient, -} from './plugin.js'; -export type {PluginClient, Props} from './plugin.js'; +} from './plugin.tsx'; +export type {PluginClient, Props} from './plugin.tsx'; export type {MetricType} from './utils/exportMetrics.js'; export {default as Client} from './Client.tsx'; export {clipboard} from 'electron'; diff --git a/src/plugin.js b/src/plugin.tsx similarity index 52% rename from src/plugin.js rename to src/plugin.tsx index f6ac712e5..2997cdf0a 100644 --- a/src/plugin.js +++ b/src/plugin.tsx @@ -5,26 +5,21 @@ * @format */ -import type {KeyboardActions} from './MenuBar.js'; -import type {App} from './App.js'; -import type {Logger} from './fb-interfaces/Logger.js'; -import type Client from './Client.tsx'; -import type {Store, MiddlewareAPI} from './reducers/index.tsx'; -import type {MetricType} from './utils/exportMetrics.js'; -import React from 'react'; -import type {Node} from 'react'; +import {KeyboardActions} from './MenuBar.js'; +import {App} from './App.js'; +import {Logger} from './fb-interfaces/Logger.js'; +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 AndroidDevice from './devices/AndroidDevice'; -import IOSDevice from './devices/IOSDevice'; - -const invariant = require('invariant'); // This function is intended to be called from outside of the plugin. // If you want to `call` from the plugin use, this.client.call export function callClient( client: Client, id: string, -): (string, ?Object) => Promise { +): (string, params: Object | null) => Promise { return (method, params) => client.call(id, method, false, params); } @@ -41,81 +36,88 @@ export interface PluginClient { type PluginTarget = BaseDevice | Client; -export type Notification = {| - id: string, - title: string, - message: string | Node, - severity: 'warning' | 'error', - timestamp?: number, - category?: string, - action?: string, -|}; - -export type Props = { - logger: Logger, - persistedState: T, - setPersistedState: (state: $Shape) => void, - target: PluginTarget, - deepLinkPayload: ?string, - selectPlugin: (pluginID: string, deepLinkPayload: ?string) => boolean, - isArchivedDevice: boolean, - selectedApp: ?string, +export type Notification = { + id: string; + title: string; + message: string | ReactNode; + severity: 'warning' | 'error'; + timestamp?: number; + category?: string; + action?: string; }; -export class FlipperBasePlugin< - State = *, - Actions = *, - PersistedState = *, -> extends React.Component, State> { - static title: ?string = null; +export type Props = { + logger: Logger; + persistedState: T; + setPersistedState: (state: Partial) => void; + target: PluginTarget; + deepLinkPayload: string | null; + selectPlugin: (pluginID: string, deepLinkPayload: string | null) => boolean; + isArchivedDevice: boolean; + selectedApp: string | null; +}; + +export type BaseAction = { + type: string; +}; + +export abstract class FlipperBasePlugin< + State, + Actions extends BaseAction, + PersistedState +> extends Component, State> { + abstract ['constructor']: any; + static title: string | null = null; static id: string = ''; - static icon: ?string = null; - static gatekeeper: ?string = null; - static entry: ?string = null; - static bugs: ?{ - email?: string, - url?: string, - } = null; - static keyboardActions: ?KeyboardActions; - static screenshot: ?string; - static defaultPersistedState: PersistedState; - static persistedStateReducer: ?( - persistedState: PersistedState, - method: string, - data: Object, - ) => $Shape; - static metricsReducer: ?( - persistedState: PersistedState, - ) => Promise; - static exportPersistedState: ?( - callClient: (string, ?Object) => Promise, - persistedState: ?PersistedState, - store: ?MiddlewareAPI, - ) => Promise; - static getActiveNotifications: ?( - persistedState: PersistedState, - ) => Array; - static onRegisterDevice: ?( - store: Store, - baseDevice: BaseDevice, - setPersistedState: ( - pluginKey: string, - newPluginState: ?PersistedState, - ) => void, - ) => void; + static icon: string | null = null; + static gatekeeper: string | null = null; + static entry: string | null = null; + static bugs: + | ({ + email?: string; + url?: string; + }) + | null = null; + static keyboardActions: KeyboardActions | null; + static screenshot: string | null; + static defaultPersistedState: any; + static persistedStateReducer: + | ((persistedState: U, method: string, data: Object) => Partial) + | null; + static metricsReducer: ((persistedState: U) => Promise) | null; + static exportPersistedState: + | (( + callClient: (string, params: Object | null) => Promise, + persistedState: U | null, + store: MiddlewareAPI | null, + ) => Promise) + | null; + static getActiveNotifications: + | ((persistedState: U) => Array) + | null; + static onRegisterDevice: + | (( + store: Store, + baseDevice: BaseDevice, + setPersistedState: ( + pluginKey: string, + newPluginState: U | null, + ) => void, + ) => void) + | null; // forbid instance properties that should be static - title: empty; - id: empty; - persist: empty; - icon: empty; - keyboardActions: empty; - screenshot: empty; + title: never; + id: never; + persist: never; + icon: never; + keyboardActions: never; + screenshot: never; reducers: { - [actionName: string]: (state: State, actionData: Object) => $Shape, + [actionName: string]: (state: State, actionData: Object) => Partial; } = {}; app: App; - onKeyboardAction: ?(action: string) => void; + onKeyboardAction: ((action: string) => void) | null; toJSON() { return `<${this.constructor.name}#${this.constructor.id}>`; @@ -124,7 +126,10 @@ export class FlipperBasePlugin< // methods to be overriden by plugins init(): void {} teardown(): void {} - computeNotifications(props: Props<*>, state: State): Array { + computeNotifications( + _props: Props, + _state: State, + ): Array { return []; } // methods to be overridden by subclasses @@ -148,11 +153,12 @@ export class FlipperBasePlugin< } } -export class FlipperDevicePlugin extends FlipperBasePlugin< +export class FlipperDevicePlugin< S, - A, - P, -> { + A extends BaseAction, + P +> extends FlipperBasePlugin { + ['constructor']: typeof FlipperPlugin; device: BaseDevice; constructor(props: Props

) { @@ -169,18 +175,19 @@ export class FlipperDevicePlugin extends FlipperBasePlugin< this.teardown(); } - static supportsDevice(device: BaseDevice) { + static supportsDevice(_device: BaseDevice) { throw new Error( 'supportsDevice is unimplemented in FlipperDevicePlugin class', ); } } -export class FlipperPlugin extends FlipperBasePlugin< +export class FlipperPlugin< S, - A, - P, -> { + A extends BaseAction, + P +> extends FlipperBasePlugin { + ['constructor']: typeof FlipperPlugin; constructor(props: Props

) { super(props); const {id} = this.constructor; @@ -202,8 +209,8 @@ export class FlipperPlugin extends FlipperBasePlugin< } subscriptions: Array<{ - method: string, - callback: Function, + method: string; + callback: Function; }>; client: PluginClient; @@ -213,24 +220,6 @@ export class FlipperPlugin extends FlipperBasePlugin< return this.realClient.device; } - getAndroidDevice(): AndroidDevice { - const device = this.getDevice(); - invariant( - device != null && device instanceof AndroidDevice, - 'expected android device', - ); - return device; - } - - getIOSDevice() { - const device = this.getDevice(); - invariant( - device != null && device instanceof IOSDevice, - 'expected ios device', - ); - return device; - } - _teardown() { // automatically unsubscribe subscriptions for (const {method, callback} of this.subscriptions) { diff --git a/src/plugins/TableNativePlugin.js b/src/plugins/TableNativePlugin.js index 405cc13ad..4cace19de 100644 --- a/src/plugins/TableNativePlugin.js +++ b/src/plugins/TableNativePlugin.js @@ -19,7 +19,7 @@ import { import ErrorBlock from '../ui/components/ErrorBlock'; import FlexColumn from '../ui/components/FlexColumn'; import DetailSidebar from '../chrome/DetailSidebar'; -import {FlipperPlugin} from '../plugin'; +import {FlipperPlugin} from '../plugin.tsx'; import SearchableTable from '../ui/components/searchable/SearchableTable'; import textContent from '../utils/textContent.js'; import createPaste from '../fb-stubs/createPaste.js'; diff --git a/src/plugins/crash_reporter/index.js b/src/plugins/crash_reporter/index.js index 8232ccbc5..987829f69 100644 --- a/src/plugins/crash_reporter/index.js +++ b/src/plugins/crash_reporter/index.js @@ -32,7 +32,7 @@ import fs from 'fs'; import os from 'os'; import util from 'util'; import path from 'path'; -import type {Notification} from '../../plugin'; +import type {Notification} from '../../plugin.tsx'; import type {Store, DeviceLogEntry, OS, Props} from 'flipper'; import {Component} from 'react'; diff --git a/src/plugins/databases/ClientProtocol.js b/src/plugins/databases/ClientProtocol.js index ddfe7ac62..423c92d98 100644 --- a/src/plugins/databases/ClientProtocol.js +++ b/src/plugins/databases/ClientProtocol.js @@ -5,7 +5,7 @@ * @format */ -import type {PluginClient} from '../../plugin'; +import type {PluginClient} from '../../plugin.tsx'; import type {Value} from '../../ui/components/table/TypeBasedValueRenderer'; type ClientCall = Params => Promise; diff --git a/src/plugins/example/index.js b/src/plugins/example/index.js index b62c9eee0..18171c3a0 100644 --- a/src/plugins/example/index.js +++ b/src/plugins/example/index.js @@ -7,7 +7,7 @@ */ import {Button, Input, FlipperPlugin, FlexColumn, styled, Text} from 'flipper'; -import type {Notification} from '../../plugin'; +import type {Notification} from '../../plugin.tsx'; type DisplayMessageResponse = { greeting: string, }; diff --git a/src/plugins/fresco/__tests__/index.node.js b/src/plugins/fresco/__tests__/index.node.js index 00e243094..cc5703978 100644 --- a/src/plugins/fresco/__tests__/index.node.js +++ b/src/plugins/fresco/__tests__/index.node.js @@ -9,7 +9,7 @@ import FrescoPlugin from '../index.js'; import type {PersistedState, ImageEventWithId} from '../index.js'; import type {AndroidCloseableReferenceLeakEvent} from '../api.js'; import type {MetricType} from 'flipper'; -import type {Notification} from '../../../plugin'; +import type {Notification} from '../../../plugin.tsx'; function mockPersistedState( imageSizes: Array<{ diff --git a/src/plugins/fresco/index.js b/src/plugins/fresco/index.js index a0cea3a83..b4f808c7b 100644 --- a/src/plugins/fresco/index.js +++ b/src/plugins/fresco/index.js @@ -31,7 +31,7 @@ import { } from 'flipper'; import ImagesSidebar from './ImagesSidebar.js'; import ImagePool from './ImagePool.js'; -import type {Notification} from '../../plugin'; +import type {Notification} from '../../plugin.tsx'; export type ImageEventWithId = ImageEvent & {eventId: number}; diff --git a/src/plugins/logs/index.js b/src/plugins/logs/index.js index 430e07fcc..7d8ff9a66 100644 --- a/src/plugins/logs/index.js +++ b/src/plugins/logs/index.js @@ -13,7 +13,7 @@ import type { } from 'flipper'; import type {Counter} from './LogWatcher.js'; import type {DeviceLogEntry} from '../../devices/BaseDevice.js'; -import type {Props as PluginProps} from '../../plugin'; +import type {Props as PluginProps} from '../../plugin.tsx'; import { Text, diff --git a/src/plugins/network/index.js b/src/plugins/network/index.js index 19ad30ed5..79a2a9aaa 100644 --- a/src/plugins/network/index.js +++ b/src/plugins/network/index.js @@ -35,7 +35,7 @@ import { import RequestDetails from './RequestDetails.js'; import {clipboard} from 'electron'; import {URL} from 'url'; -import type {Notification} from '../../plugin'; +import type {Notification} from '../../plugin.tsx'; type PersistedState = {| requests: {[id: RequestId]: Request}, diff --git a/src/reducers/__tests__/notifications.node.tsx b/src/reducers/__tests__/notifications.node.tsx index 92839fa95..c4d5ad94c 100644 --- a/src/reducers/__tests__/notifications.node.tsx +++ b/src/reducers/__tests__/notifications.node.tsx @@ -15,7 +15,9 @@ import { updateCategoryBlacklist, } from '../notifications'; -const notification = { +import {Notification} from '../../plugin'; + +const notification: Notification = { id: 'id', title: 'title', message: 'message', diff --git a/src/reducers/__tests__/plugins.node.tsx b/src/reducers/__tests__/plugins.node.tsx index 5bd9b005d..3273ab744 100644 --- a/src/reducers/__tests__/plugins.node.tsx +++ b/src/reducers/__tests__/plugins.node.tsx @@ -14,17 +14,18 @@ import { FlipperBasePlugin, FlipperPlugin, FlipperDevicePlugin, -} from '../../plugin.js'; + BaseAction, +} from '../../plugin'; -const testBasePlugin = class extends FlipperBasePlugin { +const testPlugin = class extends FlipperPlugin { static id = 'TestPlugin'; }; -const testPlugin = class extends FlipperPlugin { - static id = 'TestPlugin'; -}; - -const testDevicePlugin = class extends FlipperDevicePlugin { +const testDevicePlugin = class extends FlipperDevicePlugin< + any, + BaseAction, + any +> { static id = 'TestDevicePlugin'; }; @@ -73,22 +74,6 @@ test('do not add plugin twice', () => { expect(res.clientPlugins.size).toEqual(1); }); -test('do not add other classes', () => { - const res = reducer( - { - devicePlugins: new Map(), - clientPlugins: new Map(), - gatekeepedPlugins: [], - failedPlugins: [], - disabledPlugins: [], - selectedPlugins: [], - }, - registerPlugins([testBasePlugin]), - ); - expect(res.devicePlugins.size).toEqual(0); - expect(res.devicePlugins.size).toEqual(0); -}); - test('add gatekeeped plugin', () => { const gatekeepedPlugins = [{name: 'plugin', out: 'out.js'}]; const res = reducer( diff --git a/src/reducers/plugins.tsx b/src/reducers/plugins.tsx index 6e455ec8e..df0388cfb 100644 --- a/src/reducers/plugins.tsx +++ b/src/reducers/plugins.tsx @@ -5,7 +5,7 @@ * @format */ -import {FlipperPlugin, FlipperDevicePlugin} from '../plugin.js'; +import {FlipperPlugin, FlipperDevicePlugin} from '../plugin'; import {PluginDefinition} from '../dispatcher/plugins'; export type State = { @@ -64,10 +64,10 @@ export default function reducer( // $FlowFixMe Flow doesn't know prototype if (p.prototype instanceof FlipperDevicePlugin) { - // $FlowFixMe Flow doesn't know p must be Class here + // @ts-ignore doesn't know p must be typeof FlipperDevicePlugin here devicePlugins.set(p.id, p); } else if (p.prototype instanceof FlipperPlugin) { - // $FlowFixMe Flow doesn't know p must be Class here + // @ts-ignore doesn't know p must be typeof FlipperPlugin here clientPlugins.set(p.id, p); } }); diff --git a/src/ui/components/console.js b/src/ui/components/console.js index f434675cb..9c45a4d5b 100644 --- a/src/ui/components/console.js +++ b/src/ui/components/console.js @@ -17,7 +17,7 @@ import { } from '../index'; import styled from '../styled/index'; import type {TableBodyRow, TableRows} from 'flipper'; -import type {PluginClient} from '../../plugin'; +import type {PluginClient} from '../../plugin.tsx'; type ValueWithType = {| type: string, diff --git a/src/ui/components/elements-inspector/sidebar.js b/src/ui/components/elements-inspector/sidebar.js index a75f14fc5..d6eeb0d5f 100644 --- a/src/ui/components/elements-inspector/sidebar.js +++ b/src/ui/components/elements-inspector/sidebar.js @@ -6,7 +6,7 @@ */ import type {Element} from './ElementsInspector.js'; -import type {PluginClient} from '../../../plugin'; +import type {PluginClient} from '../../../plugin.tsx'; import type Client from '../../../Client.tsx'; import type {Logger} from '../../../fb-interfaces/Logger.js'; import Panel from '../Panel.js'; diff --git a/src/utils/__tests__/exportData.electron.js b/src/utils/__tests__/exportData.electron.js index 2eb451d1e..72c1e335c 100644 --- a/src/utils/__tests__/exportData.electron.js +++ b/src/utils/__tests__/exportData.electron.js @@ -8,8 +8,8 @@ import {default as BaseDevice} from '../../devices/BaseDevice'; import {default as ArchivedDevice} from '../../devices/ArchivedDevice'; import {processStore} from '../exportData'; -import {FlipperDevicePlugin} from '../../plugin.js'; -import type {Notification} from '../../plugin.js'; +import {FlipperDevicePlugin} from '../../plugin.tsx'; +import type {Notification} from '../../plugin.tsx'; import type {ClientExport} from '../../Client.tsx'; class TestDevicePlugin extends FlipperDevicePlugin { diff --git a/src/utils/exportData.js b/src/utils/exportData.js index 638af6677..9d4acae0f 100644 --- a/src/utils/exportData.js +++ b/src/utils/exportData.js @@ -12,7 +12,7 @@ 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.js'; +import {FlipperDevicePlugin, FlipperPlugin, callClient} from '../plugin.tsx'; import {default as BaseDevice} from '../devices/BaseDevice'; import {default as ArchivedDevice} from '../devices/ArchivedDevice'; import {default as Client} from '../Client.tsx'; diff --git a/src/utils/onRegisterDevice.js b/src/utils/onRegisterDevice.js index 7586295d0..14b472806 100644 --- a/src/utils/onRegisterDevice.js +++ b/src/utils/onRegisterDevice.js @@ -5,7 +5,7 @@ * @format */ import type {Store} from '../reducers/index.tsx'; -import {FlipperPlugin, FlipperDevicePlugin} from '../plugin.js'; +import {FlipperPlugin, FlipperDevicePlugin} from '../plugin.tsx'; import type BaseDevice from '../devices/BaseDevice.js'; import {setPluginState} from '../reducers/pluginStates.tsx'; import {getPersistedState} from '../utils/pluginUtils.js'; diff --git a/src/utils/pluginUtils.js b/src/utils/pluginUtils.js index 10d8c54a3..4d50f9a6a 100644 --- a/src/utils/pluginUtils.js +++ b/src/utils/pluginUtils.js @@ -5,7 +5,7 @@ * @format */ import type BaseDevice from '../devices/BaseDevice.js'; -import {FlipperDevicePlugin, FlipperPlugin} from '../plugin.js'; +import {FlipperDevicePlugin, FlipperPlugin} from '../plugin.tsx'; import type {State as PluginStatesState} from '../reducers/pluginStates.tsx'; import {pluginsClassMap} from './exportData.js'; import type {State as PluginsState} from '../reducers/plugins.tsx';