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:
Anton Nikolaev
2020-12-15 09:28:58 -08:00
committed by Facebook GitHub Bot
parent efb82e80b5
commit 5383017299
27 changed files with 327 additions and 216 deletions

View File

@@ -14,7 +14,11 @@ import fs from 'fs-extra';
import {spawn} from 'promisify-child-process';
import {getWatchFolders} from 'flipper-pkg-lib';
import getAppWatchFolders from './get-app-watch-folders';
import {getSourcePlugins, getPluginSourceFolders} from 'flipper-plugin-lib';
import {
getSourcePlugins,
getPluginSourceFolders,
BundledPluginDetails,
} from 'flipper-plugin-lib';
import {
appDir,
staticDir,
@@ -33,19 +37,26 @@ export function die(err: Error) {
export async function generatePluginEntryPoints() {
console.log('⚙️ Generating plugin entry points...');
const plugins = await getSourcePlugins();
for (const plugin of plugins) {
plugin.isDefault = true;
plugin.version = plugin.version === '0.0.0' ? version : plugin.version;
plugin.flipperSDKVersion =
plugin.flipperSDKVersion === '0.0.0' ? version : plugin.flipperSDKVersion;
}
const sourcePlugins = await getSourcePlugins();
const bundledPlugins = sourcePlugins.map(
(p) =>
({
...p,
isBundled: true,
version: p.version === '0.0.0' ? version : p.version,
flipperSDKVersion:
p.flipperSDKVersion === '0.0.0' ? version : p.flipperSDKVersion,
} as BundledPluginDetails),
);
if (await fs.pathExists(defaultPluginsIndexDir)) {
await fs.remove(defaultPluginsIndexDir);
}
await fs.mkdirp(defaultPluginsIndexDir);
await fs.writeJSON(path.join(defaultPluginsIndexDir, 'index.json'), plugins);
const pluginRequres = plugins
await fs.writeJSON(
path.join(defaultPluginsIndexDir, 'index.json'),
bundledPlugins,
);
const pluginRequres = bundledPlugins
.map((x) => ` '${x.name}': require('${x.name}')`)
.join(',\n');
const generatedIndex = `