Adds a kibanaVersion property to the Plugin class

This commit is contained in:
Jim Unger 2016-09-15 16:04:41 -05:00
parent 2f52be62ae
commit e920bca051
2 changed files with 12 additions and 10 deletions

View file

@ -1,14 +1,14 @@
import { cleanVersion, versionSatisfies } from '../../utils/version';
import { get } from 'lodash';
function compatibleWithKibana(kbnServer, pluginVersion) {
function compatibleWithKibana(kbnServer, plugin) {
//core plugins have a version of 'kibana' and are always compatible
if (pluginVersion === 'kibana') return true;
if (plugin.kibanaVersion === 'kibana') return true;
const cleanPluginVersion = cleanVersion(pluginVersion);
const pluginKibanaVersion = cleanVersion(plugin.kibanaVersion);
const kibanaVersion = cleanVersion(kbnServer.version);
return versionSatisfies(cleanPluginVersion, kibanaVersion);
return versionSatisfies(pluginKibanaVersion, kibanaVersion);
}
export default async function (kbnServer, server, config) {
@ -18,14 +18,10 @@ export default async function (kbnServer, server, config) {
const plugins = kbnServer.plugins;
for (let plugin of plugins) {
// Plugins must specify their version, and by default that version should match
// the version of kibana down to the patch level. If these two versions need
// to diverge, they can specify a kibana.version to indicate the version of
// kibana the plugin is intended to work with.
const version = get(plugin, 'pkg.kibana.version', get(plugin, 'pkg.version'));
const version = plugin.kibanaVersion;
const name = get(plugin, 'pkg.name');
if (!compatibleWithKibana(kbnServer, version)) {
if (!compatibleWithKibana(kbnServer, plugin)) {
const message = `Plugin "${name}" was disabled because it expected Kibana version "${version}", and found "${kbnServer.version}".`;
warningMessages.add(message);
plugins.delete(plugin);

View file

@ -59,6 +59,12 @@ module.exports = class Plugin {
this.uiExportsSpecs = opts.uiExports || {};
this.requiredIds = opts.require || [];
this.version = opts.version || pkg.version;
// Plugins must specify their version, and by default that version should match
// the version of kibana down to the patch level. If these two versions need
// to diverge, they can specify a kibana.version in the package to indicate the
// version of kibana the plugin is intended to work with.
this.kibanaVersion = opts.kibanaVersion || _.get(pkg, 'kibana.version', this.version);
this.externalPreInit = opts.preInit || _.noop;
this.externalInit = opts.init || _.noop;
this.configPrefix = opts.configPrefix || this.id;