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 0000000000000..4101c6da343e6 --- /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 4b4bb1282d939..fe9a699e37de1 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 ad743933e1171..37624ccbb9ab0 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 1bfd8d3fd073a..bfcaa04b679be 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 9d95d883d605c..879d33202f4ff 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 f8fa93765632c..2db2c5803a64e 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 8be31c27dfcf4..5c98d70edee6c 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}}