Separate interfaces for installed, bundled and downloadable plugins
Summary: I've re-designed interfaces describing plugins as I found that mental overhead working with them became too expensive because of slightly flawed design. However this cascaded changes in many files so you can see how extensively these interfaces used in our codebase. Before this change we had one interface PluginDetails which described three different entities: 1) plugins installed on the disk 2) plugins bundled into Flipper 3) plugins available on Marketplace. It's hard to use this "general" PluginDetails interface because of this as you always need to think about all three use cases everywhere. After this change we have 3 separate interfaces: InstalledPluginDetails, BundledPluginDetails and DownloadablePluginDetails and things became much type-safer now. Reviewed By: mweststrate Differential Revision: D25530383 fbshipit-source-id: b93593916a980c04e36dc6ffa168797645a0ff9c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
efb82e80b5
commit
5383017299
@@ -11,16 +11,17 @@ import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import expandTilde from 'expand-tilde';
|
||||
import {getPluginSourceFolders} from './pluginPaths';
|
||||
import {PluginDetails, getPluginDetails} from 'flipper-plugin-lib';
|
||||
import pmap from 'p-map';
|
||||
import pfilter from 'p-filter';
|
||||
import {satisfies} from 'semver';
|
||||
import {getInstalledPluginDetails} from './getPluginDetails';
|
||||
import {InstalledPluginDetails} from './PluginDetails';
|
||||
|
||||
const flipperVersion = require('../package.json').version;
|
||||
|
||||
export async function getSourcePlugins(): Promise<PluginDetails[]> {
|
||||
export async function getSourcePlugins(): Promise<InstalledPluginDetails[]> {
|
||||
const pluginFolders = await getPluginSourceFolders();
|
||||
const entryPoints: {[key: string]: PluginDetails} = {};
|
||||
const entryPoints: {[key: string]: InstalledPluginDetails} = {};
|
||||
const additionalPlugins = await pmap(pluginFolders, (path) =>
|
||||
entryPointForPluginFolder(path),
|
||||
);
|
||||
@@ -47,7 +48,7 @@ export async function getSourcePlugins(): Promise<PluginDetails[]> {
|
||||
}
|
||||
async function entryPointForPluginFolder(
|
||||
pluginsDir: string,
|
||||
): Promise<{[key: string]: PluginDetails}> {
|
||||
): Promise<{[key: string]: InstalledPluginDetails}> {
|
||||
pluginsDir = expandTilde(pluginsDir);
|
||||
if (!fs.existsSync(pluginsDir)) {
|
||||
return {};
|
||||
@@ -96,7 +97,7 @@ async function entryPointForPluginFolder(
|
||||
.then((packages) =>
|
||||
pmap(packages, async ({manifest, dir}) => {
|
||||
try {
|
||||
const details = await getPluginDetails(dir, manifest);
|
||||
const details = await getInstalledPluginDetails(dir, manifest);
|
||||
if (
|
||||
details.flipperSDKVersion &&
|
||||
!satisfies(flipperVersion, details.flipperSDKVersion)
|
||||
@@ -117,7 +118,7 @@ async function entryPointForPluginFolder(
|
||||
)
|
||||
.then((plugins) => plugins.filter(notNull))
|
||||
.then((plugins) =>
|
||||
plugins.reduce<{[key: string]: PluginDetails}>((acc, cv) => {
|
||||
plugins.reduce<{[key: string]: InstalledPluginDetails}>((acc, cv) => {
|
||||
acc[cv!.name] = cv!;
|
||||
return acc;
|
||||
}, {}),
|
||||
|
||||
Reference in New Issue
Block a user