Load bundled server add-ons

Reviewed By: antonk52

Differential Revision: D34238883

fbshipit-source-id: 01b4b1c1c0a63cbfb639e903f6a77307ae370330
This commit is contained in:
Andrey Goncharov
2022-02-28 03:50:34 -08:00
committed by Facebook GitHub Bot
parent b655efc78e
commit 2ce037d96b
3 changed files with 26 additions and 19 deletions

View File

@@ -16,13 +16,22 @@ import {
} from 'flipper-common'; } from 'flipper-common';
import {ServerAddOnDesktopToModuleConnection} from './ServerAddOnDesktopToModuleConnection'; import {ServerAddOnDesktopToModuleConnection} from './ServerAddOnDesktopToModuleConnection';
import {ServerAddOnModuleToDesktopConnection} from './ServerAddOnModuleToDesktopConnection'; import {ServerAddOnModuleToDesktopConnection} from './ServerAddOnModuleToDesktopConnection';
// @ts-ignore
import defaultPlugins from '../defaultPlugins';
interface ServerAddOnModule { interface ServerAddOnModule {
default?: ServerAddOnFn; default: ServerAddOnFn;
} }
const loadPlugin = (_pluginName: string): ServerAddOnModule => { const loadPlugin = (pluginName: string): ServerAddOnModule => {
// TODO: Implement me console.debug('loadPlugin', pluginName);
const bundledPlugin = defaultPlugins[pluginName];
if (bundledPlugin) {
return bundledPlugin;
}
// TODO: Use getInstalledPlugin
return {default: async () => async () => {}}; return {default: async () => async () => {}};
}; };
@@ -51,7 +60,7 @@ export class ServerAddOn {
assertNotNull(serverAddOn); assertNotNull(serverAddOn);
assert( assert(
typeof serverAddOn === 'function', typeof serverAddOn === 'function',
`ServerAddOn ${pluginName} must export "serverAddOn" function.`, `ServerAddOn ${pluginName} must export "serverAddOn" function as a default export.`,
); );
const serverAddOnModuleToDesktopConnection = const serverAddOnModuleToDesktopConnection =

View File

@@ -34,7 +34,7 @@ export class ServerAddOnModuleToDesktopConnection
params: { params: {
method, method,
params, params,
api: '', // TODO: Consider using here pluginId and validate it api: '', // TODO: Consider using here pluginName and validate it
}, },
}; };
this.emit('message', message); this.emit('message', message);

View File

@@ -174,20 +174,18 @@ async function generateDefaultPluginEntryPoints(
const serverAddOns = defaultPlugins.filter( const serverAddOns = defaultPlugins.filter(
({serverAddOnSource}) => !!serverAddOnSource, ({serverAddOnSource}) => !!serverAddOnSource,
); );
if (serverAddOns.length) { const serverAddOnRequires = serverAddOns
const serverAddOnRequires = serverAddOns .map(
.map( (x) =>
(x) => ` '${x.name}': tryRequire('${x.name}', () => require('${x.name}/${x.serverAddOnSource}'))`,
` '${x.name}': tryRequire('${x.serverAddOnSource}', () => require('${x.serverAddOnSource}'))`, )
) .join(',\n');
.join(',\n'); const generatedIndexServerAddOns = getGeneratedIndex(serverAddOnRequires);
const generatedIndexServerAddOns = getGeneratedIndex(serverAddOnRequires); await fs.ensureDir(path.join(serverCoreDir, 'src', 'defaultPlugins'));
await fs.ensureDir(path.join(serverCoreDir, 'src', 'defaultPlugins')); await fs.writeFile(
await fs.writeFile( path.join(serverCoreDir, 'src', 'defaultPlugins', 'index.tsx'),
path.join(serverCoreDir, 'src', 'defaultPlugins', 'index.tsx'), generatedIndexServerAddOns,
generatedIndexServerAddOns, );
);
}
console.log('✅ Generated bundled plugin entry points.'); console.log('✅ Generated bundled plugin entry points.');
} }