move plugin management from ui-core to server-core

Summary:
Follow up of D32665064, this diff moves all plugin management logic from flipper-ui to flipper-server. Things like downloading, installing, querying new plugins.

Loading plugins is handled separately in the next diff.

Reviewed By: nikoant

Differential Revision: D32666537

fbshipit-source-id: 9786b82987f00180bb26200e38735b334dc4d5c3
This commit is contained in:
Michel Weststrate
2021-12-08 04:25:28 -08:00
committed by Facebook GitHub Bot
parent f9b72ac69e
commit 64747dc417
25 changed files with 441 additions and 276 deletions

View File

@@ -1,85 +0,0 @@
/**
* 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 path from 'path';
import fs from 'fs-extra';
import {
getSourcePlugins,
moveInstalledPluginsFromLegacyDir,
getAllInstalledPluginVersions,
getAllInstalledPluginsInDir,
} from 'flipper-plugin-lib';
import {InstalledPluginDetails} from 'flipper-common';
import {getStaticPath} from '../utils/pathUtils';
// Load "dynamic" plugins, e.g. those which are either pre-installed (default), installed or loaded from sources (for development).
// This opposed to "bundled" plugins which are included into Flipper bundle.
export default async function loadDynamicPlugins(): Promise<
InstalledPluginDetails[]
> {
if (process.env.NODE_ENV === 'test') {
return [];
}
if (process.env.FLIPPER_FAST_REFRESH) {
console.log(
'❌ Skipping loading of dynamic plugins because Fast Refresh is enabled. Fast Refresh only works with bundled plugins.',
);
return [];
}
await moveInstalledPluginsFromLegacyDir().catch((ex) =>
console.error(
'Eror while migrating installed plugins from legacy folder',
ex,
),
);
const bundledPlugins = new Set<string>(
(
await fs.readJson(
getStaticPath(path.join('defaultPlugins', 'bundled.json'), {
asarUnpacked: true,
}),
)
).map((p: any) => p.name) as string[],
);
const [installedPlugins, unfilteredSourcePlugins] = await Promise.all([
process.env.FLIPPER_NO_PLUGIN_MARKETPLACE
? Promise.resolve([])
: getAllInstalledPluginVersions(),
getSourcePlugins(),
]);
const sourcePlugins = unfilteredSourcePlugins.filter(
(p) => !bundledPlugins.has(p.name),
);
const defaultPluginsDir = getStaticPath('defaultPlugins', {
asarUnpacked: true,
});
const defaultPlugins = await getAllInstalledPluginsInDir(defaultPluginsDir);
if (defaultPlugins.length > 0) {
console.log(
`✅ Loaded ${defaultPlugins.length} default plugins: ${defaultPlugins
.map((x) => x.title)
.join(', ')}.`,
);
}
if (installedPlugins.length > 0) {
console.log(
`✅ Loaded ${installedPlugins.length} installed plugins: ${Array.from(
new Set(installedPlugins.map((x) => x.title)),
).join(', ')}.`,
);
}
if (sourcePlugins.length > 0) {
console.log(
`✅ Loaded ${sourcePlugins.length} source plugins: ${sourcePlugins
.map((x) => x.title)
.join(', ')}.`,
);
}
return [...defaultPlugins, ...installedPlugins, ...sourcePlugins];
}

View File

@@ -16,6 +16,9 @@ import fs from 'fs';
import config from '../fb-stubs/config';
import {getRenderHostInstance} from '../RenderHost';
/**
* @deprecated
*/
export function getStaticPath(
relativePath: string = '.',
{asarUnpacked}: {asarUnpacked: boolean} = {asarUnpacked: false},
@@ -31,6 +34,9 @@ export function getStaticPath(
: absolutePath;
}
/**
* @deprecated
*/
export function getChangelogPath() {
const changelogPath = getStaticPath(config.isFBBuild ? 'facebook' : '.');
if (fs.existsSync(changelogPath)) {