Move files to flipper-common

Summary: Moved Logger, sleep, timeout and server contract types to flipper-common packages.

Reviewed By: passy

Differential Revision: D31475790

fbshipit-source-id: 42d2147698875f9e919ad5250f9953f3bff3ec2d
This commit is contained in:
Michel Weststrate
2021-10-12 15:59:44 -07:00
committed by Facebook GitHub Bot
parent cfd44b592a
commit 91d96774f6
67 changed files with 222 additions and 179 deletions

View File

@@ -34,6 +34,7 @@
"crc32": "^0.2.2", "crc32": "^0.2.2",
"deep-equal": "^2.0.5", "deep-equal": "^2.0.5",
"expand-tilde": "^2.0.2", "expand-tilde": "^2.0.2",
"flipper-common": "0.0.0",
"flipper-client-sdk": "^0.0.3", "flipper-client-sdk": "^0.0.3",
"flipper-doctor": "0.0.0", "flipper-doctor": "0.0.0",
"flipper-plugin": "0.0.0", "flipper-plugin": "0.0.0",

View File

@@ -12,7 +12,7 @@
import {PluginDefinition} from './plugin'; import {PluginDefinition} from './plugin';
import BaseDevice from './devices/BaseDevice'; import BaseDevice from './devices/BaseDevice';
import {Logger} from './fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {Store} from './reducers/index'; import {Store} from './reducers/index';
import {performance} from 'perf_hooks'; import {performance} from 'perf_hooks';
import {reportPluginFailures} from './utils/metrics'; import {reportPluginFailures} from './utils/metrics';
@@ -26,15 +26,17 @@ import {processMessagesLater} from './utils/messageQueue';
import {emitBytesReceived} from './dispatcher/tracking'; import {emitBytesReceived} from './dispatcher/tracking';
import {debounce} from 'lodash'; import {debounce} from 'lodash';
import {batch} from 'react-redux'; import {batch} from 'react-redux';
import {
timeout,
ClientQuery,
ClientResponseType,
ClientErrorType,
} from 'flipper-common';
import { import {
createState, createState,
_SandyPluginInstance, _SandyPluginInstance,
getFlipperLib, getFlipperLib,
timeout,
ClientQuery,
_SandyPluginDefinition, _SandyPluginDefinition,
ClientResponseType,
ClientErrorType,
} from 'flipper-plugin'; } from 'flipper-plugin';
import {freeze} from 'immer'; import {freeze} from 'immer';
import {message} from 'antd'; import {message} from 'antd';

View File

@@ -21,7 +21,7 @@ import {Store} from './reducers/';
import electron, {MenuItemConstructorOptions} from 'electron'; import electron, {MenuItemConstructorOptions} from 'electron';
import {notNull} from './utils/typeUtils'; import {notNull} from './utils/typeUtils';
import constants from './fb-stubs/constants'; import constants from './fb-stubs/constants';
import {Logger} from './fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import { import {
NormalizedMenuEntry, NormalizedMenuEntry,
_buildInMenuEntries, _buildInMenuEntries,

View File

@@ -8,7 +8,7 @@
*/ */
import {SearchableProps} from './ui'; import {SearchableProps} from './ui';
import {Logger} from './fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import { import {
Searchable, Searchable,
Button, Button,

View File

@@ -8,7 +8,7 @@
*/ */
import {FlipperPlugin, FlipperDevicePlugin} from './plugin'; import {FlipperPlugin, FlipperDevicePlugin} from './plugin';
import {Logger} from './fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import BaseDevice from './devices/BaseDevice'; import BaseDevice from './devices/BaseDevice';
import {pluginKey as getPluginKey} from './utils/pluginKey'; import {pluginKey as getPluginKey} from './utils/pluginKey';
import Client from './Client'; import Client from './Client';

View File

