Extend Flipper commands to support server add-on messaging

Reviewed By: mweststrate

Differential Revision: D34046466

fbshipit-source-id: 9acc172c1805ec724b8709999bacf9e899c39e6b
This commit is contained in:
Andrey Goncharov
2022-02-28 03:50:34 -08:00
committed by Facebook GitHub Bot
parent 3b390b74ff
commit 12151e4a71
4 changed files with 44 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ import {default as axios} from 'axios';
import {
BundledPluginDetails,
DownloadablePluginDetails,
ExecuteMessage,
InstalledPluginDetails,
} from 'flipper-common';
import {getStaticPath} from '../utils/pathUtils';
@@ -43,6 +44,9 @@ const getTempDirName = promisify(tmp.dir) as (
options?: tmp.DirOptions,
) => Promise<string>;
const isExecuteMessage = (message: object): message is ExecuteMessage =>
(message as ExecuteMessage).method === 'execute';
export class PluginManager {
private readonly serverAddOns = new Map<string, ServerAddOn>();
@@ -155,6 +159,17 @@ export class PluginManager {
}
}
getServerAddOnForMessage(message: object) {
if (!isExecuteMessage(message)) {
throw new Error(
`PluginManager.getServerAddOnForMessage supports only "execute" messages. Received ${JSON.stringify(
message,
)}`,
);
}
return this.serverAddOns.get(message.params.api);
}
async startServerAddOn(pluginName: string, owner: string) {
console.debug('PluginManager.startServerAddOn', pluginName);
const existingServerAddOn = this.serverAddOns.get(pluginName);