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

@@ -9,7 +9,7 @@
import fs from 'fs-extra';
import path from 'path';
import {getPluginDetailsFromDir} from '../getPluginDetails';
import {getInstalledPluginDetails} from '../getPluginDetails';
import {pluginInstallationDir} from '../pluginPaths';
import {normalizePath} from 'flipper-test-utils';
@@ -31,7 +31,7 @@ test('getPluginDetailsV1', async () => {
};
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV1);
const details = await getPluginDetailsFromDir(pluginPath);
const details = await getInstalledPluginDetails(pluginPath);
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
@@ -45,7 +45,8 @@ test('getPluginDetailsV1', async () => {
"gatekeeper": "GK_flipper_plugin_test",
"icon": undefined,
"id": "flipper-plugin-test",
"isDefault": false,
"isActivatable": true,
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"source": "src/index.tsx",
@@ -69,7 +70,7 @@ test('getPluginDetailsV2', async () => {
};
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getPluginDetailsFromDir(pluginPath);
const details = await getInstalledPluginDetails(pluginPath);
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
@@ -83,7 +84,8 @@ test('getPluginDetailsV2', async () => {
"gatekeeper": "GK_flipper_plugin_test",
"icon": undefined,
"id": "flipper-plugin-test",
"isDefault": false,
"isActivatable": true,
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"source": "src/index.tsx",
@@ -107,7 +109,7 @@ test('id used as title if the latter omited', async () => {
};
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getPluginDetailsFromDir(pluginPath);
const details = await getInstalledPluginDetails(pluginPath);
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
@@ -121,7 +123,8 @@ test('id used as title if the latter omited', async () => {
"gatekeeper": "GK_flipper_plugin_test",
"icon": undefined,
"id": "test",
"isDefault": false,
"isActivatable": true,
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"source": "src/index.tsx",
@@ -144,7 +147,7 @@ test('name without "flipper-plugin-" prefix is used as title if the latter omite
};
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getPluginDetailsFromDir(pluginPath);
const details = await getInstalledPluginDetails(pluginPath);
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
@@ -158,7 +161,8 @@ test('name without "flipper-plugin-" prefix is used as title if the latter omite
"gatekeeper": "GK_flipper_plugin_test",
"icon": undefined,
"id": "flipper-plugin-test",
"isDefault": false,
"isActivatable": true,
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"source": "src/index.tsx",
@@ -184,7 +188,7 @@ test('flipper-plugin-version is parsed', async () => {
};
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getPluginDetailsFromDir(pluginPath);
const details = await getInstalledPluginDetails(pluginPath);
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
@@ -198,7 +202,8 @@ test('flipper-plugin-version is parsed', async () => {
"gatekeeper": "GK_flipper_plugin_test",
"icon": undefined,
"id": "flipper-plugin-test",
"isDefault": false,
"isActivatable": true,
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"source": "src/index.tsx",

View File

@@ -18,7 +18,7 @@ import {
import {getInstalledPlugins} from '../pluginInstaller';
import {mocked} from 'ts-jest/utils';
import type {Package} from 'npm-api';
import PluginDetails from '../PluginDetails';
import {InstalledPluginDetails} from '../PluginDetails';
jest.mock('npm-api', () => {
return jest.fn().mockImplementation(() => {
@@ -54,7 +54,7 @@ jest.mock('npm-api', () => {
});
});
const installedPlugins: PluginDetails[] = [
const installedPlugins: InstalledPluginDetails[] = [
{
name: 'flipper-plugin-hello',
entry: './test/index.js',
@@ -66,7 +66,8 @@ const installedPlugins: PluginDetails[] = [
id: 'Hello',
title: 'Hello',
description: 'World?',
isDefault: false,
isBundled: false,
isActivatable: true,
},
{
name: 'flipper-plugin-world',
@@ -79,7 +80,8 @@ const installedPlugins: PluginDetails[] = [
id: 'World',
title: 'World',
description: 'Hello?',
isDefault: false,
isBundled: false,
isActivatable: true,
},
];