make sure plugins can be loaded into Flipper

Summary: Make sure Sandy plugins are loaded properly from disk

Reviewed By: jknoxville

Differential Revision: D22186275

fbshipit-source-id: fd2f560a7bed959b18e05db2a087909ad876ab9d
This commit is contained in:
Michel Weststrate
2020-07-01 08:58:40 -07:00
committed by Facebook GitHub Bot
parent 1029a6c97c
commit 12ac29685d
5 changed files with 104 additions and 19 deletions

View File

@@ -64,6 +64,12 @@ export class FlipperPluginInstance {
}
}
/**
* A sandy plugin definitions represents a loaded plugin definition, storing two things:
* the loaded JS module, and the meta data (typically coming from package.json).
*
* Also delegates some of the standard plugin functionality to have a similar public static api as FlipperPlugin
*/
export class SandyPluginDefinition {
id: string;
module: FlipperPluginModule;
@@ -86,12 +92,12 @@ export class SandyPluginDefinition {
this.details = details;
if (!module.plugin || typeof module.plugin !== 'function') {
throw new Error(
`Sandy plugin ${this.id} doesn't export a named function called 'plugin'`,
`Flipper plugin '${this.id}' should export named function called 'plugin'`,
);
}
if (!module.Component || typeof module.Component !== 'function') {
throw new Error(
`Sandy plugin ${this.id} doesn't export a named function called 'Component'`,
`Flipper plugin '${this.id}' should export named function called 'Component'`,
);
}
this.module = module;