From ff66cd18ecabc4b1492c8dbe730dd4ab3c7fb6ea Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Mon, 11 Jul 2022 07:04:55 -0700 Subject: [PATCH] isPluginCompatible for flipper-server-core Summary: Yet another implementation of this function. References: https://www.internalfb.com/code/fbsource/[85c1fe5afee7]/xplat/sonar/desktop/flipper-frontend-core/src/utils/isPluginCompatible.tsx?lines=14 https://www.internalfb.com/code/fbsource/[85c1fe5afee7]/xplat/sonar/desktop/flipper-ui-core/src/utils/isPluginCompatible.tsx?lines=15 This one: - Uses GK from the existing server config - Gets version from the existing server config It differs in: - appVersion not passed in as argument - Doesn't use RenderHost to obtain the server config I think, this is acceptable as the function body is effectively the conditional, that depends on the caller available dependencies. Reviewed By: passy Differential Revision: D37749761 fbshipit-source-id: 3094e87c7770ac66e5764c932a0a0d4e7f5b63f5 --- desktop/flipper-server-core/package.json | 1 + .../src/plugins/isPluginCompatible.tsx | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 desktop/flipper-server-core/src/plugins/isPluginCompatible.tsx diff --git a/desktop/flipper-server-core/package.json b/desktop/flipper-server-core/package.json index 639b8014f..ba170222a 100644 --- a/desktop/flipper-server-core/package.json +++ b/desktop/flipper-server-core/package.json @@ -37,6 +37,7 @@ "rsocket-flowable": "^0.0.27", "rsocket-tcp-server": "^0.0.25", "rsocket-types": "^0.0.25", + "semver": "^7.3.7", "serialize-error": "^8.1.0", "split2": "^4.1.0", "tmp": "^0.2.1", diff --git a/desktop/flipper-server-core/src/plugins/isPluginCompatible.tsx b/desktop/flipper-server-core/src/plugins/isPluginCompatible.tsx new file mode 100644 index 000000000..e68be5795 --- /dev/null +++ b/desktop/flipper-server-core/src/plugins/isPluginCompatible.tsx @@ -0,0 +1,25 @@ +/** + * 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 {PluginDetails} from 'flipper-common'; +import semver from 'semver'; +import {getFlipperServerConfig} from '../FlipperServerConfig'; + +export function isPluginCompatible(plugin: PluginDetails) { + const config = getFlipperServerConfig(); + const flipperVersion = config.environmentInfo.appVersion; + return ( + config.gatekeepers['flipper_disable_plugin_compatibility_checks'] || + flipperVersion === '0.0.0' || + !plugin.engines?.flipper || + semver.lte(plugin.engines?.flipper, flipperVersion) + ); +} + +export default isPluginCompatible;