Load only compatible plugins on startup
Summary: We currently filtering out incompatible versions from marketplace. This diff also add filtering for incompatible installed plugins on Flipper startup to ensure we always load the latest compatible version. Reviewed By: passy Differential Revision: D28341891 fbshipit-source-id: 83afc14a3c07e1763e1bd146251e6d3b71a66248
This commit is contained in:
committed by
Facebook GitHub Bot
parent
252322f525
commit
a8ca142c9a
@@ -52,7 +52,7 @@ import * as crc32 from 'crc32';
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import getDefaultPluginsIndex from '../utils/getDefaultPluginsIndex';
|
||||
import {isDevicePluginDefinition} from '../utils/pluginUtils';
|
||||
import {isPluginCompatible} from '../utils/isPluginCompatible';
|
||||
import isPluginCompatible from '../utils/isPluginCompatible';
|
||||
|
||||
let defaultPluginsIndex: any = null;
|
||||
|
||||
@@ -90,10 +90,25 @@ export default async (store: Store, logger: Logger) => {
|
||||
|
||||
const bundledPlugins = getBundledPlugins();
|
||||
|
||||
const loadedPlugins = filterNewestVersionOfEachPlugin(
|
||||
bundledPlugins,
|
||||
await getDynamicPlugins(),
|
||||
).filter((p) => !uninstalledPluginNames.has(p.name));
|
||||
const allLocalVersions = [
|
||||
...getBundledPlugins(),
|
||||
...(await getDynamicPlugins()),
|
||||
].filter((p) => !uninstalledPluginNames.has(p.name));
|
||||
|
||||
const loadedVersionsMap: Map<string, ActivatablePluginDetails> = new Map();
|
||||
for (const localVersion of allLocalVersions) {
|
||||
if (isPluginCompatible(localVersion)) {
|
||||
const loadedVersion = loadedVersionsMap.get(localVersion.id);
|
||||
if (
|
||||
!loadedVersion ||
|
||||
semver.gt(localVersion.version, loadedVersion.version)
|
||||
) {
|
||||
loadedVersionsMap.set(localVersion.id, localVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const loadedPlugins = Array.from(loadedVersionsMap.values());
|
||||
|
||||
const initialPlugins: PluginDefinition[] = loadedPlugins
|
||||
.map(reportVersion)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {PluginDetails} from 'plugin-lib';
|
||||
import {PluginDetails} from 'flipper-plugin-lib';
|
||||
import semver from 'semver';
|
||||
import GK from '../fb-stubs/GK';
|
||||
import {getAppVersion} from './info';
|
||||
|
||||
@@ -11,9 +11,9 @@ import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {
|
||||
getSourcePlugins,
|
||||
getInstalledPlugins,
|
||||
moveInstalledPluginsFromLegacyDir,
|
||||
InstalledPluginDetails,
|
||||
getAllInstalledPluginVersions,
|
||||
} from 'flipper-plugin-lib';
|
||||
import {getStaticPath} from '../utils/pathUtils';
|
||||
|
||||
@@ -43,7 +43,7 @@ export default async function loadDynamicPlugins(): Promise<
|
||||
const [installedPlugins, unfilteredSourcePlugins] = await Promise.all([
|
||||
process.env.FLIPPER_DISABLE_PLUGIN_AUTO_UPDATE
|
||||
? Promise.resolve([])
|
||||
: getInstalledPlugins(),
|
||||
: getAllInstalledPluginVersions(),
|
||||
getSourcePlugins(),
|
||||
]);
|
||||
const sourcePlugins = unfilteredSourcePlugins.filter(
|
||||
|
||||
@@ -140,6 +140,19 @@ export async function removePlugins(
|
||||
await pmap(names, (name) => removePlugin(name));
|
||||
}
|
||||
|
||||
export async function getAllInstalledPluginVersions(): Promise<
|
||||
InstalledPluginDetails[]
|
||||
> {
|
||||
const pluginDirs = await getInstalledPluginVersionDirs();
|
||||
const versionDirs = pluginDirs.map(([_, versionDirs]) => versionDirs).flat();
|
||||
return await pmap(versionDirs, (versionDir) =>
|
||||
getInstalledPluginDetails(versionDir).catch((err) => {
|
||||
console.error(`Failed to load plugin details from ${versionDir}`, err);
|
||||
return null;
|
||||
}),
|
||||
).then((versionDetails) => versionDetails.filter(notNull));
|
||||
}
|
||||
|
||||
export async function getInstalledPlugins(): Promise<InstalledPluginDetails[]> {
|
||||
const versionDirs = await getInstalledPluginVersionDirs();
|
||||
return pmap(
|
||||
|
||||
Reference in New Issue
Block a user