Load either installed or bundled version of plugin depending on which is newer
Summary: Load either installed or bundled version of plugin depending on which is newer. Reviewed By: mweststrate Differential Revision: D21858965 fbshipit-source-id: aa46eafe0b5137134fadad827749672441f2c9e5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e31ddbc648
commit
e65b355fb6
@@ -15,6 +15,7 @@ import dispatcher, {
|
||||
checkDisabled,
|
||||
checkGK,
|
||||
requirePlugin,
|
||||
filterNewestVersionOfEachPlugin,
|
||||
} from '../plugins';
|
||||
import path from 'path';
|
||||
import {ipcRenderer, remote} from 'electron';
|
||||
@@ -140,3 +141,22 @@ test('requirePlugin loads plugin', () => {
|
||||
expect(plugin!.prototype).toBeInstanceOf(FlipperPlugin);
|
||||
expect(plugin!.id).toBe(TestPlugin.id);
|
||||
});
|
||||
|
||||
test('newest version of each plugin is taken', () => {
|
||||
const plugins: PluginDefinition[] = [
|
||||
{name: 'flipper-plugin-test1', version: '0.1.0'},
|
||||
{name: 'flipper-plugin-test2', version: '0.1.0-alpha.201'},
|
||||
{name: 'flipper-plugin-test2', version: '0.1.0-alpha.21'},
|
||||
{name: 'flipper-plugin-test1', version: '0.10.0'},
|
||||
];
|
||||
const filteredPlugins = filterNewestVersionOfEachPlugin(plugins);
|
||||
expect(filteredPlugins).toHaveLength(2);
|
||||
expect(filteredPlugins).toContainEqual({
|
||||
name: 'flipper-plugin-test1',
|
||||
version: '0.10.0',
|
||||
});
|
||||
expect(filteredPlugins).toContainEqual({
|
||||
name: 'flipper-plugin-test2',
|
||||
version: '0.1.0-alpha.201',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,6 +29,7 @@ import {default as config} from '../utils/processConfig';
|
||||
import isProduction from '../utils/isProduction';
|
||||
import {notNull} from '../utils/typeUtils';
|
||||
import {sideEffect} from '../utils/sideEffect';
|
||||
import semver from 'semver';
|
||||
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import getPluginIndex from '../utils/getDefaultPluginsIndex';
|
||||
@@ -58,7 +59,10 @@ export default (store: Store, logger: Logger) => {
|
||||
|
||||
const initialPlugins: Array<
|
||||
typeof FlipperPlugin | typeof FlipperDevicePlugin
|
||||
> = [...getBundledPlugins(), ...getDynamicPlugins()]
|
||||
> = filterNewestVersionOfEachPlugin([
|
||||
...getBundledPlugins(),
|
||||
...getDynamicPlugins(),
|
||||
])
|
||||
.filter(checkDisabled(disabledPlugins))
|
||||
.filter(checkGK(gatekeepedPlugins))
|
||||
.map(requirePlugin(failedPlugins, defaultPluginsIndex))
|
||||
@@ -83,6 +87,21 @@ export default (store: Store, logger: Logger) => {
|
||||
);
|
||||
};
|
||||
|
||||
export function filterNewestVersionOfEachPlugin(
|
||||
plugins: PluginDefinition[],
|
||||
): PluginDefinition[] {
|
||||
const pluginByName: {[key: string]: PluginDefinition} = {};
|
||||
for (const plugin of plugins) {
|
||||
if (
|
||||
!pluginByName[plugin.name] ||
|
||||
semver.gt(plugin.version, pluginByName[plugin.name].version, true)
|
||||
) {
|
||||
pluginByName[plugin.name] = plugin;
|
||||
}
|
||||
}
|
||||
return Object.values(pluginByName);
|
||||
}
|
||||
|
||||
function getBundledPlugins(): Array<PluginDefinition> {
|
||||
// DefaultPlugins that are included in the bundle.
|
||||
// List of defaultPlugins is written at build time
|
||||
|
||||
Reference in New Issue
Block a user