Simplify bundled plugin setup
Summary: Stop bundling plugins into Flipper Server bundles. In later diffs, we will start building all plugins even in dev mode which removes the need to bundle them. Reviewed By: lblasa Differential Revision: D39276249 fbshipit-source-id: 091405cfcf58aa7e1bd2b382da40f8d9841ae6b1
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a67a4e5d0f
commit
a888e6affa
@@ -435,7 +435,6 @@ export class FlipperServerImpl implements FlipperServer {
|
||||
this.pluginManager.loadDynamicPlugins(),
|
||||
'plugins-load-marketplace-plugins': () =>
|
||||
this.pluginManager.loadMarketplacePlugins(),
|
||||
'plugins-get-bundled-plugins': () => this.pluginManager.getBundledPlugins(),
|
||||
'plugins-get-installed-plugins': () =>
|
||||
this.pluginManager.getInstalledPlugins(),
|
||||
'plugins-remove-plugins': (plugins) =>
|
||||
|
||||
@@ -13,7 +13,6 @@ import tmp from 'tmp';
|
||||
import {promisify} from 'util';
|
||||
import {default as axios} from 'axios';
|
||||
import {
|
||||
BundledPluginDetails,
|
||||
DownloadablePluginDetails,
|
||||
ExecuteMessage,
|
||||
FlipperServerForServerAddOn,
|
||||
@@ -77,28 +76,6 @@ export class PluginManager {
|
||||
return await fs.readFile(path, 'utf8');
|
||||
}
|
||||
|
||||
async getBundledPlugins(): Promise<Array<BundledPluginDetails>> {
|
||||
if (
|
||||
process.env.NODE_ENV === 'test' ||
|
||||
process.env.FLIPPER_NO_BUNDLED_PLUGINS === 'true'
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
// defaultPlugins that are included in the Flipper distributive.
|
||||
// List of default bundled plugins is written at build time to defaultPlugins/bundled.json.
|
||||
const pluginPath = getStaticPath(
|
||||
path.join('defaultPlugins', 'bundled.json'),
|
||||
{asarUnpacked: true},
|
||||
);
|
||||
let bundledPlugins: Array<BundledPluginDetails> = [];
|
||||
try {
|
||||
bundledPlugins = await fs.readJson(pluginPath);
|
||||
} catch (e) {
|
||||
console.error('Failed to load list of bundled plugins', e);
|
||||
}
|
||||
return bundledPlugins;
|
||||
}
|
||||
|
||||
async loadMarketplacePlugins() {
|
||||
console.info('Load available plugins from marketplace');
|
||||
return loadMarketplacePlugins(this.flipperServer, '');
|
||||
|
||||
@@ -19,7 +19,6 @@ 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 async function loadDynamicPlugins(): Promise<InstalledPluginDetails[]> {
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
return [];
|
||||
@@ -36,29 +35,14 @@ export async function loadDynamicPlugins(): Promise<InstalledPluginDetails[]> {
|
||||
ex,
|
||||
),
|
||||
);
|
||||
const bundledPlugins = new Set<string>(
|
||||
(
|
||||
await fs.readJson(
|
||||
getStaticPath(path.join('defaultPlugins', 'bundled.json'), {
|
||||
asarUnpacked: true,
|
||||
}),
|
||||
)
|
||||
).map((p: any) => p.name) as string[],
|
||||
);
|
||||
console.log(
|
||||
`✅ Detected ${bundledPlugins.size} bundled plugins: ${Array.from(
|
||||
bundledPlugins,
|
||||
).join(', ')}.`,
|
||||
);
|
||||
const [installedPlugins, unfilteredSourcePlugins] = await Promise.all([
|
||||
|
||||
const [installedPlugins, sourcePlugins] = 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,
|
||||
});
|
||||
|
||||
@@ -20,15 +20,6 @@ declare global {
|
||||
}
|
||||
global.FlipperPlugin = FlipperPluginSDK;
|
||||
|
||||
// defaultPlugins has to be required after we set FlipperPlugin.
|
||||
// In server add-ons, developers might import utilities from 'flipper-plugin'
|
||||
// In babel-transformer/plugin-flipper-requires flipper-plugin is replaces with global.FlipperPlugin.
|
||||
// If defaultPlugins is required before we set global.FlipperPlugin,
|
||||
// then flipper-plugin replaced with global.FlipperPlugin is evaluated in server add-ons before we set it - to undefined.
|
||||
//
|
||||
// The file is generated automatically by "prepareDefaultPlugins" in "scripts"
|
||||
const defaultPlugins = require('../defaultPlugins').default;
|
||||
|
||||
interface ServerAddOnModule {
|
||||
default: ServerAddOnFn<any, any>;
|
||||
}
|
||||
@@ -39,18 +30,9 @@ export const loadServerAddOn = (
|
||||
): ServerAddOnModule => {
|
||||
console.debug('loadPlugin', pluginName, details);
|
||||
|
||||
if (details.isBundled) {
|
||||
const bundledPlugin = defaultPlugins[pluginName];
|
||||
assertNotNull(
|
||||
bundledPlugin,
|
||||
`loadPlugin (isBundled = true) -> plugin ${pluginName} not found.`,
|
||||
);
|
||||
return bundledPlugin;
|
||||
}
|
||||
|
||||
assertNotNull(
|
||||
details.path,
|
||||
`loadPlugin (isBundled = false) -> server add-on path is empty plugin ${pluginName}.`,
|
||||
`loadPlugin -> server add-on path is empty plugin ${pluginName}.`,
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
|
||||
Reference in New Issue
Block a user