diff --git a/.eslintrc.js b/.eslintrc.js index c9bb5dde2e098a..3d5be9fa465010 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -109,7 +109,7 @@ module.exports = { // instructs import/no-extraneous-dependencies to treat modules // in plugins/ or ui/ namespace as "core modules" so they don't // trigger failures for not being listed in package.json - 'import/core-modules': ['plugins', 'ui', 'uiExports'], + 'import/core-modules': ['plugins', 'legacy/ui', 'uiExports'], 'import/resolver': { '@kbn/eslint-import-resolver-kibana': { diff --git a/src/cli/cluster/cluster_manager.js b/src/cli/cluster/cluster_manager.js index 95b92eb90ed1ca..e2e97d55d0fd69 100644 --- a/src/cli/cluster/cluster_manager.js +++ b/src/cli/cluster/cluster_manager.js @@ -170,7 +170,6 @@ export default class ClusterManager { fromRoot('x-pack/common'), fromRoot('x-pack/plugins'), fromRoot('x-pack/server'), - fromRoot('x-pack/webpackShims'), fromRoot('config'), ...extraPaths, ].map(path => resolve(path)); diff --git a/src/dev/precommit_hook/casing_check_config.js b/src/dev/precommit_hook/casing_check_config.js index 460a789f101337..54ed19852c18ba 100644 --- a/src/dev/precommit_hook/casing_check_config.js +++ b/src/dev/precommit_hook/casing_check_config.js @@ -174,7 +174,6 @@ export const TEMPORARILY_IGNORED_PATHS = [ 'packages/kbn-ui-framework/doc_site/src/images/elastic-logo.svg', 'packages/kbn-ui-framework/doc_site/src/images/hint-arrow.svg', 'packages/kbn-ui-framework/doc_site/src/images/react-logo.svg', - 'webpackShims/angular-ui-select.js', 'webpackShims/elasticsearch-browser.js', 'webpackShims/moment-timezone.js', 'webpackShims/ui-bootstrap.js', @@ -182,7 +181,7 @@ export const TEMPORARILY_IGNORED_PATHS = [ 'x-pack/plugins/graph/public/angular-venn-simple.js', 'x-pack/plugins/index_management/public/lib/editSettings.js', 'x-pack/plugins/license_management/public/store/reducers/licenseManagement.js', - 'x-pack/plugins/monitoring/public/components/sparkline/__mocks__/jquery-flot.js', + 'x-pack/plugins/monitoring/public/components/sparkline/__mocks__/plugins/xpack_main/jquery_flot.js', 'x-pack/plugins/ml/public/jobs/new_job/simple/components/watcher/email-influencers.html', 'x-pack/plugins/monitoring/public/icons/alert-blue.svg', 'x-pack/plugins/monitoring/public/icons/health-gray.svg', diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js b/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js index 21f8e5e1534b88..5dc65dad4deb21 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js +++ b/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js @@ -21,7 +21,7 @@ import 'ui/directives/css_truncate'; import 'ui/directives/field_name'; import 'ui/filters/unique'; import './discover_field'; -import 'angular-ui-select'; +import 'ui/angular_ui_select'; import _ from 'lodash'; import $ from 'jquery'; import rison from 'rison-node'; diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/_view.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/_view.js index 93b7db9ceed194..4db5fabd7eaf15 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/_view.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/_view.js @@ -19,6 +19,7 @@ import _ from 'lodash'; import angular from 'angular'; +import 'angular-elastic/elastic'; import rison from 'rison-node'; import { savedObjectManagementRegistry } from '../../saved_object_registry'; import objectViewHTML from './_view.html'; @@ -40,7 +41,7 @@ uiRoutes k7Breadcrumbs: getViewBreadcrumbs }); -uiModules.get('apps/management') +uiModules.get('apps/management', ['monospaced.elastic']) .directive('kbnManagementObjectsView', function (kbnIndex, confirmModal, i18n) { return { restrict: 'E', diff --git a/src/legacy/ui/public/angular-bootstrap/index.js b/src/legacy/ui/public/angular-bootstrap/index.js index b519abcaf5dee3..9a95629282717e 100644 --- a/src/legacy/ui/public/angular-bootstrap/index.js +++ b/src/legacy/ui/public/angular-bootstrap/index.js @@ -5,6 +5,14 @@ * TODO: Write custom components that address our needs to directly and deprecate these Bootstrap components. */ +import 'angular'; + +import { uiModules } from 'ui/modules'; + +uiModules.get('kibana', [ + 'ui.bootstrap', +]); + /* * angular-ui-bootstrap * http://angular-ui.github.io/bootstrap/ diff --git a/webpackShims/angular-ui-select.js b/src/legacy/ui/public/angular_ui_select.js similarity index 79% rename from webpackShims/angular-ui-select.js rename to src/legacy/ui/public/angular_ui_select.js index 2b88836fc97f1d..92b1bf53520ce3 100644 --- a/webpackShims/angular-ui-select.js +++ b/src/legacy/ui/public/angular_ui_select.js @@ -17,10 +17,11 @@ * under the License. */ -require('jquery'); -require('angular'); -require('angular-sanitize'); -require('ui-select/dist/select'); -require('ui-select/dist/select.css'); +import 'jquery'; +import 'angular'; +import 'angular-sanitize'; +import 'ui-select/dist/select'; -require('ui/modules').get('kibana', ['ui.select', 'ngSanitize']); +import { uiModules } from 'ui/modules'; + +uiModules.get('kibana', ['ui.select', 'ngSanitize']); diff --git a/src/legacy/ui/public/autoload/modules.js b/src/legacy/ui/public/autoload/modules.js index 7a747ebb269145..d9e65a99bd7b6b 100644 --- a/src/legacy/ui/public/autoload/modules.js +++ b/src/legacy/ui/public/autoload/modules.js @@ -54,3 +54,7 @@ import '../saved_objects/ui/saved_object_save_as_checkbox'; import '../react_components'; import '../i18n'; import '../query_bar/directive'; + +import '@elastic/ui-ace'; +import { uiModules } from 'ui/modules'; +uiModules.get('kibana', ['ui.ace']); diff --git a/src/legacy/ui/public/styles/bootstrap/buttons.less b/src/legacy/ui/public/styles/bootstrap/buttons.less index 910365822cb3dd..04bc13b0d9c6ef 100644 --- a/src/legacy/ui/public/styles/bootstrap/buttons.less +++ b/src/legacy/ui/public/styles/bootstrap/buttons.less @@ -1,5 +1,5 @@ /** - * angular-ui-select depends upon these styles. Don't use them in your markup. + * ui/angular-ui-select depends upon these styles. Don't use them in your markup. * Please use the UI Framework styles instead. */ diff --git a/src/legacy/ui/public/test_harness/test_harness.js b/src/legacy/ui/public/test_harness/test_harness.js index 178971c582d66e..36dc38b1c3b825 100644 --- a/src/legacy/ui/public/test_harness/test_harness.js +++ b/src/legacy/ui/public/test_harness/test_harness.js @@ -18,6 +18,8 @@ */ // chrome expects to be loaded first, let it get its way +import $ from 'jquery'; +import bindJqueryToFindTestSubject from 'ui/jquery/find_test_subject'; import chrome from '../chrome'; import { parse as parseUrl } from 'url'; @@ -30,6 +32,8 @@ import './test_harness.css'; import 'ng_mock'; import { setupTestSharding } from './test_sharding'; +bindJqueryToFindTestSubject($); + const { query } = parseUrl(window.location.href, true); if (query && query.mocha) { try { diff --git a/src/legacy/ui/public/tooltip/tooltip.js b/src/legacy/ui/public/tooltip/tooltip.js index 7ae8c54375040a..221814bfec919a 100644 --- a/src/legacy/ui/public/tooltip/tooltip.js +++ b/src/legacy/ui/public/tooltip/tooltip.js @@ -17,14 +17,18 @@ * under the License. */ +import 'ui/angular-bootstrap'; import html from './tooltip.html'; import chrome from 'ui/chrome'; +import { uiModules } from 'ui/modules'; -require('ui-bootstrap') +uiModules.get('kibana') .config(function ($tooltipProvider) { // we use the uiSettings client because the config service is not available in the config phase const uiSettings = chrome.getUiSettingsClient(); + $tooltipProvider.setTriggers({ 'mouseenter': 'mouseleave click' }); + $tooltipProvider.options({ placement: 'bottom', animation: !uiSettings.get('accessibility:disableAnimations'), diff --git a/webpackShims/ui-bootstrap.js b/src/optimize/dynamic_dll_plugin/dll_allowed_modules.js similarity index 59% rename from webpackShims/ui-bootstrap.js rename to src/optimize/dynamic_dll_plugin/dll_allowed_modules.js index e8354018e6c18c..9bc8d4504e1ff9 100644 --- a/webpackShims/ui-bootstrap.js +++ b/src/optimize/dynamic_dll_plugin/dll_allowed_modules.js @@ -17,12 +17,21 @@ * under the License. */ -require('angular'); -require('ui/angular-bootstrap'); -var uiModules = require('ui/modules').uiModules; +import path from 'path'; -var kibana = uiModules.get('kibana', ['ui.bootstrap']); +export function notInNodeModules(checkPath) { + return !checkPath.includes(`${path.sep}node_modules${path.sep}`); +} -module.exports = kibana.config(function ($tooltipProvider) { - $tooltipProvider.setTriggers({ 'mouseenter': 'mouseleave click' }); -}); +export function notInNodeModulesOrWebpackShims(checkPath) { + return notInNodeModules(checkPath) + && !checkPath.includes(`${path.sep}webpackShims${path.sep}`); +} + +export function inPluginNodeModules(checkPath) { + return checkPath.match(/[\/\\]plugins.*[\/\\]node_modules/); +} + +export function inDllPluginPublic(checkPath) { + return checkPath.includes(`${path.sep}dynamic_dll_plugin/public${path.sep}`); +} diff --git a/src/optimize/dynamic_dll_plugin/dll_compiler.js b/src/optimize/dynamic_dll_plugin/dll_compiler.js index b403afe955365d..6732ade2974f91 100644 --- a/src/optimize/dynamic_dll_plugin/dll_compiler.js +++ b/src/optimize/dynamic_dll_plugin/dll_compiler.js @@ -18,6 +18,7 @@ */ import { configModel } from './dll_config_model'; +import { notInNodeModulesOrWebpackShims, notInNodeModules, inDllPluginPublic } from './dll_allowed_modules'; import { fromRoot } from '../../legacy/utils'; import { PUBLIC_PATH_PLACEHOLDER } from '../public_path_placeholder'; import fs from 'fs'; @@ -25,11 +26,13 @@ import mkdirp from 'mkdirp'; import webpack from 'webpack'; import { promisify } from 'util'; import path from 'path'; +import rimraf from 'rimraf'; const readFileAsync = promisify(fs.readFile); const mkdirpAsync = promisify(mkdirp); const existsAsync = promisify(fs.exists); const writeFileAsync = promisify(fs.writeFile); +const rimrafAsync = promisify(rimraf); export class DllCompiler { static getRawDllConfig(uiBundles = {}, babelLoaderCacheDir = '', threadLoaderPoolConfig = {}) { @@ -163,7 +166,26 @@ export class DllCompiler { async run(dllEntries) { const dllConfig = this.dllConfigGenerator(this.rawDllConfig); await this.upsertEntryFile(dllEntries); - await this.runWebpack(dllConfig()); + + try { + this.logWithMetadata(['info', 'optimize:dynamic_dll_plugin'], 'Client vendors dll compilation started'); + + await this.runWebpack(dllConfig()); + + this.logWithMetadata( + ['info', 'optimize:dynamic_dll_plugin'], + `Client vendors dll compilation finished with success` + ); + } catch (e) { + this.logWithMetadata( + ['fatal', 'optimize:dynamic_dll_plugin'], + `Client vendors dll compilation failed` + ); + + // Still throw the original error has here we just want + // log the fail message + throw e; + } // Style dll file isn't always created but we are // expecting it to exist always as we are referencing @@ -182,9 +204,7 @@ export class DllCompiler { async runWebpack(config) { return new Promise((resolve, reject) => { - this.logWithMetadata(['info', 'optimize:dynamic_dll_plugin'], 'Client vendors dll compilation started'); - - webpack(config, (err, stats) => { + webpack(config, async (err, stats) => { // If a critical error occurs or we have // errors in the stats compilation, // reject the promise and logs the errors @@ -197,18 +217,77 @@ export class DllCompiler { })); if (webpackErrors) { - this.logWithMetadata( - ['fatal', 'optimize:dynamic_dll_plugin'], - `Client vendors dll compilation failed` - ); + // Reject with webpack fatal errors return reject(webpackErrors); } - // Otherwise let it proceed - this.logWithMetadata( - ['info', 'optimize:dynamic_dll_plugin'], - `Client vendors dll compilation finished with success` - ); + // Identify if we have not allowed modules + // bundled inside the dll bundle + const notAllowedModules = []; + + stats.compilation.modules.forEach((module) => { + // ignore if no module or userRequest are defined + if (!module || !module.resource) { + return; + } + + // ignore if this module represents the + // dll entry file + if (module.resource === this.getEntryPath()) { + return; + } + + // ignore if this module is part of the + // files inside dynamic dll plugin public folder + if (inDllPluginPublic(module.resource)) { + return; + } + + // A module is not allowed if it's not a node_module, a webpackShim + // or the reasons from being bundled into the dll are not node_modules + if(notInNodeModulesOrWebpackShims(module.resource)) { + const reasons = module.reasons || []; + + reasons.forEach((reason) => { + // Skip if we can't read the reason info + if (!reason || !reason.module || !reason.module.resource) { + return; + } + + // Is the reason for this module being bundle a + // node_module or no? + if (notInNodeModules(reason.module.resource)) { + notAllowedModules.push(module.resource); + return; + } + + // Even when the reason for the module comes from + // node_modules directory, assure it's not from + // node_modules/x-pack source code but from a real node_module + const dirs = reason.module.resource.split(path.sep); + const nodeModuleName = dirs[dirs.lastIndexOf('node_modules') + 1]; + const inXpackSource = nodeModuleName === 'x-pack'; + + if (inXpackSource) { + notAllowedModules.push(module.resource); + } + }); + } + }); + + if (notAllowedModules.length) { + // Delete the built dll, as it contains invalid modules, and reject listing + // all the not allowed modules + try { + await rimrafAsync(this.rawDllConfig.outputPath); + } catch (e) { + return reject(e); + } + + return reject(`The following modules are not allowed to be bundled into the dll: \n${notAllowedModules.join('\n')}`); + } + + // Otherwise it has succeed return resolve(stats); }); }); diff --git a/src/optimize/dynamic_dll_plugin/dll_entry_template.js b/src/optimize/dynamic_dll_plugin/dll_entry_template.js index 7f3da443b564ff..e1873b61662b9a 100644 --- a/src/optimize/dynamic_dll_plugin/dll_entry_template.js +++ b/src/optimize/dynamic_dll_plugin/dll_entry_template.js @@ -19,9 +19,9 @@ export function dllEntryTemplate(requirePaths = []) { return [ - `require('dll/set_csp_nonce')`, + `require('dll/set_csp_nonce');`, ...requirePaths - .map(path => `require('${path}')`) + .map(path => `require('${path}');`) .sort() ].join('\n'); } diff --git a/src/optimize/dynamic_dll_plugin/dynamic_dll_plugin.js b/src/optimize/dynamic_dll_plugin/dynamic_dll_plugin.js index 980c780a474cc0..c7daab37b78e37 100644 --- a/src/optimize/dynamic_dll_plugin/dynamic_dll_plugin.js +++ b/src/optimize/dynamic_dll_plugin/dynamic_dll_plugin.js @@ -18,6 +18,7 @@ */ import { DllCompiler } from './dll_compiler'; +import { notInNodeModulesOrWebpackShims, inPluginNodeModules } from './dll_allowed_modules'; import { IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils'; import { dllEntryTemplate } from './dll_entry_template'; import RawModule from 'webpack/lib/RawModule'; @@ -26,20 +27,10 @@ import path from 'path'; import normalizePosixPath from 'normalize-path'; import fs from 'fs'; import { promisify } from 'util'; -import { parseSingleFileSync, dependenciesVisitorsGenerator } from '@kbn/babel-code-parser'; const realPathAsync = promisify(fs.realpath); const DLL_ENTRY_STUB_MODULE_TYPE = 'javascript/dll-entry-stub'; -function inNodeModulesOrWebpackShims(checkPath) { - return checkPath.includes(`${path.sep}node_modules${path.sep}`) - || checkPath.includes(`${path.sep}webpackShims${path.sep}`); -} - -function inPluginNodeModules(checkPath) { - return checkPath.match(/[\/\\]plugins.*[\/\\]node_modules/); -} - export class DynamicDllPlugin { constructor({ uiBundles, threadLoaderPoolConfig, logWithMetadata, maxCompilations = 1 }) { this.logWithMetadata = logWithMetadata || (() => null); @@ -162,10 +153,8 @@ export class DynamicDllPlugin { const dllContext = rawDllConfig.context; const dllOutputPath = rawDllConfig.outputPath; const requiresMap = {}; - const resolvedShimsDependenciesMap = {}; for (const module of compilation.modules) { - let requiredModulePath = null; // re-include requires for modules already handled by the dll if (module.delegateData) { @@ -174,45 +163,15 @@ export class DynamicDllPlugin { // NOTE: normalizePosixPath is been used as we only want to have posix // paths inside our final dll entry file requiresMap[normalizePosixPath(path.relative(dllOutputPath, absoluteResource))] = true; - requiredModulePath = absoluteResource; } } // include requires for modules that need to be added to the dll if (module.stubType === DLL_ENTRY_STUB_MODULE_TYPE) { requiresMap[normalizePosixPath(path.relative(dllOutputPath, module.stubResource))] = true; - requiredModulePath = module.stubResource; - } - - // read new requires for modules that reaches the compilation, - // aren't already being handled by dll and were not also - // in the entry paths before. The majority should come - // from webpackShims, otherwise we should throw - if (requiredModulePath && !requiredModulePath.includes('node_modules')) { - if (!requiredModulePath.includes('webpackShims')) { - throw new Error( - `The following module is reaching the compilation and ins\'t either a node_module or webpackShim: - ${requiredModulePath} - ` - ); - } - - // Get dependencies found in each webpack shim entry and just - // adds them to the global map for the resolvedShimsDependencies - Object.assign( - resolvedShimsDependenciesMap, - this.getDependenciesFromShim(requiredModulePath, compilation) - ); } } - // Adds the discovered dep modules in webpackShims - // to the final require results - Object.assign( - requiresMap, - this.getRequireEntriesFromShimsDependencies(resolvedShimsDependenciesMap, dllOutputPath) - ); - // Sort and join all the discovered require deps // in order to create a consistent entry file this.afterCompilationEntryPaths = dllEntryTemplate(Object.keys(requiresMap)); @@ -248,19 +207,19 @@ export class DynamicDllPlugin { registerDoneHook(compiler) { compiler.hooks.done.tapPromise('DynamicDllPlugin', async stats => { if (stats.compilation.needsDLLCompilation) { - // Logic to run the max compilation requirements. - // Only enable this for CI builds in order to ensure - // we have an healthy dll ecosystem. - if (IS_KIBANA_DISTRIBUTABLE && (this.performedCompilations === this.maxCompilations)) { - throw new Error( - 'All the allowed dll compilations were already performed and one more is needed which is not possible' - ); - } - // Run the dlls compiler and increment // the performed compilations - await this.runDLLCompiler(compiler); - this.performedCompilations++; + // + // NOTE: check the need for this extra try/catch after upgrading + // past webpack v4.29.3. For now it is needed so we can log the error + // otherwise the error log we'll get will be something like: [fatal] [object Object] + try { + await this.runDLLCompiler(compiler); + } catch (error) { + this.logWithMetadata(['error', 'optimize:dynamic_dll_plugin'], error.message); + throw error; + } + return; } @@ -274,125 +233,6 @@ export class DynamicDllPlugin { }); } - getDependenciesFromShim(requiredModulePath, compilation) { - // NOTE: is possible we are able to do this reading and searching - // through the compilation's webpack modules, however - // for a sake of simplicity, and as the webpackShims - // should be really small files, we are parsing them - // manually and getting the requires - - // Internal map to keep track of the dependencies found for the - // current webpackShim file - const resolvedShimDependencies = {}; - - // Discover the requires inside the webpackShims - const shimsDependencies = parseSingleFileSync(requiredModulePath, dependenciesVisitorsGenerator); - - // Resolve webpackShims dependencies with alias - shimsDependencies.forEach((dep) => { - const isRelative = dep && dep.charAt(0) === '.'; - let absoluteResource = null; - - // check if the dependency value is relative - if (isRelative) { - absoluteResource = path.resolve(path.dirname(requiredModulePath), dep); - } else { - // get the imports and search for alias in the dependency - const alias = compilation.compiler.options.resolve.alias; - const aliasFound = Object.keys(alias).find((aliasKey) => { - return dep.search(`${aliasKey}/`) !== -1; - }); - // search for imports with webpack-loaders - const webpackLoaderFoundIdx = dep.search('!'); - - if (webpackLoaderFoundIdx !== -1) { - // get the loader - const loader = dep.substring(0, webpackLoaderFoundIdx); - // get the rest of the dependency require value - // after the webpack loader char (!) - const restImport = dep.substring(webpackLoaderFoundIdx + 1); - // build the first part with the loader resolved - const absoluteResourceFirstPart = require.resolve(loader); - // check if we have a relative path in the script require - // path being passed to the loader - const isRestImportRelative = restImport && restImport.charAt(0) === '.'; - // resolve the relative script dependency path - // in case we have one - const sanitizedRestImport = isRestImportRelative - ? path.resolve(path.dirname(requiredModulePath), restImport) - : restImport; - // replace the alias in the script dependency require path - // in case we have found the alias - const absoluteResourceSecondPart = aliasFound - ? require.resolve(`${alias[aliasFound]}${sanitizedRestImport.substring(aliasFound.length)}`) - : require.resolve(sanitizedRestImport); - - // finally build our absolute entry path again in the - // original loader format `webpack-loader!script_path` - absoluteResource = `${absoluteResourceFirstPart}!${absoluteResourceSecondPart}`; - } else { - // in case we don't have any webpack loader in the - // dependency require value, just replace the alias - // if we have one and then resolve the result, - // or just resolve the dependency path if we don't - // have any alias - absoluteResource = aliasFound - ? require.resolve(`${alias[aliasFound]}${dep.substring(aliasFound.length)}`) - : require.resolve(dep); - } - } - - // Only consider found js entries - if (!absoluteResource.includes('.js') || absoluteResource.includes('json')) { - return; - } - - // add the absolute built resource to the list of - // entry paths found inside the webpackShims - // to be merged with the general requiresMap - // in the end - resolvedShimDependencies[absoluteResource] = true; - }); - - return resolvedShimDependencies; - } - - getRequireEntriesFromShimsDependencies(resolvedShimsDependenciesMap, dllOutputPath) { - const internalRequiresMap = {}; - const resolvedShimsDependencies = Object.keys(resolvedShimsDependenciesMap); - - resolvedShimsDependencies.forEach((resolvedDep) => { - if (resolvedDep) { - // check if this is a require shim dependency with - // an webpack-loader - const webpackLoaderFoundIdx = resolvedDep.search('!'); - - if (webpackLoaderFoundIdx !== -1) { - // get the webpack-loader - const loader = resolvedDep.substring(0, webpackLoaderFoundIdx); - // get the rest of the dependency require value - // after the webpack-loader char (!) - const restImport = resolvedDep.substring(webpackLoaderFoundIdx + 1); - // resolve the loader and the restImport parts separately - const resolvedDepToRequireFirstPart = normalizePosixPath(path.relative(dllOutputPath, loader)); - const resolvedDepToRequireSecondPart = normalizePosixPath(path.relative(dllOutputPath, restImport)); - - // rebuild our final webpackShim entry path in the original - // webpack loader format `webpack-loader!script_path` - // but right now resolved relatively to the dll output path - internalRequiresMap[`${resolvedDepToRequireFirstPart}!${resolvedDepToRequireSecondPart}`] = true; - } else { - // in case we didn't have any webpack-loader in the require path - // resolve the dependency path relative to the dllOutput path - // to get our final entry path - internalRequiresMap[normalizePosixPath(path.relative(dllOutputPath, resolvedDep))] = true; - } - } - }); - - return internalRequiresMap; - } - isToForceDLLCreation() { return this.forceDLLCreationFlag; } @@ -413,13 +253,13 @@ export class DynamicDllPlugin { } // ignore files that are not in node_modules - if (!inNodeModulesOrWebpackShims(module.resource)) { + if (notInNodeModulesOrWebpackShims(module.resource)) { return; } // also ignore files that are symlinked into node_modules, but only // do the `realpath` call after checking the plain resource path - if (!inNodeModulesOrWebpackShims(await realPathAsync(module.resource))) { + if (notInNodeModulesOrWebpackShims(await realPathAsync(module.resource))) { return; } @@ -457,12 +297,41 @@ export class DynamicDllPlugin { return stubModule; } + async assertMaxCompilations() { + // Logic to run the max compilation requirements. + // Only enable this for CI builds in order to ensure + // we have an healthy dll ecosystem. + if (this.performedCompilations === this.maxCompilations) { + throw new Error('All the allowed dll compilations were already performed and one more is needed which is not possible'); + } + } + async runDLLCompiler(mainCompiler) { - await this.dllCompiler.run(this.entryPaths); + const runCompilerErrors = []; + + try { + await this.dllCompiler.run(this.entryPaths); + } catch (e) { + runCompilerErrors.push(e); + } + + try { + await this.assertMaxCompilations(); + } catch (e) { + runCompilerErrors.push(e); + } // We need to purge the cache into the inputFileSystem // for every single built in previous compilation // that we rely in next ones. mainCompiler.inputFileSystem.purge(this.dllCompiler.getManifestPath()); + + this.performedCompilations++; + + if (!runCompilerErrors.length) { + return; + } + + throw new Error(runCompilerErrors.join('\n-')); } } diff --git a/webpackShims/ace.js b/webpackShims/ace.js index e411b46a7a405f..61f319be574ddf 100644 --- a/webpackShims/ace.js +++ b/webpackShims/ace.js @@ -21,6 +21,4 @@ require('brace'); require('brace/mode/json'); require('../node_modules/@elastic/ui-ace/ui-ace'); -require('ui/modules').get('kibana', ['ui.ace']); - module.exports = window.ace; diff --git a/webpackShims/angular.js b/webpackShims/angular.js index ab7fc06bf3c282..4857f0f8975bca 100644 --- a/webpackShims/angular.js +++ b/webpackShims/angular.js @@ -20,7 +20,3 @@ require('jquery'); require('../node_modules/angular/angular'); module.exports = window.angular; - -require('../node_modules/angular-elastic/elastic'); - -require('ui/modules').get('kibana', ['monospaced.elastic']); diff --git a/webpackShims/elasticsearch-browser.js b/webpackShims/elasticsearch-browser.js index d8d7e439a129e2..a4373dcdfe1d14 100644 --- a/webpackShims/elasticsearch-browser.js +++ b/webpackShims/elasticsearch-browser.js @@ -19,4 +19,3 @@ require('angular'); module.exports = require('elasticsearch-browser/elasticsearch.angular.js'); -require('ui/modules').get('kibana', ['elasticsearch']); diff --git a/webpackShims/jquery.js b/webpackShims/jquery.js index 3fd7af45f12deb..da81dd18cf71e7 100644 --- a/webpackShims/jquery.js +++ b/webpackShims/jquery.js @@ -17,5 +17,4 @@ * under the License. */ -var $ = window.jQuery = window.$ = module.exports = require('../node_modules/jquery/dist/jquery'); -require('ui/jquery/find_test_subject')($); +window.jQuery = window.$ = module.exports = require('../node_modules/jquery/dist/jquery'); diff --git a/x-pack/dev-tools/jest/create_jest_config.js b/x-pack/dev-tools/jest/create_jest_config.js index 7afcc9b70a7904..cd4d6a68ef912e 100644 --- a/x-pack/dev-tools/jest/create_jest_config.js +++ b/x-pack/dev-tools/jest/create_jest_config.js @@ -22,6 +22,7 @@ export function createJestConfig({ ], moduleNameMapper: { '^ui/(.*)': `${kibanaDirectory}/src/legacy/ui/public/$1`, + '^plugins/xpack_main/(.*);': `${xPackKibanaDirectory}/plugins/xpack_main/public/$1`, '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': `${kibanaDirectory}/src/dev/jest/mocks/file_mock.js`, '\\.(css|less|scss)$': `${kibanaDirectory}/src/dev/jest/mocks/style_mock.js`, diff --git a/x-pack/package.json b/x-pack/package.json index 427e697f8caf10..722e6acf0fbd39 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -261,7 +261,7 @@ "turf": "3.0.14", "typescript-fsa": "^2.5.0", "typescript-fsa-reducers": "^0.4.5", - "ui-select": "0.19.4", + "ui-select": "0.19.6", "unbzip2-stream": "1.0.9", "unstated": "^2.1.1", "uuid": "3.0.1", diff --git a/x-pack/plugins/canvas/public/app.js b/x-pack/plugins/canvas/public/app.js index 30bf9e90e8abc1..b43f55fea891fe 100644 --- a/x-pack/plugins/canvas/public/app.js +++ b/x-pack/plugins/canvas/public/app.js @@ -5,11 +5,11 @@ */ import 'ui/autoload/all'; -import chrome from 'ui/chrome'; import './angular/config'; import './angular/services'; import React from 'react'; import ReactDOM from 'react-dom'; +import chrome from 'ui/chrome'; import { CanvasRootController } from './angular/controllers'; // Import the uiExports that the application uses diff --git a/x-pack/plugins/canvas/public/components/app/track_route_change.js b/x-pack/plugins/canvas/public/components/app/track_route_change.js index 3930a09f7645f6..fb8bd68d5401e2 100644 --- a/x-pack/plugins/canvas/public/components/app/track_route_change.js +++ b/x-pack/plugins/canvas/public/components/app/track_route_change.js @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +import { get } from 'lodash'; import chrome from 'ui/chrome'; import { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url'; -import { get } from 'lodash'; import { getWindow } from '../../lib/get_window'; import { CANVAS_APP } from '../../../common/lib/constants'; diff --git a/x-pack/plugins/canvas/public/components/expression/index.js b/x-pack/plugins/canvas/public/components/expression/index.js index 61dd91141af3eb..3459b7f2689950 100644 --- a/x-pack/plugins/canvas/public/components/expression/index.js +++ b/x-pack/plugins/canvas/public/components/expression/index.js @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Storage } from 'ui/storage'; import { connect } from 'react-redux'; import { compose, @@ -16,6 +15,7 @@ import { renderComponent, } from 'recompose'; import { fromExpression } from '@kbn/interpreter/common'; +import { Storage } from 'ui/storage'; import { getSelectedPage, getSelectedElement } from '../../state/selectors/workpad'; import { setExpression, flushContext } from '../../state/actions/elements'; import { getFunctionDefinitions } from '../../lib/function_definitions'; diff --git a/x-pack/plugins/canvas/public/components/workpad_export/utils.js b/x-pack/plugins/canvas/public/components/workpad_export/utils.js index 9fefaef09b9ab9..ec223a2e24ba41 100644 --- a/x-pack/plugins/canvas/public/components/workpad_export/utils.js +++ b/x-pack/plugins/canvas/public/components/workpad_export/utils.js @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +import rison from 'rison-node'; import chrome from 'ui/chrome'; import { QueryString } from 'ui/utils/query_string'; -import rison from 'rison-node'; import { fetch } from '../../../common/lib/fetch'; // type of the desired pdf output (print or preserve_layout) diff --git a/x-pack/plugins/canvas/public/functions/timelion.js b/x-pack/plugins/canvas/public/functions/timelion.js index 3f803e467978ec..737a17e78ececc 100644 --- a/x-pack/plugins/canvas/public/functions/timelion.js +++ b/x-pack/plugins/canvas/public/functions/timelion.js @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; import { flatten } from 'lodash'; +import chrome from 'ui/chrome'; import { fetch } from '../../common/lib/fetch'; import { buildBoolArray } from '../../server/lib/build_bool_array'; diff --git a/x-pack/plugins/canvas/public/lib/notify.js b/x-pack/plugins/canvas/public/lib/notify.js index c8cbac191caf57..928d49b7b61e07 100644 --- a/x-pack/plugins/canvas/public/lib/notify.js +++ b/x-pack/plugins/canvas/public/lib/notify.js @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +import { get } from 'lodash'; import { toastNotifications } from 'ui/notify'; import { formatMsg } from 'ui/notify/lib/format_msg'; -import { get } from 'lodash'; const getToast = (err, opts = {}) => { const errData = get(err, 'response') || err; diff --git a/x-pack/plugins/canvas/public/state/reducers/workpad.js b/x-pack/plugins/canvas/public/state/reducers/workpad.js index 894389003bc3a3..124af96888b4cd 100644 --- a/x-pack/plugins/canvas/public/state/reducers/workpad.js +++ b/x-pack/plugins/canvas/public/state/reducers/workpad.js @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { recentlyAccessed } from 'ui/persisted_log'; import { handleActions } from 'redux-actions'; +import { recentlyAccessed } from 'ui/persisted_log'; import { setWorkpad, sizeWorkpad, diff --git a/x-pack/plugins/ml/public/app.js b/x-pack/plugins/ml/public/app.js index 433eca37d8bb06..135b80bd398f4e 100644 --- a/x-pack/plugins/ml/public/app.js +++ b/x-pack/plugins/ml/public/app.js @@ -10,7 +10,7 @@ import 'uiExports/fieldFormats'; import 'uiExports/savedObjectTypes'; import 'ui/courier'; -import 'ui-bootstrap'; +import 'ui/angular-bootstrap'; import 'ui/persisted_log'; import 'ui/autoload/all'; diff --git a/x-pack/plugins/ml/public/jobs/new_job/advanced/new_job_controller.js b/x-pack/plugins/ml/public/jobs/new_job/advanced/new_job_controller.js index 348c3e98b729c7..4613467f0dabb7 100644 --- a/x-pack/plugins/ml/public/jobs/new_job/advanced/new_job_controller.js +++ b/x-pack/plugins/ml/public/jobs/new_job/advanced/new_job_controller.js @@ -9,7 +9,7 @@ import _ from 'lodash'; import angular from 'angular'; import 'ace'; -import 'angular-ui-select'; +import 'ui/angular_ui_select'; import { parseInterval } from 'ui/utils/parse_interval'; import { timefilter } from 'ui/timefilter'; diff --git a/x-pack/plugins/ml/public/jobs/new_job/simple/multi_metric/create_job/create_job_controller.js b/x-pack/plugins/ml/public/jobs/new_job/simple/multi_metric/create_job/create_job_controller.js index 1ca9efa55d958a..d32143a62ef74a 100644 --- a/x-pack/plugins/ml/public/jobs/new_job/simple/multi_metric/create_job/create_job_controller.js +++ b/x-pack/plugins/ml/public/jobs/new_job/simple/multi_metric/create_job/create_job_controller.js @@ -7,7 +7,7 @@ import _ from 'lodash'; -import 'angular-ui-select'; +import 'ui/angular_ui_select'; import { aggTypes } from 'ui/agg_types'; import { addJobValidationMethods } from 'plugins/ml/../common/util/validation_utils'; diff --git a/x-pack/plugins/ml/public/jobs/new_job/simple/population/create_job/create_job_controller.js b/x-pack/plugins/ml/public/jobs/new_job/simple/population/create_job/create_job_controller.js index 4112c2bd672263..02328817e58783 100644 --- a/x-pack/plugins/ml/public/jobs/new_job/simple/population/create_job/create_job_controller.js +++ b/x-pack/plugins/ml/public/jobs/new_job/simple/population/create_job/create_job_controller.js @@ -7,7 +7,7 @@ import _ from 'lodash'; -import 'angular-ui-select'; +import 'ui/angular_ui_select'; import { aggTypes } from 'ui/agg_types/index'; import { addJobValidationMethods } from 'plugins/ml/../common/util/validation_utils'; diff --git a/x-pack/plugins/ml/public/jobs/new_job/simple/recognize/create_job/create_job_controller.js b/x-pack/plugins/ml/public/jobs/new_job/simple/recognize/create_job/create_job_controller.js index dca6e2021b5e0b..ab29cd3410c971 100644 --- a/x-pack/plugins/ml/public/jobs/new_job/simple/recognize/create_job/create_job_controller.js +++ b/x-pack/plugins/ml/public/jobs/new_job/simple/recognize/create_job/create_job_controller.js @@ -8,7 +8,7 @@ import _ from 'lodash'; import angular from 'angular'; -import 'angular-ui-select'; +import 'ui/angular_ui_select'; import dateMath from '@elastic/datemath'; import { isJobIdValid, prefixDatafeedId } from 'plugins/ml/../common/util/job_utils'; import { getCreateRecognizerJobBreadcrumbs } from 'plugins/ml/jobs/breadcrumbs'; diff --git a/x-pack/plugins/ml/public/jobs/new_job/simple/single_metric/create_job/create_job_controller.js b/x-pack/plugins/ml/public/jobs/new_job/simple/single_metric/create_job/create_job_controller.js index b201cacd5fbfa9..30c2a8e821261f 100644 --- a/x-pack/plugins/ml/public/jobs/new_job/simple/single_metric/create_job/create_job_controller.js +++ b/x-pack/plugins/ml/public/jobs/new_job/simple/single_metric/create_job/create_job_controller.js @@ -7,7 +7,7 @@ import _ from 'lodash'; -import 'angular-ui-select'; +import 'ui/angular_ui_select'; import { aggTypes } from 'ui/agg_types'; import { addJobValidationMethods } from 'plugins/ml/../common/util/validation_utils'; diff --git a/x-pack/plugins/ml/public/lib/angular_bootstrap_patch.js b/x-pack/plugins/ml/public/lib/angular_bootstrap_patch.js index adca80311696ef..721dddbe1c7634 100644 --- a/x-pack/plugins/ml/public/lib/angular_bootstrap_patch.js +++ b/x-pack/plugins/ml/public/lib/angular_bootstrap_patch.js @@ -35,7 +35,7 @@ // and also adds support for dropdown-append-to-body flag, allowing the dropdown // menu to be appended to be the body and for the menu to be right aligned to the dropdown // (by addition of the dropdown-menu-right class to the dropdown-menu) -import 'ui-bootstrap'; +import 'ui/angular-bootstrap'; import angular from 'angular'; angular.module('ui.bootstrap.popover') .directive('popoverHtmlUnsafePopup', function ($compile) { diff --git a/x-pack/plugins/monitoring/public/components/chart/chart_target.js b/x-pack/plugins/monitoring/public/components/chart/chart_target.js index 82042927b9d4e7..62766f76ebae4a 100644 --- a/x-pack/plugins/monitoring/public/components/chart/chart_target.js +++ b/x-pack/plugins/monitoring/public/components/chart/chart_target.js @@ -6,7 +6,7 @@ import _ from 'lodash'; import React from 'react'; -import $ from 'jquery-flot'; // webpackShim +import $ from 'plugins/xpack_main/jquery_flot'; import { eventBus } from './event_bus'; import { getChartOptions } from './get_chart_options'; diff --git a/x-pack/plugins/monitoring/public/components/sparkline/__mocks__/jquery-flot.js b/x-pack/plugins/monitoring/public/components/sparkline/__mocks__/plugins/xpack_main/jquery_flot.js similarity index 100% rename from x-pack/plugins/monitoring/public/components/sparkline/__mocks__/jquery-flot.js rename to x-pack/plugins/monitoring/public/components/sparkline/__mocks__/plugins/xpack_main/jquery_flot.js diff --git a/x-pack/plugins/monitoring/public/components/sparkline/sparkline_flot_chart.js b/x-pack/plugins/monitoring/public/components/sparkline/sparkline_flot_chart.js index 6d580cc0fe13a2..fef3fec67b1e23 100644 --- a/x-pack/plugins/monitoring/public/components/sparkline/sparkline_flot_chart.js +++ b/x-pack/plugins/monitoring/public/components/sparkline/sparkline_flot_chart.js @@ -5,7 +5,7 @@ */ import { last, isFunction, debounce } from 'lodash'; -import $ from 'jquery-flot'; // webpackShim +import $ from 'plugins/xpack_main/jquery_flot'; import { DEBOUNCE_FAST_MS } from '../../../common/constants'; /** diff --git a/x-pack/plugins/security/public/views/management/edit_role/index.js b/x-pack/plugins/security/public/views/management/edit_role/index.js index b6dce0eac8cdc9..d432c0872cb5fd 100644 --- a/x-pack/plugins/security/public/views/management/edit_role/index.js +++ b/x-pack/plugins/security/public/views/management/edit_role/index.js @@ -9,7 +9,7 @@ import chrome from 'ui/chrome'; import routes from 'ui/routes'; import { fatalError } from 'ui/notify'; import template from 'plugins/security/views/management/edit_role/edit_role.html'; -import 'angular-ui-select'; +import 'ui/angular_ui_select'; import 'plugins/security/services/application_privilege'; import 'plugins/security/services/shield_user'; import 'plugins/security/services/shield_role'; diff --git a/x-pack/plugins/security/public/views/management/edit_user.js b/x-pack/plugins/security/public/views/management/edit_user.js index 2ebfc2722c1433..0a0a21d1bcb959 100644 --- a/x-pack/plugins/security/public/views/management/edit_user.js +++ b/x-pack/plugins/security/public/views/management/edit_user.js @@ -6,7 +6,7 @@ import routes from 'ui/routes'; import template from 'plugins/security/views/management/edit_user.html'; import 'angular-resource'; -import 'angular-ui-select'; +import 'ui/angular_ui_select'; import 'plugins/security/services/shield_user'; import 'plugins/security/services/shield_role'; import { EDIT_USERS_PATH } from './management_urls'; diff --git a/x-pack/plugins/uptime/public/apps/start_app.tsx b/x-pack/plugins/uptime/public/apps/start_app.tsx index 46b50546f39c8e..84172c6e39cdec 100644 --- a/x-pack/plugins/uptime/public/apps/start_app.tsx +++ b/x-pack/plugins/uptime/public/apps/start_app.tsx @@ -5,7 +5,7 @@ */ import 'react-vis/dist/style.css'; -import 'ui-bootstrap'; +import 'ui/angular-bootstrap'; import 'ui/autoload/all'; import 'ui/autoload/styles'; import 'ui/courier'; diff --git a/x-pack/plugins/watcher/public/components/action_type_select/action_type_select.js b/x-pack/plugins/watcher/public/components/action_type_select/action_type_select.js index 3705f229384466..bfe48dbb872ab0 100644 --- a/x-pack/plugins/watcher/public/components/action_type_select/action_type_select.js +++ b/x-pack/plugins/watcher/public/components/action_type_select/action_type_select.js @@ -7,7 +7,7 @@ import { map } from 'lodash'; import { uiModules } from 'ui/modules'; import template from './action_type_select.html'; -import 'angular-ui-select'; +import 'ui/angular_ui_select'; import { Action } from 'plugins/watcher/models/action'; import 'plugins/watcher/services/settings'; diff --git a/x-pack/plugins/watcher/public/components/flot_chart/flot_chart.js b/x-pack/plugins/watcher/public/components/flot_chart/flot_chart.js index 14360daa4116b0..be35b82dce61b5 100644 --- a/x-pack/plugins/watcher/public/components/flot_chart/flot_chart.js +++ b/x-pack/plugins/watcher/public/components/flot_chart/flot_chart.js @@ -7,7 +7,7 @@ import { isFunction, debounce } from 'lodash'; import { uiModules } from 'ui/modules'; import template from './flot_chart.html'; -import $ from 'jquery-flot'; // webpackShim +import $ from 'plugins/xpack_main/jquery_flot'; import { FLOT_EVENT_PLOT_HOVER_DEBOUNCE_MS } from './constants'; const app = uiModules.get('xpack/watcher'); diff --git a/x-pack/plugins/security/webpackShims/angular-ui-select.js b/x-pack/plugins/xpack_main/public/jquery_flot/index.js similarity index 50% rename from x-pack/plugins/security/webpackShims/angular-ui-select.js rename to x-pack/plugins/xpack_main/public/jquery_flot/index.js index 51a91be970d63f..abf060aca8c088 100644 --- a/x-pack/plugins/security/webpackShims/angular-ui-select.js +++ b/x-pack/plugins/xpack_main/public/jquery_flot/index.js @@ -4,11 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -/* eslint-disable no-var */ -require('jquery'); -require('angular'); -require('angular-sanitize'); -require('ui-select/dist/select'); - -var uiModules = require('ui/modules').uiModules; -uiModules.get('kibana', ['ui.select', 'ngSanitize']); +export { default } from './jquery_flot'; diff --git a/x-pack/webpackShims/jquery-flot.js b/x-pack/plugins/xpack_main/public/jquery_flot/jquery_flot.js similarity index 60% rename from x-pack/webpackShims/jquery-flot.js rename to x-pack/plugins/xpack_main/public/jquery_flot/jquery_flot.js index bebabea675002f..0df63e2d9988f2 100644 --- a/x-pack/webpackShims/jquery-flot.js +++ b/x-pack/plugins/xpack_main/public/jquery_flot/jquery_flot.js @@ -4,13 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -const $ = require('jquery'); +import $ from 'jquery'; if (window) { window.jQuery = $; } -require('ui/flot-charts/jquery.flot'); +import 'ui/flot-charts/jquery.flot'; // load flot plugins // avoid the `canvas` plugin, it causes blurry fonts -require('ui/flot-charts/jquery.flot.time'); -require('ui/flot-charts/jquery.flot.crosshair'); -require('ui/flot-charts/jquery.flot.selection'); -module.exports = $; +import 'ui/flot-charts/jquery.flot.time'; +import 'ui/flot-charts/jquery.flot.crosshair'; +import 'ui/flot-charts/jquery.flot.selection'; + +export default $; diff --git a/yarn.lock b/yarn.lock index 718c1a0f3445ff..91867bbac486a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -21785,11 +21785,6 @@ uglifyjs-webpack-plugin@^1.2.4: webpack-sources "^1.1.0" worker-farm "^1.5.2" -ui-select@0.19.4: - version "0.19.4" - resolved "https://registry.yarnpkg.com/ui-select/-/ui-select-0.19.4.tgz#f5702c90cd91eca094202188a7fdbc9483e58797" - integrity sha1-9XAskM2R7KCUICGIp/28lIPlh5c= - ui-select@0.19.6: version "0.19.6" resolved "https://registry.yarnpkg.com/ui-select/-/ui-select-0.19.6.tgz#9a824ec9d5b04c3fdc7483fa4746dd3c528d87ab"