isPluginVersionMoreRecent for flipper-server-core
Summary: Another implementation for isPluginVersionMoreRecent. References: https://www.internalfb.com/code/fbsource/[2d3c2d3ce5fb]/xplat/sonar/desktop/flipper-frontend-core/src/utils/isPluginVersionMoreRecent.tsx?lines=14 https://www.internalfb.com/code/fbsource/[2d3c2d3ce5fb]/xplat/sonar/desktop/flipper-ui-core/src/utils/isPluginVersionMoreRecent.tsx?lines=14 Is not immediately obvious what is different, but it boils down to the implementation of: ``` isPluginCompatible ``` and passing the flipper version. That one depends on the package. As with other changes, this can probably be refactored out, for left as is unless strongly advised otherwise (it seems OK as we already have 2 implementations). Reviewed By: passy Differential Revision: D37749785 fbshipit-source-id: 5a22d90f094b53223d2469c572646d5bfd3d1d33
This commit is contained in:
committed by
Facebook GitHub Bot
parent
beb0ed1991
commit
77276f5ac0
@@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* 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 {ConcretePluginDetails} from 'flipper-common';
|
||||||
|
import semver from 'semver';
|
||||||
|
import isPluginCompatible from './isPluginCompatible';
|
||||||
|
|
||||||
|
export function isPluginVersionMoreRecent(
|
||||||
|
versionDetails: ConcretePluginDetails,
|
||||||
|
otherVersionDetails: ConcretePluginDetails,
|
||||||
|
) {
|
||||||
|
const isPlugin1Compatible = isPluginCompatible(versionDetails);
|
||||||
|
const isPlugin2Compatible = isPluginCompatible(otherVersionDetails);
|
||||||
|
|
||||||
|
// prefer compatible plugins
|
||||||
|
if (isPlugin1Compatible && !isPlugin2Compatible) return true;
|
||||||
|
if (!isPlugin1Compatible && isPlugin2Compatible) return false;
|
||||||
|
|
||||||
|
// prefer plugins with greater version
|
||||||
|
if (semver.gt(versionDetails.version, otherVersionDetails.version)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
semver.eq(versionDetails.version, otherVersionDetails.version) &&
|
||||||
|
versionDetails.isBundled
|
||||||
|
) {
|
||||||
|
// prefer bundled versions
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
semver.eq(versionDetails.version, otherVersionDetails.version) &&
|
||||||
|
versionDetails.isActivatable &&
|
||||||
|
!otherVersionDetails.isActivatable
|
||||||
|
) {
|
||||||
|
// prefer locally available versions to the versions available remotely on marketplace
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default isPluginVersionMoreRecent;
|
||||||
Reference in New Issue
Block a user