Skip to content

Commit

Permalink
Merge pull request #5871 from spalger/implement/autoloadWithModules
Browse files Browse the repository at this point in the history
[autoloading] opt into autoloading with require
  • Loading branch information
spalger committed Jan 13, 2016
2 parents b6edfdf + b6a7449 commit 670c53a
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 110 deletions.
14 changes: 0 additions & 14 deletions src/plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ module.exports = function (kibana) {
'fieldFormats'
],

autoload: kibana.autoload.require.concat(
'plugins/kibana/discover',
'plugins/kibana/visualize',
'plugins/kibana/dashboard',
'plugins/kibana/settings',
'plugins/kibana/settings/sections',
'plugins/kibana/doc',
'plugins/kibana/settings/sections',
'ui/vislib',
'ui/agg_response',
'ui/agg_types',
'leaflet'
),

injectVars: function (server, options) {
let config = server.config();

Expand Down
12 changes: 10 additions & 2 deletions src/plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// autoloading
require('ui/autoload/all');

// preloading (for faster webpack builds)
require('plugins/kibana/discover/index');
require('plugins/kibana/visualize/index');
require('plugins/kibana/dashboard/index');
require('plugins/kibana/settings/index');
require('plugins/kibana/doc/index');
require('plugins/kibana/settings/sections');
require('plugins/kibana/doc');
require('ui/vislib');
require('ui/agg_response');
require('ui/agg_types');
require('ui/timepicker');
require('leaflet');

var moment = require('moment-timezone');

var chrome = require('ui/chrome');
var routes = require('ui/routes');
var modules = require('ui/modules');
Expand Down
8 changes: 1 addition & 7 deletions src/plugins/statusPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ module.exports = function (kibana) {
title: 'Server Status',
main: 'plugins/statusPage/statusPage',
hidden: true,
url: '/status',

autoload: [].concat(
kibana.autoload.styles,
'ui/chrome',
'angular'
)
url: '/status'
}
}
});
Expand Down
1 change: 1 addition & 0 deletions src/plugins/statusPage/public/statusPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var $ = require('jquery');
var _ = require('lodash');
var notify = require('ui/notify');

require('ui/autoload/styles');
require('plugins/statusPage/statusPageMetric');
require('plugins/statusPage/statusPage.less');

Expand Down
16 changes: 15 additions & 1 deletion src/server/plugins/PluginApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ module.exports = class PluginApi {
this.config = kibana.config;
this.rootDir = kibana.rootDir;
this.package = require(join(pluginPath, 'package.json'));
this.autoload = require('../../ui/autoload');
this.Plugin = Plugin.scoped(kibana, pluginPath, this.package);
}

get uiExports() {
throw new Error('plugin.uiExports is not defined until initialize phase');
}

get autoload() {
console.warn(
`${this.package.id} accessed the autoload lists which are no longer available via the Plugin API.` +
'Use the `ui/autoload/*` modules instead.'
);

return {
directives: [],
filters: [],
styles: [],
modules: [],
require: []
};
}
};
10 changes: 7 additions & 3 deletions src/ui/UiApp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var _ = require('lodash');
var { join } = require('path');
var autoload = require('./autoload');

class UiApp {
constructor(uiExports, spec) {
Expand All @@ -17,10 +16,16 @@ class UiApp {
this.description = this.spec.description;
this.icon = this.spec.icon;
this.hidden = this.spec.hidden;
this.autoloadOverrides = this.spec.autoload;
this.templateName = this.spec.templateName || 'ui_app';
this.url = `${spec.urlBasePath || ''}${this.spec.url || `/app/${this.id}`}`;

if (this.spec.autoload) {
console.warn(
`"autoload" (used by ${this.id} app) is no longer a valid app configuration directive.` +
'Use the \`ui/autoload/*\` modules instead.'
);
}

// once this resolves, no reason to run it again
this.getModules = _.once(this.getModules);

Expand All @@ -30,7 +35,6 @@ class UiApp {

getModules() {
return _.chain([
this.autoloadOverrides || autoload.require,
this.uiExports.find(_.get(this, 'spec.uses', [])),
this.uiExports.find(['chromeNavControls']),
])
Expand Down
2 changes: 1 addition & 1 deletion src/ui/appEntryTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ${pluginSlug}
*
*/
require('ui/chrome')
require('ui/chrome');
${requires}
require('ui/chrome').bootstrap(/* xoxo */);
Expand Down
82 changes: 0 additions & 82 deletions src/ui/autoload.js

This file was deleted.

4 changes: 4 additions & 0 deletions src/ui/public/autoload/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('./modules');
require('./directives');
require('./filters');
require('./styles');
2 changes: 2 additions & 0 deletions src/ui/public/autoload/directives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const context = require.context('../directives', false, /[\/\\](?!\.|_)[^\/\\]+\.js/);
context.keys().forEach(key => context(key));
2 changes: 2 additions & 0 deletions src/ui/public/autoload/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const context = require.context('../filters', false, /[\/\\](?!\.|_)[^\/\\]+\.js/);
context.keys().forEach(key => context(key));
34 changes: 34 additions & 0 deletions src/ui/public/autoload/modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require('angular');
require('ui/chrome');
require('ui/chrome/context');
require('ui/bind');
require('ui/bound_to_config_obj');
require('ui/config');
require('ui/courier');
require('ui/debounce');
require('ui/doc_title');
require('ui/elastic_textarea');
require('ui/es');
require('ui/events');
require('ui/fancy_forms');
require('ui/filter_bar');
require('ui/filter_manager');
require('ui/index_patterns');
require('ui/listen');
require('ui/notify');
require('ui/parse_query');
require('ui/persisted_log');
require('ui/private');
require('ui/promises');
require('ui/safe_confirm');
require('ui/state_management/app_state');
require('ui/state_management/global_state');
require('ui/storage');
require('ui/stringify/register');
require('ui/styleCompile');
require('ui/timefilter');
require('ui/tooltip');
require('ui/typeahead');
require('ui/url');
require('ui/validateDateInterval');
require('ui/watch_multi');
2 changes: 2 additions & 0 deletions src/ui/public/autoload/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const context = require.context('../styles', false, /[\/\\](?!mixins|variables|_|\.)[^\/\\]+\.less/);
context.keys().forEach(key => context(key));

0 comments on commit 670c53a

Please sign in to comment.