Skip to content

Commit

Permalink
Merge branch '7.x' into backport/7.x/pr-62951
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Apr 8, 2020
2 parents 0bd6ce3 + f5c8904 commit 8fb2ea8
Show file tree
Hide file tree
Showing 95 changed files with 1,467 additions and 492 deletions.
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"src/legacy/core_plugins/management",
"src/plugins/management"
],
"indexPatternManagement": "src/plugins/index_pattern_management",
"advancedSettings": "src/plugins/advanced_settings",
"kibana_legacy": "src/plugins/kibana_legacy",
"kibana_react": "src/legacy/core_plugins/kibana_react",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-optimizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"json-stable-stringify": "^1.0.1",
"loader-utils": "^1.2.3",
"node-sass": "^4.13.0",
"normalize-path": "^3.0.0",
"postcss-loader": "^3.0.0",
"raw-loader": "^3.1.0",
"resolve-url-loader": "^3.1.1",
Expand Down

Large diffs are not rendered by default.

68 changes: 64 additions & 4 deletions packages/kbn-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import Path from 'path';

import normalizePath from 'normalize-path';
import { stringifyRequest } from 'loader-utils';
import webpack from 'webpack';
// @ts-ignore
Expand All @@ -34,6 +35,59 @@ import { Bundle, WorkerConfig, parseDirPath, DisallowedSyntaxPlugin } from '../c
const PUBLIC_PATH_PLACEHOLDER = '__REPLACE_WITH_PUBLIC_PATH__';
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' },
];

/**
* Determine externals statements for require/import statements by looking
* for requests resolving to the primary public export of the data, kibanaReact,
* amd kibanaUtils plugins. If this module is being imported then rewrite
* the import to access the global `__kbnBundles__` variables and access
* the relavent properties from that global object.
*
* @param bundle
* @param context the directory containing the module which made `request`
* @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;
}

// don't allow any static bundle to rely on other static bundles
if (STATIC_BUNDLE_PLUGINS.some(p => bundle.id === p.id)) {
return;
}

// ignore requests that don't include a /data/public, /kibana_react/public, or
// /kibana_utils/public segment 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) {
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}']`;
}
}

// import doesn't match a root public import
return undefined;
}

export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) {
const commonConfig: webpack.Configuration = {
node: { fs: 'empty' },
Expand Down Expand Up @@ -61,7 +115,6 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) {
// 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}`],
libraryExport: 'plugin',
}
: {}),
},
Expand All @@ -70,9 +123,16 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) {
noEmitOnErrors: true,
},

externals: {
...UiSharedDeps.externals,
},
externals: [
UiSharedDeps.externals,
function(context, request, cb) {
try {
cb(undefined, dynamicExternals(bundle, context, request));
} catch (error) {
cb(error, undefined);
}
},
],

plugins: [new CleanWebpackPlugin(), new DisallowedSyntaxPlugin()],

Expand Down
7 changes: 7 additions & 0 deletions packages/kbn-ui-shared-deps/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
require('core-js/stable');
require('regenerator-runtime/runtime');
require('custom-event-polyfill');

if (typeof window.Event === 'object') {
// IE11 doesn't support unknown event types, required by react-use
// https://github.com/streamich/react-use/issues/73
window.Event = CustomEvent;
}

require('whatwg-fetch');
require('abortcontroller-polyfill/dist/polyfill-patch-fetch');
require('./vendor/childnode_remove_polyfill');
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/plugins/plugin_loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test('`loadPluginBundles` creates a script tag and loads initializer', async ()

// Setup a fake initializer as if a plugin bundle had actually been loaded.
const fakeInitializer = jest.fn();
coreWindow.__kbnBundles__['plugin/plugin-a'] = fakeInitializer;
coreWindow.__kbnBundles__['plugin/plugin-a'] = { plugin: fakeInitializer };
// Call the onload callback
fakeScriptTag.onload();
await expect(loadPromise).resolves.toEqual(fakeInitializer);
Expand Down
33 changes: 22 additions & 11 deletions src/core/public/plugins/plugin_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type UnknownPluginInitializer = PluginInitializer<unknown, Record<string,
*/
export interface CoreWindow {
__kbnBundles__: {
[pluginBundleName: string]: UnknownPluginInitializer | undefined;
[pluginBundleName: string]: { plugin: UnknownPluginInitializer } | undefined;
};
}

