Versioning for plugin format
Summary: Added versioning for plugin format. The first version is where "main" points to source code entry and plugins are bundled by Flipper in run-time on loading them. The second version is where "main" points to the already existing bundle and Flipper just loads it without bundling. The plugins of version 2 must be bundled using "flipper-pkg" tool before publishing. Changelog: Support new packaging format for plugins. Reviewed By: mweststrate Differential Revision: D21074173 fbshipit-source-id: 7b70250e48e5bd5d359c96149fb5b14e67783c4d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
eb34b2f6e3
commit
ca2d04a5da
25
desktop/pkg-lib/src/PluginDetails.ts
Normal file
25
desktop/pkg-lib/src/PluginDetails.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
export default interface PluginDetails {
|
||||
dir: string;
|
||||
name: string;
|
||||
specVersion: number;
|
||||
version: string;
|
||||
source: string;
|
||||
main: string;
|
||||
gatekeeper?: string;
|
||||
icon?: string;
|
||||
title?: string;
|
||||
category?: string;
|
||||
bugs?: {
|
||||
email?: string;
|
||||
url?: string;
|
||||
};
|
||||
}
|
||||
70
desktop/pkg-lib/src/__tests__/getPluginDetails.node.ts
Normal file
70
desktop/pkg-lib/src/__tests__/getPluginDetails.node.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 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,
|
||||
"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',
|
||||
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,
|
||||
"main": "dist/bundle.js",
|
||||
"name": "flipper-plugin-test",
|
||||
"source": "src/index.tsx",
|
||||
"specVersion": 2,
|
||||
"title": undefined,
|
||||
"version": "3.0.1",
|
||||
}
|
||||
`);
|
||||
});
|
||||
71
desktop/pkg-lib/src/getPluginDetails.ts
Normal file
71
desktop/pkg-lib/src/getPluginDetails.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* 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 path from 'path';
|
||||
import PluginDetails from './PluginDetails';
|
||||
|
||||
export default async function (
|
||||
pluginDir: string,
|
||||
packageJson?: any,
|
||||
): Promise<PluginDetails> {
|
||||
packageJson =
|
||||
packageJson || (await fs.readJson(path.join(pluginDir, 'package.json')));
|
||||
const specVersion = !packageJson.specVersion
|
||||
? 1
|
||||
: (packageJson.specVersion as number);
|
||||
switch (specVersion) {
|
||||
case 1:
|
||||
return await getPluginDetailsV1(pluginDir, packageJson);
|
||||
case 2:
|
||||
return await getPluginDetailsV2(pluginDir, packageJson);
|
||||
default:
|
||||
throw new Error(`Unknown plugin format version: ${specVersion}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Plugins packaged using V1 are distributed as sources and compiled in run-time.
|
||||
async function getPluginDetailsV1(
|
||||
pluginDir: string,
|
||||
packageJson: any,
|
||||
): Promise<PluginDetails> {
|
||||
return {
|
||||
specVersion: 1,
|
||||
dir: pluginDir,
|
||||
name: packageJson.name,
|
||||
version: packageJson.version,
|
||||
main: path.join('dist', 'index.js'),
|
||||
source: packageJson.main,
|
||||
gatekeeper: packageJson.gatekeeper,
|
||||
icon: packageJson.icon,
|
||||
title: packageJson.title,
|
||||
category: packageJson.category,
|
||||
bugs: packageJson.bugs,
|
||||
};
|
||||
}
|
||||
|
||||
// Plugins packaged using V2 are pre-bundled, so compilation in run-time is not required for them.
|
||||
async function getPluginDetailsV2(
|
||||
pluginDir: string,
|
||||
packageJson: any,
|
||||
): Promise<PluginDetails> {
|
||||
return {
|
||||
specVersion: 2,
|
||||
dir: pluginDir,
|
||||
name: packageJson.name,
|
||||
version: packageJson.version,
|
||||
main: packageJson.main,
|
||||
source: packageJson.flipperBundlerEntry,
|
||||
gatekeeper: packageJson.gatekeeper,
|
||||
icon: packageJson.icon,
|
||||
title: packageJson.displayName || packageJson.title,
|
||||
category: packageJson.category,
|
||||
bugs: packageJson.bugs,
|
||||
};
|
||||
}
|
||||
@@ -9,3 +9,5 @@
|
||||
|
||||
export {default as runBuild} from './runBuild';
|
||||
export {default as getWatchFolders} from './getWatchFolders';
|
||||
export {default as PluginDetails} from './PluginDetails';
|
||||
export {default as getPluginDetails} from './getPluginDetails';
|
||||
|
||||
Reference in New Issue
Block a user