Files
flipper/desktop/flipper-server-core/src/plugins/loadServerAddOn.tsx
Andrey Goncharov 01a5f3da90 Add generics to server add-on connection
Reviewed By: mweststrate

Differential Revision: D34307356

fbshipit-source-id: 27e61355a85995368ebb197c42d58f4145473567
2022-02-28 03:50:34 -08:00

47 lines
1.2 KiB
TypeScript

/**
* Copyright (c) Meta Platforms, Inc. and 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 {
ServerAddOn as ServerAddOnFn,
ServerAddOnStartDetails,
} from 'flipper-common';
import {assertNotNull} from '../comms/Utilities';
// The file is generated automatically by "prepareDefaultPlugins" in "scripts"
// @ts-ignore
import defaultPlugins from '../defaultPlugins';
interface ServerAddOnModule {
default: ServerAddOnFn<any, any>;
}
export const loadServerAddOn = (
pluginName: string,
details: ServerAddOnStartDetails,
): ServerAddOnModule => {
console.debug('loadPlugin', pluginName, details);
if (details.isBundled) {
const bundledPlugin = defaultPlugins[pluginName];
assertNotNull(
bundledPlugin,
`loadPlugin (isBundled = true) -> plugin ${pluginName} not found.`,
);
return bundledPlugin;
}
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;
};