ConfigPath
| Root [configuration path](./kibana-plugin-core-server.configpath.md) used by the plugin, defaults to "id" in snake\_case format. |
+| [extraPublicDirs](./kibana-plugin-core-server.pluginmanifest.extrapublicdirs.md) | string[]
| Specifies directory names that can be imported by other ui-plugins built using the same instance of the @kbn/optimizer. A temporary measure we plan to replace with better mechanisms for sharing static code between plugins |
| [id](./kibana-plugin-core-server.pluginmanifest.id.md) | PluginName
| Identifier of the plugin. Must be a string in camelCase. Part of a plugin public contract. Other plugins leverage it to access plugin API, navigate to the plugin, etc. |
| [kibanaVersion](./kibana-plugin-core-server.pluginmanifest.kibanaversion.md) | string
| The version of Kibana the plugin is compatible with, defaults to "version". |
| [optionalPlugins](./kibana-plugin-core-server.pluginmanifest.optionalplugins.md) | readonly PluginName[]
| An optional list of the other plugins that if installed and enabled \*\*may be\*\* leveraged by this plugin for some additional functionality but otherwise are not required for this plugin to work properly. |
diff --git a/examples/demo_search/kibana.json b/examples/demo_search/kibana.json
index cdf74121ea2db..f909ca47fcd55 100644
--- a/examples/demo_search/kibana.json
+++ b/examples/demo_search/kibana.json
@@ -5,5 +5,6 @@
"server": true,
"ui": true,
"requiredPlugins": ["data"],
- "optionalPlugins": []
+ "optionalPlugins": [],
+ "extraPublicDirs": ["common"]
}
diff --git a/examples/embeddable_examples/kibana.json b/examples/embeddable_examples/kibana.json
index 489f768552b28..b3ee0de096989 100644
--- a/examples/embeddable_examples/kibana.json
+++ b/examples/embeddable_examples/kibana.json
@@ -5,5 +5,6 @@
"server": true,
"ui": true,
"requiredPlugins": ["embeddable"],
- "optionalPlugins": []
+ "optionalPlugins": [],
+ "extraPublicDirs": ["public/todo", "public/hello_world"]
}
diff --git a/examples/url_generators_examples/kibana.json b/examples/url_generators_examples/kibana.json
index cdb2127fdd26f..9658f5c7300aa 100644
--- a/examples/url_generators_examples/kibana.json
+++ b/examples/url_generators_examples/kibana.json
@@ -5,5 +5,8 @@
"server": false,
"ui": true,
"requiredPlugins": ["share"],
- "optionalPlugins": []
+ "optionalPlugins": [],
+ "extraPublicDirs": [
+ "public/url_generator"
+ ]
}
diff --git a/package.json b/package.json
index 887ffae755e37..e8b07ae4abba2 100644
--- a/package.json
+++ b/package.json
@@ -306,6 +306,7 @@
"@kbn/expect": "1.0.0",
"@kbn/optimizer": "1.0.0",
"@kbn/plugin-generator": "1.0.0",
+ "@kbn/release-notes": "1.0.0",
"@kbn/test": "1.0.0",
"@kbn/utility-types": "1.0.0",
"@microsoft/api-documenter": "7.7.2",
diff --git a/packages/kbn-optimizer/README.md b/packages/kbn-optimizer/README.md
index c7f50c6af8dfd..9ff0f56344274 100644
--- a/packages/kbn-optimizer/README.md
+++ b/packages/kbn-optimizer/README.md
@@ -30,6 +30,18 @@ Bundles built by the the optimizer include a cache file which describes the info
When a bundle is determined to be up-to-date a worker is not started for the bundle. If running the optimizer with the `--dev/--watch` flag, then all the files referenced by cached bundles are watched for changes. Once a change is detected in any of the files referenced by the built bundle a worker is started. If a file is changed that is referenced by several bundles then workers will be started for each bundle, combining workers together to respect the worker limit.
+## Bundle Refs
+
+In order to dramatically reduce the size of our bundles, and the time it takes to build them, bundles will "ref" other bundles being built at the same time. When the optimizer starts it creates a list of "refs" that could be had from the list of bundles being built. Each worker uses that list to determine which import statements in a bundle should be replaced with a runtime reference to the output of another bundle.
+
+At runtime the bundles share a set of entry points via the `__kbnBundles__` global. By default a plugin shares `public` so that other code can use relative imports to access that directory. To expose additional directories they must be listed in the plugin's kibana.json "extraPublicDirs" field. The directories listed there will **also** be exported from the plugins bundle so that any other plugin can import that directory. "common" is commonly in the list of "extraPublicDirs".
+
+> NOTE: We plan to replace the `extraPublicDirs` functionality soon with better mechanisms for statically sharing code between bundles.
+
+When a directory is listed in the "extraPublicDirs" it will always be included in the bundle so that other plugins have access to it. The worker building the bundle has no way of knowing whether another plugin is using the directory, so be careful of adding test code or unnecessary directories to that list.
+
+Any import in a bundle which resolves into another bundles "context" directory, ie `src/plugins/*`, must map explicitly to a "public dir" exported by that plugin. If the resolved import is not in the list of public dirs an error will be thrown and the optimizer will fail to build that bundle until the error is fixed.
+
## API
To run the optimizer from code, you can import the [`OptimizerConfig`][OptimizerConfig] class and [`runOptimizer`][Optimizer] function. Create an [`OptimizerConfig`][OptimizerConfig] instance by calling it's static `create()` method with some options, then pass it to the [`runOptimizer`][Optimizer] function. `runOptimizer()` returns an observable of update objects, which are summaries of the optimizer state plus an optional `event` property which describes the internal events occuring and may be of use. You can use the [`logOptimizerState()`][LogOptimizerState] helper to write the relevant bits of state to a tooling log or checkout it's implementation to see how the internal events like [`WorkerStdio`][ObserveWorker] and [`WorkerStarted`][ObserveWorker] are used.
diff --git a/packages/kbn-optimizer/package.json b/packages/kbn-optimizer/package.json
index a372b9e394b9a..c7bf1dd60985d 100644
--- a/packages/kbn-optimizer/package.json
+++ b/packages/kbn-optimizer/package.json
@@ -45,6 +45,7 @@
"terser-webpack-plugin": "^2.1.2",
"tinymath": "1.2.1",
"url-loader": "^2.2.0",
+ "val-loader": "^1.1.1",
"watchpack": "^1.6.0",
"webpack": "^4.41.5",
"webpack-merge": "^4.2.2"
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/public/index.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/public/index.ts
index 7ddd10f4a388f..c881a15eac5b5 100644
--- a/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/public/index.ts
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/public/index.ts
@@ -19,6 +19,6 @@
import './legacy/styles.scss';
import './index.scss';
-import { fooLibFn } from '../../foo/public/index';
+import { fooLibFn } from '../../foo/public';
export * from './lib';
export { fooLibFn };
diff --git a/packages/kbn-optimizer/src/common/bundle.test.ts b/packages/kbn-optimizer/src/common/bundle.test.ts
index ec78a1bdf020e..b209bbca25ac4 100644
--- a/packages/kbn-optimizer/src/common/bundle.test.ts
+++ b/packages/kbn-optimizer/src/common/bundle.test.ts
@@ -23,7 +23,7 @@ jest.mock('fs');
const SPEC: BundleSpec = {
contextDir: '/foo/bar',
- entry: 'entry',
+ publicDirNames: ['public'],
id: 'bar',
outputDir: '/foo/bar/target',
sourceRoot: '/foo',
@@ -49,9 +49,11 @@ it('creates cache keys', () => {
},
"spec": Object {
"contextDir": "/foo/bar",
- "entry": "entry",
"id": "bar",
"outputDir": "/foo/bar/target",
+ "publicDirNames": Array [
+ "public",
+ ],
"sourceRoot": "/foo",
"type": "plugin",
},
@@ -82,9 +84,11 @@ it('parses bundles from JSON specs', () => {
"state": undefined,
},
"contextDir": "/foo/bar",
- "entry": "entry",
"id": "bar",
"outputDir": "/foo/bar/target",
+ "publicDirNames": Array [
+ "public",
+ ],
"sourceRoot": "/foo",
"type": "plugin",
},
diff --git a/packages/kbn-optimizer/src/common/bundle.ts b/packages/kbn-optimizer/src/common/bundle.ts
index 9e2ad186ba40c..80af94c30f8da 100644
--- a/packages/kbn-optimizer/src/common/bundle.ts
+++ b/packages/kbn-optimizer/src/common/bundle.ts
@@ -29,8 +29,8 @@ export interface BundleSpec {
readonly type: typeof VALID_BUNDLE_TYPES[0];
/** Unique id for this bundle */
readonly id: string;
- /** Webpack entry request for this plugin, relative to the contextDir */
- readonly entry: string;
+ /** directory names relative to the contextDir that can be imported from */
+ readonly publicDirNames: string[];
/** Absolute path to the plugin source directory */
readonly contextDir: string;
/** Absolute path to the root of the repository */
@@ -44,8 +44,8 @@ export class Bundle {
public readonly type: BundleSpec['type'];
/** Unique identifier for this bundle */
public readonly id: BundleSpec['id'];
- /** Path, relative to `contextDir`, to the entry file for the Webpack bundle */
- public readonly entry: BundleSpec['entry'];
+ /** directory names relative to the contextDir that can be imported from */
+ public readonly publicDirNames: BundleSpec['publicDirNames'];
/**
* Absolute path to the root of the bundle context (plugin directory)
* where the entry is resolved relative to and the default output paths
@@ -62,7 +62,7 @@ export class Bundle {
constructor(spec: BundleSpec) {
this.type = spec.type;
this.id = spec.id;
- this.entry = spec.entry;
+ this.publicDirNames = spec.publicDirNames;
this.contextDir = spec.contextDir;
this.sourceRoot = spec.sourceRoot;
this.outputDir = spec.outputDir;
@@ -73,8 +73,6 @@ export class Bundle {
/**
* Calculate the cache key for this bundle based from current
* mtime values.
- *
- * @param mtimes pre-fetched mtimes (ms || undefined) for all referenced files
*/
createCacheKey(files: string[], mtimes: Map(handler: RequestHandlerUser): RequestHandler
=> {
@@ -36,6 +35,7 @@ export const authorizedUserPreRoutingFactory = function authorizedUserPreRouting
if (user) {
// check allowance with the configured set of roleas + "superuser"
+ const config = reporting.getConfig();
const allowedRoles = config.get('roles', 'allow') || [];
const authorizedRoles = [superuserRole, ...allowedRoles];
diff --git a/x-pack/plugins/reporting/server/routes/lib/job_response_handler.ts b/x-pack/plugins/reporting/server/routes/lib/job_response_handler.ts
index 1a2e10cf355a2..a8492481e6b13 100644
--- a/x-pack/plugins/reporting/server/routes/lib/job_response_handler.ts
+++ b/x-pack/plugins/reporting/server/routes/lib/job_response_handler.ts
@@ -4,11 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { ElasticsearchServiceSetup, kibanaResponseFactory } from 'kibana/server';
+import { kibanaResponseFactory } from 'kibana/server';
+import { ReportingCore } from '../../';
import { AuthenticatedUser } from '../../../../security/server';
-import { ReportingConfig } from '../../';
import { WHITELISTED_JOB_CONTENT_TYPES } from '../../../common/constants';
-import { ExportTypesRegistry } from '../../lib/export_types_registry';
import { jobsQueryFactory } from '../../lib/jobs_query';
import { getDocumentPayloadFactory } from './get_document_payload';
@@ -20,12 +19,9 @@ interface JobResponseHandlerOpts {
excludeContent?: boolean;
}
-export function downloadJobResponseHandlerFactory(
- config: ReportingConfig,
- elasticsearch: ElasticsearchServiceSetup,
- exportTypesRegistry: ExportTypesRegistry
-) {
- const jobsQuery = jobsQueryFactory(config, elasticsearch);
+export function downloadJobResponseHandlerFactory(reporting: ReportingCore) {
+ const jobsQuery = jobsQueryFactory(reporting);
+ const exportTypesRegistry = reporting.getExportTypesRegistry();
const getDocumentPayload = getDocumentPayloadFactory(exportTypesRegistry);
return async function jobResponseHandler(
@@ -69,11 +65,8 @@ export function downloadJobResponseHandlerFactory(
};
}
-export function deleteJobResponseHandlerFactory(
- config: ReportingConfig,
- elasticsearch: ElasticsearchServiceSetup
-) {
- const jobsQuery = jobsQueryFactory(config, elasticsearch);
+export function deleteJobResponseHandlerFactory(reporting: ReportingCore) {
+ const jobsQuery = jobsQueryFactory(reporting);
return async function deleteJobResponseHander(
res: typeof kibanaResponseFactory,
diff --git a/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts b/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts
index 669381a92c522..579035a46f615 100644
--- a/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts
+++ b/x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts
@@ -11,18 +11,15 @@ jest.mock('../lib/create_queue');
jest.mock('../lib/enqueue_job');
jest.mock('../lib/validate');
-import { of } from 'rxjs';
-import { first } from 'rxjs/operators';
-import { coreMock } from 'src/core/server/mocks';
+import * as Rx from 'rxjs';
import { ReportingConfig, ReportingCore } from '../';
import {
chromium,
HeadlessChromiumDriverFactory,
initializeBrowserDriverFactory,
} from '../browsers';
-import { ReportingInternalSetup } from '../core';
-import { ReportingPlugin } from '../plugin';
-import { ReportingSetupDeps, ReportingStartDeps } from '../types';
+import { ReportingInternalSetup, ReportingInternalStart } from '../core';
+import { ReportingStartDeps } from '../types';
(initializeBrowserDriverFactory as jest.Mock<
Promise