Summary: Moved all types related to plugin descriptions from plugin-lib (which handles downloads and such) to flipper-common. The goal of that is to remove all plugin-lib usage from ui-core to server-core, so that the UI itself doesn't do any file operations anymore related to plugins. That will be done in next diffs, this just moves types but no code. Reviewed By: nikoant, aigoncharov Differential Revision: D32665064 fbshipit-source-id: 86d908e7264569b0229b09290a891171876c8e00
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
/**
|
|
* Copyright (c) Facebook, Inc. and its 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;
|