Skip to content

Commit

Permalink
Implement recursive plugin discovery (elastic#68811)
Browse files Browse the repository at this point in the history
* implements recursive scanning in plugin discovery system

* update optimizer to find plugins in sub-directories

* update renovate

* update optimizer IT snapshot

* refactor processPluginSearchPaths$ and add test for inaccessible manifest

* add symlink test

* add maxDepth to the optimizer

* adapt mockFs definitions

* remove `flat` usage
  • Loading branch information
pgayvallet authored and Bamieh committed Jul 1, 2020
1 parent 2a133d1 commit a841e1c
Show file tree
Hide file tree
Showing 12 changed files with 486 additions and 260 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@
"@types/markdown-it": "^0.0.7",
"@types/minimatch": "^2.0.29",
"@types/mocha": "^7.0.2",
"@types/mock-fs": "^4.10.0",
"@types/moment-timezone": "^0.5.12",
"@types/mustache": "^0.8.31",
"@types/node": ">=10.17.17 <10.20.0",
Expand Down Expand Up @@ -473,6 +474,7 @@
"listr": "^0.14.1",
"load-grunt-config": "^3.0.1",
"mocha": "^7.1.1",
"mock-fs": "^4.12.0",
"mock-http-server": "1.3.0",
"ms-chromium-edge-driver": "^0.2.3",
"multistream": "^2.1.1",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ it('parses kibana.json files of plugins found in pluginDirs', () => {
"id": "bar",
"isUiPlugin": true,
},
Object {
"directory": <absolute path>/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz,
"extraPublicDirs": Array [],
"id": "baz",
"isUiPlugin": false,
},
Object {
"directory": <absolute path>/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo,
"extraPublicDirs": Array [],
"id": "foo",
"isUiPlugin": true,
},
Object {
"directory": <absolute path>/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/nested/baz,
"extraPublicDirs": Array [],
"id": "baz",
"isUiPlugin": false,
},
Object {
"directory": <absolute path>/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz,
"extraPublicDirs": Array [],
Expand Down
13 changes: 12 additions & 1 deletion packages/kbn-optimizer/src/optimizer/kibana_platform_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function findKibanaPlatformPlugins(scanDirs: string[], paths: string[]) {
.sync(
Array.from(
new Set([
...scanDirs.map((dir) => `${dir}/*/kibana.json`),
...scanDirs.map(nestedScanDirPaths).reduce((dirs, current) => [...dirs, ...current], []),
...paths.map((path) => `${path}/kibana.json`),
])
),
Expand All @@ -51,6 +51,17 @@ export function findKibanaPlatformPlugins(scanDirs: string[], paths: string[]) {
);
}

function nestedScanDirPaths(dir: string): string[] {
// down to 5 level max
return [
`${dir}/*/kibana.json`,
`${dir}/*/*/kibana.json`,
`${dir}/*/*/*/kibana.json`,
`${dir}/*/*/*/*/kibana.json`,
`${dir}/*/*/*/*/*/kibana.json`,
];
}

function readKibanaPlatformPlugin(manifestPath: string): KibanaPlatformPlugin {
if (!Path.isAbsolute(manifestPath)) {
throw new TypeError('expected new platform manifest path to be absolute');
Expand Down
8 changes: 8 additions & 0 deletions renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,14 @@
'(\\b|_)mocha(\\b|_)',
],
},
{
groupSlug: 'mock-fs',
groupName: 'mock-fs related packages',
packageNames: [
'mock-fs',
'@types/mock-fs',
],
},
{
groupSlug: 'moment',
groupName: 'moment related packages',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,5 @@
* under the License.
*/

export const mockReaddir = jest.fn();
export const mockReadFile = jest.fn();
export const mockStat = jest.fn();
jest.mock('fs', () => ({
readdir: mockReaddir,
readFile: mockReadFile,
stat: mockStat,
}));

export const mockPackage = new Proxy({ raw: {} as any }, { get: (obj, prop) => obj.raw[prop] });
jest.mock('../../../../../package.json', () => mockPackage);
Loading

0 comments on commit a841e1c

Please sign in to comment.