Split flipper-plugin package
Summary: flipper-server-companion depends on flipper-plugin. flipper-plugin includes dependencies that run only in a browser. Splitting flipper-plugin into core and browser packages helps to avoid including browser-only dependencies into flipper-server bundle. As a result, bundle size could be cut in half. Subsequently, RSS usage drops as there is twice as less code to process for V8. Note: it currently breaks external flipper-data-source package. It will be restored in subsequent diffs Reviewed By: lblasa Differential Revision: D38658285 fbshipit-source-id: 751b11fa9f3a2d938ce166687b8310ba8b059dee
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2090120cda
commit
97b8b8a1c4
@@ -12,7 +12,7 @@
|
||||
"dependencies": {
|
||||
"eventemitter3": "^4.0.7",
|
||||
"flipper-common": "0.0.0",
|
||||
"flipper-plugin": "0.0.0",
|
||||
"flipper-plugin-core": "0.0.0",
|
||||
"immer": "^9.0.12",
|
||||
"js-base64": "^3.7.2",
|
||||
"p-map": "^4.0.0",
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
_SandyPluginInstance,
|
||||
getFlipperLib,
|
||||
_SandyPluginDefinition,
|
||||
} from 'flipper-plugin';
|
||||
} from 'flipper-plugin-core';
|
||||
import {createServerAddOnControls} from './utils/createServerAddOnControls';
|
||||
import isProduction from './utils/isProduction';
|
||||
|
||||
@@ -135,17 +135,23 @@ export default abstract class AbstractClient extends EventEmitter {
|
||||
initialState?: Record<string, any>,
|
||||
) {
|
||||
try {
|
||||
this.sandyPluginStates.set(
|
||||
plugin.id,
|
||||
new _SandyPluginInstance(
|
||||
this.serverAddOnControls,
|
||||
getFlipperLib(),
|
||||
plugin,
|
||||
this,
|
||||
getPluginKey(this.id, {serial: this.query.device_id}, plugin.id),
|
||||
initialState,
|
||||
),
|
||||
const pluginInstance = new _SandyPluginInstance(
|
||||
this.serverAddOnControls,
|
||||
getFlipperLib(),
|
||||
plugin,
|
||||
this,
|
||||
getPluginKey(this.id, {serial: this.query.device_id}, plugin.id),
|
||||
initialState,
|
||||
);
|
||||
pluginInstance.events.on('error', (message) => {
|
||||
const error: ClientErrorType = {
|
||||
message,
|
||||
name: 'Plugin Error',
|
||||
stacktrace: '',
|
||||
};
|
||||
this.emit('error', error);
|
||||
});
|
||||
this.sandyPluginStates.set(plugin.id, pluginInstance);
|
||||
} catch (e) {
|
||||
console.error(`Failed to start plugin '${plugin.id}': `, e);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {FlipperLib, Notification} from 'flipper-plugin';
|
||||
import {FlipperLib, Notification} from 'flipper-plugin-core';
|
||||
import {FlipperServer, FlipperServerConfig} from 'flipper-common';
|
||||
|
||||
type NotificationEvents = 'show' | 'click' | 'close' | 'reply' | 'action';
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
getLatestCompatibleVersionOfEachPlugin,
|
||||
} from '../plugins';
|
||||
import {BundledPluginDetails, InstalledPluginDetails} from 'flipper-common';
|
||||
import {_SandyPluginDefinition} from 'flipper-plugin';
|
||||
import {_SandyPluginDefinition} from 'flipper-plugin-core';
|
||||
import {getRenderHostInstance} from '../RenderHost';
|
||||
|
||||
let loadDynamicPluginsMock: jest.Mock;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import BaseDevice from './BaseDevice';
|
||||
import type {DeviceOS, DeviceType} from 'flipper-plugin';
|
||||
import type {DeviceOS, DeviceType} from 'flipper-plugin-core';
|
||||
|
||||
export default class ArchivedDevice extends BaseDevice {
|
||||
isArchived = true;
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
createState,
|
||||
getFlipperLib,
|
||||
CrashLogListener,
|
||||
} from 'flipper-plugin';
|
||||
} from 'flipper-plugin-core';
|
||||
import {
|
||||
DeviceLogEntry,
|
||||
DeviceOS,
|
||||
@@ -49,7 +49,11 @@ export default class BaseDevice implements Device {
|
||||
hasDevicePlugins = false; // true if there are device plugins for this device (not necessarily enabled)
|
||||
private readonly serverAddOnControls: ServerAddOnControls;
|
||||
|
||||
constructor(flipperServer: FlipperServer, description: DeviceDescription) {
|
||||
constructor(
|
||||
flipperServer: FlipperServer,
|
||||
description: DeviceDescription,
|
||||
private pluginErrorHandler?: (msg: string) => void,
|
||||
) {
|
||||
this.flipperServer = flipperServer;
|
||||
this.description = description;
|
||||
this.serverAddOnControls = createServerAddOnControls(this.flipperServer);
|
||||
@@ -341,18 +345,19 @@ export default class BaseDevice implements Device {
|
||||
this.hasDevicePlugins = true;
|
||||
if (plugin instanceof _SandyPluginDefinition) {
|
||||
try {
|
||||
this.sandyPluginStates.set(
|
||||
plugin.id,
|
||||
new _SandyDevicePluginInstance(
|
||||
this.serverAddOnControls,
|
||||
getFlipperLib(),
|
||||
plugin,
|
||||
this,
|
||||
// break circular dep, one of those days again...
|
||||
getPluginKey(undefined, {serial: this.serial}, plugin.id),
|
||||
initialState,
|
||||
),
|
||||
const pluginInstance = new _SandyDevicePluginInstance(
|
||||
this.serverAddOnControls,
|
||||
getFlipperLib(),
|
||||
plugin,
|
||||
this,
|
||||
// break circular dep, one of those days again...
|
||||
getPluginKey(undefined, {serial: this.serial}, plugin.id),
|
||||
initialState,
|
||||
);
|
||||
if (this.pluginErrorHandler) {
|
||||
pluginInstance.events.on('error', this.pluginErrorHandler);
|
||||
}
|
||||
this.sandyPluginStates.set(plugin.id, pluginInstance);
|
||||
} catch (e) {
|
||||
console.error(`Failed to start device plugin '${plugin.id}': `, e);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {DeviceOS, DeviceType} from 'flipper-plugin';
|
||||
import type {DeviceOS, DeviceType} from 'flipper-plugin-core';
|
||||
import {DeviceSpec} from 'flipper-common';
|
||||
import BaseDevice from './BaseDevice';
|
||||
import {getRenderHostInstance} from '../RenderHost';
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
TestUtils,
|
||||
_SandyPluginDefinition,
|
||||
_setFlipperLibImplementation,
|
||||
} from 'flipper-plugin';
|
||||
} from 'flipper-plugin-core';
|
||||
import {default as ArchivedDevice} from '../ArchivedDevice';
|
||||
import {TestDevice} from '../TestDevice';
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import {assertNever, DownloadFileUpdate} from 'flipper-common';
|
||||
import {FlipperLib, DownloadFileResponse} from 'flipper-plugin';
|
||||
import {FlipperLib, DownloadFileResponse} from 'flipper-plugin-core';
|
||||
import {RenderHost} from '../RenderHost';
|
||||
|
||||
export const downloadFileFactory =
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {RemoteServerContext, FlipperLib} from 'flipper-plugin';
|
||||
import {RemoteServerContext, FlipperLib} from 'flipper-plugin-core';
|
||||
import {
|
||||
BufferEncoding,
|
||||
ExecOptions,
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
ConcretePluginDetails,
|
||||
} from 'flipper-common';
|
||||
import {reportUsage} from 'flipper-common';
|
||||
import {_SandyPluginDefinition} from 'flipper-plugin';
|
||||
import {_SandyPluginDefinition} from 'flipper-plugin-core';
|
||||
import isPluginCompatible from './utils/isPluginCompatible';
|
||||
import isPluginVersionMoreRecent from './utils/isPluginVersionMoreRecent';
|
||||
import {getRenderHostInstance} from './RenderHost';
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"path": "../flipper-common"
|
||||
},
|
||||
{
|
||||
"path": "../flipper-plugin"
|
||||
"path": "../flipper-plugin-core"
|
||||
},
|
||||
{
|
||||
"path": "../test-utils"
|
||||
|
||||
Reference in New Issue
Block a user