mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[internal] Replace let with const in root of ui
This change was applied only to files in the root of the src/ui directory. All instances of `let` were replaced with `const`, and then any instance that flagged the `no-const-assign` rule in the linter was put back.
This commit is contained in:
parent
a6ed127564
commit
31a1e1aa7c
7 changed files with 42 additions and 42 deletions
|
@ -1,10 +1,10 @@
|
||||||
module.exports = function ({env, bundle}) {
|
module.exports = function ({env, bundle}) {
|
||||||
|
|
||||||
let pluginSlug = env.pluginInfo.sort()
|
const pluginSlug = env.pluginInfo.sort()
|
||||||
.map(p => ' * - ' + p)
|
.map(p => ' * - ' + p)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
let requires = bundle.modules
|
const requires = bundle.modules
|
||||||
.map(m => `require('${m}');`)
|
.map(m => `require('${m}');`)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,13 @@ import UiBundleCollection from './ui_bundle_collection';
|
||||||
import UiBundlerEnv from './ui_bundler_env';
|
import UiBundlerEnv from './ui_bundler_env';
|
||||||
module.exports = async (kbnServer, server, config) => {
|
module.exports = async (kbnServer, server, config) => {
|
||||||
|
|
||||||
let loadingGif = readFile(fromRoot('src/ui/public/loading.gif'), { encoding: 'base64'});
|
const loadingGif = readFile(fromRoot('src/ui/public/loading.gif'), { encoding: 'base64'});
|
||||||
|
|
||||||
let uiExports = kbnServer.uiExports = new UiExports({
|
const uiExports = kbnServer.uiExports = new UiExports({
|
||||||
urlBasePath: config.get('server.basePath')
|
urlBasePath: config.get('server.basePath')
|
||||||
});
|
});
|
||||||
|
|
||||||
let bundlerEnv = new UiBundlerEnv(config.get('optimize.bundleDir'));
|
const bundlerEnv = new UiBundlerEnv(config.get('optimize.bundleDir'));
|
||||||
bundlerEnv.addContext('env', config.get('env.name'));
|
bundlerEnv.addContext('env', config.get('env.name'));
|
||||||
bundlerEnv.addContext('urlBasePath', config.get('server.basePath'));
|
bundlerEnv.addContext('urlBasePath', config.get('server.basePath'));
|
||||||
bundlerEnv.addContext('sourceMaps', config.get('optimize.sourceMaps'));
|
bundlerEnv.addContext('sourceMaps', config.get('optimize.sourceMaps'));
|
||||||
|
@ -28,14 +28,14 @@ module.exports = async (kbnServer, server, config) => {
|
||||||
uiExports.consumePlugin(plugin);
|
uiExports.consumePlugin(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
let bundles = kbnServer.bundles = new UiBundleCollection(bundlerEnv, config.get('optimize.bundleFilter'));
|
const bundles = kbnServer.bundles = new UiBundleCollection(bundlerEnv, config.get('optimize.bundleFilter'));
|
||||||
|
|
||||||
for (let app of uiExports.getAllApps()) {
|
for (let app of uiExports.getAllApps()) {
|
||||||
bundles.addApp(app);
|
bundles.addApp(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let gen of uiExports.getBundleProviders()) {
|
for (let gen of uiExports.getBundleProviders()) {
|
||||||
let bundle = await gen(UiBundle, bundlerEnv, uiExports.getAllApps(), kbnServer.plugins);
|
const bundle = await gen(UiBundle, bundlerEnv, uiExports.getAllApps(), kbnServer.plugins);
|
||||||
if (bundle) bundles.add(bundle);
|
if (bundle) bundles.add(bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +47,8 @@ module.exports = async (kbnServer, server, config) => {
|
||||||
path: '/app/{id}',
|
path: '/app/{id}',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
handler: function (req, reply) {
|
handler: function (req, reply) {
|
||||||
let id = req.params.id;
|
const id = req.params.id;
|
||||||
let app = uiExports.apps.byId[id];
|
const app = uiExports.apps.byId[id];
|
||||||
if (!app) return reply(Boom.notFound('Unknown app ' + id));
|
if (!app) return reply(Boom.notFound('Unknown app ' + id));
|
||||||
|
|
||||||
if (kbnServer.status.isGreen()) {
|
if (kbnServer.status.isGreen()) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import _ from 'lodash';
|
||||||
import UiApp from './ui_app';
|
import UiApp from './ui_app';
|
||||||
import Collection from '../utils/collection';
|
import Collection from '../utils/collection';
|
||||||
|
|
||||||
let byIdCache = Symbol('byId');
|
const byIdCache = Symbol('byId');
|
||||||
|
|
||||||
module.exports = class UiAppCollection extends Collection {
|
module.exports = class UiAppCollection extends Collection {
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ module.exports = class UiAppCollection extends Collection {
|
||||||
return this.hidden.new(spec);
|
return this.hidden.new(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
let app = new UiApp(this.uiExports, spec);
|
const app = new UiApp(this.uiExports, spec);
|
||||||
|
|
||||||
if (_.includes(this.claimedIds, app.id)) {
|
if (_.includes(this.claimedIds, app.id)) {
|
||||||
throw new Error('Unable to create two apps with the id ' + app.id + '.');
|
throw new Error('Unable to create two apps with the id ' + app.id + '.');
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { promisify } from 'bluebird';
|
import { promisify } from 'bluebird';
|
||||||
|
|
||||||
let read = promisify(require('fs').readFile);
|
const read = promisify(require('fs').readFile);
|
||||||
let write = promisify(require('fs').writeFile);
|
const write = promisify(require('fs').writeFile);
|
||||||
let unlink = promisify(require('fs').unlink);
|
const unlink = promisify(require('fs').unlink);
|
||||||
let stat = promisify(require('fs').stat);
|
const stat = promisify(require('fs').stat);
|
||||||
|
|
||||||
module.exports = class UiBundle {
|
module.exports = class UiBundle {
|
||||||
constructor(opts) {
|
constructor(opts) {
|
||||||
|
@ -15,7 +15,7 @@ module.exports = class UiBundle {
|
||||||
this.template = opts.template;
|
this.template = opts.template;
|
||||||
this.env = opts.env;
|
this.env = opts.env;
|
||||||
|
|
||||||
let pathBase = join(this.env.workingDir, this.id);
|
const pathBase = join(this.env.workingDir, this.id);
|
||||||
this.entryPath = `${pathBase}.entry.js`;
|
this.entryPath = `${pathBase}.entry.js`;
|
||||||
this.outputPath = `${pathBase}.bundle.js`;
|
this.outputPath = `${pathBase}.bundle.js`;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ module.exports = class UiBundle {
|
||||||
|
|
||||||
async readEntryFile() {
|
async readEntryFile() {
|
||||||
try {
|
try {
|
||||||
let content = await read(this.entryPath);
|
const content = await read(this.entryPath);
|
||||||
return content.toString('utf8');
|
return content.toString('utf8');
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
let rimraf = promisify(require('rimraf'));
|
const rimraf = promisify(require('rimraf'));
|
||||||
let mkdirp = promisify(require('mkdirp'));
|
const mkdirp = promisify(require('mkdirp'));
|
||||||
let unlink = promisify(require('fs').unlink);
|
const unlink = promisify(require('fs').unlink);
|
||||||
let readdir = promisify(require('fs').readdir);
|
const readdir = promisify(require('fs').readdir);
|
||||||
|
|
||||||
import UiBundle from './ui_bundle';
|
import UiBundle from './ui_bundle';
|
||||||
import appEntryTemplate from './app_entry_template';
|
import appEntryTemplate from './app_entry_template';
|
||||||
|
@ -48,9 +48,9 @@ class UiBundleCollection {
|
||||||
case 1:
|
case 1:
|
||||||
return `bundle for ${this.each[0].id}`;
|
return `bundle for ${this.each[0].id}`;
|
||||||
default:
|
default:
|
||||||
let ids = this.getIds();
|
const ids = this.getIds();
|
||||||
let last = ids.pop();
|
const last = ids.pop();
|
||||||
let commas = ids.join(', ');
|
const commas = ids.join(', ');
|
||||||
return `bundles for ${commas} and ${last}`;
|
return `bundles for ${commas} and ${last}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,8 @@ class UiBundleCollection {
|
||||||
await this.ensureDir();
|
await this.ensureDir();
|
||||||
|
|
||||||
for (let bundle of this.each) {
|
for (let bundle of this.each) {
|
||||||
let existing = await bundle.readEntryFile();
|
const existing = await bundle.readEntryFile();
|
||||||
let expected = bundle.renderContent();
|
const expected = bundle.renderContent();
|
||||||
|
|
||||||
if (existing !== expected) {
|
if (existing !== expected) {
|
||||||
await bundle.writeEntryFile();
|
await bundle.writeEntryFile();
|
||||||
|
@ -74,10 +74,10 @@ class UiBundleCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getInvalidBundles() {
|
async getInvalidBundles() {
|
||||||
let invalids = new UiBundleCollection(this.env);
|
const invalids = new UiBundleCollection(this.env);
|
||||||
|
|
||||||
for (let bundle of this.each) {
|
for (let bundle of this.each) {
|
||||||
let exists = await bundle.checkForExistingOutput();
|
const exists = await bundle.checkForExistingOutput();
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
invalids.add(bundle);
|
invalids.add(bundle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ import { includes, flow, escapeRegExp } from 'lodash';
|
||||||
import { isString, isArray, isPlainObject, get } from 'lodash';
|
import { isString, isArray, isPlainObject, get } from 'lodash';
|
||||||
import { keys } from 'lodash';
|
import { keys } from 'lodash';
|
||||||
|
|
||||||
let asRegExp = flow(
|
const asRegExp = flow(
|
||||||
escapeRegExp,
|
escapeRegExp,
|
||||||
function (path) {
|
function (path) {
|
||||||
let last = path.slice(-1);
|
const last = path.slice(-1);
|
||||||
if (last === '/' || last === '\\') {
|
if (last === '/' || last === '\\') {
|
||||||
// match a directory explicitly
|
// match a directory explicitly
|
||||||
return path + '.*';
|
return path + '.*';
|
||||||
|
@ -18,7 +18,7 @@ let asRegExp = flow(
|
||||||
RegExp
|
RegExp
|
||||||
);
|
);
|
||||||
|
|
||||||
let arr = v => [].concat(v || []);
|
const arr = v => [].concat(v || []);
|
||||||
|
|
||||||
module.exports = class UiBundlerEnv {
|
module.exports = class UiBundlerEnv {
|
||||||
constructor(workingDir) {
|
constructor(workingDir) {
|
||||||
|
@ -58,7 +58,7 @@ module.exports = class UiBundlerEnv {
|
||||||
}
|
}
|
||||||
|
|
||||||
consumePlugin(plugin) {
|
consumePlugin(plugin) {
|
||||||
let tag = `${plugin.id}@${plugin.version}`;
|
const tag = `${plugin.id}@${plugin.version}`;
|
||||||
if (includes(this.pluginInfo, tag)) return;
|
if (includes(this.pluginInfo, tag)) return;
|
||||||
|
|
||||||
if (plugin.publicDir) {
|
if (plugin.publicDir) {
|
||||||
|
@ -141,7 +141,7 @@ module.exports = class UiBundlerEnv {
|
||||||
|
|
||||||
this.aliases[id] = path;
|
this.aliases[id] = path;
|
||||||
|
|
||||||
let loader = [];
|
const loader = [];
|
||||||
if (imports) {
|
if (imports) {
|
||||||
loader.push(`imports?${imports}`);
|
loader.push(`imports?${imports}`);
|
||||||
}
|
}
|
||||||
|
@ -153,10 +153,10 @@ module.exports = class UiBundlerEnv {
|
||||||
}
|
}
|
||||||
|
|
||||||
claim(id, pluginId) {
|
claim(id, pluginId) {
|
||||||
let owner = pluginId ? `Plugin ${pluginId}` : 'Kibana Server';
|
const owner = pluginId ? `Plugin ${pluginId}` : 'Kibana Server';
|
||||||
|
|
||||||
// TODO(spalger): we could do a lot more to detect colliding module defs
|
// TODO(spalger): we could do a lot more to detect colliding module defs
|
||||||
let existingOwner = this.aliasOwners[id] || this.aliasOwners[`${id}$`];
|
const existingOwner = this.aliasOwners[id] || this.aliasOwners[`${id}$`];
|
||||||
|
|
||||||
if (existingOwner) {
|
if (existingOwner) {
|
||||||
throw new TypeError(`${owner} attempted to override export "${id}" from ${existingOwner}`);
|
throw new TypeError(`${owner} attempted to override export "${id}" from ${existingOwner}`);
|
||||||
|
|
|
@ -19,10 +19,10 @@ class UiExports {
|
||||||
consumePlugin(plugin) {
|
consumePlugin(plugin) {
|
||||||
plugin.apps = new UiAppCollection(this);
|
plugin.apps = new UiAppCollection(this);
|
||||||
|
|
||||||
let types = _.keys(plugin.uiExportsSpecs);
|
const types = _.keys(plugin.uiExportsSpecs);
|
||||||
if (!types) return false;
|
if (!types) return false;
|
||||||
|
|
||||||
let unkown = _.reject(types, this.exportConsumer, this);
|
const unkown = _.reject(types, this.exportConsumer, this);
|
||||||
if (unkown.length) {
|
if (unkown.length) {
|
||||||
throw new Error('unknown export types ' + unkown.join(', ') + ' in plugin ' + plugin.id);
|
throw new Error('unknown export types ' + unkown.join(', ') + ' in plugin ' + plugin.id);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class UiExports {
|
||||||
exportConsumer(type) {
|
exportConsumer(type) {
|
||||||
for (let consumer of this.consumers) {
|
for (let consumer of this.consumers) {
|
||||||
if (!consumer.exportConsumer) continue;
|
if (!consumer.exportConsumer) continue;
|
||||||
let fn = consumer.exportConsumer(type);
|
const fn = consumer.exportConsumer(type);
|
||||||
if (fn) return fn;
|
if (fn) return fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class UiExports {
|
||||||
const id = plugin.id;
|
const id = plugin.id;
|
||||||
for (let spec of [].concat(specs || [])) {
|
for (let spec of [].concat(specs || [])) {
|
||||||
|
|
||||||
let app = this.apps.new(_.defaults({}, spec, {
|
const app = this.apps.new(_.defaults({}, spec, {
|
||||||
id: plugin.id,
|
id: plugin.id,
|
||||||
urlBasePath: this.urlBasePath
|
urlBasePath: this.urlBasePath
|
||||||
}));
|
}));
|
||||||
|
@ -110,9 +110,9 @@ class UiExports {
|
||||||
}
|
}
|
||||||
|
|
||||||
find(patterns) {
|
find(patterns) {
|
||||||
let aliases = this.aliases;
|
const aliases = this.aliases;
|
||||||
let names = _.keys(aliases);
|
const names = _.keys(aliases);
|
||||||
let matcher = _.partialRight(minimatch.filter, { matchBase: true });
|
const matcher = _.partialRight(minimatch.filter, { matchBase: true });
|
||||||
|
|
||||||
return _.chain(patterns)
|
return _.chain(patterns)
|
||||||
.map(function (pattern) {
|
.map(function (pattern) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue