Read flipper-plugin from peer deps

Summary:
To know whether plugins should be mounted with the old setup or new setup (with a Provided / context based api), we need to be able to recognize whether a plugin is written with the old or new setup.

We do this by checking if the flipper-plugin dependency is declared as peer dependency. This we can to check for SDK compatibility as well.

Reviewed By: jknoxville

Differential Revision: D22043085

fbshipit-source-id: 21afabb6e58d86253a464470f4690c51cced87ab
This commit is contained in:
Michel Weststrate
2020-07-01 08:58:40 -07:00
committed by Facebook GitHub Bot
parent 2383dc85f8
commit 845c9b67f5
5 changed files with 61 additions and 1 deletions

View File

@@ -17,6 +17,9 @@ import {
import {PluginDetails, getPluginDetails} from 'flipper-plugin-lib';
import pmap from 'p-map';
import pfilter from 'p-filter';
import {satisfies} from 'semver';
const flipperVersion = require('./package.json').version;
export async function getSourcePlugins(): Promise<PluginDetails[]> {
return await getPluginsFromFolders(await getPluginSourceFolders());
@@ -89,7 +92,16 @@ async function entryPointForPluginFolder(
.then((packages) =>
pmap(packages, async ({manifest, dir}) => {
try {
return await getPluginDetails(dir, manifest);
const details = await getPluginDetails(dir, manifest);
if (
details.flipperSDKVersion &&
!satisfies(flipperVersion, details.flipperSDKVersion)
) {
console.warn(
`⚠️ The current Flipper version (${flipperVersion}) doesn't look compatible with the plugin '${manifest.name}', which expects 'flipper-plugin: ${details.flipperSDKVersion}'`,
);
}
return details;
} catch (e) {
console.error(
`Could not load plugin from "${dir}", because package.json is invalid.`,