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

[autoloading] opt into autoloading with require #5871

Merged
merged 1 commit into from
Jan 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 0 additions & 14 deletions src/plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,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.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

);

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way to avoid the hardcoding in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's the only file that's made up of arbitrary modules which were picked with arbitrary criteria

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be changed to

context.keys().forEach(context);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I just don't like passing the other arguments (index and list). This feels concise enough.