Extend device plugin metadata to include supported devices

Summary: Plugin metadata format extended to include type of each plugin (client / device) and list of supported devices (android/ios/..., emulator/physical, etc). This will allow to detect plugins supported by device even if they are not installed and only available on Marketplace.

Reviewed By: mweststrate

Differential Revision: D26073531

fbshipit-source-id: e331f1be1af1046cd4220a286a1d52378c26cc53
This commit is contained in:
Anton Nikolaev
2021-01-27 17:23:51 -08:00
committed by Facebook GitHub Bot
parent 1ce619af7e
commit d7cfcb5d8e
22 changed files with 203 additions and 5 deletions

View File

@@ -27,8 +27,25 @@ export interface PluginDetails {
url?: string;
};
flipperSDKVersion?: string;
pluginType: PluginType;
supportedDevices?: SupportedDevice[];
}
export interface SupportedDevice {
readonly os?: OS;
readonly type?: DeviceType;
readonly archived?: boolean;
readonly specs?: DeviceSpec[];
}
export type OS = 'iOS' | 'Android' | 'Metro';
export type DeviceType = 'emulator' | 'physical';
export type PluginType = 'client' | 'device';
export type DeviceSpec = 'KaiOS';
export interface ConcretePluginDetails extends PluginDetails {
// Determines whether the plugin is a part of the Flipper JS bundle.
isBundled: boolean;

View File

@@ -49,8 +49,10 @@ test('getPluginDetailsV1', async () => {
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"pluginType": "client",
"source": "src/index.tsx",
"specVersion": 1,
"supportedDevices": undefined,
"title": "Test Plugin",
"version": "2.0.0",
}
@@ -88,8 +90,10 @@ test('getPluginDetailsV2', async () => {
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"pluginType": "client",
"source": "src/index.tsx",
"specVersion": 2,
"supportedDevices": undefined,
"title": "Test",
"version": "3.0.1",
}
@@ -127,8 +131,10 @@ test('id used as title if the latter omited', async () => {
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"pluginType": "client",
"source": "src/index.tsx",
"specVersion": 2,
"supportedDevices": undefined,
"title": "test",
"version": "3.0.1",
}
@@ -165,8 +171,10 @@ test('name without "flipper-plugin-" prefix is used as title if the latter omite
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"pluginType": "client",
"source": "src/index.tsx",
"specVersion": 2,
"supportedDevices": undefined,
"title": "test",
"version": "3.0.1",
}
@@ -206,10 +214,75 @@ test('flipper-plugin-version is parsed', async () => {
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"pluginType": "client",
"source": "src/index.tsx",
"specVersion": 2,
"supportedDevices": undefined,
"title": "test",
"version": "3.0.1",
}
`);
});
test('plugin type and supported devices parsed', async () => {
const pluginV2 = {
$schema: 'https://fbflipper.com/schemas/plugin-package/v2.json',
name: 'flipper-plugin-test',
title: 'Test',
version: '3.0.1',
pluginType: 'device',
supportedDevices: [
{os: 'Android', archived: false},
{os: 'Android', type: 'physical', specs: ['KaiOS']},
{os: 'iOS', type: 'emulator'},
],
main: 'dist/bundle.js',
flipperBundlerEntry: 'src/index.tsx',
description: 'Description of Test Plugin',
gatekeeper: 'GK_flipper_plugin_test',
};
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getInstalledPluginDetails(pluginPath);
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
"bugs": undefined,
"category": undefined,
"description": "Description of Test Plugin",
"dir": "/Users/mock/.flipper/thirdparty/flipper-plugin-test",
"entry": "/Users/mock/.flipper/thirdparty/flipper-plugin-test/dist/bundle.js",
"flipperSDKVersion": undefined,
"gatekeeper": "GK_flipper_plugin_test",
"icon": undefined,
"id": "flipper-plugin-test",
"isActivatable": true,
"isBundled": false,
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"pluginType": "device",
"source": "src/index.tsx",
"specVersion": 2,
"supportedDevices": Array [
Object {
"archived": false,
"os": "Android",
},
Object {
"os": "Android",
"specs": Array [
"KaiOS",
],
"type": "physical",
},
Object {
"os": "iOS",
"type": "emulator",
},
],
"title": "Test",
"version": "3.0.1",
}
`);
});

View File

@@ -60,6 +60,7 @@ const installedPlugins: InstalledPluginDetails[] = [
entry: './test/index.js',
version: '0.1.0',
specVersion: 2,
pluginType: 'client',
main: 'dist/bundle.js',
dir: '/Users/mock/.flipper/thirdparty/flipper-plugin-sample1',
source: 'src/index.js',
@@ -74,6 +75,7 @@ const installedPlugins: InstalledPluginDetails[] = [
entry: './test/index.js',
version: '0.2.0',
specVersion: 2,
pluginType: 'client',
main: 'dist/bundle.js',
dir: '/Users/mock/.flipper/thirdparty/flipper-plugin-sample2',
source: 'src/index.js',

View File

@@ -87,6 +87,8 @@ function getPluginDetailsV1(packageJson: any): PluginDetails {
category: packageJson.category,
bugs: packageJson.bugs,
flipperSDKVersion: packageJson?.peerDependencies?.['flipper-plugin'],
pluginType: packageJson?.pluginType || 'client',
supportedDevices: packageJson?.supportedDevices,
};
}
@@ -107,6 +109,8 @@ function getPluginDetailsV2(packageJson: any): PluginDetails {
category: packageJson.category,
bugs: packageJson.bugs,
flipperSDKVersion: packageJson?.peerDependencies?.['flipper-plugin'],
pluginType: packageJson?.pluginType || 'client',
supportedDevices: packageJson?.supportedDevices,
};
}