From 025ca05d62465bd6dca2edf53bcd3dd0eafe9fad Mon Sep 17 00:00:00 2001 From: Ananya Arun Date: Fri, 6 Aug 2021 07:13:43 -0700 Subject: [PATCH] Enrich plugin metadata on what apps they support and add unit tests Summary: - This Diff is part 1 of 2 of milestone 1 of my internship project flipper self sufficiency. The task can be found here - https://www.internalfb.com/tasks?q=958574791613645&t=91334896 - I have extended the plugin package meta data format to support a "supportedApps" field that consists of appID (facebook, instagram, messenger etc) along with OS and type that were previously defined in supportedDevices as well. - The diff also adds unit tests for this new format to ensure addition of the supportedApps field does not break anything. Reviewed By: nikoant Differential Revision: D30133225 fbshipit-source-id: 6ef0d1cadd61c0d69640cf61793322acb4cd65f4 --- desktop/pkg/schemas/plugin-package-v2.json | 24 +++++++ desktop/plugin-lib/src/PluginDetails.ts | 7 ++ .../src/__tests__/getPluginDetails.node.ts | 72 +++++++++++++++++++ desktop/plugin-lib/src/getPluginDetails.ts | 2 + 4 files changed, 105 insertions(+) diff --git a/desktop/pkg/schemas/plugin-package-v2.json b/desktop/pkg/schemas/plugin-package-v2.json index b59652da6..c6798930a 100644 --- a/desktop/pkg/schemas/plugin-package-v2.json +++ b/desktop/pkg/schemas/plugin-package-v2.json @@ -76,6 +76,30 @@ } } } + }, + "supportedApps": { + "description": "List of apps supported by the plugin.", + "type": "array", + "items": { + "description": "App definition. E.g. {\"appID\": \"Facebook\", \"os\": \"Android\", \"type\": \"physical\"} means that plugin supports only Facebook app on Android physical devices.", + "type": "object", + "properties": { + "appID": { + "description": "App name: Facebook, Instagram or Messenger.", + "type": "string" + }, + "os": { + "description": "Device OS: iOS, Android or Metro. Lack of this property means that all OSes supported.", + "type": "string", + "enum": ["iOS", "Android", "Metro"] + }, + "type": { + "description": "Device type: physical or emulator or dummy. Lack of this property means it supports physical, emulator and dummy devices.", + "type": "string", + "enum": ["physical", "emulator"] + } + } + } } }, "required": [ diff --git a/desktop/plugin-lib/src/PluginDetails.ts b/desktop/plugin-lib/src/PluginDetails.ts index af76d1361..6336aa26f 100644 --- a/desktop/plugin-lib/src/PluginDetails.ts +++ b/desktop/plugin-lib/src/PluginDetails.ts @@ -29,6 +29,7 @@ export interface PluginDetails { flipperSDKVersion?: string; pluginType?: PluginType; supportedDevices?: SupportedDevice[]; + supportedApps?: SupportedApp[]; publishedDocs?: { overview?: boolean; setup?: boolean; @@ -42,6 +43,12 @@ export interface SupportedDevice { readonly specs?: DeviceSpec[]; } +export interface SupportedApp { + readonly appID?: string; + readonly os?: OS; + readonly type?: DeviceType; +} + export type OS = 'iOS' | 'Android' | 'Metro'; export type DeviceType = 'emulator' | 'physical' | 'dummy'; diff --git a/desktop/plugin-lib/src/__tests__/getPluginDetails.node.ts b/desktop/plugin-lib/src/__tests__/getPluginDetails.node.ts index 5daad611a..4d7f9ce84 100644 --- a/desktop/plugin-lib/src/__tests__/getPluginDetails.node.ts +++ b/desktop/plugin-lib/src/__tests__/getPluginDetails.node.ts @@ -55,6 +55,7 @@ test('getPluginDetailsV1', async () => { "pluginType": undefined, "source": "src/index.tsx", "specVersion": 1, + "supportedApps": undefined, "supportedDevices": undefined, "title": "Test Plugin", "version": "2.0.0", @@ -97,6 +98,7 @@ test('getPluginDetailsV2', async () => { "publishedDocs": undefined, "source": "src/index.tsx", "specVersion": 2, + "supportedApps": undefined, "supportedDevices": undefined, "title": "Test", "version": "3.0.1", @@ -139,6 +141,7 @@ test('id used as title if the latter omited', async () => { "publishedDocs": undefined, "source": "src/index.tsx", "specVersion": 2, + "supportedApps": undefined, "supportedDevices": undefined, "title": "test", "version": "3.0.1", @@ -180,6 +183,7 @@ test('name without "flipper-plugin-" prefix is used as title if the latter omite "publishedDocs": undefined, "source": "src/index.tsx", "specVersion": 2, + "supportedApps": undefined, "supportedDevices": undefined, "title": "test", "version": "3.0.1", @@ -224,6 +228,7 @@ test('flipper-plugin-version is parsed', async () => { "publishedDocs": undefined, "source": "src/index.tsx", "specVersion": 2, + "supportedApps": undefined, "supportedDevices": undefined, "title": "test", "version": "3.0.1", @@ -272,6 +277,7 @@ test('plugin type and supported devices parsed', async () => { "publishedDocs": undefined, "source": "src/index.tsx", "specVersion": 2, + "supportedApps": undefined, "supportedDevices": Array [ Object { "archived": false, @@ -295,6 +301,71 @@ test('plugin type and supported devices parsed', async () => { `); }); +test('plugin type and supported apps parsed', async () => { + const pluginV2 = { + $schema: 'https://fbflipper.com/schemas/plugin-package/v2.json', + name: 'flipper-plugin-test', + title: 'Test', + version: '3.0.1', + pluginType: 'client', + supportedApps: [ + {appID: 'Messenger', os: 'Android', type: 'emulator'}, + {appID: 'Instagram', os: 'Android', type: 'physical'}, + {appID: 'Facebook', os: 'iOS', type: 'emulator'}, + ], + main: 'dist/bundle.js', + flipperBundlerEntry: 'src/index.tsx', + description: 'Description of Test Plugin', + gatekeeper: 'GK_flipper_plugin_test', + }; + 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", + "engines": undefined, + "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": "client", + "publishedDocs": undefined, + "source": "src/index.tsx", + "specVersion": 2, + "supportedApps": Array [ + Object { + "appID": "Messenger", + "os": "Android", + "type": "emulator", + }, + Object { + "appID": "Instagram", + "os": "Android", + "type": "physical", + }, + Object { + "appID": "Facebook", + "os": "iOS", + "type": "emulator", + }, + ], + "supportedDevices": undefined, + "title": "Test", + "version": "3.0.1", + } + `); +}); + test('can merge two package.json files', async () => { const pluginBase = { $schema: 'https://fbflipper.com/schemas/plugin-package/v2.json', @@ -359,6 +430,7 @@ test('can merge two package.json files', async () => { }, "source": "src/index.tsx", "specVersion": 2, + "supportedApps": undefined, "supportedDevices": Array [ Object { "archived": false, diff --git a/desktop/plugin-lib/src/getPluginDetails.ts b/desktop/plugin-lib/src/getPluginDetails.ts index d15e89648..daff975dd 100644 --- a/desktop/plugin-lib/src/getPluginDetails.ts +++ b/desktop/plugin-lib/src/getPluginDetails.ts @@ -126,6 +126,7 @@ function getPluginDetailsV1(packageJson: any): PluginDetails { flipperSDKVersion: packageJson?.peerDependencies?.['flipper-plugin'], pluginType: packageJson?.pluginType, supportedDevices: packageJson?.supportedDevices, + supportedApps: packageJson?.supportedApps, engines: packageJson.engines, }; } @@ -149,6 +150,7 @@ function getPluginDetailsV2(packageJson: any): PluginDetails { flipperSDKVersion: packageJson?.peerDependencies?.['flipper-plugin'], pluginType: packageJson?.pluginType, supportedDevices: packageJson?.supportedDevices, + supportedApps: packageJson?.supportedApps, engines: packageJson.engines, publishedDocs: packageJson.publishedDocs, };