Merge plugin package.json from public and fb-internal parts

Summary: Allow splitting package.json to public one and fb-internal one located in "fb/package.json". When plugin is packaged, fields in package.json are overwritten by fields from "fb/package.json" if they exist. This give us a way to specify additional metadata which only make sense internally (e.g. oncall and internal links to docs and support).

Reviewed By: mweststrate

Differential Revision: D28542101

fbshipit-source-id: c0167461897a994e5731aaf0fe625de052eda864
This commit is contained in:
Anton Nikolaev
2021-05-21 07:14:13 -07:00
committed by Facebook GitHub Bot
parent d680a2807f
commit 5ae104cc59
4 changed files with 112 additions and 52 deletions

View File

@@ -16,6 +16,16 @@ import {
} from './PluginDetails';
import {pluginCacheDir} from './pluginPaths';
export async function readPluginPackageJson(dir: string): Promise<any> {
const baseJson = await fs.readJson(path.join(dir, 'package.json'));
if (await fs.pathExists(path.join(dir, 'fb', 'package.json'))) {
const addedJson = await fs.readJson(path.join(dir, 'fb', 'package.json'));
return Object.assign({}, baseJson, addedJson);
} else {
return baseJson;
}
}
export function isPluginJson(packageJson: any): boolean {
return packageJson?.keywords?.includes('flipper-plugin');
}
@@ -51,8 +61,7 @@ export async function getInstalledPluginDetails(
dir: string,
packageJson?: any,
): Promise<InstalledPluginDetails> {
packageJson =
packageJson ?? (await fs.readJson(path.join(dir, 'package.json')));
packageJson = packageJson ?? (await readPluginPackageJson(dir));
const pluginDetails = getPluginDetails(packageJson);
const entry =
pluginDetails.specVersion === 1