Skip to content

Commit

Permalink
Added some comments, and clarified error message
Browse files Browse the repository at this point in the history
backports #8222 to 5.x
  • Loading branch information
BigFunger authored and epixa committed Sep 12, 2016
1 parent 5d14544 commit 3a96d98
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/cli_plugin/install/__tests__/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('kibana cli', function () {
expect(errorStub.called).to.be(false);
});

it('should throw an error if plugin does contain a version.', function () {
it('should throw an error if plugin is missing a kibana version.', function () {
const errorStub = sinon.stub();

try {
Expand All @@ -69,10 +69,10 @@ describe('kibana cli', function () {
errorStub(err);
}

expect(errorStub.firstCall.args[0]).to.match(/plugin version not found/i);
expect(errorStub.firstCall.args[0]).to.match(/plugin package\.json is missing both a version property/i);
});

it('should throw an error if plugin kibanaVersion does does not match kibana version', function () {
it('should throw an error if plugin kibanaVersion does not match kibana version', function () {
const errorStub = sinon.stub();
settings.plugins[0].kibanaVersion = '1.2.3.4';

Expand Down
4 changes: 4 additions & 0 deletions src/cli_plugin/install/__tests__/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ describe('kibana cli', function () {
let settings;

beforeEach(function () {
//These tests are dependent on the file system, and I had some inconsistent
//behavior with rimraf.sync show up. Until these tests are re-written to not
//depend on the file system, I make sure that each test uses a different
//working directory.
testNum += 1;
testWorkingPath = join(workingPathRoot, testNum + '');
tempArchiveFilePath = join(testWorkingPath, 'archive.part');
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/install/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function rebuildCache(settings, logger) {

export function assertVersion(settings) {
if (!settings.plugins[0].kibanaVersion) {
throw new Error (`Plugin version not found. Check package.json in archive`);
throw new Error (`Plugin package.json is missing both a version property (required) and a kibana.version property (optional).`);
}

const actual = cleanVersion(settings.plugins[0].kibanaVersion);
Expand Down
13 changes: 8 additions & 5 deletions src/cli_plugin/install/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function assertValidPackageName(plugin) {

/**
* Examine each package.json file to determine the plugin name,
* version, and platform. Mutates the package objects in the packages array
* version, kibanaVersion, and platform. Mutates the package objects
* in the packages array
* @param {object} settings - a plugin installer settings object
* @param {array} packages - array of package objects from listPackages()
*/
Expand All @@ -69,10 +70,12 @@ async function mergePackageData(settings, packages) {
pkg.version = _.get(packageInfo, 'version');
pkg.name = _.get(packageInfo, 'name');
pkg.path = resolve(settings.pluginDir, pkg.name);
pkg.kibanaVersion = _.get(packageInfo, 'kibana.version');
if (!pkg.kibanaVersion) {
pkg.kibanaVersion = 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 to indicate the version of
// kibana the plugin is intended to work with.
pkg.kibanaVersion = _.get(packageInfo, 'kibana.version', pkg.version);

const regExp = new RegExp(`${pkg.name}-(.+)`, 'i');
const matches = pkg.folder.match(regExp);
Expand Down

0 comments on commit 3a96d98

Please sign in to comment.