Summary: Added "id" field to Flipper plugin manifest which is used to match native and desktop plugin parts. Before that, "name" field was used both as npm package name and as plugin id. The problem is that currently there are a lot of plugins which has invalid values in "name", e.g. not starting with "flipper-package-", or containing upper cased letters. Simple renaming of "name" field can be very problematic, so we need a new field to avoid any breaking changes and keep historical analytics data which is also bound to plugin id. Reviewed By: mweststrate Differential Revision: D21129689 fbshipit-source-id: efd143c82a6a802cc0b5438fd3f509bd99aded0e
133 lines
3.7 KiB
TypeScript
133 lines
3.7 KiB
TypeScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import fs from 'fs-extra';
|
|
import {mocked} from 'ts-jest/utils';
|
|
import getPluginDetails from '../getPluginDetails';
|
|
|
|
jest.mock('fs-extra');
|
|
const fsMock = mocked(fs, true);
|
|
|
|
test('getPluginDetailsV1', async () => {
|
|
const pluginV1 = {
|
|
name: 'flipper-plugin-test',
|
|
version: '2.0.0',
|
|
title: 'Test Plugin',
|
|
main: 'src/index.tsx',
|
|
gatekeeper: 'GK_flipper_plugin_test',
|
|
};
|
|
fsMock.readJson.mockImplementation(() => pluginV1);
|
|
const details = await getPluginDetails('./plugins/flipper-plugin-test');
|
|
expect(details).toMatchInlineSnapshot(`
|
|
Object {
|
|
"bugs": undefined,
|
|
"category": undefined,
|
|
"dir": "./plugins/flipper-plugin-test",
|
|
"gatekeeper": "GK_flipper_plugin_test",
|
|
"icon": undefined,
|
|
"id": "flipper-plugin-test",
|
|
"main": "dist/index.js",
|
|
"name": "flipper-plugin-test",
|
|
"source": "src/index.tsx",
|
|
"specVersion": 1,
|
|
"title": "Test Plugin",
|
|
"version": "2.0.0",
|
|
}
|
|
`);
|
|
});
|
|
|
|
test('getPluginDetailsV2', async () => {
|
|
const pluginV2 = {
|
|
specVersion: 2,
|
|
name: 'flipper-plugin-test',
|
|
title: 'Test',
|
|
version: '3.0.1',
|
|
main: 'dist/bundle.js',
|
|
flipperBundlerEntry: 'src/index.tsx',
|
|
gatekeeper: 'GK_flipper_plugin_test',
|
|
};
|
|
fsMock.readJson.mockImplementation(() => pluginV2);
|
|
const details = await getPluginDetails('./plugins/flipper-plugin-test');
|
|
expect(details).toMatchInlineSnapshot(`
|
|
Object {
|
|
"bugs": undefined,
|
|
"category": undefined,
|
|
"dir": "./plugins/flipper-plugin-test",
|
|
"gatekeeper": "GK_flipper_plugin_test",
|
|
"icon": undefined,
|
|
"id": "flipper-plugin-test",
|
|
"main": "dist/bundle.js",
|
|
"name": "flipper-plugin-test",
|
|
"source": "src/index.tsx",
|
|
"specVersion": 2,
|
|
"title": "Test",
|
|
"version": "3.0.1",
|
|
}
|
|
`);
|
|
});
|
|
|
|
test('id used as title if the latter omited', async () => {
|
|
const pluginV2 = {
|
|
specVersion: 2,
|
|
name: 'flipper-plugin-test',
|
|
id: 'test',
|
|
version: '3.0.1',
|
|
main: 'dist/bundle.js',
|
|
flipperBundlerEntry: 'src/index.tsx',
|
|
gatekeeper: 'GK_flipper_plugin_test',
|
|
};
|
|
fsMock.readJson.mockImplementation(() => pluginV2);
|
|
const details = await getPluginDetails('./plugins/flipper-plugin-test');
|
|
expect(details).toMatchInlineSnapshot(`
|
|
Object {
|
|
"bugs": undefined,
|
|
"category": undefined,
|
|
"dir": "./plugins/flipper-plugin-test",
|
|
"gatekeeper": "GK_flipper_plugin_test",
|
|
"icon": undefined,
|
|
"id": "test",
|
|
"main": "dist/bundle.js",
|
|
"name": "flipper-plugin-test",
|
|
"source": "src/index.tsx",
|
|
"specVersion": 2,
|
|
"title": "test",
|
|
"version": "3.0.1",
|
|
}
|
|
`);
|
|
});
|
|
|
|
test('name without "flipper-plugin-" prefix is used as title if the latter omited', async () => {
|
|
const pluginV2 = {
|
|
specVersion: 2,
|
|
name: 'flipper-plugin-test',
|
|
version: '3.0.1',
|
|
main: 'dist/bundle.js',
|
|
flipperBundlerEntry: 'src/index.tsx',
|
|
gatekeeper: 'GK_flipper_plugin_test',
|
|
};
|
|
fsMock.readJson.mockImplementation(() => pluginV2);
|
|
const details = await getPluginDetails('./plugins/flipper-plugin-test');
|
|
expect(details).toMatchInlineSnapshot(`
|
|
Object {
|
|
"bugs": undefined,
|
|
"category": undefined,
|
|
"dir": "./plugins/flipper-plugin-test",
|
|
"gatekeeper": "GK_flipper_plugin_test",
|
|
"icon": undefined,
|
|
"id": "flipper-plugin-test",
|
|
"main": "dist/bundle.js",
|
|
"name": "flipper-plugin-test",
|
|
"source": "src/index.tsx",
|
|
"specVersion": 2,
|
|
"title": "test",
|
|
"version": "3.0.1",
|
|
}
|
|
`);
|
|
});
|