@@ -20,7 +20,7 @@ import {
useValue, useValue,
} from 'flipper-plugin'; } from 'flipper-plugin';
import {handleDeeplink} from '../deeplink'; import {handleDeeplink} from '../deeplink';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
test('Triggering a deeplink will work', async () => { test('Triggering a deeplink will work', async () => {
const linksSeen: any[] = []; const linksSeen: any[] = [];

View File

@@ -11,7 +11,7 @@ import {FlexColumn, Button, styled, Text, FlexRow, Spacer} from '../ui';
import React, {Component} from 'react'; import React, {Component} from 'react';
import {reportPlatformFailures} from '../utils/metrics'; import {reportPlatformFailures} from '../utils/metrics';
import {performance} from 'perf_hooks'; import {performance} from 'perf_hooks';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {IdlerImpl} from '../utils/Idler'; import {IdlerImpl} from '../utils/Idler';
import { import {
exportStoreToFile, exportStoreToFile,

View File

@@ -10,7 +10,7 @@
import {FlexColumn, styled, Text, FlexRow, Spacer, Input} from '../ui'; import {FlexColumn, styled, Text, FlexRow, Spacer, Input} from '../ui';
import React, {Component} from 'react'; import React, {Component} from 'react';
import {ReactReduxContext} from 'react-redux'; import {ReactReduxContext} from 'react-redux';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {IdlerImpl} from '../utils/Idler'; import {IdlerImpl} from '../utils/Idler';
import { import {
shareFlipperData, shareFlipperData,

View File

@@ -8,7 +8,7 @@
*/ */
import {Group, SUPPORTED_GROUPS} from './reducers/supportForm'; import {Group, SUPPORTED_GROUPS} from './reducers/supportForm';
import {Logger} from './fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {Store} from './reducers/index'; import {Store} from './reducers/index';
import {importDataToStore} from './utils/exportData'; import {importDataToStore} from './utils/exportData';
import {selectPlugin, getAllClients} from './reducers/connections'; import {selectPlugin, getAllClients} from './reducers/connections';

View File

@@ -7,7 +7,7 @@
* @format * @format
*/ */
import {Logger} from './fb-interfaces/Logger'; import {Logger} from 'flipper-common';
export type OpenPluginParams = { export type OpenPluginParams = {
pluginId: string; pluginId: string;

View File

@@ -9,19 +9,21 @@
import stream from 'stream'; import stream from 'stream';
import { import {
DeviceLogEntry, Device,
_SandyDevicePluginInstance, _SandyDevicePluginInstance,
_SandyPluginDefinition, _SandyPluginDefinition,
DeviceType,
DeviceLogListener, DeviceLogListener,
Idler, Idler,
createState, createState,
getFlipperLib, getFlipperLib,
} from 'flipper-plugin';
import {
DeviceLogEntry,
DeviceOS, DeviceOS,
DeviceType,
DeviceDescription, DeviceDescription,
FlipperServer, FlipperServer,
Device, } from 'flipper-common';
} from 'flipper-plugin';
import {DeviceSpec, PluginDetails} from 'flipper-plugin-lib'; import {DeviceSpec, PluginDetails} from 'flipper-plugin-lib';
import {getPluginKey} from '../utils/pluginKey'; import {getPluginKey} from '../utils/pluginKey';
import {Base64} from 'js-base64'; import {Base64} from 'js-base64';

View File

@@ -11,7 +11,7 @@
// eslint-disable-next-line flipper/no-electron-remote-imports // eslint-disable-next-line flipper/no-electron-remote-imports
import {remote, ipcRenderer, IpcRendererEvent} from 'electron'; import {remote, ipcRenderer, IpcRendererEvent} from 'electron';
import {Store} from '../reducers/index'; import {Store} from '../reducers/index';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {parseFlipperPorts} from '../server/utils/environmentVariables'; import {parseFlipperPorts} from '../server/utils/environmentVariables';
import { import {
importFileToStore, importFileToStore,

View File

@@ -9,16 +9,16 @@
import React from 'react'; import React from 'react';
import {State, Store} from '../reducers/index'; import {State, Store} from '../reducers/index';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import { import {
FlipperServerConfig, FlipperServerConfig,
FlipperServerImpl, FlipperServerImpl,
} from '../server/FlipperServerImpl'; } from '../server/FlipperServerImpl';
import {selectClient} from '../reducers/connections'; import {selectClient} from '../reducers/connections';
import Client from '../Client'; import Client from '../Client';
import {message, notification} from 'antd'; import {notification} from 'antd';
import BaseDevice from '../devices/BaseDevice'; import BaseDevice from '../devices/BaseDevice';
import {ClientDescription, timeout} from 'flipper-plugin'; import {ClientDescription, timeout} from 'flipper-common';
import {reportPlatformFailures} from '../utils/metrics'; import {reportPlatformFailures} from '../utils/metrics';
import {sideEffect} from '../utils/sideEffect'; import {sideEffect} from '../utils/sideEffect';

View File

@@ -23,7 +23,7 @@ import pluginDownloads from './pluginDownloads';
import info from '../utils/info'; import info from '../utils/info';
import pluginChangeListener from './pluginsChangeListener'; import pluginChangeListener from './pluginsChangeListener';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {Store} from '../reducers/index'; import {Store} from '../reducers/index';
import {Dispatcher} from './types'; import {Dispatcher} from './types';
import {notNull} from '../utils/typeUtils'; import {notNull} from '../utils/typeUtils';

View File

@@ -8,7 +8,7 @@
*/ */
import {Store} from '../reducers/index'; import {Store} from '../reducers/index';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {PluginNotification} from '../reducers/notifications'; import {PluginNotification} from '../reducers/notifications';
import {ipcRenderer, IpcRendererEvent} from 'electron'; import {ipcRenderer, IpcRendererEvent} from 'electron';
import { import {

View File

@@ -8,7 +8,7 @@
*/ */
import type {Store} from '../reducers/index'; import type {Store} from '../reducers/index';
import type {Logger} from '../fb-interfaces/Logger'; import type {Logger} from 'flipper-common';
import { import {
LoadPluginActionPayload, LoadPluginActionPayload,
UninstallPluginActionPayload, UninstallPluginActionPayload,

View File

@@ -8,7 +8,7 @@
*/ */
import type {Store} from '../reducers/index'; import type {Store} from '../reducers/index';
import type {Logger} from '../fb-interfaces/Logger'; import type {Logger} from 'flipper-common';
import {PluginDefinition} from '../plugin'; import {PluginDefinition} from '../plugin';
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';

View File

@@ -8,7 +8,7 @@
*/ */
import Client from '../Client'; import Client from '../Client';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {Store} from '../reducers'; import {Store} from '../reducers';
import {appPluginListChanged} from '../reducers/connections'; import {appPluginListChanged} from '../reducers/connections';
import {getActiveClient} from '../selectors/connections'; import {getActiveClient} from '../selectors/connections';

View File

@@ -14,7 +14,7 @@ import {performance} from 'perf_hooks';
import {EventEmitter} from 'events'; import {EventEmitter} from 'events';
import {State, Store} from '../reducers/index'; import {State, Store} from '../reducers/index';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import { import {
getPluginBackgroundStats, getPluginBackgroundStats,
resetPluginBackgroundStatsDelta, resetPluginBackgroundStatsDelta,

View File

@@ -8,7 +8,7 @@
*/ */
import {Store} from '../reducers/index'; import {Store} from '../reducers/index';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
export type Dispatcher = ( export type Dispatcher = (
store: Store, store: Store,

View File

@@ -1,14 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
export {LogTypes, TrackType, Logger} from 'flipper-plugin';
export type Args = {
isTest?: boolean;
};

View File

@@ -7,17 +7,17 @@
* @format * @format
*/ */
import {Logger, Args} from '../fb-interfaces/Logger'; import {Logger, LoggerArgs} from 'flipper-common';
import StubLogger from '../utils/StubLogger'; import StubLogger from '../utils/StubLogger';
import {Store} from '../reducers/index'; import {Store} from '../reducers/index';
let instance: StubLogger | null = null; let instance: StubLogger | null = null;
export function init(store: Store, _args?: Args): Logger { export function init(store: Store, _args?: LoggerArgs): Logger {
if (instance) { if (instance) {
throw new Error('Attempted to initialize Logger when already initialized'); throw new Error('Attempted to initialize Logger when already initialized');
} }
instance = new StubLogger(store); instance = new StubLogger(store, _args);
return instance; return instance;
} }

View File

@@ -12,7 +12,7 @@ import {
getErrorFromErrorLike, getErrorFromErrorLike,
getStringFromErrorLike, getStringFromErrorLike,
} from '../../utils/errors'; } from '../../utils/errors';
import {Args, Logger} from '../../fb-interfaces/Logger'; import {LoggerArgs, Logger} from 'flipper-common';
const instance = { const instance = {
track: jest.fn(), track: jest.fn(),
@@ -35,7 +35,7 @@ export function extractError(...data: Array<any>): {
}; };
} }
export function init(_store: Store, _args?: Args): Logger { export function init(_store: Store, _args?: LoggerArgs): Logger {
return instance; return instance;
} }

View File

@@ -123,7 +123,7 @@ export {default as FileSelector} from './ui/components/FileSelector';
export {KeyboardActions} from './MenuBar'; export {KeyboardActions} from './MenuBar';
export {getFlipperMediaCDN, appendAccessTokenToUrl} from './fb-stubs/user'; export {getFlipperMediaCDN, appendAccessTokenToUrl} from './fb-stubs/user';
export {Rect} from './utils/geometry'; export {Rect} from './utils/geometry';
export {Logger} from './fb-interfaces/Logger'; export {Logger} from 'flipper-common';
export {getInstance as getLogger} from './fb-stubs/Logger'; export {getInstance as getLogger} from './fb-stubs/Logger';
export {callVSCode} from './utils/vscodeUtils'; export {callVSCode} from './utils/vscodeUtils';
export {checkIdbIsInstalled} from './server/devices/ios/iOSContainerUtility'; export {checkIdbIsInstalled} from './server/devices/ios/iOSContainerUtility';

View File

@@ -8,7 +8,7 @@
*/ */
import {KeyboardActions} from './MenuBar'; import {KeyboardActions} from './MenuBar';
import {Logger} from './fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import Client from './Client'; import Client from './Client';
import {Component} from 'react'; import {Component} from 'react';
import BaseDevice from './devices/BaseDevice'; import BaseDevice from './devices/BaseDevice';

View File

@@ -12,7 +12,7 @@ import {produce} from 'immer';
import type BaseDevice from '../devices/BaseDevice'; import type BaseDevice from '../devices/BaseDevice';
import type Client from '../Client'; import type Client from '../Client';
import type {UninitializedClient} from 'flipper-plugin'; import type {UninitializedClient, DeviceOS, Logger} from 'flipper-common';
import {performance} from 'perf_hooks'; import {performance} from 'perf_hooks';
import type {Actions} from '.'; import type {Actions} from '.';
import {WelcomeScreenStaticView} from '../sandy-chrome/WelcomeScreen'; import {WelcomeScreenStaticView} from '../sandy-chrome/WelcomeScreen';
@@ -21,7 +21,6 @@ import {getPluginKey} from '../utils/pluginKey';
import {deconstructClientId} from '../utils/clientUtils'; import {deconstructClientId} from '../utils/clientUtils';
import type {RegisterPluginAction} from './plugins'; import type {RegisterPluginAction} from './plugins';
import {DeviceOS, Logger} from 'flipper-plugin';
import {FlipperServerImpl} from '../server/FlipperServerImpl'; import {FlipperServerImpl} from '../server/FlipperServerImpl';
import {shallowEqual} from 'react-redux'; import {shallowEqual} from 'react-redux';

View File

@@ -19,7 +19,7 @@ import {
import {Link, styled} from '../ui'; import {Link, styled} from '../ui';
import {theme} from 'flipper-plugin'; import {theme} from 'flipper-plugin';
import {ipcRenderer} from 'electron'; import {ipcRenderer} from 'electron';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {LeftRail} from './LeftRail'; import {LeftRail} from './LeftRail';
import {useStore, useDispatch} from '../utils/useStore'; import {useStore, useDispatch} from '../utils/useStore';

View File

@@ -8,7 +8,7 @@
*/ */
import EventEmitter from 'events'; import EventEmitter from 'events';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import ServerController from './comms/ServerController'; import ServerController from './comms/ServerController';
import {CertificateExchangeMedium} from './utils/CertificateProvider'; import {CertificateExchangeMedium} from './utils/CertificateProvider';
import {ServerPorts} from '../reducers/application'; import {ServerPorts} from '../reducers/application';
@@ -22,7 +22,7 @@ import {
FlipperServerCommands, FlipperServerCommands,
FlipperServer, FlipperServer,
UninitializedClient, UninitializedClient,
} from 'flipper-plugin'; } from 'flipper-common';
import {ServerDevice} from './devices/ServerDevice'; import {ServerDevice} from './devices/ServerDevice';
import {Base64} from 'js-base64'; import {Base64} from 'js-base64';
import MetroDevice from './devices/metro/MetroDevice'; import MetroDevice from './devices/metro/MetroDevice';

View File

@@ -7,7 +7,7 @@
* @format * @format
*/ */
import {ClientResponseType} from 'flipper-plugin'; import {ClientResponseType} from 'flipper-common';
import WebSocket from 'ws'; import WebSocket from 'ws';
import { import {
ConnectionStatusChange, ConnectionStatusChange,

View File

@@ -7,7 +7,7 @@
* @format * @format
*/ */
import {ClientResponseType} from 'flipper-plugin'; import {ClientResponseType} from 'flipper-common';
export enum ConnectionStatus { export enum ConnectionStatus {
ERROR = 'error', ERROR = 'error',

View File

@@ -13,7 +13,7 @@ import {
} from '../utils/CertificateProvider'; } from '../utils/CertificateProvider';
import {ClientConnection} from './ClientConnection'; import {ClientConnection} from './ClientConnection';
import {transformCertificateExchangeMediumToType} from './Utilities'; import {transformCertificateExchangeMediumToType} from './Utilities';
import {ClientDescription, ClientQuery} from 'flipper-plugin'; import {ClientDescription, ClientQuery} from 'flipper-common';
/** /**
* ClientCsrQuery defines a client query with CSR * ClientCsrQuery defines a client query with CSR

View File

@@ -8,11 +8,11 @@
*/ */
import {CertificateExchangeMedium} from '../utils/CertificateProvider'; import {CertificateExchangeMedium} from '../utils/CertificateProvider';
import {Logger} from '../../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {ClientDescription, ClientQuery} from 'flipper-plugin'; import {ClientDescription, ClientQuery} from 'flipper-common';
import CertificateProvider from '../utils/CertificateProvider'; import CertificateProvider from '../utils/CertificateProvider';
import {ClientConnection, ConnectionStatus} from './ClientConnection'; import {ClientConnection, ConnectionStatus} from './ClientConnection';
import {UninitializedClient} from 'flipper-plugin'; import {UninitializedClient} from 'flipper-common';
import {reportPlatformFailures} from '../../utils/metrics'; import {reportPlatformFailures} from '../../utils/metrics';
import {EventEmitter} from 'events'; import {EventEmitter} from 'events';
import invariant from 'invariant'; import invariant from 'invariant';

View File

@@ -27,7 +27,7 @@ import {
ClientDescription, ClientDescription,
ClientQuery, ClientQuery,
ClientResponseType, ClientResponseType,
} from 'flipper-plugin'; } from 'flipper-common';
/** /**
* RSocket based server. RSocket uses its own protocol for communication between * RSocket based server. RSocket uses its own protocol for communication between

View File

@@ -23,7 +23,7 @@ import {
ClientErrorType, ClientErrorType,
ClientQuery, ClientQuery,
DeviceOS, DeviceOS,
} from 'flipper-plugin'; } from 'flipper-common';
/** /**
* WebSocket-based server. * WebSocket-based server.

View File

@@ -15,7 +15,7 @@ import {ServerEventsListener} from './ServerAdapter';
import constants from '../../fb-stubs/constants'; import constants from '../../fb-stubs/constants';
import ws from 'ws'; import ws from 'ws';
import {IncomingMessage} from 'http'; import {IncomingMessage} from 'http';
import {ClientDescription, ClientQuery} from 'flipper-plugin'; import {ClientDescription, ClientQuery} from 'flipper-common';
/** /**
* WebSocket-based server which uses a connect/disconnect handshake over an insecure channel. * WebSocket-based server which uses a connect/disconnect handshake over an insecure channel.

View File

@@ -7,7 +7,7 @@
* @format * @format
*/ */
import {ClientQuery} from 'flipper-plugin'; import {ClientQuery} from 'flipper-common';
import {CertificateExchangeMedium} from '../utils/CertificateProvider'; import {CertificateExchangeMedium} from '../utils/CertificateProvider';
/** /**

View File

@@ -7,7 +7,7 @@
* @format * @format
*/ */
import {DeviceOS} from 'flipper-plugin'; import {DeviceOS} from 'flipper-common';
import {FlipperServerImpl} from '../FlipperServerImpl'; import {FlipperServerImpl} from '../FlipperServerImpl';
import {ServerDevice} from './ServerDevice'; import {ServerDevice} from './ServerDevice';

View File

@@ -7,13 +7,13 @@
* @format * @format
*/ */
import {createState, DeviceDescription, DeviceLogEntry} from 'flipper-plugin'; import {DeviceDescription, DeviceLogEntry} from 'flipper-common';
import {FlipperServerImpl} from '../FlipperServerImpl'; import {FlipperServerImpl} from '../FlipperServerImpl';
export abstract class ServerDevice { export abstract class ServerDevice {
readonly info: DeviceDescription; readonly info: DeviceDescription;
readonly connected = createState(true);
readonly flipperServer: FlipperServerImpl; readonly flipperServer: FlipperServerImpl;
connected = true;
constructor(flipperServer: FlipperServerImpl, info: DeviceDescription) { constructor(flipperServer: FlipperServerImpl, info: DeviceDescription) {
this.flipperServer = flipperServer; this.flipperServer = flipperServer;
@@ -34,7 +34,9 @@ export abstract class ServerDevice {
/** /**
* The device might have no active connection * The device might have no active connection
*/ */
disconnect(): void {} disconnect(): void {
this.connected = false;
}
startLogging() { startLogging() {
// to be subclassed // to be subclassed

View File

@@ -10,7 +10,7 @@
import adb, {Client as ADBClient, PullTransfer} from 'adbkit'; import adb, {Client as ADBClient, PullTransfer} from 'adbkit';
import {Priority, Reader} from 'adbkit-logcat'; import {Priority, Reader} from 'adbkit-logcat';
import {createWriteStream} from 'fs'; import {createWriteStream} from 'fs';
import type {LogLevel, DeviceType} from 'flipper-plugin'; import type {DeviceLogLevel, DeviceType} from 'flipper-common';
import which from 'which'; import which from 'which';
import {spawn} from 'child_process'; import {spawn} from 'child_process';
import {dirname, join} from 'path'; import {dirname, join} from 'path';
@@ -56,7 +56,7 @@ export default class AndroidDevice extends ServerDevice {
this.reader = reader; this.reader = reader;
reader reader
.on('entry', (entry) => { .on('entry', (entry) => {
let type: LogLevel = 'unknown'; let type: DeviceLogLevel = 'unknown';
if (entry.priority === Priority.VERBOSE) { if (entry.priority === Priority.VERBOSE) {
type = 'verbose'; type = 'verbose';
} }
@@ -89,7 +89,7 @@ export default class AndroidDevice extends ServerDevice {
if (this.reader) { if (this.reader) {
// logs didn't stop gracefully // logs didn't stop gracefully
setTimeout(() => { setTimeout(() => {
if (this.connected.get()) { if (this.connected) {
console.warn( console.warn(
`Log stream broken: ${this.serial} - restarting`, `Log stream broken: ${this.serial} - restarting`,
); );

View File

@@ -7,7 +7,12 @@
* @format * @format
*/ */
import {LogLevel, DeviceLogEntry, DeviceType, timeout} from 'flipper-plugin'; import {
DeviceLogLevel,
DeviceLogEntry,
DeviceType,
timeout,
} from 'flipper-common';
import child_process, {ChildProcess} from 'child_process'; import child_process, {ChildProcess} from 'child_process';
import JSONStream from 'JSONStream'; import JSONStream from 'JSONStream';
import {Transform} from 'stream'; import {Transform} from 'stream';
@@ -65,7 +70,7 @@ export default class IOSDevice extends ServerDevice {
} }
async screenshot(): Promise<Buffer> { async screenshot(): Promise<Buffer> {
if (!this.connected.get()) { if (!this.connected) {
return Buffer.from([]); return Buffer.from([]);
} }
return await this.iOSBridge.screenshot(this.serial); return await this.iOSBridge.screenshot(this.serial);
@@ -148,7 +153,7 @@ export default class IOSDevice extends ServerDevice {
} }
} }
static getLogLevel(level: string): LogLevel { static getLogLevel(level: string): DeviceLogLevel {
switch (level) { switch (level) {
case 'Default': case 'Default':
return 'debug'; return 'debug';
@@ -183,7 +188,7 @@ export default class IOSDevice extends ServerDevice {
} }
static parseJsonLogEntry(entry: RawLogEntry): DeviceLogEntry { static parseJsonLogEntry(entry: RawLogEntry): DeviceLogEntry {
let type: LogLevel = IOSDevice.getLogLevel(entry.messageType); let type: DeviceLogLevel = IOSDevice.getLogLevel(entry.messageType);
// when Apple log levels are not used, log messages can be prefixed with // when Apple log levels are not used, log messages can be prefixed with
// their loglevel. // their loglevel.
@@ -215,7 +220,7 @@ export default class IOSDevice extends ServerDevice {
} }
async screenCaptureAvailable() { async screenCaptureAvailable() {
return this.info.deviceType === 'emulator' && this.connected.get(); return this.info.deviceType === 'emulator' && this.connected;
} }
async startScreenCapture(destination: string) { async startScreenCapture(destination: string) {

View File

@@ -8,7 +8,7 @@
*/ */
import {ChildProcess} from 'child_process'; import {ChildProcess} from 'child_process';
import type {DeviceType} from 'flipper-plugin'; import type {DeviceType} from 'flipper-common';
import path from 'path'; import path from 'path';
import childProcess from 'child_process'; import childProcess from 'child_process';
import {exec, execFile} from 'promisify-child-process'; import {exec, execFile} from 'promisify-child-process';

View File

@@ -7,7 +7,7 @@
* @format * @format
*/ */
import {LogLevel} from 'flipper-plugin'; import {DeviceLogLevel} from 'flipper-common';
import util from 'util'; import util from 'util';
import {FlipperServerImpl} from '../../FlipperServerImpl'; import {FlipperServerImpl} from '../../FlipperServerImpl';
import {ServerDevice} from '../ServerDevice'; import {ServerDevice} from '../ServerDevice';
@@ -102,7 +102,7 @@ export type MetroReportableEvent =
data: Array<any>; data: Array<any>;
}; };
const metroLogLevelMapping: {[key: string]: LogLevel} = { const metroLogLevelMapping: {[key: string]: DeviceLogLevel} = {
trace: 'verbose', trace: 'verbose',
info: 'info', info: 'info',
warn: 'warn', warn: 'warn',
@@ -116,7 +116,7 @@ const metroLogLevelMapping: {[key: string]: LogLevel} = {
function getLoglevelFromMessageType( function getLoglevelFromMessageType(
type: MetroReportableEvent['type'], type: MetroReportableEvent['type'],
): LogLevel | null { ): DeviceLogLevel | null {
switch (type) { switch (type) {
case 'bundle_build_done': case 'bundle_build_done':
case 'bundle_build_started': case 'bundle_build_started':
@@ -163,7 +163,8 @@ export default class MetroDevice extends ServerDevice {
private _handleWSMessage = ({data}: any) => { private _handleWSMessage = ({data}: any) => {
const message: MetroReportableEvent = JSON.parse(data); const message: MetroReportableEvent = JSON.parse(data);
if (message.type === 'client_log') { if (message.type === 'client_log') {
const type: LogLevel = metroLogLevelMapping[message.level] || 'unknown'; const type: DeviceLogLevel =
metroLogLevelMapping[message.level] || 'unknown';
this.addLogEntry({ this.addLogEntry({
date: new Date(), date: new Date(),
pid: 0, pid: 0,

View File

@@ -7,7 +7,7 @@
* @format * @format
*/ */
import {Logger} from '../../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {internGraphPOSTAPIRequest} from '../../fb-stubs/user'; import {internGraphPOSTAPIRequest} from '../../fb-stubs/user';
import ServerController from '../comms/ServerController'; import ServerController from '../comms/ServerController';
import {promisify} from 'util'; import {promisify} from 'util';
@@ -26,7 +26,7 @@ import * as androidUtil from '../devices/android/androidContainerUtility';
import os from 'os'; import os from 'os';
import {Client as ADBClient} from 'adbkit'; import {Client as ADBClient} from 'adbkit';
import archiver from 'archiver'; import archiver from 'archiver';
import {timeout} from 'flipper-plugin'; import {timeout} from 'flipper-common';
import {v4 as uuid} from 'uuid'; import {v4 as uuid} from 'uuid';
import {isTest} from '../../utils/isProduction'; import {isTest} from '../../utils/isProduction';
import {message} from 'antd'; import {message} from 'antd';

View File

@@ -17,7 +17,7 @@ import {
ConnectionStatusChange, ConnectionStatusChange,
} from '../server/comms/ClientConnection'; } from '../server/comms/ClientConnection';
import {buildClientId} from '../utils/clientUtils'; import {buildClientId} from '../utils/clientUtils';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import {PluginDefinition} from '../plugin'; import {PluginDefinition} from '../plugin';
import {registerPlugins} from '../reducers/plugins'; import {registerPlugins} from '../reducers/plugins';
import {getInstance} from '../fb-stubs/Logger'; import {getInstance} from '../fb-stubs/Logger';
@@ -25,7 +25,7 @@ import {initializeFlipperLibImplementation} from '../utils/flipperLibImplementat
import pluginManager from '../dispatcher/pluginManager'; import pluginManager from '../dispatcher/pluginManager';
import {PluginDetails} from 'flipper-plugin-lib'; import {PluginDetails} from 'flipper-plugin-lib';
import ArchivedDevice from '../devices/ArchivedDevice'; import ArchivedDevice from '../devices/ArchivedDevice';
import {ClientQuery, DeviceOS} from 'flipper-plugin'; import {ClientQuery, DeviceOS} from 'flipper-common';
import {TestDevice} from './TestDevice'; import {TestDevice} from './TestDevice';
export interface AppOptions { export interface AppOptions {

View File

@@ -26,7 +26,7 @@ import BaseDevice from '../devices/BaseDevice';
import {Store} from '../reducers/index'; import {Store} from '../reducers/index';
import Client from '../Client'; import Client from '../Client';
import {Logger} from '../fb-interfaces/Logger'; import {ClientQuery, Logger} from 'flipper-common';
import {FlipperDevicePlugin, FlipperPlugin, PluginDefinition} from '../plugin'; import {FlipperDevicePlugin, FlipperPlugin, PluginDefinition} from '../plugin';
import PluginContainer from '../PluginContainer'; import PluginContainer from '../PluginContainer';
import {isDevicePluginDefinition} from '../utils/pluginUtils'; import {isDevicePluginDefinition} from '../utils/pluginUtils';
@@ -36,7 +36,7 @@ import MockFlipper from './MockFlipper';
import {switchPlugin} from '../reducers/pluginManager'; import {switchPlugin} from '../reducers/pluginManager';
import {createSandyPluginFromClassicPlugin} from '../dispatcher/plugins'; import {createSandyPluginFromClassicPlugin} from '../dispatcher/plugins';
import {createMockActivatablePluginDetails} from '../utils/testUtils'; import {createMockActivatablePluginDetails} from '../utils/testUtils';
import {ClientQuery, _SandyPluginDefinition} from 'flipper-plugin'; import {_SandyPluginDefinition} from 'flipper-plugin';
export type MockFlipperResult = { export type MockFlipperResult = {
client: Client; client: Client;

View File

@@ -10,7 +10,7 @@
import {ElementsInspectorElement} from 'flipper-plugin'; import {ElementsInspectorElement} from 'flipper-plugin';
import {PluginClient} from '../../../plugin'; import {PluginClient} from '../../../plugin';
import Client from '../../../Client'; import Client from '../../../Client';
import {Logger} from '../../../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
import Panel from '../Panel'; import Panel from '../Panel';
import {DataInspector} from 'flipper-plugin'; import {DataInspector} from 'flipper-plugin';
import {Component} from 'react'; import {Component} from 'react';

View File

@@ -7,13 +7,18 @@
* @format * @format
*/ */
import {Logger, Args, TrackType} from '../fb-interfaces/Logger'; import {Logger, LoggerTrackType, LoggerArgs} from 'flipper-common';
import {Store} from '../reducers/index'; import {Store} from '../reducers/index';
export default class StubLogger implements Logger { export default class StubLogger implements Logger {
constructor(_store: Store, _args?: Args) {} constructor(_store: Store, _args?: LoggerArgs) {}
track(_type: TrackType, _event: string, _data?: any, _plugin?: string) {} track(
_type: LoggerTrackType,
_event: string,
_data?: any,
_plugin?: string,
) {}
trackTimeSince(_mark: string, _eventName?: string) {} trackTimeSince(_mark: string, _eventName?: string) {}

View File

@@ -40,7 +40,8 @@ import {processMessageQueue} from './messageQueue';
import {getPluginTitle} from './pluginUtils'; import {getPluginTitle} from './pluginUtils';
import {capture} from './screenshot'; import {capture} from './screenshot';
import {uploadFlipperMedia} from '../fb-stubs/user'; import {uploadFlipperMedia} from '../fb-stubs/user';
import {ClientQuery, Dialog, Idler} from 'flipper-plugin'; import {Dialog, Idler} from 'flipper-plugin';
import {ClientQuery} from 'flipper-common';
import ShareSheetExportUrl from '../chrome/ShareSheetExportUrl'; import ShareSheetExportUrl from '../chrome/ShareSheetExportUrl';
import ShareSheetExportFile from '../chrome/ShareSheetExportFile'; import ShareSheetExportFile from '../chrome/ShareSheetExportFile';
import ExportDataPluginSheet from '../chrome/ExportDataPluginSheet'; import ExportDataPluginSheet from '../chrome/ExportDataPluginSheet';

View File

@@ -8,7 +8,7 @@
*/ */
import {_setFlipperLibImplementation} from 'flipper-plugin'; import {_setFlipperLibImplementation} from 'flipper-plugin';
import type {Logger} from '../fb-interfaces/Logger'; import type {Logger} from 'flipper-common';
import type {Store} from '../reducers'; import type {Store} from '../reducers';
import createPaste from '../fb-stubs/createPaste'; import createPaste from '../fb-stubs/createPaste';
import GK from '../fb-stubs/GK'; import GK from '../fb-stubs/GK';

View File

@@ -14,7 +14,7 @@ import {getStaticPath} from './pathUtils';
import type {State, Store} from '../reducers/index'; import type {State, Store} from '../reducers/index';
import {deconstructClientId} from './clientUtils'; import {deconstructClientId} from './clientUtils';
import {sideEffect} from './sideEffect'; import {sideEffect} from './sideEffect';
import {Logger} from '../fb-interfaces/Logger'; import {Logger} from 'flipper-common';
type PlatformInfo = { type PlatformInfo = {
arch: string; arch: string;

View File

@@ -0,0 +1,44 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
export type LoggerTypes = 'error' | 'warn' | 'info' | 'debug';
export type LoggerTrackType =
| 'duration'
| 'usage'
| 'performance'
| 'success-rate'
| 'operation-cancelled';
export type LoggerArgs = {
isTest?: boolean;
};
export interface Logger {
track(
type: LoggerTrackType,
event: string,
data?: any,
plugin?: string,
): void;
trackTimeSince(
mark: string,
eventName?: string | null | undefined,
data?: any,
): void;
info(data: any, category: string): void;
warn(data: any, category: string): void;
error(data: any, category: string): void;
debug(data: any, category: string): void;
}

View File

@@ -7,6 +7,12 @@
* @format * @format
*/ */
export function helloWorld() { export {
return true; Logger,
} LoggerTrackType,
LoggerTypes,
LoggerArgs,
} from './fb-interfaces/Logger';
export * from './server-types';
export {sleep} from './utils/sleep';
export {timeout} from './utils/timeout';

View File

@@ -12,7 +12,6 @@ import {
DeviceType as PluginDeviceType, DeviceType as PluginDeviceType,
OS as PluginOS, OS as PluginOS,
} from 'flipper-plugin-lib'; } from 'flipper-plugin-lib';
import {DeviceLogEntry} from '../plugin/DevicePlugin';
// In the future, this file would deserve it's own package, as it doesn't really relate to plugins. // In the future, this file would deserve it's own package, as it doesn't really relate to plugins.
// Since flipper-plugin however is currently shared among server, client and defines a lot of base types, leaving it here for now. // Since flipper-plugin however is currently shared among server, client and defines a lot of base types, leaving it here for now.
@@ -40,6 +39,25 @@ export type DeviceDescription = {
readonly sdkVersion?: string; readonly sdkVersion?: string;
}; };
export type DeviceLogEntry = {
readonly date: Date;
readonly type: DeviceLogLevel;
readonly message: string;
readonly pid: number;
readonly tid: number;
readonly app?: string;
readonly tag: string;
};
export type DeviceLogLevel =
| 'unknown'
| 'verbose'
| 'debug'
| 'info'
| 'warn'
| 'error'
| 'fatal';
export type UninitializedClient = { export type UninitializedClient = {
os: string; os: string;
deviceName: string; deviceName: string;

View File

@@ -4,5 +4,9 @@
"outDir": "lib", "outDir": "lib",
"rootDir": "src" "rootDir": "src"
}, },
"references": [] "references": [
{
"path": "../plugin-lib"
}
]
} }

View File

@@ -14,6 +14,7 @@
"@emotion/react": "^11.4.1", "@emotion/react": "^11.4.1",
"@reach/observe-rect": "^1.2.0", "@reach/observe-rect": "^1.2.0",
"@types/uuid": "^8.3.1", "@types/uuid": "^8.3.1",
"flipper-common": "0.0.0",
"immer": "^9.0.6", "immer": "^9.0.6",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"react-color": "^2.19.3", "react-color": "^2.19.3",

View File

@@ -83,8 +83,11 @@ test('Correct top level API exposed', () => {
"DefaultKeyboardAction", "DefaultKeyboardAction",
"Device", "Device",
"DeviceLogEntry", "DeviceLogEntry",
"DeviceLogLevel",
"DeviceLogListener", "DeviceLogListener",
"DeviceOS",
"DevicePluginClient", "DevicePluginClient",
"DeviceType",
"DialogResult", "DialogResult",
"Draft", "Draft",
"ElementAttribute", "ElementAttribute",
@@ -99,15 +102,12 @@ test('Correct top level API exposed', () => {
"Idler", "Idler",
"InteractionReport", "InteractionReport",
"InteractionReporter", "InteractionReporter",
"LogLevel",
"LogTypes",
"Logger", "Logger",
"MenuEntry", "MenuEntry",
"MockedConsole", "MockedConsole",
"NormalizedMenuEntry", "NormalizedMenuEntry",
"Notification", "Notification",
"PluginClient", "PluginClient",
"TrackType",
] ]
`); `);
}); });

View File

@@ -13,7 +13,7 @@ import {createState} from '../state/atom';
import {PluginClient} from '../plugin/Plugin'; import {PluginClient} from '../plugin/Plugin';
import {DevicePluginClient} from '../plugin/DevicePlugin'; import {DevicePluginClient} from '../plugin/DevicePlugin';
import mockConsole from 'jest-mock-console'; import mockConsole from 'jest-mock-console';
import {sleep} from '../utils/sleep'; import {sleep} from 'flipper-common';
import {createDataSource} from '../state/createDataSource'; import {createDataSource} from '../state/createDataSource';
test('it can start a plugin and lifecycle events', () => { test('it can start a plugin and lifecycle events', () => {

View File

@@ -21,10 +21,8 @@ export {
} from './plugin/Plugin'; } from './plugin/Plugin';
export { export {
Device, Device,
DeviceLogEntry,
DeviceLogListener, DeviceLogListener,
DevicePluginClient, DevicePluginClient,
LogLevel,
SandyDevicePluginInstance as _SandyDevicePluginInstance, SandyDevicePluginInstance as _SandyDevicePluginInstance,
} from './plugin/DevicePlugin'; } from './plugin/DevicePlugin';
export {SandyPluginDefinition as _SandyPluginDefinition} from './plugin/SandyPluginDefinition'; export {SandyPluginDefinition as _SandyPluginDefinition} from './plugin/SandyPluginDefinition';
@@ -75,16 +73,8 @@ export {
export {DataFormatter} from './ui/DataFormatter'; export {DataFormatter} from './ui/DataFormatter';
export {sleep} from './utils/sleep'; export {useLogger, _LoggerContext} from './utils/useLogger';
export {timeout} from './utils/timeout';
export {
LogTypes,
TrackType,
Logger,
useLogger,
_LoggerContext,
} from './utils/Logger';
export {Idler} from './utils/Idler'; export {Idler} from './utils/Idler';
// Import from the index file directly, to make sure package.json's main field is skipped. // Import from the index file directly, to make sure package.json's main field is skipped.
@@ -143,4 +133,12 @@ export {textContent} from './utils/textContent';
// T69106962 // T69106962
export const TestUtils = TestUtilites; export const TestUtils = TestUtilites;
export * from './types/server-types'; export {
sleep,
timeout,
DeviceOS,
DeviceType,
DeviceLogEntry,
DeviceLogLevel,
Logger,
} from 'flipper-common';

View File

@@ -11,29 +11,10 @@ import {SandyPluginDefinition} from './SandyPluginDefinition';
import {BasePluginInstance, BasePluginClient} from './PluginBase'; import {BasePluginInstance, BasePluginClient} from './PluginBase';
import {FlipperLib} from './FlipperLib'; import {FlipperLib} from './FlipperLib';
import {Atom, ReadOnlyAtom} from '../state/atom'; import {Atom, ReadOnlyAtom} from '../state/atom';
import {DeviceOS, DeviceType} from '../types/server-types'; import {DeviceOS, DeviceType, DeviceLogEntry} from 'flipper-common';
export type DeviceLogListener = (entry: DeviceLogEntry) => void; export type DeviceLogListener = (entry: DeviceLogEntry) => void;
export type DeviceLogEntry = {
readonly date: Date;
readonly type: LogLevel;
readonly message: string;
readonly pid: number;
readonly tid: number;
readonly app?: string;
readonly tag: string;
};
export type LogLevel =
| 'unknown'
| 'verbose'
| 'debug'
| 'info'
| 'warn'
| 'error'
| 'fatal';
export interface Device { export interface Device {
readonly isArchived: boolean; readonly isArchived: boolean;
readonly isConnected: boolean; readonly isConnected: boolean;

View File

@@ -30,7 +30,6 @@ import {
import {SandyPluginRenderer} from '../plugin/PluginRenderer'; import {SandyPluginRenderer} from '../plugin/PluginRenderer';
import {act} from '@testing-library/react'; import {act} from '@testing-library/react';
import { import {
DeviceLogEntry,
SandyDevicePluginInstance, SandyDevicePluginInstance,
Device, Device,
DeviceLogListener, DeviceLogListener,
@@ -41,6 +40,7 @@ import {stubLogger} from '../utils/Logger';
import {Idler} from '../utils/Idler'; import {Idler} from '../utils/Idler';
import {createState} from '../state/atom'; import {createState} from '../state/atom';
import baseMockConsole from 'jest-mock-console'; import baseMockConsole from 'jest-mock-console';
import {DeviceLogEntry} from 'flipper-common';
type Renderer = RenderResult<typeof queries>; type Renderer = RenderResult<typeof queries>;

View File

@@ -11,7 +11,7 @@
import {render, fireEvent} from '@testing-library/react'; import {render, fireEvent} from '@testing-library/react';
import {TestUtils} from '../../'; import {TestUtils} from '../../';
import {sleep} from '../../utils/sleep'; import {sleep} from 'flipper-common';
import React, {Component} from 'react'; import React, {Component} from 'react';
import { import {
setGlobalInteractionReporter, setGlobalInteractionReporter,

View File

@@ -11,7 +11,7 @@ import * as React from 'react';
import {render, fireEvent, waitFor, act} from '@testing-library/react'; import {render, fireEvent, waitFor, act} from '@testing-library/react';
import {DataInspector} from '../DataInspector'; import {DataInspector} from '../DataInspector';
import {sleep} from '../../../utils/sleep'; import {sleep} from 'flipper-common';
const json = { const json = {
data: { data: {

View File

@@ -7,33 +7,8 @@
* @format * @format
*/ */
import {createContext, useContext} from 'react'; import {Logger} from 'flipper-common';
export {Logger} from 'flipper-common';
export type LogTypes = 'error' | 'warn' | 'info' | 'debug';
export type TrackType =
| 'duration'
| 'usage'
| 'performance'
| 'success-rate'
| 'operation-cancelled';
export interface Logger {
track(type: TrackType, event: string, data?: any, plugin?: string): void;
trackTimeSince(
mark: string,
eventName?: string | null | undefined,
data?: any,
): void;
info(data: any, category: string): void;
warn(data: any, category: string): void;
error(data: any, category: string): void;
debug(data: any, category: string): void;
}
export const stubLogger: Logger = { export const stubLogger: Logger = {
track() {}, track() {},
@@ -55,15 +30,3 @@ export const stubLogger: Logger = {
console.debug.apply(console, arguments as any); console.debug.apply(console, arguments as any);
}, },
}; };
export const _LoggerContext = createContext<Logger>(stubLogger);
/**
* Provides the default logger that can be used for console logging,
* error reporting and performance measurements.
* In internal Facebook builds this is wired up to the internal statistic reporting.
* Prefer using `logger` over using `console` directly.
*/
export function useLogger(): Logger {
return useContext(_LoggerContext);
}

View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {Logger} from 'flipper-common';
import {createContext, useContext} from 'react';
import {stubLogger} from './Logger';
export const _LoggerContext = createContext<Logger>(stubLogger);
/**
* Provides the default logger that can be used for console logging,
* error reporting and performance measurements.
* In internal Facebook builds this is wired up to the internal statistic reporting.
* Prefer using `logger` over using `console` directly.
*/
export function useLogger(): Logger {
return useContext(_LoggerContext);
}

View File

@@ -7,12 +7,12 @@
* @format * @format
*/ */
import {DeviceLogEntry, LogLevel} from 'flipper-plugin'; import {DeviceLogEntry, DeviceLogLevel} from 'flipper-plugin';
import {shouldParseAndroidLog} from '../android-crash-utils'; import {shouldParseAndroidLog} from '../android-crash-utils';
function getAndroidLog( function getAndroidLog(
date: Date, date: Date,
type: LogLevel, type: DeviceLogLevel,
tag: string, tag: string,
message: string, message: string,
): DeviceLogEntry { ): DeviceLogEntry {