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",
"deep-equal": "^2.0.5",
"expand-tilde": "^2.0.2",
"flipper-common": "0.0.0",
"flipper-client-sdk": "^0.0.3",
"flipper-doctor": "0.0.0",
"flipper-plugin": "0.0.0",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -12,7 +12,7 @@ import {
getErrorFromErrorLike,
getStringFromErrorLike,
} from '../../utils/errors';
import {Args, Logger} from '../../fb-interfaces/Logger';
import {LoggerArgs, Logger} from 'flipper-common';
const instance = {
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;
}

View File

@@ -123,7 +123,7 @@ export {default as FileSelector} from './ui/components/FileSelector';
export {KeyboardActions} from './MenuBar';
export {getFlipperMediaCDN, appendAccessTokenToUrl} from './fb-stubs/user';
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 {callVSCode} from './utils/vscodeUtils';
export {checkIdbIsInstalled} from './server/devices/ios/iOSContainerUtility';

View File

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

View File

@@ -12,7 +12,7 @@ import {produce} from 'immer';
import type BaseDevice from '../devices/BaseDevice';
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 type {Actions} from '.';
import {WelcomeScreenStaticView} from '../sandy-chrome/WelcomeScreen';
@@ -21,7 +21,6 @@ import {getPluginKey} from '../utils/pluginKey';
import {deconstructClientId} from '../utils/clientUtils';
import type {RegisterPluginAction} from './plugins';
import {DeviceOS, Logger} from 'flipper-plugin';
import {FlipperServerImpl} from '../server/FlipperServerImpl';
import {shallowEqual} from 'react-redux';

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -15,7 +15,7 @@ import {ServerEventsListener} from './ServerAdapter';
import constants from '../../fb-stubs/constants';
import ws from 'ws';
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.

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,7 +7,12 @@
* @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 JSONStream from 'JSONStream';
import {Transform} from 'stream';
@@ -65,7 +70,7 @@ export default class IOSDevice extends ServerDevice {
}
async screenshot(): Promise<Buffer> {
if (!this.connected.get()) {
if (!this.connected) {
return Buffer.from([]);
}
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) {
case 'Default':
return 'debug';
@@ -183,7 +188,7 @@ export default class IOSDevice extends ServerDevice {
}
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
// their loglevel.
@@ -215,7 +220,7 @@ export default class IOSDevice extends ServerDevice {
}
async screenCaptureAvailable() {
return this.info.deviceType === 'emulator' && this.connected.get();
return this.info.deviceType === 'emulator' && this.connected;
}
async startScreenCapture(destination: string) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,13 +7,18 @@
* @format
*/
import {Logger, Args, TrackType} from '../fb-interfaces/Logger';
import {Logger, LoggerTrackType, LoggerArgs} from 'flipper-common';
import {Store} from '../reducers/index';
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) {}

View File

@@ -40,7 +40,8 @@ import {processMessageQueue} from './messageQueue';
import {getPluginTitle} from './pluginUtils';
import {capture} from './screenshot';
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 ShareSheetExportFile from '../chrome/ShareSheetExportFile';
import ExportDataPluginSheet from '../chrome/ExportDataPluginSheet';

View File

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

View File

@@ -14,7 +14,7 @@ import {getStaticPath} from './pathUtils';
import type {State, Store} from '../reducers/index';
import {deconstructClientId} from './clientUtils';
import {sideEffect} from './sideEffect';
import {Logger} from '../fb-interfaces/Logger';
import {Logger} from 'flipper-common';
type PlatformInfo = {
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
*/
export function helloWorld() {
return true;
}
export {
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,
OS as PluginOS,
} 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.
// 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;
};
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 = {
os: string;
deviceName: string;

View File

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

View File

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

View File

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

View File

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

View File

@@ -21,10 +21,8 @@ export {
} from './plugin/Plugin';
export {
Device,
DeviceLogEntry,
DeviceLogListener,
DevicePluginClient,
LogLevel,
SandyDevicePluginInstance as _SandyDevicePluginInstance,
} from './plugin/DevicePlugin';
export {SandyPluginDefinition as _SandyPluginDefinition} from './plugin/SandyPluginDefinition';
@@ -75,16 +73,8 @@ export {
export {DataFormatter} from './ui/DataFormatter';
export {sleep} from './utils/sleep';
export {timeout} from './utils/timeout';
export {useLogger, _LoggerContext} from './utils/useLogger';
export {
LogTypes,
TrackType,
Logger,
useLogger,
_LoggerContext,
} from './utils/Logger';
export {Idler} from './utils/Idler';
// 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
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 {FlipperLib} from './FlipperLib';
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 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 {
readonly isArchived: boolean;
readonly isConnected: boolean;

View File

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

View File

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

View File

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

View File

@@ -7,33 +7,8 @@
* @format
*/
import {createContext, useContext} from 'react';
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;
}
import {Logger} from 'flipper-common';
export {Logger} from 'flipper-common';
export const stubLogger: Logger = {
track() {},
@@ -55,15 +30,3 @@ export const stubLogger: Logger = {
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
*/
import {DeviceLogEntry, LogLevel} from 'flipper-plugin';
import {DeviceLogEntry, DeviceLogLevel} from 'flipper-plugin';
import {shouldParseAndroidLog} from '../android-crash-utils';
function getAndroidLog(
date: Date,
type: LogLevel,
type: DeviceLogLevel,
tag: string,
message: string,
): DeviceLogEntry {