Summary: Flipper plugins fail when importing css from third-party dependencies. This diff tries to fix that. Effectively, the plugin can import the css and export it when is bundled. When we load the plugin, we check if there's a css file for it. If there's one, we return it and try to use it. Reviewed By: aigoncharov Differential Revision: D40758178 fbshipit-source-id: e53afffcc481504905d5eeb1aea1f9114ee2a86b
60 lines
1.7 KiB
TypeScript
60 lines
1.7 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, InstalledPluginDetails} from 'flipper-common';
|
|
import {
|
|
AbstractPluginInitializer,
|
|
getRenderHostInstance,
|
|
isSandyPlugin,
|
|
} from 'flipper-frontend-core';
|
|
import {_SandyPluginDefinition} from 'flipper-plugin-core';
|
|
|
|
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 requiredPlugin = await getRenderHostInstance().requirePlugin(
|
|
pluginDetails.entry,
|
|
);
|
|
if (!requiredPlugin || !requiredPlugin.plugin) {
|
|
throw new Error(
|
|
`Failed to obtain plugin source for: ${pluginDetails.name}`,
|
|
);
|
|
}
|
|
return new _SandyPluginDefinition(pluginDetails, requiredPlugin.plugin);
|
|
}
|
|
|
|
protected async filterAllLocalVersions(
|
|
allLocalVersions: 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);
|
|
}
|
|
}
|
|
}
|