Skip to content

Commit

Permalink
Merge branch 'master' into chore/reporting-np-move
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Jun 2, 2020
2 parents 7b320c0 + 0247df4 commit e0aa98f
Show file tree
Hide file tree
Showing 104 changed files with 853 additions and 711 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/src/optimizer/optimizer_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class OptimizerConfig {
new Bundle({
type: 'entry',
id: 'core',
entry: './public/entry_point',
entry: './public/index',
sourceRoot: options.repoRoot,
contextDir: Path.resolve(options.repoRoot, 'src/core'),
outputDir: Path.resolve(options.repoRoot, 'src/core/target/public'),
Expand Down
66 changes: 39 additions & 27 deletions packages/kbn-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,32 @@ const IS_CODE_COVERAGE = !!process.env.CODE_COVERAGE;
const ISTANBUL_PRESET_PATH = require.resolve('@kbn/babel-preset/istanbul_preset');
const BABEL_PRESET_PATH = require.resolve('@kbn/babel-preset/webpack_preset');

const STATIC_BUNDLE_PLUGINS = [
{ id: 'data', dirname: 'data' },
{ id: 'kibanaReact', dirname: 'kibana_react' },
{ id: 'kibanaUtils', dirname: 'kibana_utils' },
{ id: 'esUiShared', dirname: 'es_ui_shared' },
const SHARED_BUNDLES = [
{
type: 'entry',
id: 'core',
rootRelativeDir: 'src/core/public',
},
{
type: 'plugin',
id: 'data',
rootRelativeDir: 'src/plugins/data/public',
},
{
type: 'plugin',
id: 'kibanaReact',
rootRelativeDir: 'src/plugins/kibana_react/public',
},
{
type: 'plugin',
id: 'kibanaUtils',
rootRelativeDir: 'src/plugins/kibana_utils/public',
},
{
type: 'plugin',
id: 'esUiShared',
rootRelativeDir: 'src/plugins/es_ui_shared/public',
},
];

/**
Expand All @@ -57,29 +78,24 @@ const STATIC_BUNDLE_PLUGINS = [
* @param request the request for a module from a commonjs require() call or import statement
*/
function dynamicExternals(bundle: Bundle, context: string, request: string) {
// ignore imports that have loaders defined
if (request.includes('!')) {
return;
}

// ignore requests that don't include a /{dirname}/public for one of our
// "static" bundles as a cheap way to avoid doing path resolution
// for paths that couldn't possibly resolve to what we're looking for
const reqToStaticBundle = STATIC_BUNDLE_PLUGINS.some((p) =>
request.includes(`/${p.dirname}/public`)
);
if (!reqToStaticBundle) {
// ignore imports that have loaders defined or are not relative seeming
if (request.includes('!') || !request.startsWith('.')) {
return;
}

// determine the most acurate resolution string we can without running full resolution
const rootRelative = normalizePath(
Path.relative(bundle.sourceRoot, Path.resolve(context, request))
);
for (const { id, dirname } of STATIC_BUNDLE_PLUGINS) {
if (rootRelative === `src/plugins/${dirname}/public`) {
return `__kbnBundles__['plugin/${id}']`;
for (const sharedBundle of SHARED_BUNDLES) {
if (
rootRelative !== sharedBundle.rootRelativeDir ||
`${bundle.type}/${bundle.id}` === `${sharedBundle.type}/${sharedBundle.id}`
) {
continue;
}

return `__kbnBundles__['${sharedBundle.type}/${sharedBundle.id}']`;
}

// import doesn't match a root public import
Expand Down Expand Up @@ -112,13 +128,9 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) {
info.absoluteResourcePath
)}${info.query}`,
jsonpFunction: `${bundle.id}_bundle_jsonpfunction`,
...(bundle.type === 'plugin'
? {
// When the entry point is loaded, assign it's exported `plugin`
// value to a key on the global `__kbnBundles__` object.
library: ['__kbnBundles__', `plugin/${bundle.id}`],
}
: {}),
// When the entry point is loaded, assign it's default export
// to a key on the global `__kbnBundles__` object.
library: ['__kbnBundles__', `${bundle.type}/${bundle.id}`],
},

optimization: {
Expand Down
4 changes: 1 addition & 3 deletions src/core/public/chrome/nav_links/to_nav_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export function toNavLink(
legacy: isLegacyApp(app),
baseUrl,
...(isLegacyApp(app)
? {
href: url && !url.startsWith(app.subUrlBase!) ? url : baseUrl,
}
? {}
: {
href: url,
url,
Expand Down
7 changes: 6 additions & 1 deletion src/core/public/chrome/ui/header/nav_link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ export function createEuiListItem({
navigateToApp,
dataTestSubj,
}: Props) {
const { legacy, active, id, title, disabled, euiIconType, icon, tooltip, href } = link;
const { legacy, active, id, title, disabled, euiIconType, icon, tooltip } = link;
let { href } = link;

if (legacy) {
href = link.url && !active ? link.url : link.baseUrl;
}

return {
label: tooltip ?? title,
Expand Down
4 changes: 4 additions & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* @packageDocumentation
*/

import './index.scss';

import {
ChromeBadge,
ChromeBrand,
Expand Down Expand Up @@ -363,3 +365,5 @@ export {
UiSettingsState,
NavType,
};

export { __kbnBootstrap__ } from './kbn_bootstrap';
60 changes: 31 additions & 29 deletions src/core/public/entry_point.ts → src/core/public/kbn_bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,41 @@
* src/legacy/ui/ui_bundles/app_entry_template.js
*/

import './index.scss';
import { i18n } from '@kbn/i18n';
import { CoreSystem } from './core_system';

const injectedMetadata = JSON.parse(
document.querySelector('kbn-injected-metadata')!.getAttribute('data')!
);
/** @internal */
export function __kbnBootstrap__() {
const injectedMetadata = JSON.parse(
document.querySelector('kbn-injected-metadata')!.getAttribute('data')!
);

/**
* `apmConfig` would be populated with relavant APM RUM agent
* configuration if server is started with `ELASTIC_APM_ACTIVE=true`
*/
if (process.env.IS_KIBANA_DISTRIBUTABLE !== 'true' && injectedMetadata.vars.apmConfig != null) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { init } = require('@elastic/apm-rum');
init(injectedMetadata.vars.apmConfig);
}
/**
* `apmConfig` would be populated with relavant APM RUM agent
* configuration if server is started with `ELASTIC_APM_ACTIVE=true`
*/
if (process.env.IS_KIBANA_DISTRIBUTABLE !== 'true' && injectedMetadata.vars.apmConfig != null) {
// @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__,
});
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);
}
const setup = await coreSystem.setup();
if (i18nError && setup) {
setup.fatalErrors.add(i18nError);
}

await coreSystem.start();
});
await coreSystem.start();
});
}
3 changes: 3 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { Type } from '@kbn/config-schema';
import { UnregisterCallback } from 'history';
import { UserProvidedValues as UserProvidedValues_2 } from 'src/core/server/types';

// @internal (undocumented)
export function __kbnBootstrap__(): void;

// @public
export interface App<HistoryLocationState = unknown> extends AppBase {
appRoute?: string;
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/dev/typescript/run_type_check_cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function runTypeCheckCli() {
}

execInProjects(log, projects, process.execPath, (project) => [
...(project.name === 'x-pack' ? ['--max-old-space-size=4096'] : []),
...(project.name.startsWith('x-pack') ? ['--max-old-space-size=4096'] : []),
require.resolve('typescript/bin/tsc'),
...['--project', project.tsConfigPath],
...tscArgs,
Expand Down
19 changes: 15 additions & 4 deletions src/legacy/ui/ui_render/bootstrap/template.js.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,23 @@ if (window.__kbnStrictCsp__ && window.__kbnCspNotEnforced__) {
}

load([
{{#each jsDependencyPaths}}
'{{this}}',
{{/each}}
{{#each jsDependencyPaths}}
'{{this}}',
{{/each}}
], function () {
{{#unless legacyBundlePath}}
if (!__kbnBundles__ || !__kbnBundles__['entry/core'] || typeof __kbnBundles__['entry/core'].__kbnBootstrap__ !== 'function') {
console.error('entry/core bundle did not load correctly');
failure();
} else {
__kbnBundles__['entry/core'].__kbnBootstrap__()
}
{{/unless}}

load([
'{{entryBundlePath}}',
{{#if legacyBundlePath}}
'{{legacyBundlePath}}',
{{/if}}
{{#each styleSheetPaths}}
'{{this}}',
{{/each}}
Expand Down
5 changes: 2 additions & 3 deletions src/legacy/ui/ui_render/ui_render_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export function uiRenderMixin(kbnServer, server, config) {
`${regularBundlePath}/commons.bundle.js`,
]),

`${regularBundlePath}/core/core.entry.js`,
...kpPluginIds.map(
(pluginId) => `${regularBundlePath}/plugin/${pluginId}/${pluginId}.plugin.js`
),
Expand All @@ -199,9 +200,7 @@ export function uiRenderMixin(kbnServer, server, config) {
jsDependencyPaths,
styleSheetPaths,
publicPathMap,
entryBundlePath: isCore
? `${regularBundlePath}/core/core.entry.js`
: `${regularBundlePath}/${app.getId()}.bundle.js`,
legacyBundlePath: isCore ? undefined : `${regularBundlePath}/${app.getId()}.bundle.js`,
},
});

Expand Down
Loading

0 comments on commit e0aa98f

Please sign in to comment.