Load installed server add-ons
Reviewed By: nikoant Differential Revision: D34300475 fbshipit-source-id: 6bb6c0ab811e28806a0924b3487931bdb0dd2c59
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b4b9c0ab28
commit
8b94186783
@@ -18,6 +18,7 @@ import {
|
||||
ExecuteMessage,
|
||||
FlipperServerForServerAddOn,
|
||||
InstalledPluginDetails,
|
||||
ServerAddOnStartDetails,
|
||||
} from 'flipper-common';
|
||||
import {getStaticPath} from '../utils/pathUtils';
|
||||
import {loadDynamicPlugins} from './loadDynamicPlugins';
|
||||
@@ -173,7 +174,11 @@ export class PluginManager {
|
||||
return this.serverAddOns.get(message.params.api);
|
||||
}
|
||||
|
||||
async startServerAddOn(pluginName: string, owner: string) {
|
||||
async startServerAddOn(
|
||||
pluginName: string,
|
||||
details: ServerAddOnStartDetails,
|
||||
owner: string,
|
||||
) {
|
||||
console.debug('PluginManager.startServerAddOn', pluginName);
|
||||
const existingServerAddOn = this.serverAddOns.get(pluginName);
|
||||
if (existingServerAddOn) {
|
||||
@@ -188,6 +193,7 @@ export class PluginManager {
|
||||
|
||||
const newServerAddOn = await ServerAddOn.start(
|
||||
pluginName,
|
||||
details,
|
||||
owner,
|
||||
() => this.serverAddOns.delete(pluginName),
|
||||
this.flipperServer,
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
FlipperServerForServerAddOn,
|
||||
ServerAddOnCleanup,
|
||||
ServerAddOn as ServerAddOnFn,
|
||||
ServerAddOnStartDetails,
|
||||
} from 'flipper-common';
|
||||
import {ServerAddOnDesktopToModuleConnection} from './ServerAddOnDesktopToModuleConnection';
|
||||
import {ServerAddOnModuleToDesktopConnection} from './ServerAddOnModuleToDesktopConnection';
|
||||
@@ -23,16 +24,29 @@ interface ServerAddOnModule {
|
||||
default: ServerAddOnFn;
|
||||
}
|
||||
|
||||
const loadPlugin = (pluginName: string): ServerAddOnModule => {
|
||||
console.debug('loadPlugin', pluginName);
|
||||
const loadPlugin = (
|
||||
pluginName: string,
|
||||
details: ServerAddOnStartDetails,
|
||||
): ServerAddOnModule => {
|
||||
console.debug('loadPlugin', pluginName, details);
|
||||
|
||||
const bundledPlugin = defaultPlugins[pluginName];
|
||||
if (bundledPlugin) {
|
||||
if (details.isBundled) {
|
||||
const bundledPlugin = defaultPlugins[pluginName];
|
||||
assertNotNull(
|
||||
bundledPlugin,
|
||||
`loadPlugin (isBundled = true) -> plugin ${pluginName} not found.`,
|
||||
);
|
||||
return bundledPlugin;
|
||||
}
|
||||
|
||||
// TODO: Use getInstalledPlugin
|
||||
return {default: async () => async () => {}};
|
||||
assertNotNull(
|
||||
details.path,
|
||||
`loadPlugin (isBundled = false) -> server add-on path is empty plugin ${pluginName}.`,
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
const serverAddOnModule = eval(`require("${details.path}")`);
|
||||
return serverAddOnModule;
|
||||
};
|
||||
|
||||
// TODO: Fix potential race conditions when starting/stopping concurrently
|
||||
@@ -50,13 +64,14 @@ export class ServerAddOn {
|
||||
|
||||
static async start(
|
||||
pluginName: string,
|
||||
details: ServerAddOnStartDetails,
|
||||
initialOwner: string,
|
||||
onStop: () => void,
|
||||
flipperServer: FlipperServerForServerAddOn,
|
||||
): Promise<ServerAddOn> {
|
||||
console.info('ServerAddOn.start', pluginName);
|
||||
console.info('ServerAddOn.start', pluginName, details);
|
||||
|
||||
const {default: serverAddOn} = loadPlugin(pluginName);
|
||||
const {default: serverAddOn} = loadPlugin(pluginName, details);
|
||||
assertNotNull(serverAddOn);
|
||||
assert(
|
||||
typeof serverAddOn === 'function',
|
||||
|
||||
Reference in New Issue
Block a user