Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dll plugin relation with webpackshims #30129

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e663376
chore(NA): remove specific watch for x-pack webpackShims folder.
mistic Feb 5, 2019
db1667f
chore(NA): remove xpack security plugin angular-ui-select webpackShim.
mistic Feb 5, 2019
a960069
chore(NA): bump ui-select version on x-pack to match the one used on …
mistic Feb 5, 2019
7d8db6c
chore(NA): remove manual searching for webpackShim imports into the d…
mistic Feb 5, 2019
6694a7d
refact(NA): move ui related actions inside webpackShims to proper ui …
mistic Feb 5, 2019
b6d55fc
chore(NA): move angular ui dependencies from webpackShims to kibana c…
mistic Feb 5, 2019
95ab580
test(NA): enable xpack jest tests to be able to resolve plugins/xpack…
mistic Feb 5, 2019
bbb166a
refact(NA): use the already declared ui module get to list the depend…
mistic Feb 6, 2019
8694733
Merge remote-tracking branch 'upstream/master' into improve-dll-plugi…
mistic Feb 6, 2019
5721a3b
chore(NA): merge and solve conflicts with last master
mistic Feb 11, 2019
aa2e09f
chore(NA): move angular ui requires to a better centralized place.
mistic Feb 11, 2019
a5799ef
refact(NA): rename areMaxCompilationsPerformed to assertMaxCompilations.
mistic Feb 11, 2019
9c8d345
refact(NA): remove unnecessary promise resolve on async function.
mistic Feb 11, 2019
1f3ed2c
refact(NA): remove unnecessary promise resolve on async function.
mistic Feb 11, 2019
c6d59c6
refact(NA): apply changes according pr review.
mistic Feb 11, 2019
8c6a0cd
refact(NA): change from requires to imports in xpack_main plugin jque…
mistic Feb 12, 2019
d00296c
refact(NA): jquery flots missing statements.
mistic Feb 12, 2019
c9c42e2
Merge remote-tracking branch 'upstream/master' into improve-dll-plugi…
mistic Feb 12, 2019
1fac849
fix(na): linting problems.
mistic Feb 12, 2019
ab5712f
chore(na): re add jquery flot requires instead of imports.
mistic Feb 12, 2019
6375ec7
refact(NA): moving jquery flots from require to import. test(NA): fix…
mistic Feb 12, 2019
cd43fa0
Merge branch 'master' into improve-dll-plugin-relation-with-webpackshims
mistic Feb 12, 2019
904fd90
Merge branch 'master' into improve-dll-plugin-relation-with-webpackshims
mistic Feb 13, 2019
467c0e5
chore(NA): merge and solve conflicts with last master
mistic Feb 14, 2019
46e0108
Merge branch 'master' into improve-dll-plugin-relation-with-webpackshims
mistic Feb 14, 2019
a176661
feat(na): allow dynamic dll plugin public modules on dll bundle.
mistic Feb 14, 2019
9ff3f07
chore(NA): merge and solve conflicts with last master.
mistic Feb 18, 2019
c42ba9d
Merge branch 'master' into improve-dll-plugin-relation-with-webpackshims
mistic Feb 19, 2019
c035a44
feat(NA): step verification to not allow modules from xpack source.
mistic Feb 19, 2019
dd8b140
Merge branch 'master' into improve-dll-plugin-relation-with-webpackshims
mistic Feb 19, 2019
1415b26
Merge branch 'master' into improve-dll-plugin-relation-with-webpackshims
mistic Feb 21, 2019
39f6114
chore(na): merge and solve confclits with last master.
mistic Feb 21, 2019
12183f5
chore(NA): fix linting problems.
mistic Feb 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
1 change: 0 additions & 1 deletion src/cli/cluster/cluster_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 0 additions & 1 deletion src/dev/precommit_hook/casing_check_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions src/legacy/ui/public/angular-bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
4 changes: 4 additions & 0 deletions src/legacy/ui/public/autoload/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ import '../courier/saved_object/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']);
2 changes: 1 addition & 1 deletion src/legacy/ui/public/styles/bootstrap/buttons.less
Original file line number Diff line number Diff line change
@@ -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.
*/

Expand Down
4 changes: 4 additions & 0 deletions src/legacy/ui/public/test_harness/test_harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion src/legacy/ui/public/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
* 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/);
}
87 changes: 74 additions & 13 deletions src/optimize/dynamic_dll_plugin/dll_compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
*/

import { configModel } from './dll_config_model';
import { notInNodeModulesOrWebpackShims, notInNodeModules } from './dll_allowed_modules';
import { fromRoot } from '../../legacy/utils';
import { PUBLIC_PATH_PLACEHOLDER } from '../public_path_placeholder';
import fs from 'fs';
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 = {}) {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -197,18 +217,59 @@ 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;
}

// 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
mistic marked this conversation as resolved.
Show resolved Hide resolved
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);
}
});
}
});

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);
});
});
Expand Down
Loading