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:
Andrey Goncharov
2022-09-15 10:02:19 -07:00
committed by Facebook GitHub Bot
parent 2090120cda
commit 97b8b8a1c4
86 changed files with 813 additions and 645 deletions

View File

@@ -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);
}