Move the code related to plugin loading / installation to "flipper-plugin-lib"

Summary:
Sorry for so long diff, but actually there are no functional changes, just refactoring to make further changes of Plugin Manager easier to understand.

I've de-coupled the code related to plugin management from UI code and moved it from PluginInstaller UI component (which will be replaced soon by new UI) to "flipper-plugin-lib".  So pretty much everything related to plugin discovery and installation now consolidated in this package.

Additionally, this refactoring enables re-using of plugin management code in "flipper-pkg", e.g. to create CLI command for plugin installation from NPM, e.g.: `flipper-pkg install flipper-plugin-reactotron`.

Reviewed By: passy

Differential Revision: D23679346

fbshipit-source-id: 82e7b9de9afa08c508c1b228c2038b4ba423571c
This commit is contained in:
Anton Nikolaev
2020-09-16 06:30:20 -07:00
committed by Facebook GitHub Bot
parent 72ff87d7cd
commit e48707151a
18 changed files with 1274 additions and 483 deletions

View File

@@ -8,10 +8,11 @@
*/
import {default as reducer, registerInstalledPlugins} from '../pluginManager';
import {InstalledPluginDetails} from 'flipper-plugin-lib';
test('reduce empty registerInstalledPlugins', () => {
const result = reducer(undefined, registerInstalledPlugins(new Map()));
expect(result).toEqual({installedPlugins: new Map()});
const result = reducer(undefined, registerInstalledPlugins([]));
expect(result).toEqual({installedPlugins: []});
});
const EXAMPLE_PLUGIN = {
@@ -26,17 +27,15 @@ const EXAMPLE_PLUGIN = {
title: 'test',
id: 'test',
entry: '/plugins/test/lib/index.js',
};
installationStatus: 'installed',
} as InstalledPluginDetails;
test('reduce registerInstalledPlugins, clear again', () => {
const result = reducer(
undefined,
registerInstalledPlugins(new Map([['test', EXAMPLE_PLUGIN]])),
);
const result = reducer(undefined, registerInstalledPlugins([EXAMPLE_PLUGIN]));
expect(result).toEqual({
installedPlugins: new Map([['test', EXAMPLE_PLUGIN]]),
installedPlugins: [EXAMPLE_PLUGIN],
});
const result2 = reducer(result, registerInstalledPlugins(new Map()));
expect(result2).toEqual({installedPlugins: new Map()});
const result2 = reducer(result, registerInstalledPlugins([]));
expect(result2).toEqual({installedPlugins: []});
});