From 1a3c2e3ba219518a13332575b037df37a0511b7d Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Tue, 15 Oct 2019 15:42:22 +0200 Subject: [PATCH] Expose package info to NP plugins (#48101) (#48215) * provide packageInfo to server plugins * provide env to kbn server * provide env to client plugins * update server mocks and tests * update client mocks and tests * add integration test * regen docs * remove weird file * export types for the client from special folder * env should not affect test ourcome --- .eslintrc.js | 1 + ...ibana-plugin-public.environmentmode.dev.md | 11 +++++ .../kibana-plugin-public.environmentmode.md | 21 +++++++++ ...bana-plugin-public.environmentmode.name.md | 11 +++++ ...bana-plugin-public.environmentmode.prod.md | 11 +++++ .../core/public/kibana-plugin-public.md | 2 + ...kibana-plugin-public.packageinfo.branch.md | 11 +++++ ...bana-plugin-public.packageinfo.buildnum.md | 11 +++++ ...bana-plugin-public.packageinfo.buildsha.md | 11 +++++ .../kibana-plugin-public.packageinfo.dist.md | 11 +++++ .../kibana-plugin-public.packageinfo.md | 23 ++++++++++ ...ibana-plugin-public.packageinfo.version.md | 11 +++++ ...gin-public.plugininitializercontext.env.md | 14 ++++++ ...-plugin-public.plugininitializercontext.md | 1 + ...ibana-plugin-server.environmentmode.dev.md | 11 +++++ .../kibana-plugin-server.environmentmode.md | 21 +++++++++ ...bana-plugin-server.environmentmode.name.md | 11 +++++ ...bana-plugin-server.environmentmode.prod.md | 11 +++++ .../core/server/kibana-plugin-server.md | 2 + ...kibana-plugin-server.packageinfo.branch.md | 11 +++++ ...bana-plugin-server.packageinfo.buildnum.md | 11 +++++ ...bana-plugin-server.packageinfo.buildsha.md | 11 +++++ .../kibana-plugin-server.packageinfo.dist.md | 11 +++++ .../kibana-plugin-server.packageinfo.md | 23 ++++++++++ ...ibana-plugin-server.packageinfo.version.md | 11 +++++ ...gin-server.plugininitializercontext.env.md | 1 + ...-plugin-server.plugininitializercontext.md | 2 +- .../public/context/context_service.test.ts | 7 +-- src/core/public/core_system.ts | 8 +++- src/core/public/index.ts | 1 + .../injected_metadata_service.ts | 5 ++ src/core/public/mocks.ts | 46 ++++++++++++++++++- src/core/public/plugins/plugin.test.ts | 3 +- src/core/public/plugins/plugin_context.ts | 8 +++- .../public/plugins/plugins_service.test.ts | 4 +- src/core/public/public.api.md | 34 ++++++++++++++ src/core/server/config/env.ts | 15 +----- src/core/server/config/index.ts | 4 +- .../{types.ts~master => config/types.ts} | 20 +++++++- src/core/server/index.ts | 2 +- src/core/server/legacy/legacy_service.ts | 4 ++ src/core/server/mocks.ts | 9 +++- src/core/server/plugins/plugin_context.ts | 5 +- src/core/server/plugins/types.ts | 7 ++- src/core/server/server.api.md | 26 ++++++++++- src/core/server/types.ts | 1 + src/legacy/server/kbn_server.d.ts | 6 +++ src/legacy/server/kbn_server.js | 6 ++- src/legacy/ui/ui_render/ui_render_mixin.js | 1 + .../es_search/es_search_service.test.ts | 3 +- .../public/search/es_search/index.test.ts | 4 +- .../data/public/search/search_service.test.ts | 4 +- .../es_search/es_search_service.test.ts | 20 +------- .../plugins/core_plugin_b/public/index.ts | 4 +- .../plugins/core_plugin_b/public/plugin.tsx | 6 ++- .../test_suites/core_plugins/ui_plugins.js | 11 +++++ .../plugins/uptime/public/apps/index.ts | 2 +- 57 files changed, 498 insertions(+), 65 deletions(-) create mode 100644 docs/development/core/public/kibana-plugin-public.environmentmode.dev.md create mode 100644 docs/development/core/public/kibana-plugin-public.environmentmode.md create mode 100644 docs/development/core/public/kibana-plugin-public.environmentmode.name.md create mode 100644 docs/development/core/public/kibana-plugin-public.environmentmode.prod.md create mode 100644 docs/development/core/public/kibana-plugin-public.packageinfo.branch.md create mode 100644 docs/development/core/public/kibana-plugin-public.packageinfo.buildnum.md create mode 100644 docs/development/core/public/kibana-plugin-public.packageinfo.buildsha.md create mode 100644 docs/development/core/public/kibana-plugin-public.packageinfo.dist.md create mode 100644 docs/development/core/public/kibana-plugin-public.packageinfo.md create mode 100644 docs/development/core/public/kibana-plugin-public.packageinfo.version.md create mode 100644 docs/development/core/public/kibana-plugin-public.plugininitializercontext.env.md create mode 100644 docs/development/core/server/kibana-plugin-server.environmentmode.dev.md create mode 100644 docs/development/core/server/kibana-plugin-server.environmentmode.md create mode 100644 docs/development/core/server/kibana-plugin-server.environmentmode.name.md create mode 100644 docs/development/core/server/kibana-plugin-server.environmentmode.prod.md create mode 100644 docs/development/core/server/kibana-plugin-server.packageinfo.branch.md create mode 100644 docs/development/core/server/kibana-plugin-server.packageinfo.buildnum.md create mode 100644 docs/development/core/server/kibana-plugin-server.packageinfo.buildsha.md create mode 100644 docs/development/core/server/kibana-plugin-server.packageinfo.dist.md create mode 100644 docs/development/core/server/kibana-plugin-server.packageinfo.md create mode 100644 docs/development/core/server/kibana-plugin-server.packageinfo.version.md rename src/core/server/{types.ts~master => config/types.ts} (74%) diff --git a/.eslintrc.js b/.eslintrc.js index ce4aea3c0230..56950a70970d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -149,6 +149,7 @@ module.exports = { 'src/core/server/**/*', '!src/core/server/index.ts', '!src/core/server/mocks.ts', + '!src/core/server/types.ts', '!src/core/server/*.test.mocks.ts', 'src/plugins/**/public/**/*', diff --git a/docs/development/core/public/kibana-plugin-public.environmentmode.dev.md b/docs/development/core/public/kibana-plugin-public.environmentmode.dev.md new file mode 100644 index 000000000000..b82e851da2b6 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.environmentmode.dev.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [EnvironmentMode](./kibana-plugin-public.environmentmode.md) > [dev](./kibana-plugin-public.environmentmode.dev.md) + +## EnvironmentMode.dev property + +Signature: + +```typescript +dev: boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.environmentmode.md b/docs/development/core/public/kibana-plugin-public.environmentmode.md new file mode 100644 index 000000000000..14ab1316f526 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.environmentmode.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [EnvironmentMode](./kibana-plugin-public.environmentmode.md) + +## EnvironmentMode interface + + +Signature: + +```typescript +export interface EnvironmentMode +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [dev](./kibana-plugin-public.environmentmode.dev.md) | boolean | | +| [name](./kibana-plugin-public.environmentmode.name.md) | 'development' | 'production' | | +| [prod](./kibana-plugin-public.environmentmode.prod.md) | boolean | | + diff --git a/docs/development/core/public/kibana-plugin-public.environmentmode.name.md b/docs/development/core/public/kibana-plugin-public.environmentmode.name.md new file mode 100644 index 000000000000..5983fea85675 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.environmentmode.name.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [EnvironmentMode](./kibana-plugin-public.environmentmode.md) > [name](./kibana-plugin-public.environmentmode.name.md) + +## EnvironmentMode.name property + +Signature: + +```typescript +name: 'development' | 'production'; +``` diff --git a/docs/development/core/public/kibana-plugin-public.environmentmode.prod.md b/docs/development/core/public/kibana-plugin-public.environmentmode.prod.md new file mode 100644 index 000000000000..4b46e8b9cc9f --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.environmentmode.prod.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [EnvironmentMode](./kibana-plugin-public.environmentmode.md) > [prod](./kibana-plugin-public.environmentmode.prod.md) + +## EnvironmentMode.prod property + +Signature: + +```typescript +prod: boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.md b/docs/development/core/public/kibana-plugin-public.md index f55705fb2fae..1e1a4f38a7c6 100644 --- a/docs/development/core/public/kibana-plugin-public.md +++ b/docs/development/core/public/kibana-plugin-public.md @@ -46,6 +46,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [CoreSetup](./kibana-plugin-public.coresetup.md) | Core services exposed to the Plugin setup lifecycle | | [CoreStart](./kibana-plugin-public.corestart.md) | Core services exposed to the Plugin start lifecycle | | [DocLinksStart](./kibana-plugin-public.doclinksstart.md) | | +| [EnvironmentMode](./kibana-plugin-public.environmentmode.md) | | | [ErrorToastOptions](./kibana-plugin-public.errortoastoptions.md) | | | [FatalErrorInfo](./kibana-plugin-public.fatalerrorinfo.md) | Represents the message and stack of a fatal Error | | [FatalErrorsSetup](./kibana-plugin-public.fatalerrorssetup.md) | FatalErrors stop the Kibana Public Core and displays a fatal error screen with details about the Kibana build and the error. | @@ -68,6 +69,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [OverlayBannersStart](./kibana-plugin-public.overlaybannersstart.md) | | | [OverlayRef](./kibana-plugin-public.overlayref.md) | | | [OverlayStart](./kibana-plugin-public.overlaystart.md) | | +| [PackageInfo](./kibana-plugin-public.packageinfo.md) | | | [Plugin](./kibana-plugin-public.plugin.md) | The interface that should be returned by a PluginInitializer. | | [PluginInitializerContext](./kibana-plugin-public.plugininitializercontext.md) | The available core services passed to a PluginInitializer | | [SavedObject](./kibana-plugin-public.savedobject.md) | | diff --git a/docs/development/core/public/kibana-plugin-public.packageinfo.branch.md b/docs/development/core/public/kibana-plugin-public.packageinfo.branch.md new file mode 100644 index 000000000000..774a29096993 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.packageinfo.branch.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [PackageInfo](./kibana-plugin-public.packageinfo.md) > [branch](./kibana-plugin-public.packageinfo.branch.md) + +## PackageInfo.branch property + +Signature: + +```typescript +branch: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.packageinfo.buildnum.md b/docs/development/core/public/kibana-plugin-public.packageinfo.buildnum.md new file mode 100644 index 000000000000..0c1003f8d8af --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.packageinfo.buildnum.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [PackageInfo](./kibana-plugin-public.packageinfo.md) > [buildNum](./kibana-plugin-public.packageinfo.buildnum.md) + +## PackageInfo.buildNum property + +Signature: + +```typescript +buildNum: number; +``` diff --git a/docs/development/core/public/kibana-plugin-public.packageinfo.buildsha.md b/docs/development/core/public/kibana-plugin-public.packageinfo.buildsha.md new file mode 100644 index 000000000000..98a7916c142e --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.packageinfo.buildsha.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [PackageInfo](./kibana-plugin-public.packageinfo.md) > [buildSha](./kibana-plugin-public.packageinfo.buildsha.md) + +## PackageInfo.buildSha property + +Signature: + +```typescript +buildSha: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.packageinfo.dist.md b/docs/development/core/public/kibana-plugin-public.packageinfo.dist.md new file mode 100644 index 000000000000..c70299bbe6fc --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.packageinfo.dist.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [PackageInfo](./kibana-plugin-public.packageinfo.md) > [dist](./kibana-plugin-public.packageinfo.dist.md) + +## PackageInfo.dist property + +Signature: + +```typescript +dist: boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.packageinfo.md b/docs/development/core/public/kibana-plugin-public.packageinfo.md new file mode 100644 index 000000000000..1dbd8cb85c56 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.packageinfo.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [PackageInfo](./kibana-plugin-public.packageinfo.md) + +## PackageInfo interface + + +Signature: + +```typescript +export interface PackageInfo +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [branch](./kibana-plugin-public.packageinfo.branch.md) | string | | +| [buildNum](./kibana-plugin-public.packageinfo.buildnum.md) | number | | +| [buildSha](./kibana-plugin-public.packageinfo.buildsha.md) | string | | +| [dist](./kibana-plugin-public.packageinfo.dist.md) | boolean | | +| [version](./kibana-plugin-public.packageinfo.version.md) | string | | + diff --git a/docs/development/core/public/kibana-plugin-public.packageinfo.version.md b/docs/development/core/public/kibana-plugin-public.packageinfo.version.md new file mode 100644 index 000000000000..26def753e424 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.packageinfo.version.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [PackageInfo](./kibana-plugin-public.packageinfo.md) > [version](./kibana-plugin-public.packageinfo.version.md) + +## PackageInfo.version property + +Signature: + +```typescript +version: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.plugininitializercontext.env.md b/docs/development/core/public/kibana-plugin-public.plugininitializercontext.env.md new file mode 100644 index 000000000000..92f36ab64a1d --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.plugininitializercontext.env.md @@ -0,0 +1,14 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [PluginInitializerContext](./kibana-plugin-public.plugininitializercontext.md) > [env](./kibana-plugin-public.plugininitializercontext.env.md) + +## PluginInitializerContext.env property + +Signature: + +```typescript +readonly env: { + mode: Readonly; + packageInfo: Readonly; + }; +``` diff --git a/docs/development/core/public/kibana-plugin-public.plugininitializercontext.md b/docs/development/core/public/kibana-plugin-public.plugininitializercontext.md index 3ad220349c45..87c39a502040 100644 --- a/docs/development/core/public/kibana-plugin-public.plugininitializercontext.md +++ b/docs/development/core/public/kibana-plugin-public.plugininitializercontext.md @@ -16,5 +16,6 @@ export interface PluginInitializerContext | Property | Type | Description | | --- | --- | --- | +| [env](./kibana-plugin-public.plugininitializercontext.env.md) | {
mode: Readonly<EnvironmentMode>;
packageInfo: Readonly<PackageInfo>;
} | | | [opaqueId](./kibana-plugin-public.plugininitializercontext.opaqueid.md) | PluginOpaqueId | A symbol used to identify this plugin in the system. Needed when registering handlers or context providers. | diff --git a/docs/development/core/server/kibana-plugin-server.environmentmode.dev.md b/docs/development/core/server/kibana-plugin-server.environmentmode.dev.md new file mode 100644 index 000000000000..d60fcc58d1b6 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.environmentmode.dev.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [EnvironmentMode](./kibana-plugin-server.environmentmode.md) > [dev](./kibana-plugin-server.environmentmode.dev.md) + +## EnvironmentMode.dev property + +Signature: + +```typescript +dev: boolean; +``` diff --git a/docs/development/core/server/kibana-plugin-server.environmentmode.md b/docs/development/core/server/kibana-plugin-server.environmentmode.md new file mode 100644 index 000000000000..b325f74a0a44 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.environmentmode.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [EnvironmentMode](./kibana-plugin-server.environmentmode.md) + +## EnvironmentMode interface + + +Signature: + +```typescript +export interface EnvironmentMode +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [dev](./kibana-plugin-server.environmentmode.dev.md) | boolean | | +| [name](./kibana-plugin-server.environmentmode.name.md) | 'development' | 'production' | | +| [prod](./kibana-plugin-server.environmentmode.prod.md) | boolean | | + diff --git a/docs/development/core/server/kibana-plugin-server.environmentmode.name.md b/docs/development/core/server/kibana-plugin-server.environmentmode.name.md new file mode 100644 index 000000000000..c3243075866f --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.environmentmode.name.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [EnvironmentMode](./kibana-plugin-server.environmentmode.md) > [name](./kibana-plugin-server.environmentmode.name.md) + +## EnvironmentMode.name property + +Signature: + +```typescript +name: 'development' | 'production'; +``` diff --git a/docs/development/core/server/kibana-plugin-server.environmentmode.prod.md b/docs/development/core/server/kibana-plugin-server.environmentmode.prod.md new file mode 100644 index 000000000000..86a94775358e --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.environmentmode.prod.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [EnvironmentMode](./kibana-plugin-server.environmentmode.md) > [prod](./kibana-plugin-server.environmentmode.prod.md) + +## EnvironmentMode.prod property + +Signature: + +```typescript +prod: boolean; +``` diff --git a/docs/development/core/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md index 02bbd028ac41..3e3e2bd57db9 100644 --- a/docs/development/core/server/kibana-plugin-server.md +++ b/docs/development/core/server/kibana-plugin-server.md @@ -49,6 +49,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [DiscoveredPlugin](./kibana-plugin-server.discoveredplugin.md) | Small container object used to expose information about discovered plugins that may or may not have been started. | | [ElasticsearchError](./kibana-plugin-server.elasticsearcherror.md) | | | [ElasticsearchServiceSetup](./kibana-plugin-server.elasticsearchservicesetup.md) | | +| [EnvironmentMode](./kibana-plugin-server.environmentmode.md) | | | [ErrorHttpResponseOptions](./kibana-plugin-server.errorhttpresponseoptions.md) | HTTP response parameters | | [FakeRequest](./kibana-plugin-server.fakerequest.md) | Fake request object created manually by Kibana plugins. | | [HttpResponseOptions](./kibana-plugin-server.httpresponseoptions.md) | HTTP response parameters | @@ -67,6 +68,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [LogMeta](./kibana-plugin-server.logmeta.md) | Contextual metadata | | [OnPostAuthToolkit](./kibana-plugin-server.onpostauthtoolkit.md) | A tool set defining an outcome of OnPostAuth interceptor for incoming request. | | [OnPreAuthToolkit](./kibana-plugin-server.onpreauthtoolkit.md) | A tool set defining an outcome of OnPreAuth interceptor for incoming request. | +| [PackageInfo](./kibana-plugin-server.packageinfo.md) | | | [Plugin](./kibana-plugin-server.plugin.md) | The interface that should be returned by a PluginInitializer. | | [PluginInitializerContext](./kibana-plugin-server.plugininitializercontext.md) | Context that's available to plugins during initialization stage. | | [PluginManifest](./kibana-plugin-server.pluginmanifest.md) | Describes the set of required and optional properties plugin can define in its mandatory JSON manifest file. | diff --git a/docs/development/core/server/kibana-plugin-server.packageinfo.branch.md b/docs/development/core/server/kibana-plugin-server.packageinfo.branch.md new file mode 100644 index 000000000000..36f187180d31 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.packageinfo.branch.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [PackageInfo](./kibana-plugin-server.packageinfo.md) > [branch](./kibana-plugin-server.packageinfo.branch.md) + +## PackageInfo.branch property + +Signature: + +```typescript +branch: string; +``` diff --git a/docs/development/core/server/kibana-plugin-server.packageinfo.buildnum.md b/docs/development/core/server/kibana-plugin-server.packageinfo.buildnum.md new file mode 100644 index 000000000000..c0a231ee27ab --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.packageinfo.buildnum.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [PackageInfo](./kibana-plugin-server.packageinfo.md) > [buildNum](./kibana-plugin-server.packageinfo.buildnum.md) + +## PackageInfo.buildNum property + +Signature: + +```typescript +buildNum: number; +``` diff --git a/docs/development/core/server/kibana-plugin-server.packageinfo.buildsha.md b/docs/development/core/server/kibana-plugin-server.packageinfo.buildsha.md new file mode 100644 index 000000000000..5e8de48067dd --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.packageinfo.buildsha.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [PackageInfo](./kibana-plugin-server.packageinfo.md) > [buildSha](./kibana-plugin-server.packageinfo.buildsha.md) + +## PackageInfo.buildSha property + +Signature: + +```typescript +buildSha: string; +``` diff --git a/docs/development/core/server/kibana-plugin-server.packageinfo.dist.md b/docs/development/core/server/kibana-plugin-server.packageinfo.dist.md new file mode 100644 index 000000000000..e45970780d52 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.packageinfo.dist.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [PackageInfo](./kibana-plugin-server.packageinfo.md) > [dist](./kibana-plugin-server.packageinfo.dist.md) + +## PackageInfo.dist property + +Signature: + +```typescript +dist: boolean; +``` diff --git a/docs/development/core/server/kibana-plugin-server.packageinfo.md b/docs/development/core/server/kibana-plugin-server.packageinfo.md new file mode 100644 index 000000000000..3ff02c9cda85 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.packageinfo.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [PackageInfo](./kibana-plugin-server.packageinfo.md) + +## PackageInfo interface + + +Signature: + +```typescript +export interface PackageInfo +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [branch](./kibana-plugin-server.packageinfo.branch.md) | string | | +| [buildNum](./kibana-plugin-server.packageinfo.buildnum.md) | number | | +| [buildSha](./kibana-plugin-server.packageinfo.buildsha.md) | string | | +| [dist](./kibana-plugin-server.packageinfo.dist.md) | boolean | | +| [version](./kibana-plugin-server.packageinfo.version.md) | string | | + diff --git a/docs/development/core/server/kibana-plugin-server.packageinfo.version.md b/docs/development/core/server/kibana-plugin-server.packageinfo.version.md new file mode 100644 index 000000000000..e99e3c48d704 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.packageinfo.version.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [PackageInfo](./kibana-plugin-server.packageinfo.md) > [version](./kibana-plugin-server.packageinfo.version.md) + +## PackageInfo.version property + +Signature: + +```typescript +version: string; +``` diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.env.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.env.md index fde398faf132..fd4caa605c0e 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.env.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.env.md @@ -9,5 +9,6 @@ ```typescript env: { mode: EnvironmentMode; + packageInfo: Readonly; }; ``` diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md index 2bba3d408f68..e7aa32edaa29 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md @@ -17,7 +17,7 @@ export interface PluginInitializerContext | Property | Type | Description | | --- | --- | --- | | [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
} | | -| [env](./kibana-plugin-server.plugininitializercontext.env.md) | {
mode: EnvironmentMode;
} | | +| [env](./kibana-plugin-server.plugininitializercontext.env.md) | {
mode: EnvironmentMode;
packageInfo: Readonly<PackageInfo>;
} | | | [logger](./kibana-plugin-server.plugininitializercontext.logger.md) | LoggerFactory | | | [opaqueId](./kibana-plugin-server.plugininitializercontext.opaqueid.md) | PluginOpaqueId | | diff --git a/src/core/public/context/context_service.test.ts b/src/core/public/context/context_service.test.ts index d575d57a6b27..934ea77df6fd 100644 --- a/src/core/public/context/context_service.test.ts +++ b/src/core/public/context/context_service.test.ts @@ -20,17 +20,18 @@ import { PluginOpaqueId } from '../../server'; import { MockContextConstructor } from './context_service.test.mocks'; import { ContextService } from './context_service'; +import { coreMock } from '../mocks'; const pluginDependencies = new Map(); describe('ContextService', () => { describe('#setup()', () => { test('createContextContainer returns a new container configured with pluginDependencies', () => { - const coreId = Symbol(); - const service = new ContextService({ coreId }); + const context = coreMock.createCoreContext(); + const service = new ContextService(context); const setup = service.setup({ pluginDependencies }); expect(setup.createContextContainer()).toBeDefined(); - expect(MockContextConstructor).toHaveBeenCalledWith(pluginDependencies, coreId); + expect(MockContextConstructor).toHaveBeenCalledWith(pluginDependencies, context.coreId); }); }); }); diff --git a/src/core/public/core_system.ts b/src/core/public/core_system.ts index 193e4dd23f23..7104b9e10c74 100644 --- a/src/core/public/core_system.ts +++ b/src/core/public/core_system.ts @@ -20,6 +20,7 @@ import './core.css'; import { CoreId } from '../server'; +import { PackageInfo, EnvironmentMode } from '../server/types'; import { CoreSetup, CoreStart } from '.'; import { ChromeService } from './chrome'; import { FatalErrorsService, FatalErrorsSetup } from './fatal_errors'; @@ -55,6 +56,10 @@ interface Params { /** @internal */ export interface CoreContext { coreId: CoreId; + env: { + mode: Readonly; + packageInfo: Readonly; + }; } /** @internal */ @@ -130,7 +135,8 @@ export class CoreSystem { this.rendering = new RenderingService(); this.application = new ApplicationService(); - this.coreContext = { coreId: Symbol('core') }; + this.coreContext = { coreId: Symbol('core'), env: injectedMetadata.env }; + this.context = new ContextService(this.coreContext); this.plugins = new PluginsService(this.coreContext, injectedMetadata.uiPlugins); diff --git a/src/core/public/index.ts b/src/core/public/index.ts index 07be026e965a..42dc8707588b 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -67,6 +67,7 @@ import { UiSettingsClient, UiSettingsState, UiSettingsClientContract } from './u import { ApplicationSetup, Capabilities, ApplicationStart } from './application'; import { DocLinksStart } from './doc_links'; import { SavedObjectsStart } from './saved_objects'; +export { PackageInfo, EnvironmentMode } from '../server/types'; import { IContextContainer, IContextProvider, diff --git a/src/core/public/injected_metadata/injected_metadata_service.ts b/src/core/public/injected_metadata/injected_metadata_service.ts index aa9d2a145873..478285a70771 100644 --- a/src/core/public/injected_metadata/injected_metadata_service.ts +++ b/src/core/public/injected_metadata/injected_metadata_service.ts @@ -19,6 +19,7 @@ import { get } from 'lodash'; import { DiscoveredPlugin, PluginName } from '../../server'; +import { EnvironmentMode, PackageInfo } from '../../server/types'; import { UiSettingsState } from '../ui_settings'; import { deepFreeze } from '../../utils/'; import { Capabilities } from '..'; @@ -46,6 +47,10 @@ export interface InjectedMetadataParams { vars: { [key: string]: unknown; }; + env: { + mode: Readonly; + packageInfo: Readonly; + }; uiPlugins: Array<{ id: PluginName; plugin: DiscoveredPlugin; diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts index 8ce163fd59e1..8345980b6869 100644 --- a/src/core/public/mocks.ts +++ b/src/core/public/mocks.ts @@ -18,7 +18,7 @@ */ import { applicationServiceMock } from './application/application_service.mock'; import { chromeServiceMock } from './chrome/chrome_service.mock'; -import { CoreSetup, CoreStart, PluginInitializerContext } from '.'; +import { CoreContext, CoreSetup, CoreStart, PluginInitializerContext } from '.'; import { docLinksServiceMock } from './doc_links/doc_links_service.mock'; import { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock'; import { httpServiceMock } from './http/http_service.mock'; @@ -75,9 +75,51 @@ function createCoreStartMock() { return mock; } +function pluginInitializerContextMock() { + const mock: PluginInitializerContext = { + opaqueId: Symbol(), + env: { + mode: { + dev: true, + name: 'development', + prod: false, + }, + packageInfo: { + version: 'version', + branch: 'branch', + buildNum: 100, + buildSha: 'buildSha', + dist: false, + }, + }, + }; + + return mock; +} + +function createCoreContext(): CoreContext { + return { + coreId: Symbol('core context mock'), + env: { + mode: { + dev: true, + name: 'development', + prod: false, + }, + packageInfo: { + version: 'version', + branch: 'branch', + buildNum: 100, + buildSha: 'buildSha', + dist: false, + }, + }, + }; +} export const coreMock = { + createCoreContext, createSetup: createCoreSetupMock, createStart: createCoreStartMock, - createPluginInitializerContext: jest.fn() as jest.Mock, + createPluginInitializerContext: pluginInitializerContextMock, }; diff --git a/src/core/public/plugins/plugin.test.ts b/src/core/public/plugins/plugin.test.ts index 6cbe0c7e0ed8..85de5c6620cc 100644 --- a/src/core/public/plugins/plugin.test.ts +++ b/src/core/public/plugins/plugin.test.ts @@ -19,6 +19,7 @@ import { mockInitializer, mockPlugin, mockPluginLoader } from './plugin.test.mocks'; import { DiscoveredPlugin } from '../../server'; +import { coreMock } from '../mocks'; import { PluginWrapper } from './plugin'; function createManifest( @@ -36,7 +37,7 @@ function createManifest( let plugin: PluginWrapper>; const opaqueId = Symbol(); -const initializerContext = { opaqueId }; +const initializerContext = coreMock.createPluginInitializerContext(); const addBasePath = (path: string) => path; beforeEach(() => { diff --git a/src/core/public/plugins/plugin_context.ts b/src/core/public/plugins/plugin_context.ts index 51bd118d280e..eae45654fce1 100644 --- a/src/core/public/plugins/plugin_context.ts +++ b/src/core/public/plugins/plugin_context.ts @@ -19,7 +19,8 @@ import { omit } from 'lodash'; -import { DiscoveredPlugin, PluginOpaqueId } from '../../server'; +import { DiscoveredPlugin } from '../../server'; +import { PluginOpaqueId, PackageInfo, EnvironmentMode } from '../../server/types'; import { CoreContext } from '../core_system'; import { PluginWrapper } from './plugin'; import { PluginsServiceSetupDeps, PluginsServiceStartDeps } from './plugins_service'; @@ -35,6 +36,10 @@ export interface PluginInitializerContext { * A symbol used to identify this plugin in the system. Needed when registering handlers or context providers. */ readonly opaqueId: PluginOpaqueId; + readonly env: { + mode: Readonly; + packageInfo: Readonly; + }; } /** @@ -52,6 +57,7 @@ export function createPluginInitializerContext( ): PluginInitializerContext { return { opaqueId, + env: coreContext.env, }; } diff --git a/src/core/public/plugins/plugins_service.test.ts b/src/core/public/plugins/plugins_service.test.ts index 358bf71ac918..cfac4c364805 100644 --- a/src/core/public/plugins/plugins_service.test.ts +++ b/src/core/public/plugins/plugins_service.test.ts @@ -26,7 +26,7 @@ import { } from './plugins_service.test.mocks'; import { PluginName, DiscoveredPlugin } from 'src/core/server'; -import { CoreContext } from '../core_system'; +import { coreMock } from '../mocks'; import { PluginsService, PluginsServiceStartDeps, @@ -56,7 +56,7 @@ let plugins: Array<{ id: string; plugin: DiscoveredPlugin }>; type DeeplyMocked = { [P in keyof T]: jest.Mocked }; -const mockCoreContext: CoreContext = { coreId: Symbol() }; +const mockCoreContext = coreMock.createCoreContext(); let mockSetupDeps: DeeplyMocked; let mockSetupContext: DeeplyMocked; let mockStartDeps: DeeplyMocked; diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index e45c7710dc38..e7f1db8b1676 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -226,6 +226,11 @@ export interface CoreContext { // // (undocumented) coreId: CoreId; + // (undocumented) + env: { + mode: Readonly; + packageInfo: Readonly; + }; } // @public @@ -379,6 +384,16 @@ export interface DocLinksStart { }; } +// @public (undocumented) +export interface EnvironmentMode { + // (undocumented) + dev: boolean; + // (undocumented) + name: 'development' | 'production'; + // (undocumented) + prod: boolean; +} + // Warning: (ae-missing-release-tag) "ErrorToastOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -681,6 +696,20 @@ export interface OverlayStart { }) => OverlayRef; } +// @public (undocumented) +export interface PackageInfo { + // (undocumented) + branch: string; + // (undocumented) + buildNum: number; + // (undocumented) + buildSha: string; + // (undocumented) + dist: boolean; + // (undocumented) + version: string; +} + // @public export interface Plugin { // (undocumented) @@ -696,6 +725,11 @@ export type PluginInitializer; + packageInfo: Readonly; + }; readonly opaqueId: PluginOpaqueId; } diff --git a/src/core/server/config/env.ts b/src/core/server/config/env.ts index 89d0e68ed276..bb6064c71742 100644 --- a/src/core/server/config/env.ts +++ b/src/core/server/config/env.ts @@ -18,25 +18,12 @@ */ import { resolve, dirname } from 'path'; +import { PackageInfo, EnvironmentMode } from './types'; // `require` is necessary for this to work inside x-pack code as well // eslint-disable-next-line @typescript-eslint/no-var-requires const pkg = require('../../../../package.json'); -export interface PackageInfo { - version: string; - branch: string; - buildNum: number; - buildSha: string; - dist: boolean; -} - -export interface EnvironmentMode { - name: 'development' | 'production'; - dev: boolean; - prod: boolean; -} - /** @internal */ export interface EnvOptions { configs: string[]; diff --git a/src/core/server/config/index.ts b/src/core/server/config/index.ts index d27462a86a9c..491a24b2ab3d 100644 --- a/src/core/server/config/index.ts +++ b/src/core/server/config/index.ts @@ -21,6 +21,6 @@ export { ConfigService, IConfigService } from './config_service'; export { RawConfigService } from './raw_config_service'; export { Config, ConfigPath, isConfigPath, hasConfigPathIntersection } from './config'; export { ObjectToConfigAdapter } from './object_to_config_adapter'; -export { CliArgs } from './env'; +export { CliArgs, Env } from './env'; -export { Env, EnvironmentMode, PackageInfo } from './env'; +export { EnvironmentMode, PackageInfo } from './types'; diff --git a/src/core/server/types.ts~master b/src/core/server/config/types.ts similarity index 74% rename from src/core/server/types.ts~master rename to src/core/server/config/types.ts index 9b55da17a40a..117c8bf7c3b4 100644 --- a/src/core/server/types.ts~master +++ b/src/core/server/config/types.ts @@ -17,6 +17,22 @@ * under the License. */ -/** This module is intended for consumption by public to avoid import issues with server-side code */ +/** + * @public + */ +export interface PackageInfo { + version: string; + branch: string; + buildNum: number; + buildSha: string; + dist: boolean; +} -export { PluginOpaqueId } from './plugins/types'; +/** + * @public + */ +export interface EnvironmentMode { + name: 'development' | 'production'; + dev: boolean; + prod: boolean; +} diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 027c82e419b5..6add81af863d 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -58,7 +58,7 @@ import { ContextSetup } from './context'; import { SavedObjectsServiceStart } from './saved_objects'; export { bootstrap } from './bootstrap'; -export { ConfigPath, ConfigService } from './config'; +export { ConfigPath, ConfigService, EnvironmentMode, PackageInfo } from './config'; export { IContextContainer, IContextProvider, diff --git a/src/core/server/legacy/legacy_service.ts b/src/core/server/legacy/legacy_service.ts index 500f50fcd831..52e999f5e03a 100644 --- a/src/core/server/legacy/legacy_service.ts +++ b/src/core/server/legacy/legacy_service.ts @@ -257,6 +257,10 @@ export class LegacyService implements CoreService { settings, config, { + env: { + mode: this.coreContext.env.mode, + packageInfo: this.coreContext.env.packageInfo, + }, handledConfigPaths: await this.coreContext.configService.getUsedPaths(), setupDeps: { core: coreSetup, diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index f072ae5fd4db..c3d524c77402 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -40,7 +40,7 @@ export function pluginInitializerContextConfigMock(config: T) { return mock; } -function pluginInitializerContextMock(config: T) { +function pluginInitializerContextMock(config: T = {} as T) { const mock: PluginInitializerContext = { opaqueId: Symbol(), logger: loggingServiceMock.create(), @@ -50,6 +50,13 @@ function pluginInitializerContextMock(config: T) { name: 'development', prod: false, }, + packageInfo: { + version: 'version', + branch: 'branch', + buildNum: 100, + buildSha: 'buildSha', + dist: false, + }, }, config: pluginInitializerContextConfigMock(config), }; diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 46432cbb0da7..edcafbb9a3dc 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -47,7 +47,10 @@ export function createPluginInitializerContext( /** * Environment information that is safe to expose to plugins and may be beneficial for them. */ - env: { mode: coreContext.env.mode }, + env: { + mode: coreContext.env.mode, + packageInfo: coreContext.env.packageInfo, + }, /** * Plugin-scoped logger diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index 4b66c9fb65c1..9a3e922b3cb8 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs'; import { Type } from '@kbn/config-schema'; -import { ConfigPath, EnvironmentMode } from '../config'; +import { ConfigPath, EnvironmentMode, PackageInfo } from '../config'; import { LoggerFactory } from '../logging'; import { CoreSetup, CoreStart } from '..'; @@ -159,7 +159,10 @@ export interface Plugin< */ export interface PluginInitializerContext { opaqueId: PluginOpaqueId; - env: { mode: EnvironmentMode }; + env: { + mode: EnvironmentMode; + packageInfo: Readonly; + }; logger: LoggerFactory; config: { create: () => Observable; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 01e6b63ee433..d1d6f35b4da1 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -618,6 +618,16 @@ export interface ElasticsearchServiceSetup { }; } +// @public (undocumented) +export interface EnvironmentMode { + // (undocumented) + dev: boolean; + // (undocumented) + name: 'development' | 'production'; + // (undocumented) + prod: boolean; +} + // @public export interface ErrorHttpResponseOptions { body?: ResponseError; @@ -957,6 +967,20 @@ export interface OnPreAuthToolkit { rewriteUrl: (url: string) => OnPreAuthResult; } +// @public (undocumented) +export interface PackageInfo { + // (undocumented) + branch: string; + // (undocumented) + buildNum: number; + // (undocumented) + buildSha: string; + // (undocumented) + dist: boolean; + // (undocumented) + version: string; +} + // @public export interface Plugin { // (undocumented) @@ -980,6 +1004,7 @@ export interface PluginInitializerContext { // (undocumented) env: { mode: EnvironmentMode; + packageInfo: Readonly; }; // (undocumented) logger: LoggerFactory; @@ -1553,6 +1578,5 @@ export interface SessionStorageFactory { // Warnings were encountered during analysis: // // src/core/server/plugins/plugins_service.ts:39:5 - (ae-forgotten-export) The symbol "DiscoveredPluginInternal" needs to be exported by the entry point index.d.ts -// src/core/server/plugins/types.ts:162:10 - (ae-forgotten-export) The symbol "EnvironmentMode" needs to be exported by the entry point index.d.ts ``` diff --git a/src/core/server/types.ts b/src/core/server/types.ts index d712c804d45d..46c70a91721b 100644 --- a/src/core/server/types.ts +++ b/src/core/server/types.ts @@ -20,3 +20,4 @@ /** This module is intended for consumption by public to avoid import issues with server-side code */ export { PluginOpaqueId } from './plugins/types'; export * from './saved_objects/types'; +export { EnvironmentMode, PackageInfo } from './config/types'; diff --git a/src/legacy/server/kbn_server.d.ts b/src/legacy/server/kbn_server.d.ts index 2448614c5852..50cb7e939fb3 100644 --- a/src/legacy/server/kbn_server.d.ts +++ b/src/legacy/server/kbn_server.d.ts @@ -24,9 +24,11 @@ import { SavedObjectsClientProviderOptions, CoreSetup } from 'src/core/server'; import { ConfigService, ElasticsearchServiceSetup, + EnvironmentMode, LoggerFactory, SavedObjectsClientContract, SavedObjectsLegacyService, + PackageInfo, } from '../../core/server'; import { LegacyServiceSetupDeps, LegacyServiceStartDeps } from '../../core/server/'; @@ -102,6 +104,10 @@ type KbnMixinFunc = (kbnServer: KbnServer, server: Server, config: any) => Promi // eslint-disable-next-line import/no-default-export export default class KbnServer { public readonly newPlatform: { + env: { + mode: Readonly; + packageInfo: Readonly; + }; coreContext: { logger: LoggerFactory; }; diff --git a/src/legacy/server/kbn_server.js b/src/legacy/server/kbn_server.js index 56539f409a34..f7ed56b10c26 100644 --- a/src/legacy/server/kbn_server.js +++ b/src/legacy/server/kbn_server.js @@ -57,10 +57,14 @@ export default class KbnServer { this.settings = settings || {}; this.config = config; - const { setupDeps, startDeps, handledConfigPaths, logger, __internals } = core; + const { setupDeps, startDeps, handledConfigPaths, logger, __internals, env } = core; this.server = __internals.hapiServer; this.newPlatform = { + env: { + mode: env.mode, + packageInfo: env.packageInfo, + }, __internals, coreContext: { logger, diff --git a/src/legacy/ui/ui_render/ui_render_mixin.js b/src/legacy/ui/ui_render/ui_render_mixin.js index 68cfd756acf6..883358e0d3c9 100644 --- a/src/legacy/ui/ui_render/ui_render_mixin.js +++ b/src/legacy/ui/ui_render/ui_render_mixin.js @@ -237,6 +237,7 @@ export function uiRenderMixin(kbnServer, server, config) { buildNumber: config.get('pkg.buildNum'), branch: config.get('pkg.branch'), basePath, + env: kbnServer.newPlatform.env, legacyMode: app.getId() !== 'core', i18n: { translationsUrl: `${basePath}/translations/${i18n.getLocale()}.json`, diff --git a/src/plugins/data/public/search/es_search/es_search_service.test.ts b/src/plugins/data/public/search/es_search/es_search_service.test.ts index d1069cd6815f..d756b54a5cce 100644 --- a/src/plugins/data/public/search/es_search/es_search_service.test.ts +++ b/src/plugins/data/public/search/es_search/es_search_service.test.ts @@ -25,10 +25,9 @@ import { searchSetupMock } from '../mocks'; describe('ES search strategy service', () => { let service: EsSearchService; let mockCoreSetup: MockedKeys; - const opaqueId = Symbol(); beforeEach(() => { - service = new EsSearchService({ opaqueId }); + service = new EsSearchService(coreMock.createPluginInitializerContext()); mockCoreSetup = coreMock.createSetup(); }); diff --git a/src/plugins/data/public/search/es_search/index.test.ts b/src/plugins/data/public/search/es_search/index.test.ts index 7f7a2ed397d4..ecceffc752e9 100644 --- a/src/plugins/data/public/search/es_search/index.test.ts +++ b/src/plugins/data/public/search/es_search/index.test.ts @@ -16,10 +16,10 @@ * specific language governing permissions and limitations * under the License. */ - +import { coreMock } from '../../../../../../src/core/public/mocks'; import { esSearchService } from '.'; it('es search service is instantiated', () => { - const esSearch = esSearchService({ opaqueId: Symbol() }); + const esSearch = esSearchService(coreMock.createPluginInitializerContext()); expect(esSearch).toBeDefined(); }); diff --git a/src/plugins/data/public/search/search_service.test.ts b/src/plugins/data/public/search/search_service.test.ts index 8102b0e915fb..69e05e8df48e 100644 --- a/src/plugins/data/public/search/search_service.test.ts +++ b/src/plugins/data/public/search/search_service.test.ts @@ -25,9 +25,9 @@ import { CoreSetup } from '../../../../core/public'; describe('Search service', () => { let searchService: SearchService; let mockCoreSetup: MockedKeys; - const opaqueId = Symbol(); + beforeEach(() => { - searchService = new SearchService({ opaqueId }); + searchService = new SearchService(coreMock.createPluginInitializerContext()); mockCoreSetup = coreMock.createSetup(); }); diff --git a/src/plugins/data/server/search/es_search/es_search_service.test.ts b/src/plugins/data/server/search/es_search/es_search_service.test.ts index faf9487159c1..0b274c62958a 100644 --- a/src/plugins/data/server/search/es_search/es_search_service.test.ts +++ b/src/plugins/data/server/search/es_search/es_search_service.test.ts @@ -19,31 +19,13 @@ import { coreMock } from '../../../../../core/server/mocks'; import { EsSearchService } from './es_search_service'; -import { PluginInitializerContext } from '../../../../../core/server'; import { searchSetupMock } from '../mocks'; describe('ES search strategy service', () => { let service: EsSearchService; const mockCoreSetup = coreMock.createSetup(); - const opaqueId = Symbol(); - const context: PluginInitializerContext = { - opaqueId, - config: { - createIfExists: jest.fn(), - create: jest.fn(), - }, - env: { - mode: { - dev: false, - name: 'development', - prod: false, - }, - }, - logger: { - get: jest.fn(), - }, - }; + const context = coreMock.createPluginInitializerContext(); beforeEach(() => { service = new EsSearchService(context); diff --git a/test/plugin_functional/plugins/core_plugin_b/public/index.ts b/test/plugin_functional/plugins/core_plugin_b/public/index.ts index db3b5c42a964..31aa7f81c2ac 100644 --- a/test/plugin_functional/plugins/core_plugin_b/public/index.ts +++ b/test/plugin_functional/plugins/core_plugin_b/public/index.ts @@ -17,7 +17,7 @@ * under the License. */ -import { PluginInitializer } from 'kibana/public'; +import { PluginInitializer, PluginInitializerContext } from 'kibana/public'; import { CorePluginBDeps, CorePluginBPlugin, @@ -29,4 +29,4 @@ export const plugin: PluginInitializer< CorePluginBPluginSetup, CorePluginBPluginStart, CorePluginBDeps -> = () => new CorePluginBPlugin(); +> = (context: PluginInitializerContext) => new CorePluginBPlugin(context); diff --git a/test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx b/test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx index 627fd05404b2..56cc1cb4ab42 100644 --- a/test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx +++ b/test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx @@ -17,13 +17,14 @@ * under the License. */ -import { Plugin, CoreSetup } from 'kibana/public'; +import { CoreSetup, Plugin, PluginInitializerContext } from 'kibana/public'; import { CorePluginAPluginSetup } from '../../core_plugin_a/public/plugin'; declare global { interface Window { corePluginB?: string; hasAccessToInjectedMetadata?: boolean; + env?: PluginInitializerContext['env']; } } @@ -33,6 +34,9 @@ export interface CorePluginBDeps { export class CorePluginBPlugin implements Plugin { + constructor(pluginContext: PluginInitializerContext) { + window.env = pluginContext.env; + } public setup(core: CoreSetup, deps: CorePluginBDeps) { window.corePluginB = `Plugin A said: ${deps.core_plugin_a.getGreeting()}`; window.hasAccessToInjectedMetadata = 'getInjectedVar' in core.injectedMetadata; diff --git a/test/plugin_functional/test_suites/core_plugins/ui_plugins.js b/test/plugin_functional/test_suites/core_plugins/ui_plugins.js index df855f243d40..15a4dcabddbd 100644 --- a/test/plugin_functional/test_suites/core_plugins/ui_plugins.js +++ b/test/plugin_functional/test_suites/core_plugins/ui_plugins.js @@ -44,5 +44,16 @@ export default function ({ getService, getPageObjects }) { expect(hasAccessToInjectedMetadata).to.equal(true); }); }); + describe('have env data provided', function describeIndexTests() { + before(async () => { + await PageObjects.common.navigateToApp('bar'); + }); + + it('should attach pluginContext to window.corePluginB', async () => { + const envData = await browser.execute('return window.env'); + expect(envData.mode.dev).to.be(true); + expect(envData.packageInfo.version).to.be.a('string'); + }); + }); }); } diff --git a/x-pack/legacy/plugins/uptime/public/apps/index.ts b/x-pack/legacy/plugins/uptime/public/apps/index.ts index 2fa548c3c271..3b328b3ff232 100644 --- a/x-pack/legacy/plugins/uptime/public/apps/index.ts +++ b/x-pack/legacy/plugins/uptime/public/apps/index.ts @@ -8,4 +8,4 @@ import chrome from 'ui/chrome'; import { npStart } from 'ui/new_platform'; import { Plugin } from './plugin'; -new Plugin({ opaqueId: Symbol('uptime') }, chrome).start(npStart); +new Plugin({ opaqueId: Symbol('uptime'), env: {} as any }, chrome).start(npStart);