Skip to content

Commit 25315d3

Browse files
committed
Example plugins in X-Pack (#63823)
* feat: 🎸 add example plugin ability to X-Pack * style: πŸ’„ spread array items from one array * chore: πŸ€– add x-pack/examples tsconfigs to global list * fix: πŸ› don't import non-existing plugin * fix: πŸ› fix TypeScript error * test: πŸ’ update Jest snapshot
1 parent ac81c03 commit 25315d3

12 files changed

Lines changed: 123 additions & 3 deletions

File tree

β€Žpackages/kbn-optimizer/src/optimizer/optimizer_config.test.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ describe('OptimizerConfig::parseOptions()', () => {
146146
<absolute path>/x-pack/plugins,
147147
<absolute path>/plugins,
148148
<absolute path>/examples,
149+
<absolute path>/x-pack/examples,
149150
<absolute path>-extra,
150151
],
151152
"profileWebpack": false,

β€Žpackages/kbn-optimizer/src/optimizer/optimizer_config.tsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ export class OptimizerConfig {
9191

9292
/**
9393
* BEWARE: this needs to stay roughly synchronized with
94-
* `src/core/server/config/env.ts` which determins which paths
94+
* `src/core/server/config/env.ts` which determines which paths
9595
* should be searched for plugins to load
9696
*/
9797
const pluginScanDirs = options.pluginScanDirs || [
9898
Path.resolve(repoRoot, 'src/plugins'),
9999
...(oss ? [] : [Path.resolve(repoRoot, 'x-pack/plugins')]),
100100
Path.resolve(repoRoot, 'plugins'),
101-
...(examples ? [Path.resolve('examples')] : []),
101+
...(examples ? [Path.resolve('examples'), Path.resolve('x-pack/examples')] : []),
102102
Path.resolve(repoRoot, '../kibana-extra'),
103103
];
104104
if (!pluginScanDirs.every(p => Path.isAbsolute(p))) {

β€Žsrc/core/server/config/env.test.tsβ€Ž

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ test('pluginSearchPaths contains examples plugins path if --run-examples flag is
164164
expect(env.pluginSearchPaths).toContain('/some/home/dir/examples');
165165
});
166166

167+
test('pluginSearchPaths contains x-pack/examples plugins path if --run-examples flag is true', () => {
168+
const env = new Env(
169+
'/some/home/dir',
170+
getEnvOptions({
171+
cliArgs: { runExamples: true },
172+
})
173+
);
174+
175+
expect(env.pluginSearchPaths).toContain('/some/home/dir/x-pack/examples');
176+
});
177+
167178
test('pluginSearchPaths does not contains examples plugins path if --run-examples flag is false', () => {
168179
const env = new Env(
169180
'/some/home/dir',
@@ -174,3 +185,14 @@ test('pluginSearchPaths does not contains examples plugins path if --run-example
174185

175186
expect(env.pluginSearchPaths).not.toContain('/some/home/dir/examples');
176187
});
188+
189+
test('pluginSearchPaths does not contains x-pack/examples plugins path if --run-examples flag is false', () => {
190+
const env = new Env(
191+
'/some/home/dir',
192+
getEnvOptions({
193+
cliArgs: { runExamples: false },
194+
})
195+
);
196+
197+
expect(env.pluginSearchPaths).not.toContain('/some/home/dir/x-pack/examples');
198+
});

β€Žsrc/core/server/config/env.tsβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ export class Env {
109109
resolve(this.homeDir, 'src', 'plugins'),
110110
...(options.cliArgs.oss ? [] : [resolve(this.homeDir, 'x-pack', 'plugins')]),
111111
resolve(this.homeDir, 'plugins'),
112-
...(options.cliArgs.runExamples ? [resolve(this.homeDir, 'examples')] : []),
112+
...(options.cliArgs.runExamples
113+
? [resolve(this.homeDir, 'examples'), resolve(this.homeDir, 'x-pack', 'examples')]
114+
: []),
113115
resolve(this.homeDir, '..', 'kibana-extra'),
114116
];
115117

β€Žsrc/dev/typescript/projects.tsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export const PROJECTS = [
4444
...glob
4545
.sync('examples/*/tsconfig.json', { cwd: REPO_ROOT })
4646
.map(path => new Project(resolve(REPO_ROOT, path))),
47+
...glob
48+
.sync('x-pack/examples/*/tsconfig.json', { cwd: REPO_ROOT })
49+
.map(path => new Project(resolve(REPO_ROOT, path))),
4750
...glob
4851
.sync('test/plugin_functional/plugins/*/tsconfig.json', { cwd: REPO_ROOT })
4952
.map(path => new Project(resolve(REPO_ROOT, path))),

β€Žx-pack/examples/README.mdβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Example plugins
2+
3+
This folder contains X-Pack example plugins. To run the plugins in this folder, use the `--run-examples` flag, via
4+
5+
```
6+
yarn start --run-examples
7+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Ui actions enhanced examples
2+
3+
To run this example, use the command `yarn start --run-examples`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": "uiActionsEnhancedExamples",
3+
"version": "0.0.1",
4+
"kibanaVersion": "kibana",
5+
"configPath": ["ui_actions_enhanced_examples"],
6+
"server": false,
7+
"ui": true,
8+
"requiredPlugins": ["uiActions", "data"],
9+
"optionalPlugins": []
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "ui_actions_enhanced_examples",
3+
"version": "1.0.0",
4+
"main": "target/examples/ui_actions_enhanced_examples",
5+
"kibana": {
6+
"version": "kibana",
7+
"templateVersion": "1.0.0"
8+
},
9+
"license": "Apache-2.0",
10+
"scripts": {
11+
"kbn": "node ../../scripts/kbn.js",
12+
"build": "rm -rf './target' && tsc"
13+
},
14+
"devDependencies": {
15+
"typescript": "3.7.2"
16+
}
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { UiActionsEnhancedExamplesPlugin } from './plugin';
8+
9+
export const plugin = () => new UiActionsEnhancedExamplesPlugin();

0 commit comments

Comments
Β (0)