Summary: Allow adding plugins after initialisation. Effectively: - Load the plugin creates the SandyPluginDefinition - Add the definition to the existing loaded plugins Reviewed By: passy Differential Revision: D37749811 fbshipit-source-id: ea834b9e6105cf605fc906a794022f61807ce1d8
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and 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 {
|
|
ActivatablePluginDetails,
|
|
BundledPluginDetails,
|
|
InstalledPluginDetails,
|
|
} from 'flipper-common';
|
|
import {
|
|
AbstractPluginInitializer,
|
|
getRenderHostInstance,
|
|
isSandyPlugin,
|
|
} from 'flipper-frontend-core';
|
|
import {_SandyPluginDefinition} from 'flipper-plugin';
|
|
|
|
export class HeadlessPluginInitializer extends AbstractPluginInitializer {
|
|
protected async getFlipperVersion() {
|
|
const config = await getRenderHostInstance().flipperServer.exec(
|
|
'get-config',
|
|
);
|
|
return config.environmentInfo.appVersion;
|
|
}
|
|
|
|
protected async requirePluginImpl(
|
|
pluginDetails: ActivatablePluginDetails,
|
|
): Promise<_SandyPluginDefinition> {
|
|
const plugin = pluginDetails.isBundled
|
|
? this.defaultPluginsIndex[pluginDetails.name]
|
|
: await getRenderHostInstance().requirePlugin(pluginDetails.entry);
|
|
if (!plugin) {
|
|
throw new Error(
|
|
`Failed to obtain plugin source for: ${pluginDetails.name}`,
|
|
);
|
|
}
|
|
return new _SandyPluginDefinition(pluginDetails, plugin);
|
|
}
|
|
|
|
protected async filterAllLocalVersions(
|
|
allLocalVersions: (BundledPluginDetails | InstalledPluginDetails)[],
|
|
): Promise<ActivatablePluginDetails[]> {
|
|
const pluginsToLoad = await super.filterAllLocalVersions(allLocalVersions);
|
|
return pluginsToLoad
|
|
.filter(isSandyPlugin)
|
|
.filter((plugin) => plugin.headless);
|
|
}
|
|
|
|
async installPlugin(
|
|
plugin: InstalledPluginDetails,
|
|
): Promise<_SandyPluginDefinition | undefined> {
|
|
const loaded = await this.loadPlugins([plugin]);
|
|
this._initialPlugins.push(...loaded);
|
|
|
|
if (loaded.length > 0) {
|
|
return loaded.at(0);
|
|
}
|
|
}
|
|
}
|