Skip to content

Commit 73c3e3f

Browse files
committed
Implement recursive plugin discovery (#68811)
* 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 # Conflicts: # renovate.json5
1 parent fd47408 commit 73c3e3f

11 files changed

Lines changed: 478 additions & 260 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
"@types/markdown-it": "^0.0.7",
357357
"@types/minimatch": "^2.0.29",
358358
"@types/mocha": "^7.0.2",
359+
"@types/mock-fs": "^4.10.0",
359360
"@types/moment-timezone": "^0.5.12",
360361
"@types/mustache": "^0.8.31",
361362
"@types/node": ">=10.17.17 <10.20.0",
@@ -468,6 +469,7 @@
468469
"listr": "^0.14.1",
469470
"load-grunt-config": "^3.0.1",
470471
"mocha": "^7.1.1",
472+
"mock-fs": "^4.12.0",
471473
"mock-http-server": "1.3.0",
472474
"ms-chromium-edge-driver": "^0.2.3",
473475
"multistream": "^2.1.1",

packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/kibana.json renamed to packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/nested/baz/kibana.json

File renamed without changes.

packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/server/index.ts renamed to packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/nested/baz/server/index.ts

File renamed without changes.

packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/server/lib.ts renamed to packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/nested/baz/server/lib.ts

File renamed without changes.

packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/kbn-optimizer/src/optimizer/kibana_platform_plugins.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ it('parses kibana.json files of plugins found in pluginDirs', () => {
4141
"id": "bar",
4242
"isUiPlugin": true,
4343
},
44-
Object {
45-
"directory": <absolute path>/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz,
46-
"extraPublicDirs": Array [],
47-
"id": "baz",
48-
"isUiPlugin": false,
49-
},
5044
Object {
5145
"directory": <absolute path>/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo,
5246
"extraPublicDirs": Array [],
5347
"id": "foo",
5448
"isUiPlugin": true,
5549
},
50+
Object {
51+
"directory": <absolute path>/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/nested/baz,
52+
"extraPublicDirs": Array [],
53+
"id": "baz",
54+
"isUiPlugin": false,
55+
},
5656
Object {
5757
"directory": <absolute path>/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz,
5858
"extraPublicDirs": Array [],

packages/kbn-optimizer/src/optimizer/kibana_platform_plugins.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function findKibanaPlatformPlugins(scanDirs: string[], paths: string[]) {
3737
.sync(
3838
Array.from(
3939
new Set([
40-
...scanDirs.map((dir) => `${dir}/*/kibana.json`),
40+
...scanDirs.map(nestedScanDirPaths).reduce((dirs, current) => [...dirs, ...current], []),
4141
...paths.map((path) => `${path}/kibana.json`),
4242
])
4343
),
@@ -51,6 +51,17 @@ export function findKibanaPlatformPlugins(scanDirs: string[], paths: string[]) {
5151
);
5252
}
5353

54+
function nestedScanDirPaths(dir: string): string[] {
55+
// down to 5 level max
56+
return [
57+
`${dir}/*/kibana.json`,
58+
`${dir}/*/*/kibana.json`,
59+
`${dir}/*/*/*/kibana.json`,
60+
`${dir}/*/*/*/*/kibana.json`,
61+
`${dir}/*/*/*/*/*/kibana.json`,
62+
];
63+
}
64+
5465
function readKibanaPlatformPlugin(manifestPath: string): KibanaPlatformPlugin {
5566
if (!Path.isAbsolute(manifestPath)) {
5667
throw new TypeError('expected new platform manifest path to be absolute');

src/core/server/plugins/discovery/plugins_discovery.test.mocks.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,5 @@
1717
* under the License.
1818
*/
1919

20-
export const mockReaddir = jest.fn();
21-
export const mockReadFile = jest.fn();
22-
export const mockStat = jest.fn();
23-
jest.mock('fs', () => ({
24-
readdir: mockReaddir,
25-
readFile: mockReadFile,
26-
stat: mockStat,
27-
}));
28-
2920
export const mockPackage = new Proxy({ raw: {} as any }, { get: (obj, prop) => obj.raw[prop] });
3021
jest.mock('../../../../../package.json', () => mockPackage);

0 commit comments

Comments
 (0)