flipper-plugin-lib
Version:
Library containing common Flipper plugin installation utilities
77 lines • 3.35 kB
JavaScript
;
/**
* 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
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSourcePlugins = void 0;
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const pluginPaths_1 = require("./pluginPaths");
const p_map_1 = __importDefault(require("p-map"));
const p_filter_1 = __importDefault(require("p-filter"));
const semver_1 = require("semver");
const getPluginDetails_1 = require("./getPluginDetails");
const flipperVersion = require('../package.json').version;
async function getSourcePlugins() {
const pluginFolders = await (0, pluginPaths_1.getPluginSourceFolders)();
const entryPoints = {};
const additionalPlugins = await (0, p_map_1.default)(pluginFolders, (path) => entryPointForPluginFolder(path));
for (const p of additionalPlugins) {
Object.keys(p).forEach((key) => {
entryPoints[key] = p[key];
});
}
const allPlugins = Object.values(entryPoints);
if (process.env.FLIPPER_ENABLED_PLUGINS) {
const pluginNames = new Set(process.env.FLIPPER_ENABLED_PLUGINS.split(',').map((x) => x.toLowerCase()));
return allPlugins.filter((x) => pluginNames.has(x.name) ||
pluginNames.has(x.id) ||
pluginNames.has(x.name.replace('flipper-plugin-', '')));
}
return allPlugins;
}
exports.getSourcePlugins = getSourcePlugins;
async function entryPointForPluginFolder(pluginsDir) {
if (!(await fs_extra_1.default.pathExists(pluginsDir))) {
return {};
}
return await fs_extra_1.default
.readdir(pluginsDir)
.then((entries) => entries.map((name) => path_1.default.join(pluginsDir, name)))
.then((entries) => (0, p_filter_1.default)(entries, getPluginDetails_1.isPluginDir))
.then((packages) => (0, p_map_1.default)(packages, async (dir) => {
try {
const details = await (0, getPluginDetails_1.getInstalledPluginDetails)(dir);
if (details.flipperSDKVersion &&
!(0, semver_1.satisfies)(flipperVersion, details.flipperSDKVersion)) {
console.warn(`⚠️ The current Flipper version (${flipperVersion}) doesn't look compatible with the plugin '${details.name}', which expects 'flipper-plugin: ${details.flipperSDKVersion}'`);
}
return details;
}
catch (e) {
console.error(`Could not load plugin from "${dir}", because package.json is invalid.`, e);
return null;
}
}))
.then((plugins) => plugins
.filter(notNull)
.filter(({ deprecated }) => typeof deprecated !== 'string'))
.then((plugins) => plugins.reduce((acc, cv) => {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
acc[cv.name] = cv;
return acc;
}, {}));
}
function notNull(x) {
return x !== null && x !== undefined;
}
//# sourceMappingURL=getSourcePlugins.js.map