mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[pluginDiscovery] dedupe packs by absolute path (#16829)
* [pluginDiscovery] dedupe packs by absolute path * [pluginDiscovery] extract distinct keySelector, add more docs
This commit is contained in:
parent
293f280b14
commit
366f47476a
2 changed files with 45 additions and 0 deletions
|
@ -70,5 +70,27 @@ describe('plugin discovery', () => {
|
|||
expect(specs.map(s => s.getId()).sort())
|
||||
.to.eql(['bar:two', 'foo']);
|
||||
});
|
||||
|
||||
it('dedupes duplicate packs', async () => {
|
||||
const { spec$ } = findPluginSpecs({
|
||||
plugins: {
|
||||
scanDirs: [PLUGIN_FIXTURES],
|
||||
paths: [
|
||||
resolve(PLUGIN_FIXTURES, 'foo'),
|
||||
resolve(PLUGIN_FIXTURES, 'foo'),
|
||||
resolve(PLUGIN_FIXTURES, 'bar'),
|
||||
resolve(PLUGIN_FIXTURES, 'bar'),
|
||||
],
|
||||
}
|
||||
});
|
||||
|
||||
const specs = await spec$.toArray().toPromise();
|
||||
expect(specs).to.have.length(3);
|
||||
specs.forEach(spec => {
|
||||
expect(spec).to.be.a(PluginSpec);
|
||||
});
|
||||
expect(specs.map(s => s.getId()).sort())
|
||||
.to.eql(['bar:one', 'bar:two', 'foo']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Observable } from 'rxjs';
|
||||
import { realpathSync } from 'fs';
|
||||
|
||||
import { transformDeprecations, Config } from '../server/config';
|
||||
|
||||
|
@ -31,6 +32,27 @@ function bufferAllResults(observable) {
|
|||
.mergeMap(array => array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine a distinct value for each result from find$
|
||||
* so they can be deduplicated
|
||||
* @param {{error?,pack?}} result
|
||||
* @return {Any}
|
||||
*/
|
||||
function getDistinctKeyForFindResult(result) {
|
||||
// errors are distinct by their message
|
||||
if (result.error) {
|
||||
return result.error.message;
|
||||
}
|
||||
|
||||
// packs are distinct by their absolute and real path
|
||||
if (result.pack) {
|
||||
return realpathSync(result.pack.getPath());
|
||||
}
|
||||
|
||||
// non error/pack results shouldn't exist, but if they do they are all unique
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a collection of observables for discovering pluginSpecs
|
||||
* using Kibana's defaults, settings, and config service
|
||||
|
@ -46,6 +68,7 @@ export function findPluginSpecs(settings, config = defaultConfig(settings)) {
|
|||
...config.get('plugins.paths').map(createPackAtPath$),
|
||||
...config.get('plugins.scanDirs').map(createPacksInDirectory$)
|
||||
)
|
||||
.distinct(getDistinctKeyForFindResult)
|
||||
.share();
|
||||
|
||||
const extendConfig$ = find$
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue