Versioning for plugin format
Summary: Added versioning for plugin format. The first version is where "main" points to source code entry and plugins are bundled by Flipper in run-time on loading them. The second version is where "main" points to the already existing bundle and Flipper just loads it without bundling. The plugins of version 2 must be bundled using "flipper-pkg" tool before publishing. Changelog: Support new packaging format for plugins. Reviewed By: mweststrate Differential Revision: D21074173 fbshipit-source-id: 7b70250e48e5bd5d359c96149fb5b14e67783c4d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
eb34b2f6e3
commit
ca2d04a5da
@@ -143,14 +143,7 @@ class PluginDebugger extends Component<Props> {
|
||||
getRows(): Array<TableBodyRow> {
|
||||
const rows: Array<TableBodyRow> = [];
|
||||
|
||||
// bundled plugins are loaded from the defaultPlugins directory within
|
||||
// Flipper's package.
|
||||
const externalPluginPath = (p: any) =>
|
||||
p.out
|
||||
? p.out.startsWith('./defaultPlugins/')
|
||||
? null
|
||||
: p.entry
|
||||
: 'Native Plugin';
|
||||
const externalPluginPath = (p: any) => p.entry || 'Native Plugin';
|
||||
|
||||
this.props.gatekeepedPlugins.forEach((plugin) =>
|
||||
rows.push(
|
||||
|
||||
@@ -69,14 +69,14 @@ test('checkDisabled', () => {
|
||||
expect(
|
||||
disabled({
|
||||
name: 'other Name',
|
||||
out: './test/index.js',
|
||||
entry: './test/index.js',
|
||||
}),
|
||||
).toBeTruthy();
|
||||
|
||||
expect(
|
||||
disabled({
|
||||
name: disabledPlugin,
|
||||
out: './test/index.js',
|
||||
entry: './test/index.js',
|
||||
}),
|
||||
).toBeFalsy();
|
||||
});
|
||||
@@ -85,7 +85,7 @@ test('checkGK for plugin without GK', () => {
|
||||
expect(
|
||||
checkGK([])({
|
||||
name: 'pluginID',
|
||||
out: './test/index.js',
|
||||
entry: './test/index.js',
|
||||
}),
|
||||
).toBeTruthy();
|
||||
});
|
||||
@@ -95,7 +95,7 @@ test('checkGK for passing plugin', () => {
|
||||
checkGK([])({
|
||||
name: 'pluginID',
|
||||
gatekeeper: TEST_PASSING_GK,
|
||||
out: './test/index.js',
|
||||
entry: './test/index.js',
|
||||
}),
|
||||
).toBeTruthy();
|
||||
});
|
||||
@@ -106,7 +106,7 @@ test('checkGK for failing plugin', () => {
|
||||
const plugins = checkGK(gatekeepedPlugins)({
|
||||
name,
|
||||
gatekeeper: TEST_FAILING_GK,
|
||||
out: './test/index.js',
|
||||
entry: './test/index.js',
|
||||
});
|
||||
|
||||
expect(plugins).toBeFalsy();
|
||||
@@ -117,7 +117,7 @@ test('requirePlugin returns null for invalid requires', () => {
|
||||
const requireFn = requirePlugin([], require);
|
||||
const plugin = requireFn({
|
||||
name: 'pluginID',
|
||||
out: 'this/path/does not/exist',
|
||||
entry: 'this/path/does not/exist',
|
||||
});
|
||||
|
||||
expect(plugin).toBeNull();
|
||||
@@ -128,7 +128,7 @@ test('requirePlugin loads plugin', () => {
|
||||
const requireFn = requirePlugin([], require);
|
||||
const plugin = requireFn({
|
||||
name,
|
||||
out: path.join(__dirname, 'TestPlugin'),
|
||||
entry: path.join(__dirname, 'TestPlugin'),
|
||||
});
|
||||
expect(plugin!.prototype).toBeInstanceOf(FlipperPlugin);
|
||||
expect(plugin!.id).toBe(TestPlugin.id);
|
||||
|
||||
@@ -96,15 +96,15 @@ function getBundledPlugins(): Array<PluginDefinition> {
|
||||
}
|
||||
|
||||
return bundledPlugins
|
||||
.filter((plugin) => notNull(plugin.out))
|
||||
.filter((plugin) => notNull(plugin.entry))
|
||||
.map(
|
||||
(plugin) =>
|
||||
({
|
||||
...plugin,
|
||||
out: path.join(pluginPath, plugin.out!),
|
||||
entry: path.resolve(pluginPath, plugin.entry!),
|
||||
} as PluginDefinition),
|
||||
)
|
||||
.concat(bundledPlugins.filter((plugin) => !plugin.out));
|
||||
.concat(bundledPlugins.filter((plugin) => !plugin.entry));
|
||||
}
|
||||
|
||||
export function getDynamicPlugins() {
|
||||
@@ -155,8 +155,8 @@ export const requirePlugin = (
|
||||
pluginDefinition: PluginDefinition,
|
||||
): typeof FlipperPlugin | typeof FlipperDevicePlugin | null => {
|
||||
try {
|
||||
let plugin = pluginDefinition.out
|
||||
? reqFn(pluginDefinition.out)
|
||||
let plugin = pluginDefinition.entry
|
||||
? reqFn(pluginDefinition.entry)
|
||||
: defaultPluginsIndex[pluginDefinition.name];
|
||||
if (plugin.default) {
|
||||
plugin = plugin.default;
|
||||
|
||||
Reference in New Issue
Block a user