Expand Down Expand Up @@ -70,9 +70,28 @@ export const loadPluginBundle: LoadPluginBundle = <
) =>
new Promise<PluginInitializer<TSetup, TStart, TPluginsSetup, TPluginsStart>>(
(resolve, reject) => {
const script = document.createElement('script');
const coreWindow = (window as unknown) as CoreWindow;
const exportId = `plugin/${pluginName}`;

const readPluginExport = () => {
const PluginExport: any = coreWindow.__kbnBundles__[exportId];
if (typeof PluginExport?.plugin !== 'function') {
reject(
new Error(`Definition of plugin "${pluginName}" should be a function (${bundlePath}).`)
);
} else {
resolve(
PluginExport.plugin as PluginInitializer<TSetup, TStart, TPluginsSetup, TPluginsStart>
);
}
};

if (coreWindow.__kbnBundles__[exportId]) {
readPluginExport();
return;
}

const script = document.createElement('script');
// Assumes that all plugin bundles get put into the bundles/plugins subdirectory
const bundlePath = addBasePath(`/bundles/plugin/${pluginName}/${pluginName}.plugin.js`);
script.setAttribute('src', bundlePath);
Expand All @@ -89,15 +108,7 @@ export const loadPluginBundle: LoadPluginBundle = <
// Wire up resolve and reject
script.onload = () => {
cleanupTag();

const initializer = coreWindow.__kbnBundles__[`plugin/${pluginName}`];
if (!initializer || typeof initializer !== 'function') {
reject(
new Error(`Definition of plugin "${pluginName}" should be a function (${bundlePath}).`)
);
} else {
resolve(initializer as PluginInitializer<TSetup, TStart, TPluginsSetup, TPluginsStart>);
}
readPluginExport();
};

script.onerror = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { createInputControlVisController } from './vis_controller';
import { getControlsTab } from './components/editor/controls_tab';
import { OptionsTab } from './components/editor/options_tab';
import { InputControlVisDependencies } from './plugin';
import { defaultFeedbackMessage } from '../../../../plugins/kibana_utils/common';
import { defaultFeedbackMessage } from '../../../../plugins/kibana_utils/public';

export function createInputControlVisTypeDefinition(deps: InputControlVisDependencies) {
const InputControlVisController = createInputControlVisController(deps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/
import { DiscoverServices } from './build_services';
import { createGetterSetter } from '../../../../../plugins/kibana_utils/public';
import { search } from '../../../../../plugins/data/public';

let angularModule: any = null;
let services: DiscoverServices | null = null;
Expand Down Expand Up @@ -50,8 +52,6 @@ export const [getUrlTracker, setUrlTracker] = createGetterSetter<{
setTrackedUrl: (url: string) => void;
}>('urlTracker');

import { search } from '../../../../../plugins/data/public';
import { createGetterSetter } from '../../../../../plugins/kibana_utils/common';
export const { getRequestInspectorStats, getResponseInspectorStats, tabifyAggResponse } = search;
export {
unhashUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
* under the License.
*/

export * from './index_pattern_management';
export {
ProcessedImportResponse,
processImportResponse,
} from './management/sections/objects/lib/process_import_response';
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import React from 'react';
import { StepIndexPattern } from '../step_index_pattern';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
import { Header } from './components/header';
import { IndexPatternCreationConfig } from '../../../../../../../../management/public';
import { IndexPatternCreationConfig } from '../../../../../../../../../../plugins/index_pattern_management/public';
import { coreMock } from '../../../../../../../../../../core/public/mocks';
import { dataPluginMock } from '../../../../../../../../../../plugins/data/public/mocks';
import { SavedObjectsFindResponsePublic } from '../../../../../../../../../../core/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { LoadingIndices } from './components/loading_indices';
import { StatusMessage } from './components/status_message';
import { IndicesList } from './components/indices_list';
import { Header } from './components/header';
import { IndexPatternCreationConfig } from '../../../../../../../../management/public';
import { IndexPatternCreationConfig } from '../../../../../../../../../../plugins/index_pattern_management/public';
import { MatchedIndex } from '../../types';

interface StepIndexPatternProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React from 'react';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
import { IndexPatternCreationConfig } from '../../../../../../../../management/public';
import { IndexPatternCreationConfig } from '../../../../../../../../../../plugins/index_pattern_management/public';
import { IFieldType } from '../../../../../../../../../../plugins/data/public';

import { StepTimeField } from '../step_time_field';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { Header } from './components/header';
import { TimeField } from './components/time_field';
import { AdvancedOptions } from './components/advanced_options';
import { ActionButtons } from './components/action_buttons';
import { IndexPatternCreationConfig } from '../../../../../../../../management/public';
import { IndexPatternCreationConfig } from '../../../../../../../../../../plugins/index_pattern_management/public';
import { DataPublicPluginStart } from '../../../../../../../../../../plugins/data/public';

interface StepTimeFieldProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import uiRoutes from 'ui/routes';
import angularTemplate from './angular_template.html';
import { npStart } from 'ui/new_platform';
import { setup as managementSetup } from '../../../../../../management/public/legacy';
import { getCreateBreadcrumbs } from '../breadcrumbs';

import { renderCreateIndexPatternWizard, destroyCreateIndexPatternWizard } from './render';
Expand All @@ -33,7 +32,7 @@ uiRoutes.when('/management/kibana/index_pattern', {
const kbnUrl = $injector.get('kbnUrl');
$scope.$$postDigest(() => {
const $routeParams = $injector.get('$routeParams');
const indexPatternCreationType = managementSetup.indexPattern.creation.getType(
const indexPatternCreationType = npStart.plugins.indexPatternManagement.creation.getType(
$routeParams.type
);
const services = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { getIndices } from './get_indices';
import { IndexPatternCreationConfig } from './../../../../../../../management/public';
import { IndexPatternCreationConfig } from '../../../../../../../../../plugins/index_pattern_management/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LegacyApiCaller } from '../../../../../../../../../plugins/data/public/search';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { get, sortBy } from 'lodash';
import { IndexPatternCreationConfig } from '../../../../../../../management/public';
import { IndexPatternCreationConfig } from '../../../../../../../../../plugins/index_pattern_management/public';
import { DataPublicPluginStart } from '../../../../../../../../../plugins/data/public';
import { MatchedIndex } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { uiModules } from 'ui/modules';
import template from './edit_index_pattern.html';
import { fieldWildcardMatcher } from '../../../../../../../../plugins/kibana_utils/public';
import { subscribeWithScope } from '../../../../../../../../plugins/kibana_legacy/public';
import { setup as managementSetup } from '../../../../../../management/public/legacy';
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { SourceFiltersTable } from './source_filters_table';
Expand Down Expand Up @@ -239,14 +238,12 @@ uiModules
$scope.editSectionsProvider = Private(IndicesEditSectionsProvider);
$scope.kbnUrl = Private(KbnUrlProvider);
$scope.indexPattern = $route.current.locals.indexPattern;
$scope.indexPatternListProvider = managementSetup.indexPattern.list;
$scope.indexPattern.tags = managementSetup.indexPattern.list.getIndexPatternTags(
$scope.indexPatternListProvider = npStart.plugins.indexPatternManagement.list;
$scope.indexPattern.tags = npStart.plugins.indexPatternManagement.list.getIndexPatternTags(
$scope.indexPattern,
$scope.indexPattern.id === config.get('defaultIndex')
);
$scope.getFieldInfo = managementSetup.indexPattern.list.getFieldInfo.bind(
managementSetup.indexPattern.list
);
$scope.getFieldInfo = npStart.plugins.indexPatternManagement.list.getFieldInfo;
docTitle.change($scope.indexPattern.title);

const otherPatterns = _.filter($route.current.locals.indexPatterns, pattern => {
Expand All @@ -257,7 +254,7 @@ uiModules
$scope.editSections = $scope.editSectionsProvider(
$scope.indexPattern,
$scope.fieldFilter,
managementSetup.indexPattern.list
npStart.plugins.indexPatternManagement.list
);
$scope.refreshFilters();
$scope.fields = $scope.indexPattern.getNonScriptedFields();
Expand Down Expand Up @@ -375,7 +372,7 @@ uiModules
$scope.editSections = $scope.editSectionsProvider(
$scope.indexPattern,
$scope.fieldFilter,
managementSetup.indexPattern.list
npStart.plugins.indexPatternManagement.list
);

if ($scope.fieldFilter === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import { management } from 'ui/management';
import { setup as managementSetup } from '../../../../../management/public/legacy';
import './create_index_pattern_wizard';
import './edit_index_pattern';
import uiRoutes from 'ui/routes';
Expand Down Expand Up @@ -111,7 +110,7 @@ uiModules
transclude: true,
template: indexTemplate,
link: async function($scope) {
const indexPatternCreationOptions = await managementSetup.indexPattern.creation.getIndexPatternCreationOptions(
const indexPatternCreationOptions = await npStart.plugins.indexPatternManagement.creation.getIndexPatternCreationOptions(
url => {
$scope.$evalAsync(() => kbnUrl.change(url));
}
Expand All @@ -124,7 +123,7 @@ uiModules
const id = pattern.id;
const title = pattern.get('title');
const isDefault = $scope.defaultIndex === id;
const tags = managementSetup.indexPattern.list.getIndexPatternTags(
const tags = npStart.plugins.indexPatternManagement.list.getIndexPatternTags(
pattern,
isDefault
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React from 'react';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
import { mockManagementPlugin } from '../../../../../../../../management/public/np_ready/mocks';
import { mockManagementPlugin } from '../../../../../../../../../../plugins/index_pattern_management/public/mocks';
import { Query } from '@elastic/eui';

import { ObjectsTable, POSSIBLE_TYPES } from '../objects_table';
Expand All @@ -30,7 +30,7 @@ import { extractExportDetails } from '../../../lib/extract_export_details';

jest.mock('ui/kfetch', () => ({ kfetch: jest.fn() }));

jest.mock('../../../../../../../../management/public/legacy', () => ({
jest.mock('../../../../../../../../../../plugins/index_pattern_management/public', () => ({
setup: mockManagementPlugin.createSetupContract(),
start: mockManagementPlugin.createStartContract(),
}));
Expand Down
Loading

0 comments on commit 8fb2ea8

Please sign in to comment.