From 7af955563bcbd3434b3df7c6438d184f6a332c9f Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Mon, 23 Mar 2020 16:50:31 -0600 Subject: [PATCH 01/16] Remove legacy imports from core/public --- src/core/public/core_system.test.ts | 12 +- src/core/public/core_system.ts | 11 +- .../__snapshots__/legacy_service.test.ts.snap | 11 +- src/core/public/legacy/legacy_service.test.ts | 107 +++++------------- src/core/public/legacy/legacy_service.ts | 49 ++++---- .../saved_objects/saved_objects_client.ts | 16 +-- .../tests_bundle/tests_entry_template.js | 3 +- .../ui/ui_bundles/app_entry_template.js | 4 +- 8 files changed, 86 insertions(+), 127 deletions(-) diff --git a/src/core/public/core_system.test.ts b/src/core/public/core_system.test.ts index 94fa74f4bd861f..559dadfc3dba4b 100644 --- a/src/core/public/core_system.test.ts +++ b/src/core/public/core_system.test.ts @@ -59,7 +59,6 @@ const defaultCoreSystemParams = { warnLegacyBrowsers: true, }, } as any, - requireLegacyFiles: jest.fn(), }; beforeEach(() => { @@ -104,19 +103,22 @@ describe('constructor', () => { }); }); - it('passes requireLegacyFiles, useLegacyTestHarness, and a dom element to LegacyPlatformService', () => { + it('passes requireLegacyFiles, requireNewPlatformShimModule, requireLegacyBootstrapModule and a dom element to LegacyPlatformService', () => { const requireLegacyFiles = { requireLegacyFiles: true }; - const useLegacyTestHarness = { useLegacyTestHarness: true }; + const requireLegacyBootstrapModule = { requireLegacyBootstrapModule: true }; + const requireNewPlatformShimModule = { requireNewPlatformShimModule: true }; createCoreSystem({ requireLegacyFiles, - useLegacyTestHarness, + requireLegacyBootstrapModule, + requireNewPlatformShimModule, }); expect(LegacyPlatformServiceConstructor).toHaveBeenCalledTimes(1); expect(LegacyPlatformServiceConstructor).toHaveBeenCalledWith({ requireLegacyFiles, - useLegacyTestHarness, + requireLegacyBootstrapModule, + requireNewPlatformShimModule, }); }); diff --git a/src/core/public/core_system.ts b/src/core/public/core_system.ts index 5c10d894591286..9b3c4e32db5614 100644 --- a/src/core/public/core_system.ts +++ b/src/core/public/core_system.ts @@ -50,8 +50,9 @@ interface Params { rootDomElement: HTMLElement; browserSupportsCsp: boolean; injectedMetadata: InjectedMetadataParams['injectedMetadata']; - requireLegacyFiles: LegacyPlatformParams['requireLegacyFiles']; - useLegacyTestHarness?: LegacyPlatformParams['useLegacyTestHarness']; + requireLegacyFiles?: LegacyPlatformParams['requireLegacyFiles']; + requireLegacyBootstrapModule?: LegacyPlatformParams['requireLegacyBootstrapModule']; + requireNewPlatformShimModule?: LegacyPlatformParams['requireNewPlatformShimModule']; } /** @internal */ @@ -111,7 +112,8 @@ export class CoreSystem { browserSupportsCsp, injectedMetadata, requireLegacyFiles, - useLegacyTestHarness, + requireLegacyBootstrapModule, + requireNewPlatformShimModule, } = params; this.rootDomElement = rootDomElement; @@ -145,7 +147,8 @@ export class CoreSystem { this.legacy = new LegacyPlatformService({ requireLegacyFiles, - useLegacyTestHarness, + requireLegacyBootstrapModule, + requireNewPlatformShimModule, }); } diff --git a/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap b/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap index 97629fdd1add5c..304d748f88020c 100644 --- a/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap +++ b/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap @@ -1,21 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`#start() load order useLegacyTestHarness = false loads ui/modules before ui/chrome, and both before legacy files 1`] = ` +exports[`#start() load order loads ui/modules before ui/chrome, and both before legacy files 1`] = ` Array [ - "ui/new_platform", "ui/chrome", "legacy files", ] `; -exports[`#start() load order useLegacyTestHarness = true loads ui/modules before ui/test_harness, and both before legacy files 1`] = ` -Array [ - "ui/new_platform", - "ui/test_harness", - "legacy files", -] -`; - exports[`#stop() destroys the angular scope and empties the targetDomElement if angular is bootstrapped to targetDomElement 1`] = `
{ - mockLoadOrder.push('ui/new_platform'); - return { - __setup__: mockUiNewPlatformSetup, - __start__: mockUiNewPlatformStart, - }; -}); - -const mockUiChromeBootstrap = jest.fn(); -jest.mock('ui/chrome', () => { - mockLoadOrder.push('ui/chrome'); - return { - bootstrap: mockUiChromeBootstrap, - }; -}); - -const mockUiTestHarnessBootstrap = jest.fn(); -jest.mock('ui/test_harness', () => { - mockLoadOrder.push('ui/test_harness'); - return { - bootstrap: mockUiTestHarnessBootstrap, - }; -}); - import { chromeServiceMock } from '../chrome/chrome_service.mock'; import { fatalErrorsServiceMock } from '../fatal_errors/fatal_errors_service.mock'; import { httpServiceMock } from '../http/http_service.mock'; @@ -69,10 +41,24 @@ const injectedMetadataSetup = injectedMetadataServiceMock.createSetupContract(); const notificationsSetup = notificationServiceMock.createSetupContract(); const uiSettingsSetup = uiSettingsServiceMock.createSetupContract(); +const mockLoadOrder: string[] = []; +const mockUiNewPlatformSetup = jest.fn(); +const mockUiNewPlatformStart = jest.fn(); +const mockUiChromeBootstrap = jest.fn(); const defaultParams = { requireLegacyFiles: jest.fn(() => { mockLoadOrder.push('legacy files'); }), + requireLegacyBootstrapModule: jest.fn(() => { + mockLoadOrder.push('ui/chrome'); + return { + bootstrap: mockUiChromeBootstrap, + }; + }), + requireNewPlatformShimModule: jest.fn(() => ({ + __setup__: mockUiNewPlatformSetup, + __start__: mockUiNewPlatformStart, + })), }; const defaultSetupDeps = { @@ -128,7 +114,7 @@ afterEach(() => { describe('#setup()', () => { describe('default', () => { - it('initializes ui/new_platform with core APIs', () => { + it('initializes new platform shim module with core APIs', () => { const legacyPlatform = new LegacyPlatformService({ ...defaultParams, }); @@ -185,67 +171,30 @@ describe('#start()', () => { expect(pluginsStart).toBe(defaultStartDeps.plugins); }); - describe('useLegacyTestHarness = false', () => { - it('passes the targetDomElement to ui/chrome', () => { - const legacyPlatform = new LegacyPlatformService({ - ...defaultParams, - }); + it('passes the targetDomElement to legacy bootstrap module', () => { + const legacyPlatform = new LegacyPlatformService({ + ...defaultParams, + }); - legacyPlatform.setup(defaultSetupDeps); - legacyPlatform.start(defaultStartDeps); + legacyPlatform.setup(defaultSetupDeps); + legacyPlatform.start(defaultStartDeps); - expect(mockUiTestHarnessBootstrap).not.toHaveBeenCalled(); - expect(mockUiChromeBootstrap).toHaveBeenCalledTimes(1); - expect(mockUiChromeBootstrap).toHaveBeenCalledWith(defaultStartDeps.targetDomElement); - }); + expect(mockUiChromeBootstrap).toHaveBeenCalledTimes(1); + expect(mockUiChromeBootstrap).toHaveBeenCalledWith(defaultStartDeps.targetDomElement); }); - describe('useLegacyTestHarness = true', () => { - it('passes the targetDomElement to ui/test_harness', () => { + describe('load order', () => { + it('loads ui/modules before ui/chrome, and both before legacy files', () => { const legacyPlatform = new LegacyPlatformService({ ...defaultParams, - useLegacyTestHarness: true, }); + expect(mockLoadOrder).toEqual([]); + legacyPlatform.setup(defaultSetupDeps); legacyPlatform.start(defaultStartDeps); - expect(mockUiChromeBootstrap).not.toHaveBeenCalled(); - expect(mockUiTestHarnessBootstrap).toHaveBeenCalledTimes(1); - expect(mockUiTestHarnessBootstrap).toHaveBeenCalledWith(defaultStartDeps.targetDomElement); - }); - }); - - describe('load order', () => { - describe('useLegacyTestHarness = false', () => { - it('loads ui/modules before ui/chrome, and both before legacy files', () => { - const legacyPlatform = new LegacyPlatformService({ - ...defaultParams, - }); - - expect(mockLoadOrder).toEqual([]); - - legacyPlatform.setup(defaultSetupDeps); - legacyPlatform.start(defaultStartDeps); - - expect(mockLoadOrder).toMatchSnapshot(); - }); - }); - - describe('useLegacyTestHarness = true', () => { - it('loads ui/modules before ui/test_harness, and both before legacy files', () => { - const legacyPlatform = new LegacyPlatformService({ - ...defaultParams, - useLegacyTestHarness: true, - }); - - expect(mockLoadOrder).toEqual([]); - - legacyPlatform.setup(defaultSetupDeps); - legacyPlatform.start(defaultStartDeps); - - expect(mockLoadOrder).toMatchSnapshot(); - }); + expect(mockLoadOrder).toMatchSnapshot(); }); }); }); diff --git a/src/core/public/legacy/legacy_service.ts b/src/core/public/legacy/legacy_service.ts index 39ca7bdf54b7c2..01837ba6f5940b 100644 --- a/src/core/public/legacy/legacy_service.ts +++ b/src/core/public/legacy/legacy_service.ts @@ -25,8 +25,12 @@ import { LegacyCoreSetup, LegacyCoreStart, MountPoint } from '../'; /** @internal */ export interface LegacyPlatformParams { - requireLegacyFiles: () => void; - useLegacyTestHarness?: boolean; + requireLegacyFiles?: () => void; + requireLegacyBootstrapModule?: () => BootstrapModule; + requireNewPlatformShimModule?: () => { + __setup__: (legacyCore: LegacyCoreSetup, plugins: Record) => void; + __start__: (legacyCore: LegacyCoreStart, plugins: Record) => void; + }; } interface SetupDeps { @@ -92,7 +96,13 @@ export class LegacyPlatformService { // Inject parts of the new platform into parts of the legacy platform // so that legacy APIs/modules can mimic their new platform counterparts if (core.injectedMetadata.getLegacyMode()) { - require('ui/new_platform').__setup__(legacyCore, plugins); + if (!this.params.requireNewPlatformShimModule) { + throw new Error( + `requireNewPlatformShimModule must be specified when rendering a legacy application` + ); + } + + this.params.requireNewPlatformShimModule().__setup__(legacyCore, plugins); } } @@ -131,16 +141,29 @@ export class LegacyPlatformService { this.startDependencies$.next([legacyCore, plugins, {}]); + if (!this.params.requireNewPlatformShimModule) { + throw new Error( + `requireNewPlatformShimModule must be specified when rendering a legacy application` + ); + } + if (!this.params.requireLegacyBootstrapModule) { + throw new Error( + `requireLegacyBootstrapModule must be specified when rendering a legacy application` + ); + } + // Inject parts of the new platform into parts of the legacy platform // so that legacy APIs/modules can mimic their new platform counterparts - require('ui/new_platform').__start__(legacyCore, plugins); + this.params.requireNewPlatformShimModule().__start__(legacyCore, plugins); // Load the bootstrap module before loading the legacy platform files so that // the bootstrap module can modify the environment a bit first - this.bootstrapModule = this.loadBootstrapModule(); + this.bootstrapModule = this.params.requireLegacyBootstrapModule(); // require the files that will tie into the legacy platform - this.params.requireLegacyFiles(); + if (this.params.requireLegacyFiles) { + this.params.requireLegacyFiles(); + } if (!this.bootstrapModule) { throw new Error('Bootstrap module must be loaded before `start`'); @@ -172,20 +195,6 @@ export class LegacyPlatformService { // clear the inner html of the root angular element this.targetDomElement.textContent = ''; } - - private loadBootstrapModule(): BootstrapModule { - if (this.params.useLegacyTestHarness) { - // wrapped in NODE_ENV check so the `ui/test_harness` module - // is not included in the distributable - if (process.env.IS_KIBANA_DISTRIBUTABLE !== 'true') { - return require('ui/test_harness'); - } - - throw new Error('tests bundle is not available in the distributable'); - } - - return require('ui/chrome'); - } } const notSupported = (methodName: string) => (...args: any[]) => { diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index afc77806afb914..d26cadecb184a8 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -28,12 +28,6 @@ import { SavedObjectsMigrationVersion, } from '../../server'; -// TODO: Migrate to an error modal powered by the NP? -import { - isAutoCreateIndexError, - showAutoCreateIndexErrorPage, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../legacy/ui/public/error_auto_create_index/error_auto_create_index'; import { SimpleSavedObject } from './simple_saved_object'; import { HttpFetchOptions, HttpSetup } from '../http'; @@ -226,7 +220,9 @@ export class SavedObjectsClient { .then(resp => this.createSavedObject(resp)) .catch((error: object) => { if (isAutoCreateIndexError(error)) { - showAutoCreateIndexErrorPage(); + window.location.assign( + this.http.basePath.prepend('/app/kibana#/error/action.auto_create_index') + ); } throw error; @@ -472,3 +468,9 @@ const renameKeys = , U extends Record ...{ [keysMap[key] || key]: obj[key] }, }; }, {}); + +const isAutoCreateIndexError = (error: any) => { + return ( + error?.res?.status === 503 && error?.body?.attributes?.code === 'ES_AUTO_CREATE_INDEX_ERROR' + ); +}; diff --git a/src/legacy/core_plugins/tests_bundle/tests_entry_template.js b/src/legacy/core_plugins/tests_bundle/tests_entry_template.js index 3e3dc284671da0..cc00b5616f2163 100644 --- a/src/legacy/core_plugins/tests_bundle/tests_entry_template.js +++ b/src/legacy/core_plugins/tests_bundle/tests_entry_template.js @@ -135,7 +135,8 @@ const coreSystem = new CoreSystem({ }, }, rootDomElement, - useLegacyTestHarness: true, + requireLegacyBootstrapModule: () => require('ui/test_harness'), + requireNewPlatformShimModule: () => require('ui/new_platform'), requireLegacyFiles: () => { ${bundle.getRequires().join('\n ')} } diff --git a/src/legacy/ui/ui_bundles/app_entry_template.js b/src/legacy/ui/ui_bundles/app_entry_template.js index a1c3a153a196cf..bf926c4a7b61d7 100644 --- a/src/legacy/ui/ui_bundles/app_entry_template.js +++ b/src/legacy/ui/ui_bundles/app_entry_template.js @@ -45,7 +45,9 @@ i18n.load(injectedMetadata.i18n.translationsUrl) browserSupportsCsp: !window.__kbnCspNotEnforced__, requireLegacyFiles: () => { ${bundle.getRequires().join('\n ')} - } + }, + requireLegacyBootstrapModule: () => require('ui/chrome'), + requireNewPlatformShimModule: () => require('ui/new_platform'), }); coreSystem From 76f0ee8eba14f42094593ace49f83a3ecfc63fab Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Mon, 23 Mar 2020 16:51:03 -0600 Subject: [PATCH 02/16] Add core bundle to @kbn/optimizer --- packages/kbn-optimizer/src/common/bundle.ts | 2 +- .../src/optimizer/get_bundles.ts | 13 ++++- .../src/worker/webpack.config.ts | 2 +- src/core/public/entry_point.ts | 55 +++++++++++++++++++ .../tests_bundle/tests_entry_template.js | 10 +++- 5 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/core/public/entry_point.ts diff --git a/packages/kbn-optimizer/src/common/bundle.ts b/packages/kbn-optimizer/src/common/bundle.ts index f1bc0965a46cc7..40f7aa600892b9 100644 --- a/packages/kbn-optimizer/src/common/bundle.ts +++ b/packages/kbn-optimizer/src/common/bundle.ts @@ -23,7 +23,7 @@ import { BundleCache } from './bundle_cache'; import { UnknownVals } from './ts_helpers'; import { includes, ascending, entriesToObject } from './array_helpers'; -const VALID_BUNDLE_TYPES = ['plugin' as const]; +const VALID_BUNDLE_TYPES = ['plugin' as const, 'standalone' as const]; export interface BundleSpec { readonly type: typeof VALID_BUNDLE_TYPES[0]; diff --git a/packages/kbn-optimizer/src/optimizer/get_bundles.ts b/packages/kbn-optimizer/src/optimizer/get_bundles.ts index 7cd7bf15317e0e..364099102fa22f 100644 --- a/packages/kbn-optimizer/src/optimizer/get_bundles.ts +++ b/packages/kbn-optimizer/src/optimizer/get_bundles.ts @@ -24,7 +24,16 @@ import { Bundle } from '../common'; import { KibanaPlatformPlugin } from './kibana_platform_plugins'; export function getBundles(plugins: KibanaPlatformPlugin[], repoRoot: string) { - return plugins + const coreBundle = new Bundle({ + type: 'standalone', + id: 'core', + entry: './public/entry_point', + sourceRoot: repoRoot, + contextDir: Path.resolve(repoRoot, 'src/core'), + outputDir: Path.resolve(repoRoot, 'src/core/public/target/public'), + }); + + const pluginBundles = plugins .filter(p => p.isUiPlugin) .map( p => @@ -37,4 +46,6 @@ export function getBundles(plugins: KibanaPlatformPlugin[], repoRoot: string) { outputDir: Path.resolve(p.directory, 'target/public'), }) ); + + return [coreBundle, ...pluginBundles]; } diff --git a/packages/kbn-optimizer/src/worker/webpack.config.ts b/packages/kbn-optimizer/src/worker/webpack.config.ts index 2f81d92ec923c8..f8fa93765632c2 100644 --- a/packages/kbn-optimizer/src/worker/webpack.config.ts +++ b/packages/kbn-optimizer/src/worker/webpack.config.ts @@ -162,7 +162,7 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) { ], }, { - test: /\.scss$/, + test: /\.(scss|css)$/, exclude: /node_modules/, oneOf: [ { diff --git a/src/core/public/entry_point.ts b/src/core/public/entry_point.ts new file mode 100644 index 00000000000000..847d5dbcb413b1 --- /dev/null +++ b/src/core/public/entry_point.ts @@ -0,0 +1,55 @@ +/* + * 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. + */ + +/** + * This is the entry point used to boot the frontend when serving a application + * that lives in the Kibana Platform. + */ + +import { i18n } from '@kbn/i18n'; +import { CoreSystem } from './core_system'; + +const injectedMetadata = JSON.parse( + document.querySelector('kbn-injected-metadata')!.getAttribute('data')! +); + +if (process.env.IS_KIBANA_DISTRIBUTABLE !== 'true' && process.env.ELASTIC_APM_ACTIVE === 'true') { + // @ts-ignore + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { init } = require('@elastic/apm-rum'); + init(injectedMetadata.vars.apmConfig); +} + +i18n + .load(injectedMetadata.i18n.translationsUrl) + .catch(e => e) + .then(async i18nError => { + const coreSystem = new CoreSystem({ + injectedMetadata, + rootDomElement: document.body, + browserSupportsCsp: !(window as any).__kbnCspNotEnforced__, + }); + + const setup = await coreSystem.setup(); + if (i18nError && setup) { + setup.fatalErrors.add(i18nError); + } + + await coreSystem.start(); + }); diff --git a/src/legacy/core_plugins/tests_bundle/tests_entry_template.js b/src/legacy/core_plugins/tests_bundle/tests_entry_template.js index cc00b5616f2163..f075d8365c2993 100644 --- a/src/legacy/core_plugins/tests_bundle/tests_entry_template.js +++ b/src/legacy/core_plugins/tests_bundle/tests_entry_template.js @@ -135,7 +135,15 @@ const coreSystem = new CoreSystem({ }, }, rootDomElement, - requireLegacyBootstrapModule: () => require('ui/test_harness'), + requireLegacyBootstrapModule: () => { + // wrapped in NODE_ENV check so the 'ui/test_harness' module + // is not included in the distributable + if (process.env.IS_KIBANA_DISTRIBUTABLE !== 'true') { + return require('ui/test_harness'); + } + + throw new Error('tests bundle is not available in the distributable'); + }, requireNewPlatformShimModule: () => require('ui/new_platform'), requireLegacyFiles: () => { ${bundle.getRequires().join('\n ')} From a37876fd7889dcdd9d2bfb221f77bdf249dbf776 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Tue, 7 Apr 2020 16:43:15 -0600 Subject: [PATCH 03/16] Add core-only bundle loading strategy --- .../ui/ui_bundles/ui_bundles_controller.js | 7 ------ .../ui/ui_render/bootstrap/template.js.hbs | 25 ++++++++++++++++++- src/optimize/bundles_route/bundles_route.js | 8 +++++- x-pack/plugins/graph/public/application.ts | 2 ++ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/legacy/ui/ui_bundles/ui_bundles_controller.js b/src/legacy/ui/ui_bundles/ui_bundles_controller.js index 7afa283af83e01..79112fd687e847 100644 --- a/src/legacy/ui/ui_bundles/ui_bundles_controller.js +++ b/src/legacy/ui/ui_bundles/ui_bundles_controller.js @@ -99,13 +99,6 @@ export class UiBundlesController { this._postLoaders = []; this._bundles = []; - // create a bundle for core-only with no modules - this.add({ - id: 'core', - modules: [], - template: appEntryTemplate, - }); - // create a bundle for each uiApp for (const uiApp of uiApps) { this.add({ diff --git a/src/legacy/ui/ui_render/bootstrap/template.js.hbs b/src/legacy/ui/ui_render/bootstrap/template.js.hbs index 1093153edbbf7e..8be31c27dfcf45 100644 --- a/src/legacy/ui/ui_render/bootstrap/template.js.hbs +++ b/src/legacy/ui/ui_render/bootstrap/template.js.hbs @@ -68,7 +68,30 @@ if (window.__kbnStrictCsp__ && window.__kbnCspNotEnforced__) { }); } - load([ + // When rendering in Kibana Platform mode, only serve the assets needed by Core. + if ('{{appId}}' === 'core') { + return load({ + deps: [ + {{#each sharedJsDepFilenames}} + '{{../regularBundlePath}}/kbn-ui-shared-deps/{{this}}', + {{/each}} + '{{regularBundlePath}}/kbn-ui-shared-deps/{{sharedJsFilename}}', + '{{regularBundlePath}}/plugin/kibanaUtils/kibanaUtils.plugin.js', + '{{regularBundlePath}}/plugin/esUiShared/esUiShared.plugin.js', + '{{regularBundlePath}}/plugin/kibanaReact/kibanaReact.plugin.js' + ], function() { + load([ + '{{regularBundlePath}}/core/core.plugin.js', + {{#each styleSheetPaths}} + '{{this}}', + {{/each}} + ]) + }, + }); + } + + load({ + deps: [ {{#each sharedJsDepFilenames}} '{{../regularBundlePath}}/kbn-ui-shared-deps/{{this}}', {{/each}} diff --git a/src/optimize/bundles_route/bundles_route.js b/src/optimize/bundles_route/bundles_route.js index 0c2e98b5acd63c..8cb7596015abdb 100644 --- a/src/optimize/bundles_route/bundles_route.js +++ b/src/optimize/bundles_route/bundles_route.js @@ -17,7 +17,7 @@ * under the License. */ -import { isAbsolute, extname } from 'path'; +import { isAbsolute, extname, resolve, join } from 'path'; import LruCache from 'lru-cache'; import * as UiSharedDeps from '@kbn/ui-shared-deps'; import { createDynamicAssetResponse } from './dynamic_asset_response'; @@ -85,6 +85,12 @@ export function createBundlesRoute({ fileHashCache ) ), + buildRouteForBundles( + `${basePublicPath}/bundles/core/`, + `/bundles/core/`, + resolve(__dirname, join('..', '..', 'core', 'public', 'target', 'public')), + fileHashCache + ), buildRouteForBundles( `${basePublicPath}/bundles/`, '/bundles/', diff --git a/x-pack/plugins/graph/public/application.ts b/x-pack/plugins/graph/public/application.ts index f804265f1f5ab2..fee42bdbeaf3b6 100644 --- a/x-pack/plugins/graph/public/application.ts +++ b/x-pack/plugins/graph/public/application.ts @@ -12,6 +12,8 @@ import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular'; import '../../../../webpackShims/ace'; // required for i18nIdDirective import 'angular-sanitize'; +// required for ngRoute +import 'angular-route'; // type imports import { AppMountContext, From 4aba2c5b0d6cc71dbca169bc2d448e68ef49e8bd Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Wed, 8 Apr 2020 08:52:51 -0600 Subject: [PATCH 04/16] Update kbn-optimizer tests --- .../mock_repo/src/core/public/entry_point.ts | 21 +++++++++++++ .../basic_optimization.test.ts.snap | 18 +++++++++++ .../basic_optimization.test.ts | 16 +++++++--- .../integration_tests/bundle_cache.test.ts | 30 +++++++++++++++++++ .../src/optimizer/get_bundles.test.ts | 10 ++++++- .../src/worker/webpack.config.ts | 2 +- .../ui/ui_render/bootstrap/template.js.hbs | 2 +- 7 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 packages/kbn-optimizer/src/__fixtures__/mock_repo/src/core/public/entry_point.ts diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/src/core/public/entry_point.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/src/core/public/entry_point.ts new file mode 100644 index 00000000000000..4101c6da343e69 --- /dev/null +++ b/packages/kbn-optimizer/src/__fixtures__/mock_repo/src/core/public/entry_point.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. + */ + +// eslint-disable-next-line no-console +console.log(`core entry point`); diff --git a/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap b/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap index 4b4bb1282d9395..fe9a699e37de18 100644 --- a/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap +++ b/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap @@ -5,6 +5,18 @@ exports[`builds expected bundles, saves bundle counts to metadata: 1 async bundl exports[`builds expected bundles, saves bundle counts to metadata: OptimizerConfig 1`] = ` OptimizerConfig { "bundles": Array [ + Bundle { + "cache": BundleCache { + "path": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/public/target/public/.kbn-optimizer-cache, + "state": undefined, + }, + "contextDir": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core, + "entry": "./public/entry_point", + "id": "core", + "outputDir": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/public/target/public, + "sourceRoot": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo, + "type": "standalone", + }, Bundle { "cache": BundleCache { "path": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/target/public/.kbn-optimizer-cache, @@ -59,4 +71,10 @@ OptimizerConfig { exports[`builds expected bundles, saves bundle counts to metadata: bar bundle 1`] = `"var __kbnBundles__=typeof __kbnBundles__===\\"object\\"?__kbnBundles__:{};__kbnBundles__[\\"plugin/bar\\"]=function(modules){function webpackJsonpCallback(data){var chunkIds=data[0];var moreModules=data[1];var moduleId,chunkId,i=0,resolves=[];for(;i>>>>>> Update kbn-optimizer tests diff --git a/packages/kbn-optimizer/src/integration_tests/basic_optimization.test.ts b/packages/kbn-optimizer/src/integration_tests/basic_optimization.test.ts index ad743933e11711..37624ccbb9ab08 100644 --- a/packages/kbn-optimizer/src/integration_tests/basic_optimization.test.ts +++ b/packages/kbn-optimizer/src/integration_tests/basic_optimization.test.ts @@ -91,7 +91,7 @@ it('builds expected bundles, saves bundle counts to metadata', async () => { (msg.event?.type === 'bundle cached' || msg.event?.type === 'bundle not cached') && msg.state.phase === 'initializing' ); - assert('produce two bundle cache events while initializing', bundleCacheStates.length === 2); + assert('produce three bundle cache events while initializing', bundleCacheStates.length === 3); const initializedStates = msgs.filter(msg => msg.state.phase === 'initialized'); assert('produce at least one initialized event', initializedStates.length >= 1); @@ -101,12 +101,12 @@ it('builds expected bundles, saves bundle counts to metadata', async () => { const runningStates = msgs.filter(msg => msg.state.phase === 'running'); assert( - 'produce two or three "running" states', - runningStates.length === 2 || runningStates.length === 3 + 'produce four or five "running" states', + runningStates.length === 4 || runningStates.length === 5 ); const bundleNotCachedEvents = msgs.filter(msg => msg.event?.type === 'bundle not cached'); - assert('produce two "bundle not cached" events', bundleNotCachedEvents.length === 2); + assert('produce three "bundle not cached" events', bundleNotCachedEvents.length === 3); const successStates = msgs.filter(msg => msg.state.phase === 'success'); assert( @@ -124,6 +124,13 @@ it('builds expected bundles, saves bundle counts to metadata', async () => { ); assert('produce zero unexpected states', otherStates.length === 0, otherStates); + expect( + Fs.readFileSync( + Path.resolve(MOCK_REPO_DIR, 'src/core/public/target/public/core.standalone.js'), + 'utf8' + ) + ).toMatchSnapshot('core bundle'); + expect( Fs.readFileSync(Path.resolve(MOCK_REPO_DIR, 'plugins/foo/target/public/foo.plugin.js'), 'utf8') ).toMatchSnapshot('foo bundle'); @@ -198,6 +205,7 @@ it('uses cache on second run and exist cleanly', async () => { "initializing", "initializing", "initializing", + "initializing", "initialized", "success", ] diff --git a/packages/kbn-optimizer/src/integration_tests/bundle_cache.test.ts b/packages/kbn-optimizer/src/integration_tests/bundle_cache.test.ts index 1bfd8d3fd073a2..bfcaa04b679be5 100644 --- a/packages/kbn-optimizer/src/integration_tests/bundle_cache.test.ts +++ b/packages/kbn-optimizer/src/integration_tests/bundle_cache.test.ts @@ -83,6 +83,11 @@ it('emits "bundle cached" event when everything is updated', async () => { expect(cacheEvents).toMatchInlineSnapshot(` Array [ + Object { + "bundle": , + "reason": "missing optimizer cache key", + "type": "bundle not cached", + }, Object { "bundle": , "type": "bundle cached", @@ -128,6 +133,11 @@ it('emits "bundle not cached" event when cacheKey is up to date but caching is d "reason": "cache disabled", "type": "bundle not cached", }, + Object { + "bundle": , + "reason": "cache disabled", + "type": "bundle not cached", + }, ] `); }); @@ -168,6 +178,11 @@ it('emits "bundle not cached" event when optimizerCacheKey is missing', async () "reason": "missing optimizer cache key", "type": "bundle not cached", }, + Object { + "bundle": , + "reason": "missing optimizer cache key", + "type": "bundle not cached", + }, ] `); }); @@ -213,6 +228,11 @@ it('emits "bundle not cached" event when optimizerCacheKey is outdated, includes "reason": "optimizer cache key mismatch", "type": "bundle not cached", }, + Object { + "bundle": , + "reason": "missing optimizer cache key", + "type": "bundle not cached", + }, ] `); }); @@ -251,6 +271,11 @@ it('emits "bundle not cached" event when cacheKey is missing', async () => { "reason": "missing cache key", "type": "bundle not cached", }, + Object { + "bundle": , + "reason": "missing optimizer cache key", + "type": "bundle not cached", + }, ] `); }); @@ -286,6 +311,11 @@ it('emits "bundle not cached" event when cacheKey is outdated', async () => { expect(cacheEvents).toMatchInlineSnapshot(` Array [ + Object { + "bundle": , + "reason": "missing optimizer cache key", + "type": "bundle not cached", + }, Object { "bundle": , "diff": "- Expected diff --git a/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts b/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts index 9d95d883d605c9..879d33202f4ff4 100644 --- a/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts +++ b/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts @@ -23,7 +23,7 @@ import { getBundles } from './get_bundles'; expect.addSnapshotSerializer(createAbsolutePathSerializer('/repo')); -it('returns a bundle for each plugin', () => { +it('returns a bundle for core and each plugin', () => { expect( getBundles( [ @@ -47,6 +47,14 @@ it('returns a bundle for each plugin', () => { ).map(b => b.toSpec()) ).toMatchInlineSnapshot(` Array [ + Object { + "contextDir": /src/core, + "entry": "./public/entry_point", + "id": "core", + "outputDir": /src/core/public/target/public, + "sourceRoot": , + "type": "standalone", + }, Object { "contextDir": /plugins/foo, "entry": "./public/index", diff --git a/packages/kbn-optimizer/src/worker/webpack.config.ts b/packages/kbn-optimizer/src/worker/webpack.config.ts index f8fa93765632c2..2db2c5803a64e2 100644 --- a/packages/kbn-optimizer/src/worker/webpack.config.ts +++ b/packages/kbn-optimizer/src/worker/webpack.config.ts @@ -104,7 +104,7 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) { output: { path: bundle.outputDir, - filename: '[name].plugin.js', + filename: `[name].${bundle.type}.js`, publicPath: PUBLIC_PATH_PLACEHOLDER, devtoolModuleFilenameTemplate: info => `/${bundle.type}:${bundle.id}/${Path.relative( diff --git a/src/legacy/ui/ui_render/bootstrap/template.js.hbs b/src/legacy/ui/ui_render/bootstrap/template.js.hbs index 8be31c27dfcf45..5c98d70edee6cc 100644 --- a/src/legacy/ui/ui_render/bootstrap/template.js.hbs +++ b/src/legacy/ui/ui_render/bootstrap/template.js.hbs @@ -81,7 +81,7 @@ if (window.__kbnStrictCsp__ && window.__kbnCspNotEnforced__) { '{{regularBundlePath}}/plugin/kibanaReact/kibanaReact.plugin.js' ], function() { load([ - '{{regularBundlePath}}/core/core.plugin.js', + '{{regularBundlePath}}/core/core.standalone.js', {{#each styleSheetPaths}} '{{this}}', {{/each}} From ef11745c2fe612724daefbed36d8e6de4371b0c2 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Thu, 9 Apr 2020 14:58:26 -0600 Subject: [PATCH 05/16] Rename standalone to entry, fix bootstrap --- packages/kbn-optimizer/src/common/bundle.ts | 2 +- .../basic_optimization.test.ts.snap | 8 ++--- .../basic_optimization.test.ts | 2 +- .../src/optimizer/get_bundles.test.ts | 2 +- .../src/optimizer/get_bundles.ts | 2 +- .../ui/ui_render/bootstrap/template.js.hbs | 31 +++++++------------ 6 files changed, 17 insertions(+), 30 deletions(-) diff --git a/packages/kbn-optimizer/src/common/bundle.ts b/packages/kbn-optimizer/src/common/bundle.ts index 40f7aa600892b9..7581b90d60af23 100644 --- a/packages/kbn-optimizer/src/common/bundle.ts +++ b/packages/kbn-optimizer/src/common/bundle.ts @@ -23,7 +23,7 @@ import { BundleCache } from './bundle_cache'; import { UnknownVals } from './ts_helpers'; import { includes, ascending, entriesToObject } from './array_helpers'; -const VALID_BUNDLE_TYPES = ['plugin' as const, 'standalone' as const]; +const VALID_BUNDLE_TYPES = ['plugin' as const, 'entry' as const]; export interface BundleSpec { readonly type: typeof VALID_BUNDLE_TYPES[0]; diff --git a/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap b/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap index fe9a699e37de18..85f1c29950f12d 100644 --- a/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap +++ b/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap @@ -15,7 +15,7 @@ OptimizerConfig { "id": "core", "outputDir": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/public/target/public, "sourceRoot": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo, - "type": "standalone", + "type": "entry", }, Bundle { "cache": BundleCache { @@ -71,10 +71,6 @@ OptimizerConfig { exports[`builds expected bundles, saves bundle counts to metadata: bar bundle 1`] = `"var __kbnBundles__=typeof __kbnBundles__===\\"object\\"?__kbnBundles__:{};__kbnBundles__[\\"plugin/bar\\"]=function(modules){function webpackJsonpCallback(data){var chunkIds=data[0];var moreModules=data[1];var moduleId,chunkId,i=0,resolves=[];for(;i>>>>>> Update kbn-optimizer tests +exports[`builds expected bundles, saves bundle counts to metadata: foo bundle 1`] = `"var __kbnBundles__=typeof __kbnBundles__===\\"object\\"?__kbnBundles__:{};__kbnBundles__[\\"plugin/foo\\"]=function(modules){function webpackJsonpCallback(data){var chunkIds=data[0];var moreModules=data[1];var moduleId,chunkId,i=0,resolves=[];for(;i { expect( Fs.readFileSync( - Path.resolve(MOCK_REPO_DIR, 'src/core/public/target/public/core.standalone.js'), + Path.resolve(MOCK_REPO_DIR, 'src/core/public/target/public/core.entry.js'), 'utf8' ) ).toMatchSnapshot('core bundle'); diff --git a/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts b/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts index 879d33202f4ff4..9bc51ad8d88e4e 100644 --- a/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts +++ b/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts @@ -53,7 +53,7 @@ it('returns a bundle for core and each plugin', () => { "id": "core", "outputDir": /src/core/public/target/public, "sourceRoot": , - "type": "standalone", + "type": "entry", }, Object { "contextDir": /plugins/foo, diff --git a/packages/kbn-optimizer/src/optimizer/get_bundles.ts b/packages/kbn-optimizer/src/optimizer/get_bundles.ts index 364099102fa22f..110891565c27a5 100644 --- a/packages/kbn-optimizer/src/optimizer/get_bundles.ts +++ b/packages/kbn-optimizer/src/optimizer/get_bundles.ts @@ -25,7 +25,7 @@ import { KibanaPlatformPlugin } from './kibana_platform_plugins'; export function getBundles(plugins: KibanaPlatformPlugin[], repoRoot: string) { const coreBundle = new Bundle({ - type: 'standalone', + type: 'entry', id: 'core', entry: './public/entry_point', sourceRoot: repoRoot, diff --git a/src/legacy/ui/ui_render/bootstrap/template.js.hbs b/src/legacy/ui/ui_render/bootstrap/template.js.hbs index 5c98d70edee6cc..66d86be41abdb2 100644 --- a/src/legacy/ui/ui_render/bootstrap/template.js.hbs +++ b/src/legacy/ui/ui_render/bootstrap/template.js.hbs @@ -70,28 +70,23 @@ if (window.__kbnStrictCsp__ && window.__kbnCspNotEnforced__) { // When rendering in Kibana Platform mode, only serve the assets needed by Core. if ('{{appId}}' === 'core') { - return load({ - deps: [ + load([ {{#each sharedJsDepFilenames}} '{{../regularBundlePath}}/kbn-ui-shared-deps/{{this}}', {{/each}} '{{regularBundlePath}}/kbn-ui-shared-deps/{{sharedJsFilename}}', '{{regularBundlePath}}/plugin/kibanaUtils/kibanaUtils.plugin.js', '{{regularBundlePath}}/plugin/esUiShared/esUiShared.plugin.js', - '{{regularBundlePath}}/plugin/kibanaReact/kibanaReact.plugin.js' - ], function() { - load([ - '{{regularBundlePath}}/core/core.standalone.js', - {{#each styleSheetPaths}} - '{{this}}', - {{/each}} - ]) - }, - }); + '{{regularBundlePath}}/plugin/kibanaReact/kibanaReact.plugin.js', + '{{regularBundlePath}}/core/core.entry.js', + {{#each styleSheetPaths}} + '{{this}}', + {{/each}} + ]); + return; } - load({ - deps: [ + load([ {{#each sharedJsDepFilenames}} '{{../regularBundlePath}}/kbn-ui-shared-deps/{{this}}', {{/each}} @@ -101,17 +96,13 @@ if (window.__kbnStrictCsp__ && window.__kbnCspNotEnforced__) { '{{this}}', {{/each}} '{{regularBundlePath}}/commons.bundle.js', - {{!-- '{{regularBundlePath}}/plugin/data/data.plugin.js', --}} '{{regularBundlePath}}/plugin/kibanaUtils/kibanaUtils.plugin.js', '{{regularBundlePath}}/plugin/esUiShared/esUiShared.plugin.js', - '{{regularBundlePath}}/plugin/kibanaReact/kibanaReact.plugin.js' - ], function () { - load([ + '{{regularBundlePath}}/plugin/kibanaReact/kibanaReact.plugin.js', '{{regularBundlePath}}/{{appId}}.bundle.js', {{#each styleSheetPaths}} '{{this}}', {{/each}} - ]) - }); + ]); }; } From 79c1a43bf8da29807ad126001a06d2e2aae25c5c Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Thu, 9 Apr 2020 15:18:12 -0600 Subject: [PATCH 06/16] Avoid importing all of react-use in core --- src/core/public/application/ui/app_router.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/public/application/ui/app_router.tsx b/src/core/public/application/ui/app_router.tsx index 61c8bc3cadae5c..4c135c57690676 100644 --- a/src/core/public/application/ui/app_router.tsx +++ b/src/core/public/application/ui/app_router.tsx @@ -21,7 +21,7 @@ import React, { FunctionComponent, useMemo } from 'react'; import { Route, RouteComponentProps, Router, Switch } from 'react-router-dom'; import { History } from 'history'; import { Observable } from 'rxjs'; -import { useObservable } from 'react-use'; +import useObservable from 'react-use/lib/useObservable'; import { AppLeaveHandler, AppStatus, Mounter } from '../types'; import { AppContainer } from './app_container'; From 32c572ae7eaad8355728465a3efd4148e8d76b36 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Sun, 19 Apr 2020 10:40:55 -0600 Subject: [PATCH 07/16] PR comments --- .../src/optimizer/get_bundles.ts | 2 +- src/core/public/core_system.test.ts | 2 +- src/core/public/entry_point.ts | 1 + src/core/public/index.scss | 49 ++++++++++++++- .../__snapshots__/legacy_service.test.ts.snap | 26 -------- src/core/public/legacy/legacy_service.test.ts | 55 ++++++++++++++++- src/legacy/ui/public/_index.scss | 1 - src/legacy/ui/public/chrome/_index.scss | 3 - src/legacy/ui/public/chrome/_variables.scss | 4 -- .../ui/public/chrome/directives/_index.scss | 1 - .../public/chrome/directives/_kbn_chrome.scss | 46 -------------- .../ui/ui_render/bootstrap/template.js.hbs | 37 ++---------- src/legacy/ui/ui_render/ui_render_mixin.js | 60 +++++++++++++------ src/optimize/bundles_route/bundles_route.js | 5 +- .../public/angular/templates/_graph.scss | 2 - 15 files changed, 152 insertions(+), 142 deletions(-) delete mode 100644 src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap delete mode 100644 src/legacy/ui/public/chrome/_index.scss delete mode 100644 src/legacy/ui/public/chrome/_variables.scss delete mode 100644 src/legacy/ui/public/chrome/directives/_index.scss delete mode 100644 src/legacy/ui/public/chrome/directives/_kbn_chrome.scss diff --git a/packages/kbn-optimizer/src/optimizer/get_bundles.ts b/packages/kbn-optimizer/src/optimizer/get_bundles.ts index 110891565c27a5..b20ee6dcfdd538 100644 --- a/packages/kbn-optimizer/src/optimizer/get_bundles.ts +++ b/packages/kbn-optimizer/src/optimizer/get_bundles.ts @@ -30,7 +30,7 @@ export function getBundles(plugins: KibanaPlatformPlugin[], repoRoot: string) { entry: './public/entry_point', sourceRoot: repoRoot, contextDir: Path.resolve(repoRoot, 'src/core'), - outputDir: Path.resolve(repoRoot, 'src/core/public/target/public'), + outputDir: Path.resolve(repoRoot, 'src/core/target/public'), }); const pluginBundles = plugins diff --git a/src/core/public/core_system.test.ts b/src/core/public/core_system.test.ts index 559dadfc3dba4b..a42719417a2b17 100644 --- a/src/core/public/core_system.test.ts +++ b/src/core/public/core_system.test.ts @@ -103,7 +103,7 @@ describe('constructor', () => { }); }); - it('passes requireLegacyFiles, requireNewPlatformShimModule, requireLegacyBootstrapModule and a dom element to LegacyPlatformService', () => { + it('passes required params to LegacyPlatformService', () => { const requireLegacyFiles = { requireLegacyFiles: true }; const requireLegacyBootstrapModule = { requireLegacyBootstrapModule: true }; const requireNewPlatformShimModule = { requireNewPlatformShimModule: true }; diff --git a/src/core/public/entry_point.ts b/src/core/public/entry_point.ts index 847d5dbcb413b1..c40fc5247d28c4 100644 --- a/src/core/public/entry_point.ts +++ b/src/core/public/entry_point.ts @@ -22,6 +22,7 @@ * that lives in the Kibana Platform. */ +import './index.scss'; import { i18n } from '@kbn/i18n'; import { CoreSystem } from './core_system'; diff --git a/src/core/public/index.scss b/src/core/public/index.scss index 86f2efdff77020..104819632572ee 100644 --- a/src/core/public/index.scss +++ b/src/core/public/index.scss @@ -7,5 +7,52 @@ // Mixins provide generic code expansion through helpers @import '@elastic/eui/src/global_styling/mixins/index'; +$kbnGlobalNavClosedWidth: 53px; +$kbnGlobalNavOpenWidth: 180px; +$kbnGlobalNavLogoHeight: 70px; +$kbnGlobalNavAppIconHeight: $euiSizeXXL + $euiSizeXS; + +#kibana-body { + overflow-x: hidden; + min-height: 100%; +} + +.app-wrapper { + display: flex; + flex-flow: column nowrap; + position: absolute; + left: $kbnGlobalNavClosedWidth; + top: 0; + right: 0; + bottom: 0; + z-index: 5; + margin: 0 auto; + + /** + * 1. Dirty, but we need to override the .kbnGlobalNav-isOpen state + * when we're looking at the log-in screen. + */ + &.hidden-chrome { + left: 0 !important; /* 1 */ + } + + .navbar-right { + margin-right: 0; + } +} + +.app-wrapper-panel { + display: flex; + flex-grow: 1; + flex-shrink: 0; + flex-basis: auto; + flex-direction: column; + + > * { + flex-shrink: 0; + } +} + + @import './chrome/index'; -@import './overlays/index'; +@import './overlays/index'; \ No newline at end of file diff --git a/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap b/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap deleted file mode 100644 index 304d748f88020c..00000000000000 --- a/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap +++ /dev/null @@ -1,26 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`#start() load order loads ui/modules before ui/chrome, and both before legacy files 1`] = ` -Array [ - "ui/chrome", - "legacy files", -] -`; - -exports[`#stop() destroys the angular scope and empties the targetDomElement if angular is bootstrapped to targetDomElement 1`] = ` -
-`; - -exports[`#stop() does nothing if angular was not bootstrapped to targetDomElement 1`] = ` -
- - -

- this should not be removed -

- - -
-`; diff --git a/src/core/public/legacy/legacy_service.test.ts b/src/core/public/legacy/legacy_service.test.ts index 73d615042ef041..fa29320aab4e67 100644 --- a/src/core/public/legacy/legacy_service.test.ts +++ b/src/core/public/legacy/legacy_service.test.ts @@ -124,6 +124,21 @@ describe('#setup()', () => { expect(mockUiNewPlatformSetup).toHaveBeenCalledTimes(1); expect(mockUiNewPlatformSetup).toHaveBeenCalledWith(expect.any(Object), {}); }); + + it('throws error if requireNewPlatformShimModule is undefined', () => { + const legacyPlatform = new LegacyPlatformService({ + ...defaultParams, + requireNewPlatformShimModule: undefined, + }); + + expect(() => { + legacyPlatform.setup(defaultSetupDeps); + }).toThrowErrorMatchingInlineSnapshot( + `"requireNewPlatformShimModule must be specified when rendering a legacy application"` + ); + + expect(mockUiNewPlatformSetup).not.toHaveBeenCalled(); + }); }); }); @@ -157,6 +172,21 @@ describe('#start()', () => { expect(mockUiNewPlatformStart).toHaveBeenCalledWith(expect.any(Object), {}); }); + it('throws error if requireNewPlatformShimeModule is undefined', () => { + const legacyPlatform = new LegacyPlatformService({ + ...defaultParams, + requireNewPlatformShimModule: undefined, + }); + + expect(() => { + legacyPlatform.start(defaultStartDeps); + }).toThrowErrorMatchingInlineSnapshot( + `"requireNewPlatformShimModule must be specified when rendering a legacy application"` + ); + + expect(mockUiNewPlatformStart).not.toHaveBeenCalled(); + }); + it('resolves getStartServices with core and plugin APIs', async () => { const legacyPlatform = new LegacyPlatformService({ ...defaultParams, @@ -194,7 +224,12 @@ describe('#start()', () => { legacyPlatform.setup(defaultSetupDeps); legacyPlatform.start(defaultStartDeps); - expect(mockLoadOrder).toMatchSnapshot(); + expect(mockLoadOrder).toMatchInlineSnapshot(` + Array [ + "ui/chrome", + "legacy files", + ] + `); }); }); }); @@ -211,7 +246,17 @@ describe('#stop()', () => { }); legacyPlatform.stop(); - expect(targetDomElement).toMatchSnapshot(); + expect(targetDomElement).toMatchInlineSnapshot(` +
+ + +

+ this should not be removed +

+ + +
+ `); }); it('destroys the angular scope and empties the targetDomElement if angular is bootstrapped to targetDomElement', async () => { @@ -240,7 +285,11 @@ describe('#stop()', () => { legacyPlatform.start({ ...defaultStartDeps, targetDomElement }); legacyPlatform.stop(); - expect(targetDomElement).toMatchSnapshot(); + expect(targetDomElement).toMatchInlineSnapshot(` +
+ `); expect(scopeDestroySpy).toHaveBeenCalledTimes(1); }); }); diff --git a/src/legacy/ui/public/_index.scss b/src/legacy/ui/public/_index.scss index aaed52f8b120a9..b36e62297cc235 100644 --- a/src/legacy/ui/public/_index.scss +++ b/src/legacy/ui/public/_index.scss @@ -9,7 +9,6 @@ // kbnChart__legend-isLoading @import './accessibility/index'; -@import './chrome/index'; @import './directives/index'; @import './error_auto_create_index/index'; @import './error_url_overflow/index'; diff --git a/src/legacy/ui/public/chrome/_index.scss b/src/legacy/ui/public/chrome/_index.scss deleted file mode 100644 index 7e6c3ebaccc5cc..00000000000000 --- a/src/legacy/ui/public/chrome/_index.scss +++ /dev/null @@ -1,3 +0,0 @@ -@import './variables'; - -@import './directives/index'; diff --git a/src/legacy/ui/public/chrome/_variables.scss b/src/legacy/ui/public/chrome/_variables.scss deleted file mode 100644 index 5097fe4c9bfae1..00000000000000 --- a/src/legacy/ui/public/chrome/_variables.scss +++ /dev/null @@ -1,4 +0,0 @@ -$kbnGlobalNavClosedWidth: 53px; -$kbnGlobalNavOpenWidth: 180px; -$kbnGlobalNavLogoHeight: 70px; -$kbnGlobalNavAppIconHeight: $euiSizeXXL + $euiSizeXS; diff --git a/src/legacy/ui/public/chrome/directives/_index.scss b/src/legacy/ui/public/chrome/directives/_index.scss deleted file mode 100644 index 4d00b022791168..00000000000000 --- a/src/legacy/ui/public/chrome/directives/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import './kbn_chrome'; diff --git a/src/legacy/ui/public/chrome/directives/_kbn_chrome.scss b/src/legacy/ui/public/chrome/directives/_kbn_chrome.scss deleted file mode 100644 index b29a83848d2913..00000000000000 --- a/src/legacy/ui/public/chrome/directives/_kbn_chrome.scss +++ /dev/null @@ -1,46 +0,0 @@ -/** - * stretch the root element of the Kibana application to set the base-size that - * flexed children should keep. Only works when paired with root styles applied - * by core service from new platform - */ -// SASSTODO: Naming here is too embedded and high up that changing them could cause major breaks -#kibana-body { - overflow-x: hidden; - min-height: 100%; -} - -.app-wrapper { - display: flex; - flex-flow: column nowrap; - position: absolute; - left: $kbnGlobalNavClosedWidth; - top: 0; - right: 0; - bottom: 0; - z-index: 5; - margin: 0 auto; - - /** - * 1. Dirty, but we need to override the .kbnGlobalNav-isOpen state - * when we're looking at the log-in screen. - */ - &.hidden-chrome { - left: 0 !important; /* 1 */ - } - - .navbar-right { - margin-right: 0; - } -} - -.app-wrapper-panel { - display: flex; - flex-grow: 1; - flex-shrink: 0; - flex-basis: auto; - flex-direction: column; - - > * { - flex-shrink: 0; - } -} diff --git a/src/legacy/ui/ui_render/bootstrap/template.js.hbs b/src/legacy/ui/ui_render/bootstrap/template.js.hbs index 2d0792cb78c2af..ffabc6a33b61fb 100644 --- a/src/legacy/ui/ui_render/bootstrap/template.js.hbs +++ b/src/legacy/ui/ui_render/bootstrap/template.js.hbs @@ -68,44 +68,17 @@ if (window.__kbnStrictCsp__ && window.__kbnCspNotEnforced__) { }); } - // When rendering in Kibana Platform mode, only serve the assets needed by Core. - if ('{{appId}}' === 'core') { - load([ - {{#each sharedJsDepFilenames}} - '{{../regularBundlePath}}/kbn-ui-shared-deps/{{this}}', - {{/each}} - '{{regularBundlePath}}/kbn-ui-shared-deps/{{sharedJsFilename}}', - '{{regularBundlePath}}/plugin/kibanaUtils/kibanaUtils.plugin.js', - '{{regularBundlePath}}/plugin/esUiShared/esUiShared.plugin.js', - '{{regularBundlePath}}/plugin/kibanaReact/kibanaReact.plugin.js', - '{{regularBundlePath}}/core/core.entry.js', - {{#each styleSheetPaths}} - '{{this}}', - {{/each}} - ]); - return; - } - load([ - {{#each sharedJsDepFilenames}} - '{{../regularBundlePath}}/kbn-ui-shared-deps/{{this}}', - {{/each}} - '{{regularBundlePath}}/kbn-ui-shared-deps/{{sharedJsFilename}}', - '{{dllBundlePath}}/vendors_runtime.bundle.dll.js', - {{#each dllJsChunks}} + {{#each jsDependencies}} '{{this}}', {{/each}} - '{{regularBundlePath}}/commons.bundle.js', - {{!-- '{{regularBundlePath}}/plugin:data/data.plugin.js', --}} - '{{regularBundlePath}}/plugin:kibanaUtils/kibanaUtils.plugin.js', - '{{regularBundlePath}}/plugin:esUiShared/esUiShared.plugin.js', - '{{regularBundlePath}}/plugin:kibanaReact/kibanaReact.plugin.js' ], function () { load([ - '{{regularBundlePath}}/{{appId}}.bundle.js', + '{{entryBundle}}', {{#each styleSheetPaths}} '{{this}}', {{/each}} - ]); - }; + ]); + }); + } } diff --git a/src/legacy/ui/ui_render/ui_render_mixin.js b/src/legacy/ui/ui_render/ui_render_mixin.js index 0912d8683fc485..e4813bd4c56def 100644 --- a/src/legacy/ui/ui_render/ui_render_mixin.js +++ b/src/legacy/ui/ui_render/ui_render_mixin.js @@ -103,8 +103,9 @@ export function uiRenderMixin(kbnServer, server, config) { const dllJsChunks = DllCompiler.getRawDllConfig().chunks.map( chunk => `${dllBundlePath}/vendors${chunk}.bundle.dll.js` ); + const styleSheetPaths = [ - ...dllStyleChunks, + ...(isCore ? [] : dllStyleChunks), `${basePath}/bundles/kbn-ui-shared-deps/${UiSharedDeps.baseCssDistFilename}`, ...(darkMode ? [ @@ -115,29 +116,50 @@ export function uiRenderMixin(kbnServer, server, config) { `${basePath}/bundles/kbn-ui-shared-deps/${UiSharedDeps.lightCssDistFilename}`, `${basePath}/node_modules/@kbn/ui-framework/dist/kui_light.css`, ]), - `${regularBundlePath}/${darkMode ? 'dark' : 'light'}_theme.style.css`, - `${regularBundlePath}/commons.style.css`, - ...(!isCore ? [`${regularBundlePath}/${app.getId()}.style.css`] : []), - ...kbnServer.uiExports.styleSheetPaths - .filter(path => path.theme === '*' || path.theme === (darkMode ? 'dark' : 'light')) - .map(path => - path.localPath.endsWith('.scss') - ? `${basePath}/built_assets/css/${path.publicPath}` - : `${basePath}/${path.publicPath}` - ) - .reverse(), + ...(isCore + ? [] + : [ + `${regularBundlePath}/${darkMode ? 'dark' : 'light'}_theme.style.css`, + `${regularBundlePath}/commons.style.css`, + `${regularBundlePath}/${app.getId()}.style.css`, + ...kbnServer.uiExports.styleSheetPaths + .filter( + path => path.theme === '*' || path.theme === (darkMode ? 'dark' : 'light') + ) + .map(path => + path.localPath.endsWith('.scss') + ? `${basePath}/built_assets/css/${path.publicPath}` + : `${basePath}/${path.publicPath}` + ) + .reverse(), + ]), + ]; + + const jsDependencies = [ + ...UiSharedDeps.jsDepFilenames.map( + filename => `${regularBundlePath}/kbn-ui-shared-deps/${filename}` + ), + `${regularBundlePath}/kbn-ui-shared-deps/${UiSharedDeps.jsFilename}`, + ...(isCore + ? [] + : [ + `${dllBundlePath}/vendors_runtime.bundle.dll.js`, + ...dllJsChunks, + `${regularBundlePath}/commons.bundle.js`, + ]), + `${regularBundlePath}/plugin:kibanaUtils/kibanaUtils.plugin.js`, + `${regularBundlePath}/plugin:esUiShared/esUiShared.plugin.js`, + `${regularBundlePath}/plugin:kibanaReact/kibanaReact.plugin.js`, ]; const bootstrap = new AppBootstrap({ templateData: { - appId: isCore ? 'core' : app.getId(), - regularBundlePath, - dllBundlePath, - dllJsChunks, - styleSheetPaths, - sharedJsFilename: UiSharedDeps.jsFilename, - sharedJsDepFilenames: UiSharedDeps.jsDepFilenames, darkMode, + jsDependencies, + styleSheetPaths, + entryBundle: isCore + ? `${regularBundlePath}/core/core.entry.js` + : `${regularBundlePath}/${app.getId()}.bundle.js`, }, }); diff --git a/src/optimize/bundles_route/bundles_route.js b/src/optimize/bundles_route/bundles_route.js index 24bc11eede7f48..f15760795391a2 100644 --- a/src/optimize/bundles_route/bundles_route.js +++ b/src/optimize/bundles_route/bundles_route.js @@ -17,11 +17,12 @@ * under the License. */ -import { isAbsolute, extname, resolve, join } from 'path'; +import { isAbsolute, extname, join } from 'path'; import LruCache from 'lru-cache'; import * as UiSharedDeps from '@kbn/ui-shared-deps'; import { createDynamicAssetResponse } from './dynamic_asset_response'; import { assertIsNpUiPluginPublicDirs } from '../np_ui_plugin_public_dirs'; +import { fromRoot } from '../../core/server/utils'; /** * Creates the routes that serves files from `bundlesPath` or from @@ -88,7 +89,7 @@ export function createBundlesRoute({ buildRouteForBundles( `${basePublicPath}/bundles/core/`, `/bundles/core/`, - resolve(__dirname, join('..', '..', 'core', 'public', 'target', 'public')), + fromRoot(join('src', 'core', 'target', 'public')), fileHashCache ), buildRouteForBundles( diff --git a/x-pack/plugins/graph/public/angular/templates/_graph.scss b/x-pack/plugins/graph/public/angular/templates/_graph.scss index e6bd4693d1e9b8..4ba65e7ec6b96a 100644 --- a/x-pack/plugins/graph/public/angular/templates/_graph.scss +++ b/x-pack/plugins/graph/public/angular/templates/_graph.scss @@ -1,5 +1,3 @@ -@import 'src/legacy/ui/public/chrome/variables'; - @mixin gphSvgText() { font-family: $euiFontFamily; font-size: $euiSizeS; From f9cc17d924527d3e093626c62040c64a2d1c2bbc Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Sun, 19 Apr 2020 12:15:21 -0600 Subject: [PATCH 08/16] Fix legacy CSS --- src/core/public/index.scss | 4 +++- src/legacy/ui/ui_render/ui_render_mixin.js | 4 ++-- x-pack/plugins/graph/public/index.scss | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/public/index.scss b/src/core/public/index.scss index 104819632572ee..7ab70c244e9a6b 100644 --- a/src/core/public/index.scss +++ b/src/core/public/index.scss @@ -55,4 +55,6 @@ $kbnGlobalNavAppIconHeight: $euiSizeXXL + $euiSizeXS; @import './chrome/index'; -@import './overlays/index'; \ No newline at end of file +@import './overlays/index'; +// Global styles need to be migrated +@import '../../legacy/ui/public/styles/_legacy/_index'; diff --git a/src/legacy/ui/ui_render/ui_render_mixin.js b/src/legacy/ui/ui_render/ui_render_mixin.js index e4813bd4c56def..14d8e8650254e9 100644 --- a/src/legacy/ui/ui_render/ui_render_mixin.js +++ b/src/legacy/ui/ui_render/ui_render_mixin.js @@ -116,11 +116,11 @@ export function uiRenderMixin(kbnServer, server, config) { `${basePath}/bundles/kbn-ui-shared-deps/${UiSharedDeps.lightCssDistFilename}`, `${basePath}/node_modules/@kbn/ui-framework/dist/kui_light.css`, ]), + `${regularBundlePath}/${darkMode ? 'dark' : 'light'}_theme.style.css`, + `${regularBundlePath}/commons.style.css`, ...(isCore ? [] : [ - `${regularBundlePath}/${darkMode ? 'dark' : 'light'}_theme.style.css`, - `${regularBundlePath}/commons.style.css`, `${regularBundlePath}/${app.getId()}.style.css`, ...kbnServer.uiExports.styleSheetPaths .filter( diff --git a/x-pack/plugins/graph/public/index.scss b/x-pack/plugins/graph/public/index.scss index f4e38de3e93a44..964ef320e4352c 100644 --- a/x-pack/plugins/graph/public/index.scss +++ b/x-pack/plugins/graph/public/index.scss @@ -12,3 +12,5 @@ @import './main'; @import './angular/templates/index'; @import './components/index'; +// Local application mount wrapper styles +@import 'src/legacy/core_plugins/kibana/public/local_application_service/index'; From af039ee8f2e6437d9db3fc32c246bf8dc1eadc55 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Sun, 19 Apr 2020 12:16:13 -0600 Subject: [PATCH 09/16] Fix optimizer test --- .../__snapshots__/basic_optimization.test.ts.snap | 4 ++-- packages/kbn-optimizer/src/optimizer/get_bundles.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap b/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap index 85f1c29950f12d..4b9a6562ffeca5 100644 --- a/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap +++ b/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap @@ -7,13 +7,13 @@ OptimizerConfig { "bundles": Array [ Bundle { "cache": BundleCache { - "path": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/public/target/public/.kbn-optimizer-cache, + "path": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/target/public/.kbn-optimizer-cache, "state": undefined, }, "contextDir": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core, "entry": "./public/entry_point", "id": "core", - "outputDir": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/public/target/public, + "outputDir": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/target/public, "sourceRoot": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo, "type": "entry", }, diff --git a/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts b/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts index 9bc51ad8d88e4e..e52ec2ca664de7 100644 --- a/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts +++ b/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts @@ -51,7 +51,7 @@ it('returns a bundle for core and each plugin', () => { "contextDir": /src/core, "entry": "./public/entry_point", "id": "core", - "outputDir": /src/core/public/target/public, + "outputDir": /src/core/target/public, "sourceRoot": , "type": "entry", }, From 6834f591d2df42a120f5d2b028f92e567eaf7f10 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Mon, 20 Apr 2020 11:50:13 -0600 Subject: [PATCH 10/16] Rollback css changes --- src/core/public/index.scss | 49 ------------------- src/legacy/ui/public/_index.scss | 1 + src/legacy/ui/public/chrome/_index.scss | 3 ++ src/legacy/ui/public/chrome/_variables.scss | 4 ++ .../ui/public/chrome/directives/_index.scss | 1 + .../public/chrome/directives/_kbn_chrome.scss | 46 +++++++++++++++++ .../public/angular/templates/_graph.scss | 2 + x-pack/plugins/graph/public/index.scss | 2 - 8 files changed, 57 insertions(+), 51 deletions(-) create mode 100644 src/legacy/ui/public/chrome/_index.scss create mode 100644 src/legacy/ui/public/chrome/_variables.scss create mode 100644 src/legacy/ui/public/chrome/directives/_index.scss create mode 100644 src/legacy/ui/public/chrome/directives/_kbn_chrome.scss diff --git a/src/core/public/index.scss b/src/core/public/index.scss index 7ab70c244e9a6b..86f2efdff77020 100644 --- a/src/core/public/index.scss +++ b/src/core/public/index.scss @@ -7,54 +7,5 @@ // Mixins provide generic code expansion through helpers @import '@elastic/eui/src/global_styling/mixins/index'; -$kbnGlobalNavClosedWidth: 53px; -$kbnGlobalNavOpenWidth: 180px; -$kbnGlobalNavLogoHeight: 70px; -$kbnGlobalNavAppIconHeight: $euiSizeXXL + $euiSizeXS; - -#kibana-body { - overflow-x: hidden; - min-height: 100%; -} - -.app-wrapper { - display: flex; - flex-flow: column nowrap; - position: absolute; - left: $kbnGlobalNavClosedWidth; - top: 0; - right: 0; - bottom: 0; - z-index: 5; - margin: 0 auto; - - /** - * 1. Dirty, but we need to override the .kbnGlobalNav-isOpen state - * when we're looking at the log-in screen. - */ - &.hidden-chrome { - left: 0 !important; /* 1 */ - } - - .navbar-right { - margin-right: 0; - } -} - -.app-wrapper-panel { - display: flex; - flex-grow: 1; - flex-shrink: 0; - flex-basis: auto; - flex-direction: column; - - > * { - flex-shrink: 0; - } -} - - @import './chrome/index'; @import './overlays/index'; -// Global styles need to be migrated -@import '../../legacy/ui/public/styles/_legacy/_index'; diff --git a/src/legacy/ui/public/_index.scss b/src/legacy/ui/public/_index.scss index b36e62297cc235..aaed52f8b120a9 100644 --- a/src/legacy/ui/public/_index.scss +++ b/src/legacy/ui/public/_index.scss @@ -9,6 +9,7 @@ // kbnChart__legend-isLoading @import './accessibility/index'; +@import './chrome/index'; @import './directives/index'; @import './error_auto_create_index/index'; @import './error_url_overflow/index'; diff --git a/src/legacy/ui/public/chrome/_index.scss b/src/legacy/ui/public/chrome/_index.scss new file mode 100644 index 00000000000000..7e6c3ebaccc5cc --- /dev/null +++ b/src/legacy/ui/public/chrome/_index.scss @@ -0,0 +1,3 @@ +@import './variables'; + +@import './directives/index'; diff --git a/src/legacy/ui/public/chrome/_variables.scss b/src/legacy/ui/public/chrome/_variables.scss new file mode 100644 index 00000000000000..5097fe4c9bfae1 --- /dev/null +++ b/src/legacy/ui/public/chrome/_variables.scss @@ -0,0 +1,4 @@ +$kbnGlobalNavClosedWidth: 53px; +$kbnGlobalNavOpenWidth: 180px; +$kbnGlobalNavLogoHeight: 70px; +$kbnGlobalNavAppIconHeight: $euiSizeXXL + $euiSizeXS; diff --git a/src/legacy/ui/public/chrome/directives/_index.scss b/src/legacy/ui/public/chrome/directives/_index.scss new file mode 100644 index 00000000000000..4d00b022791168 --- /dev/null +++ b/src/legacy/ui/public/chrome/directives/_index.scss @@ -0,0 +1 @@ +@import './kbn_chrome'; diff --git a/src/legacy/ui/public/chrome/directives/_kbn_chrome.scss b/src/legacy/ui/public/chrome/directives/_kbn_chrome.scss new file mode 100644 index 00000000000000..b29a83848d2913 --- /dev/null +++ b/src/legacy/ui/public/chrome/directives/_kbn_chrome.scss @@ -0,0 +1,46 @@ +/** + * stretch the root element of the Kibana application to set the base-size that + * flexed children should keep. Only works when paired with root styles applied + * by core service from new platform + */ +// SASSTODO: Naming here is too embedded and high up that changing them could cause major breaks +#kibana-body { + overflow-x: hidden; + min-height: 100%; +} + +.app-wrapper { + display: flex; + flex-flow: column nowrap; + position: absolute; + left: $kbnGlobalNavClosedWidth; + top: 0; + right: 0; + bottom: 0; + z-index: 5; + margin: 0 auto; + + /** + * 1. Dirty, but we need to override the .kbnGlobalNav-isOpen state + * when we're looking at the log-in screen. + */ + &.hidden-chrome { + left: 0 !important; /* 1 */ + } + + .navbar-right { + margin-right: 0; + } +} + +.app-wrapper-panel { + display: flex; + flex-grow: 1; + flex-shrink: 0; + flex-basis: auto; + flex-direction: column; + + > * { + flex-shrink: 0; + } +} diff --git a/x-pack/plugins/graph/public/angular/templates/_graph.scss b/x-pack/plugins/graph/public/angular/templates/_graph.scss index 4ba65e7ec6b96a..e6bd4693d1e9b8 100644 --- a/x-pack/plugins/graph/public/angular/templates/_graph.scss +++ b/x-pack/plugins/graph/public/angular/templates/_graph.scss @@ -1,3 +1,5 @@ +@import 'src/legacy/ui/public/chrome/variables'; + @mixin gphSvgText() { font-family: $euiFontFamily; font-size: $euiSizeS; diff --git a/x-pack/plugins/graph/public/index.scss b/x-pack/plugins/graph/public/index.scss index 964ef320e4352c..f4e38de3e93a44 100644 --- a/x-pack/plugins/graph/public/index.scss +++ b/x-pack/plugins/graph/public/index.scss @@ -12,5 +12,3 @@ @import './main'; @import './angular/templates/index'; @import './components/index'; -// Local application mount wrapper styles -@import 'src/legacy/core_plugins/kibana/public/local_application_service/index'; From c7c6738a1607d1050a8dc721cb8c12a3d57f73e4 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Mon, 20 Apr 2020 11:52:58 -0600 Subject: [PATCH 11/16] Fix optimizer tests for real --- .../src/integration_tests/basic_optimization.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/kbn-optimizer/src/integration_tests/basic_optimization.test.ts b/packages/kbn-optimizer/src/integration_tests/basic_optimization.test.ts index 8c551c726e4ed3..459a1ed2049c20 100644 --- a/packages/kbn-optimizer/src/integration_tests/basic_optimization.test.ts +++ b/packages/kbn-optimizer/src/integration_tests/basic_optimization.test.ts @@ -125,10 +125,7 @@ it('builds expected bundles, saves bundle counts to metadata', async () => { assert('produce zero unexpected states', otherStates.length === 0, otherStates); expect( - Fs.readFileSync( - Path.resolve(MOCK_REPO_DIR, 'src/core/public/target/public/core.entry.js'), - 'utf8' - ) + Fs.readFileSync(Path.resolve(MOCK_REPO_DIR, 'src/core/target/public/core.entry.js'), 'utf8') ).toMatchSnapshot('core bundle'); expect( From 9b6d30a22c464e220eac0d6de3ce220421983134 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Mon, 20 Apr 2020 13:23:47 -0600 Subject: [PATCH 12/16] Revert colon in plugin URL --- src/legacy/ui/ui_render/ui_render_mixin.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/legacy/ui/ui_render/ui_render_mixin.js b/src/legacy/ui/ui_render/ui_render_mixin.js index 14d8e8650254e9..7821400fdc3077 100644 --- a/src/legacy/ui/ui_render/ui_render_mixin.js +++ b/src/legacy/ui/ui_render/ui_render_mixin.js @@ -147,9 +147,9 @@ export function uiRenderMixin(kbnServer, server, config) { ...dllJsChunks, `${regularBundlePath}/commons.bundle.js`, ]), - `${regularBundlePath}/plugin:kibanaUtils/kibanaUtils.plugin.js`, - `${regularBundlePath}/plugin:esUiShared/esUiShared.plugin.js`, - `${regularBundlePath}/plugin:kibanaReact/kibanaReact.plugin.js`, + `${regularBundlePath}/plugin/kibanaUtils/kibanaUtils.plugin.js`, + `${regularBundlePath}/plugin/esUiShared/esUiShared.plugin.js`, + `${regularBundlePath}/plugin/kibanaReact/kibanaReact.plugin.js`, ]; const bootstrap = new AppBootstrap({ From 5d893d6ac022ce049e694dafb27d09eb4eea018b Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Mon, 20 Apr 2020 14:37:51 -0600 Subject: [PATCH 13/16] Move legacy CSS again --- src/core/public/index.scss | 3 +++ .../_kbn_chrome.scss => core/public/rendering/_base.scss} | 2 +- src/core/public/rendering/_index.scss | 1 + src/legacy/ui/public/_index.scss | 1 - src/legacy/ui/public/chrome/_index.scss | 3 --- src/legacy/ui/public/chrome/_variables.scss | 4 ---- src/legacy/ui/public/chrome/directives/_index.scss | 1 - x-pack/plugins/graph/public/angular/templates/_graph.scss | 2 -- x-pack/plugins/graph/public/index.scss | 2 ++ 9 files changed, 7 insertions(+), 12 deletions(-) rename src/{legacy/ui/public/chrome/directives/_kbn_chrome.scss => core/public/rendering/_base.scss} (96%) create mode 100644 src/core/public/rendering/_index.scss delete mode 100644 src/legacy/ui/public/chrome/_index.scss delete mode 100644 src/legacy/ui/public/chrome/_variables.scss delete mode 100644 src/legacy/ui/public/chrome/directives/_index.scss diff --git a/src/core/public/index.scss b/src/core/public/index.scss index 86f2efdff77020..628b23d39142c0 100644 --- a/src/core/public/index.scss +++ b/src/core/public/index.scss @@ -9,3 +9,6 @@ @import './chrome/index'; @import './overlays/index'; +@import './rendering/index'; +// Global styles need to be migrated +@import '../../legacy/ui/public/styles/_legacy/_index'; diff --git a/src/legacy/ui/public/chrome/directives/_kbn_chrome.scss b/src/core/public/rendering/_base.scss similarity index 96% rename from src/legacy/ui/public/chrome/directives/_kbn_chrome.scss rename to src/core/public/rendering/_base.scss index b29a83848d2913..ff28fc75e367db 100644 --- a/src/legacy/ui/public/chrome/directives/_kbn_chrome.scss +++ b/src/core/public/rendering/_base.scss @@ -13,7 +13,7 @@ display: flex; flex-flow: column nowrap; position: absolute; - left: $kbnGlobalNavClosedWidth; + left: 0; top: 0; right: 0; bottom: 0; diff --git a/src/core/public/rendering/_index.scss b/src/core/public/rendering/_index.scss new file mode 100644 index 00000000000000..c8567498b42ec2 --- /dev/null +++ b/src/core/public/rendering/_index.scss @@ -0,0 +1 @@ +@import './base'; diff --git a/src/legacy/ui/public/_index.scss b/src/legacy/ui/public/_index.scss index aaed52f8b120a9..b36e62297cc235 100644 --- a/src/legacy/ui/public/_index.scss +++ b/src/legacy/ui/public/_index.scss @@ -9,7 +9,6 @@ // kbnChart__legend-isLoading @import './accessibility/index'; -@import './chrome/index'; @import './directives/index'; @import './error_auto_create_index/index'; @import './error_url_overflow/index'; diff --git a/src/legacy/ui/public/chrome/_index.scss b/src/legacy/ui/public/chrome/_index.scss deleted file mode 100644 index 7e6c3ebaccc5cc..00000000000000 --- a/src/legacy/ui/public/chrome/_index.scss +++ /dev/null @@ -1,3 +0,0 @@ -@import './variables'; - -@import './directives/index'; diff --git a/src/legacy/ui/public/chrome/_variables.scss b/src/legacy/ui/public/chrome/_variables.scss deleted file mode 100644 index 5097fe4c9bfae1..00000000000000 --- a/src/legacy/ui/public/chrome/_variables.scss +++ /dev/null @@ -1,4 +0,0 @@ -$kbnGlobalNavClosedWidth: 53px; -$kbnGlobalNavOpenWidth: 180px; -$kbnGlobalNavLogoHeight: 70px; -$kbnGlobalNavAppIconHeight: $euiSizeXXL + $euiSizeXS; diff --git a/src/legacy/ui/public/chrome/directives/_index.scss b/src/legacy/ui/public/chrome/directives/_index.scss deleted file mode 100644 index 4d00b022791168..00000000000000 --- a/src/legacy/ui/public/chrome/directives/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import './kbn_chrome'; diff --git a/x-pack/plugins/graph/public/angular/templates/_graph.scss b/x-pack/plugins/graph/public/angular/templates/_graph.scss index e6bd4693d1e9b8..4ba65e7ec6b96a 100644 --- a/x-pack/plugins/graph/public/angular/templates/_graph.scss +++ b/x-pack/plugins/graph/public/angular/templates/_graph.scss @@ -1,5 +1,3 @@ -@import 'src/legacy/ui/public/chrome/variables'; - @mixin gphSvgText() { font-family: $euiFontFamily; font-size: $euiSizeS; diff --git a/x-pack/plugins/graph/public/index.scss b/x-pack/plugins/graph/public/index.scss index f4e38de3e93a44..964ef320e4352c 100644 --- a/x-pack/plugins/graph/public/index.scss +++ b/x-pack/plugins/graph/public/index.scss @@ -12,3 +12,5 @@ @import './main'; @import './angular/templates/index'; @import './components/index'; +// Local application mount wrapper styles +@import 'src/legacy/core_plugins/kibana/public/local_application_service/index'; From 329c044f858fb733dc3e51fe2f50906251ca6ba3 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Mon, 20 Apr 2020 16:14:24 -0600 Subject: [PATCH 14/16] Fix mixins import --- src/core/public/index.scss | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/core/public/index.scss b/src/core/public/index.scss index 628b23d39142c0..dc8dbc970452dc 100644 --- a/src/core/public/index.scss +++ b/src/core/public/index.scss @@ -1,14 +1,10 @@ -// Functions need to be first, since we use them in our variables and mixin definitions -@import '@elastic/eui/src/global_styling/functions/index'; - -// Variables come next, and are used in some mixins -@import '@elastic/eui/src/global_styling/variables/index'; - -// Mixins provide generic code expansion through helpers -@import '@elastic/eui/src/global_styling/mixins/index'; +// This file is built by both the legacy and KP build systems so we need to +// import this explicitly +@import '../../legacy/ui/public/styles/_styling_constants'; @import './chrome/index'; @import './overlays/index'; @import './rendering/index'; + // Global styles need to be migrated @import '../../legacy/ui/public/styles/_legacy/_index'; From fb444675756090f3dfb6a0ffbc2d7b5f42d8c16b Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 20 Apr 2020 16:14:50 -0700 Subject: [PATCH 15/16] implement `includeCoreBundle: boolean` config --- packages/kbn-optimizer/src/cli.ts | 10 ++++++- .../basic_optimization.test.ts.snap | 14 --------- .../basic_optimization.test.ts | 13 +++----- .../integration_tests/bundle_cache.test.ts | 30 ------------------- ...les.test.ts => get_plugin_bundles.test.ts} | 12 ++------ .../{get_bundles.ts => get_plugin_bundles.ts} | 15 ++-------- .../src/optimizer/optimizer_config.test.ts | 28 +++++++++++++---- .../src/optimizer/optimizer_config.ts | 24 +++++++++++++-- src/cli/cluster/run_kbn_optimizer.ts | 1 + .../tasks/build_kibana_platform_plugins.js | 1 + 10 files changed, 63 insertions(+), 85 deletions(-) rename packages/kbn-optimizer/src/optimizer/{get_bundles.test.ts => get_plugin_bundles.test.ts} (86%) rename packages/kbn-optimizer/src/optimizer/{get_bundles.ts => get_plugin_bundles.ts} (75%) diff --git a/packages/kbn-optimizer/src/cli.ts b/packages/kbn-optimizer/src/cli.ts index dcb4dcd35698d0..c0bb408d60d8f8 100644 --- a/packages/kbn-optimizer/src/cli.ts +++ b/packages/kbn-optimizer/src/cli.ts @@ -44,6 +44,11 @@ run( throw createFlagError('expected --cache to have no value'); } + const includeCoreBundle = flags.core ?? true; + if (typeof includeCoreBundle !== 'boolean') { + throw createFlagError('expected --core to have no value'); + } + const dist = flags.dist ?? false; if (typeof dist !== 'boolean') { throw createFlagError('expected --dist to have no value'); @@ -87,6 +92,7 @@ run( profileWebpack, extraPluginScanDirs, inspectWorkers, + includeCoreBundle, }); await runOptimizer(config) @@ -95,9 +101,10 @@ run( }, { flags: { - boolean: ['watch', 'oss', 'examples', 'dist', 'cache', 'profile', 'inspect-workers'], + boolean: ['core', 'watch', 'oss', 'examples', 'dist', 'cache', 'profile', 'inspect-workers'], string: ['workers', 'scan-dir'], default: { + core: true, examples: true, cache: true, 'inspect-workers': true, @@ -107,6 +114,7 @@ run( --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-core disable generating the core bundle --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 diff --git a/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap b/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap index 4b9a6562ffeca5..4b4bb1282d9395 100644 --- a/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap +++ b/packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap @@ -5,18 +5,6 @@ exports[`builds expected bundles, saves bundle counts to metadata: 1 async bundl exports[`builds expected bundles, saves bundle counts to metadata: OptimizerConfig 1`] = ` OptimizerConfig { "bundles": Array [ - Bundle { - "cache": BundleCache { - "path": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/target/public/.kbn-optimizer-cache, - "state": undefined, - }, - "contextDir": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core, - "entry": "./public/entry_point", - "id": "core", - "outputDir": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/core/target/public, - "sourceRoot": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo, - "type": "entry", - }, Bundle { "cache": BundleCache { "path": /packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/target/public/.kbn-optimizer-cache, @@ -71,6 +59,4 @@ OptimizerConfig { exports[`builds expected bundles, saves bundle counts to metadata: bar bundle 1`] = `"var __kbnBundles__=typeof __kbnBundles__===\\"object\\"?__kbnBundles__:{};__kbnBundles__[\\"plugin/bar\\"]=function(modules){function webpackJsonpCallback(data){var chunkIds=data[0];var moreModules=data[1];var moduleId,chunkId,i=0,resolves=[];for(;i { (msg.event?.type === 'bundle cached' || msg.event?.type === 'bundle not cached') && msg.state.phase === 'initializing' ); - assert('produce three bundle cache events while initializing', bundleCacheStates.length === 3); + assert('produce two bundle cache events while initializing', bundleCacheStates.length === 2); const initializedStates = msgs.filter(msg => msg.state.phase === 'initialized'); assert('produce at least one initialized event', initializedStates.length >= 1); @@ -101,12 +101,12 @@ it('builds expected bundles, saves bundle counts to metadata', async () => { const runningStates = msgs.filter(msg => msg.state.phase === 'running'); assert( - 'produce four or five "running" states', - runningStates.length === 4 || runningStates.length === 5 + 'produce two or three "running" states', + runningStates.length === 2 || runningStates.length === 3 ); const bundleNotCachedEvents = msgs.filter(msg => msg.event?.type === 'bundle not cached'); - assert('produce three "bundle not cached" events', bundleNotCachedEvents.length === 3); + assert('produce two "bundle not cached" events', bundleNotCachedEvents.length === 2); const successStates = msgs.filter(msg => msg.state.phase === 'success'); assert( @@ -124,10 +124,6 @@ it('builds expected bundles, saves bundle counts to metadata', async () => { ); assert('produce zero unexpected states', otherStates.length === 0, otherStates); - expect( - Fs.readFileSync(Path.resolve(MOCK_REPO_DIR, 'src/core/target/public/core.entry.js'), 'utf8') - ).toMatchSnapshot('core bundle'); - expect( Fs.readFileSync(Path.resolve(MOCK_REPO_DIR, 'plugins/foo/target/public/foo.plugin.js'), 'utf8') ).toMatchSnapshot('foo bundle'); @@ -202,7 +198,6 @@ it('uses cache on second run and exist cleanly', async () => { "initializing", "initializing", "initializing", - "initializing", "initialized", "success", ] diff --git a/packages/kbn-optimizer/src/integration_tests/bundle_cache.test.ts b/packages/kbn-optimizer/src/integration_tests/bundle_cache.test.ts index bfcaa04b679be5..1bfd8d3fd073a2 100644 --- a/packages/kbn-optimizer/src/integration_tests/bundle_cache.test.ts +++ b/packages/kbn-optimizer/src/integration_tests/bundle_cache.test.ts @@ -83,11 +83,6 @@ it('emits "bundle cached" event when everything is updated', async () => { expect(cacheEvents).toMatchInlineSnapshot(` Array [ - Object { - "bundle": , - "reason": "missing optimizer cache key", - "type": "bundle not cached", - }, Object { "bundle": , "type": "bundle cached", @@ -133,11 +128,6 @@ it('emits "bundle not cached" event when cacheKey is up to date but caching is d "reason": "cache disabled", "type": "bundle not cached", }, - Object { - "bundle": , - "reason": "cache disabled", - "type": "bundle not cached", - }, ] `); }); @@ -178,11 +168,6 @@ it('emits "bundle not cached" event when optimizerCacheKey is missing', async () "reason": "missing optimizer cache key", "type": "bundle not cached", }, - Object { - "bundle": , - "reason": "missing optimizer cache key", - "type": "bundle not cached", - }, ] `); }); @@ -228,11 +213,6 @@ it('emits "bundle not cached" event when optimizerCacheKey is outdated, includes "reason": "optimizer cache key mismatch", "type": "bundle not cached", }, - Object { - "bundle": , - "reason": "missing optimizer cache key", - "type": "bundle not cached", - }, ] `); }); @@ -271,11 +251,6 @@ it('emits "bundle not cached" event when cacheKey is missing', async () => { "reason": "missing cache key", "type": "bundle not cached", }, - Object { - "bundle": , - "reason": "missing optimizer cache key", - "type": "bundle not cached", - }, ] `); }); @@ -311,11 +286,6 @@ it('emits "bundle not cached" event when cacheKey is outdated', async () => { expect(cacheEvents).toMatchInlineSnapshot(` Array [ - Object { - "bundle": , - "reason": "missing optimizer cache key", - "type": "bundle not cached", - }, Object { "bundle": , "diff": "- Expected diff --git a/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts b/packages/kbn-optimizer/src/optimizer/get_plugin_bundles.test.ts similarity index 86% rename from packages/kbn-optimizer/src/optimizer/get_bundles.test.ts rename to packages/kbn-optimizer/src/optimizer/get_plugin_bundles.test.ts index e52ec2ca664de7..36dc0ca64c6ca8 100644 --- a/packages/kbn-optimizer/src/optimizer/get_bundles.test.ts +++ b/packages/kbn-optimizer/src/optimizer/get_plugin_bundles.test.ts @@ -19,13 +19,13 @@ import { createAbsolutePathSerializer } from '@kbn/dev-utils'; -import { getBundles } from './get_bundles'; +import { getPluginBundles } from './get_plugin_bundles'; expect.addSnapshotSerializer(createAbsolutePathSerializer('/repo')); it('returns a bundle for core and each plugin', () => { expect( - getBundles( + getPluginBundles( [ { directory: '/repo/plugins/foo', @@ -47,14 +47,6 @@ it('returns a bundle for core and each plugin', () => { ).map(b => b.toSpec()) ).toMatchInlineSnapshot(` Array [ - Object { - "contextDir": /src/core, - "entry": "./public/entry_point", - "id": "core", - "outputDir": /src/core/target/public, - "sourceRoot": , - "type": "entry", - }, Object { "contextDir": /plugins/foo, "entry": "./public/index", diff --git a/packages/kbn-optimizer/src/optimizer/get_bundles.ts b/packages/kbn-optimizer/src/optimizer/get_plugin_bundles.ts similarity index 75% rename from packages/kbn-optimizer/src/optimizer/get_bundles.ts rename to packages/kbn-optimizer/src/optimizer/get_plugin_bundles.ts index b20ee6dcfdd538..4741cc3c30af70 100644 --- a/packages/kbn-optimizer/src/optimizer/get_bundles.ts +++ b/packages/kbn-optimizer/src/optimizer/get_plugin_bundles.ts @@ -23,17 +23,8 @@ import { Bundle } from '../common'; import { KibanaPlatformPlugin } from './kibana_platform_plugins'; -export function getBundles(plugins: KibanaPlatformPlugin[], repoRoot: string) { - const coreBundle = new Bundle({ - type: 'entry', - id: 'core', - entry: './public/entry_point', - sourceRoot: repoRoot, - contextDir: Path.resolve(repoRoot, 'src/core'), - outputDir: Path.resolve(repoRoot, 'src/core/target/public'), - }); - - const pluginBundles = plugins +export function getPluginBundles(plugins: KibanaPlatformPlugin[], repoRoot: string) { + return plugins .filter(p => p.isUiPlugin) .map( p => @@ -46,6 +37,4 @@ export function getBundles(plugins: KibanaPlatformPlugin[], repoRoot: string) { outputDir: Path.resolve(p.directory, 'target/public'), }) ); - - return [coreBundle, ...pluginBundles]; } diff --git a/packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts b/packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts index cc564dd4a8387c..d4152133f289de 100644 --- a/packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts +++ b/packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts @@ -19,7 +19,7 @@ jest.mock('./assign_bundles_to_workers.ts'); jest.mock('./kibana_platform_plugins.ts'); -jest.mock('./get_bundles.ts'); +jest.mock('./get_plugin_bundles.ts'); import Path from 'path'; import Os from 'os'; @@ -90,6 +90,7 @@ describe('OptimizerConfig::parseOptions()', () => { Object { "cache": true, "dist": false, + "includeCoreBundle": false, "inspectWorkers": false, "maxWorkerCount": 2, "pluginPaths": Array [], @@ -114,6 +115,7 @@ describe('OptimizerConfig::parseOptions()', () => { Object { "cache": false, "dist": false, + "includeCoreBundle": false, "inspectWorkers": false, "maxWorkerCount": 2, "pluginPaths": Array [], @@ -138,6 +140,7 @@ describe('OptimizerConfig::parseOptions()', () => { Object { "cache": true, "dist": false, + "includeCoreBundle": false, "inspectWorkers": false, "maxWorkerCount": 2, "pluginPaths": Array [], @@ -164,6 +167,7 @@ describe('OptimizerConfig::parseOptions()', () => { Object { "cache": true, "dist": false, + "includeCoreBundle": false, "inspectWorkers": false, "maxWorkerCount": 2, "pluginPaths": Array [], @@ -187,6 +191,7 @@ describe('OptimizerConfig::parseOptions()', () => { Object { "cache": true, "dist": false, + "includeCoreBundle": false, "inspectWorkers": false, "maxWorkerCount": 2, "pluginPaths": Array [], @@ -210,6 +215,7 @@ describe('OptimizerConfig::parseOptions()', () => { Object { "cache": true, "dist": false, + "includeCoreBundle": false, "inspectWorkers": false, "maxWorkerCount": 100, "pluginPaths": Array [], @@ -230,6 +236,7 @@ describe('OptimizerConfig::parseOptions()', () => { Object { "cache": false, "dist": false, + "includeCoreBundle": false, "inspectWorkers": false, "maxWorkerCount": 100, "pluginPaths": Array [], @@ -250,6 +257,7 @@ describe('OptimizerConfig::parseOptions()', () => { Object { "cache": false, "dist": false, + "includeCoreBundle": false, "inspectWorkers": false, "maxWorkerCount": 100, "pluginPaths": Array [], @@ -271,6 +279,7 @@ describe('OptimizerConfig::parseOptions()', () => { Object { "cache": false, "dist": false, + "includeCoreBundle": false, "inspectWorkers": false, "maxWorkerCount": 100, "pluginPaths": Array [], @@ -292,6 +301,7 @@ describe('OptimizerConfig::parseOptions()', () => { Object { "cache": true, "dist": false, + "includeCoreBundle": false, "inspectWorkers": false, "maxWorkerCount": 100, "pluginPaths": Array [], @@ -314,7 +324,7 @@ describe('OptimizerConfig::create()', () => { .assignBundlesToWorkers; const findKibanaPlatformPlugins: jest.Mock = jest.requireMock('./kibana_platform_plugins.ts') .findKibanaPlatformPlugins; - const getBundles: jest.Mock = jest.requireMock('./get_bundles.ts').getBundles; + const getPluginBundles: jest.Mock = jest.requireMock('./get_plugin_bundles.ts').getPluginBundles; beforeEach(() => { if ('mock' in OptimizerConfig.parseOptions) { @@ -326,7 +336,7 @@ describe('OptimizerConfig::create()', () => { { config: Symbol('worker config 2') }, ]); findKibanaPlatformPlugins.mockReturnValue(Symbol('new platform plugins')); - getBundles.mockReturnValue(Symbol('bundles')); + getPluginBundles.mockReturnValue([Symbol('bundle1'), Symbol('bundle2')]); jest.spyOn(OptimizerConfig, 'parseOptions').mockImplementation((): any => ({ cache: Symbol('parsed cache'), @@ -348,7 +358,10 @@ describe('OptimizerConfig::create()', () => { expect(config).toMatchInlineSnapshot(` OptimizerConfig { - "bundles": Symbol(bundles), + "bundles": Array [ + Symbol(bundle1), + Symbol(bundle2), + ], "cache": Symbol(parsed cache), "dist": Symbol(parsed dist), "inspectWorkers": Symbol(parsed inspect workers), @@ -383,7 +396,7 @@ describe('OptimizerConfig::create()', () => { } `); - expect(getBundles.mock).toMatchInlineSnapshot(` + expect(getPluginBundles.mock).toMatchInlineSnapshot(` Object { "calls": Array [ Array [ @@ -400,7 +413,10 @@ describe('OptimizerConfig::create()', () => { "results": Array [ Object { "type": "return", - "value": Symbol(bundles), + "value": Array [ + Symbol(bundle1), + Symbol(bundle2), + ], }, ], } diff --git a/packages/kbn-optimizer/src/optimizer/optimizer_config.ts b/packages/kbn-optimizer/src/optimizer/optimizer_config.ts index 7e1514058446b9..d6336cf8674705 100644 --- a/packages/kbn-optimizer/src/optimizer/optimizer_config.ts +++ b/packages/kbn-optimizer/src/optimizer/optimizer_config.ts @@ -23,7 +23,7 @@ import Os from 'os'; import { Bundle, WorkerConfig } from '../common'; import { findKibanaPlatformPlugins, KibanaPlatformPlugin } from './kibana_platform_plugins'; -import { getBundles } from './get_bundles'; +import { getPluginBundles } from './get_plugin_bundles'; function pickMaxWorkerCount(dist: boolean) { // don't break if cpus() returns nothing, or an empty array @@ -60,6 +60,9 @@ interface Options { pluginScanDirs?: string[]; /** absolute paths that should be added to the default scan dirs */ extraPluginScanDirs?: string[]; + + /** flag that causes the core bundle to be built along with plugins */ + includeCoreBundle?: boolean; } interface ParsedOptions { @@ -72,6 +75,7 @@ interface ParsedOptions { pluginPaths: string[]; pluginScanDirs: string[]; inspectWorkers: boolean; + includeCoreBundle: boolean; } export class OptimizerConfig { @@ -83,6 +87,7 @@ export class OptimizerConfig { const profileWebpack = !!options.profileWebpack; const inspectWorkers = !!options.inspectWorkers; const cache = options.cache !== false && !process.env.KBN_OPTIMIZER_NO_CACHE; + const includeCoreBundle = !!options.includeCoreBundle; const repoRoot = options.repoRoot; if (!Path.isAbsolute(repoRoot)) { @@ -134,13 +139,28 @@ export class OptimizerConfig { pluginScanDirs, pluginPaths, inspectWorkers, + includeCoreBundle, }; } static create(inputOptions: Options) { const options = OptimizerConfig.parseOptions(inputOptions); const plugins = findKibanaPlatformPlugins(options.pluginScanDirs, options.pluginPaths); - const bundles = getBundles(plugins, options.repoRoot); + const bundles = [ + ...(options.includeCoreBundle + ? [ + new Bundle({ + type: 'entry', + id: 'core', + entry: './public/entry_point', + sourceRoot: options.repoRoot, + contextDir: Path.resolve(options.repoRoot, 'src/core'), + outputDir: Path.resolve(options.repoRoot, 'src/core/target/public'), + }), + ] + : []), + ...getPluginBundles(plugins, options.repoRoot), + ]; return new OptimizerConfig( bundles, diff --git a/src/cli/cluster/run_kbn_optimizer.ts b/src/cli/cluster/run_kbn_optimizer.ts index 7752d4a45ab655..b811fc1f6b294d 100644 --- a/src/cli/cluster/run_kbn_optimizer.ts +++ b/src/cli/cluster/run_kbn_optimizer.ts @@ -34,6 +34,7 @@ export function runKbnOptimizer(opts: Record, config: LegacyConfig) const optimizerConfig = OptimizerConfig.create({ repoRoot: REPO_ROOT, watch: true, + includeCoreBundle: true, oss: !!opts.oss, examples: !!opts.runExamples, pluginPaths: config.get('plugins.paths'), diff --git a/src/dev/build/tasks/build_kibana_platform_plugins.js b/src/dev/build/tasks/build_kibana_platform_plugins.js index 101d6bd15fc102..79cd698e4782c8 100644 --- a/src/dev/build/tasks/build_kibana_platform_plugins.js +++ b/src/dev/build/tasks/build_kibana_platform_plugins.js @@ -29,6 +29,7 @@ export const BuildKibanaPlatformPluginsTask = { examples: false, watch: false, dist: true, + includeCoreBundle: true, }); await runOptimizer(optimizerConfig) From 237e2c5b452f4137c77bbcbde48b17ade7b27092 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Tue, 21 Apr 2020 11:12:15 -0600 Subject: [PATCH 16/16] PR comments --- .../mock_repo/src/core/public/entry_point.ts | 21 ------------------- .../src/worker/webpack.config.ts | 2 +- src/core/public/{core.css => _core.scss} | 0 src/core/public/core_system.ts | 2 -- src/core/public/entry_point.ts | 3 +++ src/core/public/index.scss | 1 + .../ui/ui_bundles/app_entry_template.js | 3 +++ .../ui/ui_render/bootstrap/template.js.hbs | 4 ++-- src/legacy/ui/ui_render/ui_render_mixin.js | 9 ++++---- 9 files changed, 15 insertions(+), 30 deletions(-) delete mode 100644 packages/kbn-optimizer/src/__fixtures__/mock_repo/src/core/public/entry_point.ts rename src/core/public/{core.css => _core.scss} (100%) diff --git a/packages/kbn-optimizer/src/__fixtures__/mock_repo/src/core/public/entry_point.ts b/packages/kbn-optimizer/src/__fixtures__/mock_repo/src/core/public/entry_point.ts deleted file mode 100644 index 4101c6da343e69..00000000000000 --- a/packages/kbn-optimizer/src/__fixtures__/mock_repo/src/core/public/entry_point.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ - -// eslint-disable-next-line no-console -console.log(`core entry point`); diff --git a/packages/kbn-optimizer/src/worker/webpack.config.ts b/packages/kbn-optimizer/src/worker/webpack.config.ts index 2db2c5803a64e2..bb58bd0a3f0059 100644 --- a/packages/kbn-optimizer/src/worker/webpack.config.ts +++ b/packages/kbn-optimizer/src/worker/webpack.config.ts @@ -162,7 +162,7 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) { ], }, { - test: /\.(scss|css)$/, + test: /\.scss$/, exclude: /node_modules/, oneOf: [ { diff --git a/src/core/public/core.css b/src/core/public/_core.scss similarity index 100% rename from src/core/public/core.css rename to src/core/public/_core.scss diff --git a/src/core/public/core_system.ts b/src/core/public/core_system.ts index 9b3c4e32db5614..e58114b69dcc1e 100644 --- a/src/core/public/core_system.ts +++ b/src/core/public/core_system.ts @@ -17,8 +17,6 @@ * under the License. */ -import './core.css'; - import { CoreId } from '../server'; import { PackageInfo, EnvironmentMode } from '../server/types'; import { CoreSetup, CoreStart } from '.'; diff --git a/src/core/public/entry_point.ts b/src/core/public/entry_point.ts index c40fc5247d28c4..9461acccf30b9e 100644 --- a/src/core/public/entry_point.ts +++ b/src/core/public/entry_point.ts @@ -20,6 +20,9 @@ /** * This is the entry point used to boot the frontend when serving a application * that lives in the Kibana Platform. + * + * Any changes to this file should be kept in sync with + * src/legacy/ui/ui_bundles/app_entry_template.js */ import './index.scss'; diff --git a/src/core/public/index.scss b/src/core/public/index.scss index dc8dbc970452dc..4be46899cff67b 100644 --- a/src/core/public/index.scss +++ b/src/core/public/index.scss @@ -2,6 +2,7 @@ // import this explicitly @import '../../legacy/ui/public/styles/_styling_constants'; +@import './core'; @import './chrome/index'; @import './overlays/index'; @import './rendering/index'; diff --git a/src/legacy/ui/ui_bundles/app_entry_template.js b/src/legacy/ui/ui_bundles/app_entry_template.js index bf926c4a7b61d7..683fedd34316f2 100644 --- a/src/legacy/ui/ui_bundles/app_entry_template.js +++ b/src/legacy/ui/ui_bundles/app_entry_template.js @@ -25,6 +25,9 @@ export const appEntryTemplate = bundle => ` * * This is programmatically created and updated, do not modify * + * Any changes to this file should be kept in sync with + * src/core/public/entry_point.ts + * * context: ${bundle.getContext()} */ diff --git a/src/legacy/ui/ui_render/bootstrap/template.js.hbs b/src/legacy/ui/ui_render/bootstrap/template.js.hbs index ffabc6a33b61fb..7250fa4fc9ecae 100644 --- a/src/legacy/ui/ui_render/bootstrap/template.js.hbs +++ b/src/legacy/ui/ui_render/bootstrap/template.js.hbs @@ -69,12 +69,12 @@ if (window.__kbnStrictCsp__ && window.__kbnCspNotEnforced__) { } load([ - {{#each jsDependencies}} + {{#each jsDependencyPaths}} '{{this}}', {{/each}} ], function () { load([ - '{{entryBundle}}', + '{{entryBundlePath}}', {{#each styleSheetPaths}} '{{this}}', {{/each}} diff --git a/src/legacy/ui/ui_render/ui_render_mixin.js b/src/legacy/ui/ui_render/ui_render_mixin.js index 7821400fdc3077..1e84405dd51538 100644 --- a/src/legacy/ui/ui_render/ui_render_mixin.js +++ b/src/legacy/ui/ui_render/ui_render_mixin.js @@ -111,12 +111,13 @@ export function uiRenderMixin(kbnServer, server, config) { ? [ `${basePath}/bundles/kbn-ui-shared-deps/${UiSharedDeps.darkCssDistFilename}`, `${basePath}/node_modules/@kbn/ui-framework/dist/kui_dark.css`, + `${regularBundlePath}/dark_theme.style.css`, ] : [ `${basePath}/bundles/kbn-ui-shared-deps/${UiSharedDeps.lightCssDistFilename}`, `${basePath}/node_modules/@kbn/ui-framework/dist/kui_light.css`, + `${regularBundlePath}/light_theme.style.css`, ]), - `${regularBundlePath}/${darkMode ? 'dark' : 'light'}_theme.style.css`, `${regularBundlePath}/commons.style.css`, ...(isCore ? [] @@ -135,7 +136,7 @@ export function uiRenderMixin(kbnServer, server, config) { ]), ]; - const jsDependencies = [ + const jsDependencyPaths = [ ...UiSharedDeps.jsDepFilenames.map( filename => `${regularBundlePath}/kbn-ui-shared-deps/${filename}` ), @@ -155,9 +156,9 @@ export function uiRenderMixin(kbnServer, server, config) { const bootstrap = new AppBootstrap({ templateData: { darkMode, - jsDependencies, + jsDependencyPaths, styleSheetPaths, - entryBundle: isCore + entryBundlePath: isCore ? `${regularBundlePath}/core/core.entry.js` : `${regularBundlePath}/${app.getId()}.bundle.js`, },