string
| |
-| options | {
path?: string;
}
| |
+| options | {
path?: string;
absolute?: boolean;
}
| |
Returns:
diff --git a/docs/development/core/public/kibana-plugin-public.applicationstart.md b/docs/development/core/public/kibana-plugin-public.applicationstart.md
index 3ad7e3b1656d80..d5a0bef9470f78 100644
--- a/docs/development/core/public/kibana-plugin-public.applicationstart.md
+++ b/docs/development/core/public/kibana-plugin-public.applicationstart.md
@@ -16,12 +16,13 @@ export interface ApplicationStart
| Property | Type | Description |
| --- | --- | --- |
| [capabilities](./kibana-plugin-public.applicationstart.capabilities.md) | RecursiveReadonly<Capabilities>
| Gets the read-only capabilities. |
+| [currentAppId$](./kibana-plugin-public.applicationstart.currentappid_.md) | Observable<string | undefined>
| An observable that emits the current application id and each subsequent id update. |
## Methods
| Method | Description |
| --- | --- |
-| [getUrlForApp(appId, options)](./kibana-plugin-public.applicationstart.geturlforapp.md) | Returns a relative URL to a given app, including the global base path. |
+| [getUrlForApp(appId, options)](./kibana-plugin-public.applicationstart.geturlforapp.md) | Returns an URL to a given app, including the global base path. By default, the URL is relative (/basePath/app/my-app). Use the absolute
option to generate an absolute url (http://host:port/basePath/app/my-app)Note that when generating absolute urls, the protocol, host and port are determined from the browser location. |
| [navigateToApp(appId, options)](./kibana-plugin-public.applicationstart.navigatetoapp.md) | Navigate to a given app |
| [registerMountContext(contextName, provider)](./kibana-plugin-public.applicationstart.registermountcontext.md) | Register a context provider for application mounting. Will only be available to applications that depend on the plugin that registered this context. Deprecated, use [CoreSetup.getStartServices()](./kibana-plugin-public.coresetup.getstartservices.md). |
diff --git a/docs/development/core/public/kibana-plugin-public.ihttpfetcherror.md b/docs/development/core/public/kibana-plugin-public.ihttpfetcherror.md
index 6109671bb1aa66..49287cc6e261e0 100644
--- a/docs/development/core/public/kibana-plugin-public.ihttpfetcherror.md
+++ b/docs/development/core/public/kibana-plugin-public.ihttpfetcherror.md
@@ -16,6 +16,7 @@ export interface IHttpFetchError extends Error
| Property | Type | Description |
| --- | --- | --- |
| [body](./kibana-plugin-public.ihttpfetcherror.body.md) | any
| |
+| [name](./kibana-plugin-public.ihttpfetcherror.name.md) | string
| |
| [req](./kibana-plugin-public.ihttpfetcherror.req.md) | Request
| |
| [request](./kibana-plugin-public.ihttpfetcherror.request.md) | Request
| |
| [res](./kibana-plugin-public.ihttpfetcherror.res.md) | Response
| |
diff --git a/docs/images/controls/controls_in_dashboard.png b/docs/images/controls/controls_in_dashboard.png
deleted file mode 100644
index 5ea6b3ad0ca88a..00000000000000
Binary files a/docs/images/controls/controls_in_dashboard.png and /dev/null differ
diff --git a/docs/images/dashboard-controls.png b/docs/images/dashboard-controls.png
new file mode 100644
index 00000000000000..d121ce561e341b
Binary files /dev/null and b/docs/images/dashboard-controls.png differ
diff --git a/docs/images/markdown-example.png b/docs/images/markdown-example.png
new file mode 100644
index 00000000000000..79daa1298883dd
Binary files /dev/null and b/docs/images/markdown-example.png differ
diff --git a/docs/images/markdown_example_1.png b/docs/images/markdown_example_1.png
new file mode 100644
index 00000000000000..71dd9b76b8cafd
Binary files /dev/null and b/docs/images/markdown_example_1.png differ
diff --git a/docs/images/markdown_example_2.png b/docs/images/markdown_example_2.png
new file mode 100644
index 00000000000000..f2094c3cbb3f1b
Binary files /dev/null and b/docs/images/markdown_example_2.png differ
diff --git a/docs/images/markdown_example_3.png b/docs/images/markdown_example_3.png
new file mode 100644
index 00000000000000..eca9735b495d0f
Binary files /dev/null and b/docs/images/markdown_example_3.png differ
diff --git a/docs/images/markdown_example_4.png b/docs/images/markdown_example_4.png
new file mode 100644
index 00000000000000..d4a0829fef64e7
Binary files /dev/null and b/docs/images/markdown_example_4.png differ
diff --git a/docs/index.asciidoc b/docs/index.asciidoc
index 491a9629e983e6..5474772ab7da81 100644
--- a/docs/index.asciidoc
+++ b/docs/index.asciidoc
@@ -22,6 +22,8 @@ include::{asciidoc-dir}/../../shared/attributes.asciidoc[]
include::user/index.asciidoc[]
+include::accessibility.asciidoc[]
+
include::limitations.asciidoc[]
include::release-notes/highlights.asciidoc[]
diff --git a/docs/infrastructure/images/infra-sysmon.png b/docs/infrastructure/images/infra-sysmon.png
index 5b82d8c9b4e194..dd653bb046f451 100644
Binary files a/docs/infrastructure/images/infra-sysmon.png and b/docs/infrastructure/images/infra-sysmon.png differ
diff --git a/docs/infrastructure/images/infra-view-metrics.png b/docs/infrastructure/images/infra-view-metrics.png
index 9ad862ec6515d8..6001f18d283fe5 100644
Binary files a/docs/infrastructure/images/infra-view-metrics.png and b/docs/infrastructure/images/infra-view-metrics.png differ
diff --git a/docs/infrastructure/images/metrics-add-data.png b/docs/infrastructure/images/metrics-add-data.png
index d9640e0d9f5da1..f96c30f0e18488 100644
Binary files a/docs/infrastructure/images/metrics-add-data.png and b/docs/infrastructure/images/metrics-add-data.png differ
diff --git a/docs/infrastructure/images/metrics-explorer-screen.png b/docs/infrastructure/images/metrics-explorer-screen.png
index 7ccf8891678afe..6d56491f7d4850 100644
Binary files a/docs/infrastructure/images/metrics-explorer-screen.png and b/docs/infrastructure/images/metrics-explorer-screen.png differ
diff --git a/docs/limitations.asciidoc b/docs/limitations.asciidoc
index 818cc766bf6a93..30a716641cc5d9 100644
--- a/docs/limitations.asciidoc
+++ b/docs/limitations.asciidoc
@@ -1,22 +1,38 @@
+[chapter]
[[limitations]]
= Limitations
-[partintro]
---
-{kib} currently has the following limitations.
+Following are the known limitations in {kib}.
-* <= Readonly<{ [K in keyof P]: TypeO export type ObjectTypeOptions
= TypeOptions< { [K in keyof P]: TypeOf
} > & { + /** Should uknown keys not be defined in the schema be allowed. Defaults to `false` */ allowUnknowns?: boolean; }; export class ObjectType
extends Type = {}) {
+ constructor(props: P, { allowUnknowns = false, ...typeOptions }: ObjectTypeOptions = {}) {
const schemaKeys = {} as Record
+
+
+Workers have several error message they may emit which indicate unrecoverable errors. When any of those messages are received the stream will error and the workers will be torn down.
+
+For an example of how to handle these states checkout the [`logOptimizerState()`][LogOptimizerState] helper.
+
+[PostCss]: https://postcss.org/
+[Cli]: src/cli.ts
+[Optimizer]: src/optimizer.ts
+[ObserveWorker]: src/observe_worker.ts
+[CompilerMsg]: src/common/compiler_messages.ts
+[WorkerMsg]: src/common/worker_messages.ts
+[Bundle]: src/common/bundle.ts
+[WebpackConfig]: src/worker/webpack.config.ts
+[BundleDefinition]: src/common/bundle_definition.ts
+[WorkerConfig]: src/common/worker_config.ts
+[OptimizerConfig]: src/optimizer_config.ts
+[LogOptimizerState]: src/log_optimizer_state.ts
+[AssignBundlesToWorkers]: src/assign_bundles_to_workers.ts
+[BuildTask]: ../../src/dev/build/tasks/build_kibana_platform_plugins.js
\ No newline at end of file
diff --git a/packages/kbn-optimizer/babel.config.js b/packages/kbn-optimizer/babel.config.js
new file mode 100644
index 00000000000000..ff657603f4c8d2
--- /dev/null
+++ b/packages/kbn-optimizer/babel.config.js
@@ -0,0 +1,23 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+module.exports = {
+ presets: ['@kbn/babel-preset/node_preset'],
+ ignore: ['**/*.test.js'],
+};
diff --git a/src/legacy/core_plugins/telemetry/public/hacks/welcome_banner/index.js b/packages/kbn-optimizer/index.d.ts
similarity index 94%
rename from src/legacy/core_plugins/telemetry/public/hacks/welcome_banner/index.js
rename to packages/kbn-optimizer/index.d.ts
index ffb0e88c60a0da..aa55df9215c2f9 100644
--- a/src/legacy/core_plugins/telemetry/public/hacks/welcome_banner/index.js
+++ b/packages/kbn-optimizer/index.d.ts
@@ -17,4 +17,4 @@
* under the License.
*/
-export { injectBanner } from './inject_banner';
+export * from './src/index';
diff --git a/packages/kbn-optimizer/package.json b/packages/kbn-optimizer/package.json
new file mode 100644
index 00000000000000..e8bb31f1e365da
--- /dev/null
+++ b/packages/kbn-optimizer/package.json
@@ -0,0 +1,44 @@
+{
+ "name": "@kbn/optimizer",
+ "version": "1.0.0",
+ "private": true,
+ "license": "Apache-2.0",
+ "main": "./target/index.js",
+ "scripts": {
+ "build": "babel src --out-dir target --copy-files --delete-dir-on-start --extensions .ts --ignore *.test.ts --source-maps=inline",
+ "kbn:bootstrap": "yarn build",
+ "kbn:watch": "yarn build --watch"
+ },
+ "dependencies": {
+ "@babel/cli": "^7.5.5",
+ "@kbn/babel-preset": "1.0.0",
+ "@kbn/dev-utils": "1.0.0",
+ "@kbn/ui-shared-deps": "1.0.0",
+ "@types/loader-utils": "^1.1.3",
+ "@types/watchpack": "^1.1.5",
+ "@types/webpack": "^4.41.3",
+ "autoprefixer": "^9.7.4",
+ "babel-loader": "^8.0.6",
+ "clean-webpack-plugin": "^3.0.0",
+ "cpy": "^8.0.0",
+ "css-loader": "^3.4.2",
+ "del": "^5.1.0",
+ "file-loader": "^4.2.0",
+ "istanbul-instrumenter-loader": "^3.0.1",
+ "jest-diff": "^25.1.0",
+ "json-stable-stringify": "^1.0.1",
+ "loader-utils": "^1.2.3",
+ "node-sass": "^4.13.0",
+ "postcss-loader": "^3.0.0",
+ "raw-loader": "^3.1.0",
+ "rxjs": "^6.5.3",
+ "sass-loader": "^8.0.2",
+ "style-loader": "^1.1.3",
+ "terser-webpack-plugin": "^2.1.2",
+ "tinymath": "1.2.1",
+ "url-loader": "^2.2.0",
+ "watchpack": "^1.6.0",
+ "webpack": "^4.41.5",
+ "webpack-merge": "^4.2.2"
+ }
+}
\ No newline at end of file
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/kibana.json b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/kibana.json
new file mode 100644
index 00000000000000..20c8046daa65e5
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/kibana.json
@@ -0,0 +1,4 @@
+{
+ "id": "bar",
+ "ui": true
+}
diff --git a/src/legacy/core_plugins/telemetry/public/services/index.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/public/index.ts
similarity index 88%
rename from src/legacy/core_plugins/telemetry/public/services/index.ts
rename to packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/public/index.ts
index 8b02f8ce4c5b0a..66fa55479f3b9e 100644
--- a/src/legacy/core_plugins/telemetry/public/services/index.ts
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/public/index.ts
@@ -17,5 +17,6 @@
* under the License.
*/
-export { TelemetryOptInProvider } from './telemetry_opt_in';
-export { isUnauthenticated } from './path';
+import { fooLibFn } from '../../foo/public/index';
+export * from './lib';
+export { fooLibFn };
diff --git a/webpackShims/tinymath.js b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/public/lib.ts
similarity index 93%
rename from webpackShims/tinymath.js
rename to packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/public/lib.ts
index 45aa86a6ef64a7..091fae72ad635f 100644
--- a/webpackShims/tinymath.js
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/bar/public/lib.ts
@@ -17,4 +17,6 @@
* under the License.
*/
-module.exports = require('tinymath/lib/tinymath.es5.js');
+export function barLibFn() {
+ return 'bar';
+}
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/kibana.json b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/kibana.json
new file mode 100644
index 00000000000000..6e4e9c70a115c0
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/kibana.json
@@ -0,0 +1,3 @@
+{
+ "id": "baz"
+}
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/server/index.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/server/index.ts
new file mode 100644
index 00000000000000..12e580bbb76b37
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/server/index.ts
@@ -0,0 +1,20 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export * from './lib';
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/server/lib.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/server/lib.ts
new file mode 100644
index 00000000000000..870e5a80452808
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/baz/server/lib.ts
@@ -0,0 +1,22 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export function bazLibFn() {
+ return 'baz';
+}
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/kibana.json b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/kibana.json
new file mode 100644
index 00000000000000..256856181ccd84
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/kibana.json
@@ -0,0 +1,4 @@
+{
+ "id": "foo",
+ "ui": true
+}
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/public/ext.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/public/ext.ts
new file mode 100644
index 00000000000000..3064d6814e2b1b
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/public/ext.ts
@@ -0,0 +1,20 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export const ext = 'TRUE';
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/public/index.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/public/index.ts
new file mode 100644
index 00000000000000..9d3871df247397
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/public/index.ts
@@ -0,0 +1,21 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export * from './lib';
+export * from './ext';
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/public/lib.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/public/lib.ts
new file mode 100644
index 00000000000000..04a8c7e5b1eec2
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/plugins/foo/public/lib.ts
@@ -0,0 +1,22 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export function fooLibFn() {
+ return 'foo';
+}
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz/kibana.json b/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz/kibana.json
new file mode 100644
index 00000000000000..b9e044523a6a51
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz/kibana.json
@@ -0,0 +1,3 @@
+{
+ "id": "test_baz"
+}
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz/server/index.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz/server/index.ts
new file mode 100644
index 00000000000000..12e580bbb76b37
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz/server/index.ts
@@ -0,0 +1,20 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export * from './lib';
diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz/server/lib.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz/server/lib.ts
new file mode 100644
index 00000000000000..870e5a80452808
--- /dev/null
+++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/test_plugins/test_baz/server/lib.ts
@@ -0,0 +1,22 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export function bazLibFn() {
+ return 'baz';
+}
diff --git a/packages/kbn-optimizer/src/cli.ts b/packages/kbn-optimizer/src/cli.ts
new file mode 100644
index 00000000000000..dcb4dcd35698d0
--- /dev/null
+++ b/packages/kbn-optimizer/src/cli.ts
@@ -0,0 +1,118 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import 'source-map-support/register';
+
+import Path from 'path';
+
+import { run, REPO_ROOT, createFlagError } from '@kbn/dev-utils';
+
+import { logOptimizerState } from './log_optimizer_state';
+import { OptimizerConfig } from './optimizer';
+import { runOptimizer } from './run_optimizer';
+
+run(
+ async ({ log, flags }) => {
+ const watch = flags.watch ?? false;
+ if (typeof watch !== 'boolean') {
+ throw createFlagError('expected --watch to have no value');
+ }
+
+ const oss = flags.oss ?? false;
+ if (typeof oss !== 'boolean') {
+ throw createFlagError('expected --oss to have no value');
+ }
+
+ const cache = flags.cache ?? true;
+ if (typeof cache !== 'boolean') {
+ throw createFlagError('expected --cache to have no value');
+ }
+
+ const dist = flags.dist ?? false;
+ if (typeof dist !== 'boolean') {
+ throw createFlagError('expected --dist to have no value');
+ }
+
+ const examples = flags.examples ?? false;
+ if (typeof examples !== 'boolean') {
+ throw createFlagError('expected --no-examples to have no value');
+ }
+
+ const profileWebpack = flags.profile ?? false;
+ if (typeof profileWebpack !== 'boolean') {
+ throw createFlagError('expected --profile to have no value');
+ }
+
+ const inspectWorkers = flags['inspect-workers'] ?? false;
+ if (typeof inspectWorkers !== 'boolean') {
+ throw createFlagError('expected --no-inspect-workers to have no value');
+ }
+
+ const maxWorkerCount = flags.workers ? Number.parseInt(String(flags.workers), 10) : undefined;
+ if (maxWorkerCount !== undefined && (!Number.isFinite(maxWorkerCount) || maxWorkerCount < 1)) {
+ throw createFlagError('expected --workers to be a number greater than 0');
+ }
+
+ const extraPluginScanDirs = ([] as string[])
+ .concat((flags['scan-dir'] as string | string[]) || [])
+ .map(p => Path.resolve(p));
+ if (!extraPluginScanDirs.every(s => typeof s === 'string')) {
+ throw createFlagError('expected --scan-dir to be a string');
+ }
+
+ const config = OptimizerConfig.create({
+ repoRoot: REPO_ROOT,
+ watch,
+ maxWorkerCount,
+ oss,
+ dist,
+ cache,
+ examples,
+ profileWebpack,
+ extraPluginScanDirs,
+ inspectWorkers,
+ });
+
+ await runOptimizer(config)
+ .pipe(logOptimizerState(log, config))
+ .toPromise();
+ },
+ {
+ flags: {
+ boolean: ['watch', 'oss', 'examples', 'dist', 'cache', 'profile', 'inspect-workers'],
+ string: ['workers', 'scan-dir'],
+ default: {
+ examples: true,
+ cache: true,
+ 'inspect-workers': true,
+ },
+ help: `
+ --watch run the optimizer in watch mode
+ --workers max number of workers to use
+ --oss only build oss plugins
+ --profile profile the webpack builds and write stats.json files to build outputs
+ --no-cache disable the cache
+ --no-examples don't build the example plugins
+ --dist create bundles that are suitable for inclusion in the Kibana distributable
+ --scan-dir add a directory to the list of directories scanned for plugins (specify as many times as necessary)
+ --no-inspect-workers when inspecting the parent process, don't inspect the workers
+ `,
+ },
+ }
+);
diff --git a/packages/kbn-optimizer/src/common/array_helpers.test.ts b/packages/kbn-optimizer/src/common/array_helpers.test.ts
new file mode 100644
index 00000000000000..9d45217486ee89
--- /dev/null
+++ b/packages/kbn-optimizer/src/common/array_helpers.test.ts
@@ -0,0 +1,112 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { ascending, descending } from './array_helpers';
+
+describe('ascending/descending', () => {
+ interface Item {
+ a: number;
+ b: number | string;
+ c?: number;
+ }
+
+ const a = (x: Item) => x.a;
+ const b = (x: Item) => x.b;
+ const c = (x: Item) => x.c;
+ const print = (x: Item) => `${x.a}/${x.b}/${x.c}`;
+ const values: Item[] = [
+ { a: 1, b: 2, c: 3 },
+ { a: 3, b: 2, c: 1 },
+ { a: 9, b: 9, c: 9 },
+ { a: 8, b: 5, c: 8 },
+ { a: 8, b: 5 },
+ { a: 8, b: 4 },
+ { a: 8, b: 3, c: 8 },
+ { a: 8, b: 2 },
+ { a: 8, b: 1, c: 8 },
+ { a: 8, b: 1 },
+ { a: 8, b: 0 },
+ { a: 8, b: -1, c: 8 },
+ { a: 8, b: -2 },
+ { a: 8, b: -3, c: 8 },
+ { a: 8, b: -4 },
+ { a: 8, b: 'foo', c: 8 },
+ { a: 8, b: 'foo' },
+ { a: 8, b: 'bar', c: 8 },
+ { a: 8, b: 'bar' },
+ ].sort(() => 0.5 - Math.random());
+
+ it('sorts items using getters', () => {
+ expect(
+ Array.from(values)
+ .sort(ascending(a, b, c))
+ .map(print)
+ ).toMatchInlineSnapshot(`
+ Array [
+ "1/2/3",
+ "3/2/1",
+ "8/-4/undefined",
+ "8/-3/8",
+ "8/-2/undefined",
+ "8/-1/8",
+ "8/0/undefined",
+ "8/1/undefined",
+ "8/1/8",
+ "8/2/undefined",
+ "8/3/8",
+ "8/4/undefined",
+ "8/5/undefined",
+ "8/5/8",
+ "8/bar/undefined",
+ "8/bar/8",
+ "8/foo/undefined",
+ "8/foo/8",
+ "9/9/9",
+ ]
+ `);
+
+ expect(
+ Array.from(values)
+ .sort(descending(a, b, c))
+ .map(print)
+ ).toMatchInlineSnapshot(`
+ Array [
+ "9/9/9",
+ "8/foo/8",
+ "8/foo/undefined",
+ "8/bar/8",
+ "8/bar/undefined",
+ "8/5/8",
+ "8/5/undefined",
+ "8/4/undefined",
+ "8/3/8",
+ "8/2/undefined",
+ "8/1/8",
+ "8/1/undefined",
+ "8/0/undefined",
+ "8/-1/8",
+ "8/-2/undefined",
+ "8/-3/8",
+ "8/-4/undefined",
+ "3/2/1",
+ "1/2/3",
+ ]
+ `);
+ });
+});
diff --git a/packages/kbn-optimizer/src/common/array_helpers.ts b/packages/kbn-optimizer/src/common/array_helpers.ts
new file mode 100644
index 00000000000000..740f018d192981
--- /dev/null
+++ b/packages/kbn-optimizer/src/common/array_helpers.ts
@@ -0,0 +1,84 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+type SortPropGetter'initializing'
'initialized'
'running'
BundleState
objects with type 'running'
.'issue'
'compiler issue'
status. Compiler issues include things like "unable to resolve module" or syntax errors in the source modules and can be fixed by users when running in watch mode.'success'
'compiler success'
.'reallocating'