Skip to content

Commit

Permalink
Backport PR #6882
Browse files Browse the repository at this point in the history
---------

**Commit 1:**
[internal] Replace var with let in root of ui

This change was applied only to files in the root of the src/ui
directory.

This was an automatic replacement from var to let for any variable
declaration that doubles as the initial assignment. Ultimately we want
most of these to be converted to const, but that can happen in a future
commit.

For example:

`var foo = 'bar';` becomes `let foo = 'var';`

This was accomplished by replacing:
find: `var ([a-zA-Z_$][0-9a-zA-Z_$]*)(\s+)=`
replace: `let $1$2=`

* Original sha: a6ed127
* Authored by Court Ewing <court@epixa.com> on 2016-04-12T21:50:00Z

**Commit 2:**
[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.

* Original sha: 31a1e1a
* Authored by Court Ewing <court@epixa.com> on 2016-04-12T21:55:25Z
  • Loading branch information
epixa committed Apr 13, 2016
1 parent 3a36b4b commit e683b1d
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 74 deletions.
4 changes: 2 additions & 2 deletions src/ui/UiApp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require('lodash');
const _ = require('lodash');
var { join } = require('path');
var autoload = require('./autoload');
const autoload = require('./autoload');

class UiApp {
constructor(uiExports, spec) {
Expand Down
10 changes: 5 additions & 5 deletions src/ui/UiAppCollection.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
let _ = require('lodash');
let UiApp = require('./UiApp');
let Collection = require('requirefrom')('src')('utils/Collection');
const _ = require('lodash');
const UiApp = require('./UiApp');
const Collection = require('requirefrom')('src')('utils/Collection');

let byIdCache = Symbol('byId');
const byIdCache = Symbol('byId');

module.exports = class UiAppCollection extends Collection {

Expand All @@ -25,7 +25,7 @@ module.exports = class UiAppCollection extends Collection {
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)) {
throw new Error('Unable to create two apps with the id ' + app.id + '.');
Expand Down
12 changes: 6 additions & 6 deletions src/ui/UiBundle.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

let { join } = require('path');
let { promisify } = require('bluebird');
let read = promisify(require('fs').readFile);
let write = promisify(require('fs').writeFile);
let unlink = promisify(require('fs').unlink);
let stat = promisify(require('fs').stat);
const read = promisify(require('fs').readFile);
const write = promisify(require('fs').writeFile);
const unlink = promisify(require('fs').unlink);
const stat = promisify(require('fs').stat);

module.exports = class UiBundle {
constructor(opts) {
Expand All @@ -15,7 +15,7 @@ module.exports = class UiBundle {
this.template = opts.template;
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.outputPath = `${pathBase}.bundle.js`;

Expand All @@ -30,7 +30,7 @@ module.exports = class UiBundle {

async readEntryFile() {
try {
let content = await read(this.entryPath);
const content = await read(this.entryPath);
return content.toString('utf8');
}
catch (e) {
Expand Down
28 changes: 14 additions & 14 deletions src/ui/UiBundleCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ let { pull, transform, pluck } = require('lodash');
let { join } = require('path');
let { resolve, promisify } = require('bluebird');
let { makeRe } = require('minimatch');
let rimraf = promisify(require('rimraf'));
let mkdirp = promisify(require('mkdirp'));
let unlink = promisify(require('fs').unlink);
let readdir = promisify(require('fs').readdir);
let readSync = require('fs').readFileSync;
const rimraf = promisify(require('rimraf'));
const mkdirp = promisify(require('mkdirp'));
const unlink = promisify(require('fs').unlink);
const readdir = promisify(require('fs').readdir);
const readSync = require('fs').readFileSync;

let UiBundle = require('./UiBundle');
let appEntryTemplate = require('./appEntryTemplate');
const UiBundle = require('./UiBundle');
const appEntryTemplate = require('./appEntryTemplate');

class UiBundleCollection {
constructor(bundlerEnv, filter) {
Expand Down Expand Up @@ -48,9 +48,9 @@ class UiBundleCollection {
case 1:
return `bundle for ${this.each[0].id}`;
default:
var ids = this.getIds();
var last = ids.pop();
var commas = ids.join(', ');
const ids = this.getIds();
const last = ids.pop();
const commas = ids.join(', ');
return `bundles for ${commas} and ${last}`;
}
}
Expand All @@ -63,8 +63,8 @@ class UiBundleCollection {
await this.ensureDir();

for (let bundle of this.each) {
let existing = await bundle.readEntryFile();
let expected = bundle.renderContent();
const existing = await bundle.readEntryFile();
const expected = bundle.renderContent();

if (existing !== expected) {
await bundle.writeEntryFile();
Expand All @@ -74,10 +74,10 @@ class UiBundleCollection {
}

async getInvalidBundles() {
let invalids = new UiBundleCollection(this.env);
const invalids = new UiBundleCollection(this.env);

for (let bundle of this.each) {
let exists = await bundle.checkForExistingOutput();
const exists = await bundle.checkForExistingOutput();
if (!exists) {
invalids.add(bundle);
}
Expand Down
16 changes: 8 additions & 8 deletions src/ui/UiBundlerEnv.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
let { includes, flow, escapeRegExp } = require('lodash');
let { isString, isArray, isPlainObject, get } = require('lodash');
let { keys } = require('lodash');
let fromRoot = require('../utils/fromRoot');
const fromRoot = require('../utils/fromRoot');

let asRegExp = flow(
const asRegExp = flow(
escapeRegExp,
function (path) {
let last = path.slice(-1);
const last = path.slice(-1);
if (last === '/' || last === '\\') {
// match a directory explicitly
return path + '.*';
Expand All @@ -18,7 +18,7 @@ let asRegExp = flow(
RegExp
);

let arr = v => [].concat(v || []);
const arr = v => [].concat(v || []);

module.exports = class UiBundlerEnv {
constructor(workingDir) {
Expand Down Expand Up @@ -58,7 +58,7 @@ module.exports = class UiBundlerEnv {
}

consumePlugin(plugin) {
let tag = `${plugin.id}@${plugin.version}`;
const tag = `${plugin.id}@${plugin.version}`;
if (includes(this.pluginInfo, tag)) return;

if (plugin.publicDir) {
Expand Down Expand Up @@ -141,7 +141,7 @@ module.exports = class UiBundlerEnv {

this.aliases[id] = path;

let loader = [];
const loader = [];
if (imports) {
loader.push(`imports?${imports}`);
}
Expand All @@ -153,10 +153,10 @@ module.exports = class UiBundlerEnv {
}

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
var existingOwner = this.aliasOwners[id] || this.aliasOwners[`${id}$`];
const existingOwner = this.aliasOwners[id] || this.aliasOwners[`${id}$`];

if (existingOwner) {
throw new TypeError(`${owner} attempted to override export "${id}" from ${existingOwner}`);
Expand Down
20 changes: 10 additions & 10 deletions src/ui/UiExports.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var _ = require('lodash');
var minimatch = require('minimatch');
const _ = require('lodash');
const minimatch = require('minimatch');

var UiAppCollection = require('./UiAppCollection');
const UiAppCollection = require('./UiAppCollection');

class UiExports {
constructor({ urlBasePath }) {
Expand All @@ -16,10 +16,10 @@ class UiExports {
consumePlugin(plugin) {
plugin.apps = new UiAppCollection(this);

var types = _.keys(plugin.uiExportsSpecs);
const types = _.keys(plugin.uiExportsSpecs);
if (!types) return false;

var unkown = _.reject(types, this.exportConsumer, this);
const unkown = _.reject(types, this.exportConsumer, this);
if (unkown.length) {
throw new Error('unknown export types ' + unkown.join(', ') + ' in plugin ' + plugin.id);
}
Expand All @@ -40,7 +40,7 @@ class UiExports {
exportConsumer(type) {
for (let consumer of this.consumers) {
if (!consumer.exportConsumer) continue;
let fn = consumer.exportConsumer(type);
const fn = consumer.exportConsumer(type);
if (fn) return fn;
}

Expand All @@ -49,7 +49,7 @@ class UiExports {
case 'apps':
return (plugin, specs) => {
for (let spec of [].concat(specs || [])) {
let app = this.apps.new(_.defaults({}, spec, {
const app = this.apps.new(_.defaults({}, spec, {
id: plugin.id,
urlBasePath: this.urlBasePath
}));
Expand Down Expand Up @@ -80,9 +80,9 @@ class UiExports {
}

find(patterns) {
var aliases = this.aliases;
var names = _.keys(aliases);
var matcher = _.partialRight(minimatch.filter, { matchBase: true });
const aliases = this.aliases;
const names = _.keys(aliases);
const matcher = _.partialRight(minimatch.filter, { matchBase: true });

return _.chain(patterns)
.map(function (pattern) {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/appEntryTemplate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = function ({env, bundle}) {

let pluginSlug = env.pluginInfo.sort()
const pluginSlug = env.pluginInfo.sort()
.map(p => ' * - ' + p)
.join('\n');

let requires = bundle.modules
const requires = bundle.modules
.map(m => `require('${m}');`)
.join('\n');

Expand Down
24 changes: 12 additions & 12 deletions src/ui/autoload.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
var _ = require('lodash');
var resolve = require('path').resolve;
var basename = require('path').basename;
var readdir = require('fs').readdirSync;
const _ = require('lodash');
const resolve = require('path').resolve;
const basename = require('path').basename;
const readdir = require('fs').readdirSync;

var utils = require('requirefrom')('src/utils');
var fromRoot = utils('fromRoot');
const utils = require('requirefrom')('src/utils');
const fromRoot = utils('fromRoot');

function scan(type) {
var dir = fromRoot('src/ui/public', type);
const dir = fromRoot('src/ui/public', type);

return _.chain(readdir(dir))
.reject(function (name) {
return name[0] === '.' || name[0] === '_';
})
.map(function (filename) {
var path = resolve(dir, filename);
var name = basename(filename, '.js');
const path = resolve(dir, filename);
const name = basename(filename, '.js');
return `ui/${type}/${name}`;
})
.value();
}

function findStyles() {
var base = ['ui/styles/theme.less', 'ui/styles/base.less'];
var exclude = ['ui/styles/mixins.less', 'ui/styles/variables.less'];
var found = scan('styles', true);
const base = ['ui/styles/theme.less', 'ui/styles/base.less'];
const exclude = ['ui/styles/mixins.less', 'ui/styles/variables.less'];
const found = scan('styles', true);

return _.difference(_.union(base, found), exclude);
}
Expand Down
30 changes: 15 additions & 15 deletions src/ui/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
module.exports = async (kbnServer, server, config) => {
let { defaults } = require('lodash');
let Boom = require('boom');
let formatUrl = require('url').format;
const Boom = require('boom');
const formatUrl = require('url').format;
let { resolve } = require('path');
let readFile = require('fs').readFileSync;
const readFile = require('fs').readFileSync;

let fromRoot = require('../utils/fromRoot');
let UiExports = require('./UiExports');
let UiBundle = require('./UiBundle');
let UiBundleCollection = require('./UiBundleCollection');
let UiBundlerEnv = require('./UiBundlerEnv');
let loadingGif = readFile(fromRoot('src/ui/public/loading.gif'), { encoding: 'base64'});
const fromRoot = require('../utils/fromRoot');
const UiExports = require('./UiExports');
const UiBundle = require('./UiBundle');
const UiBundleCollection = require('./UiBundleCollection');
const UiBundlerEnv = require('./UiBundlerEnv');
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')
});

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('urlBasePath', config.get('server.basePath'));
bundlerEnv.addContext('sourceMaps', config.get('optimize.sourceMaps'));
Expand All @@ -28,14 +28,14 @@ module.exports = async (kbnServer, server, config) => {
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()) {
bundles.addApp(app);
}

for (let gen of uiExports.getBundleProviders()) {
let bundle = await gen(UiBundle, bundlerEnv, uiExports.getAllApps());
const bundle = await gen(UiBundle, bundlerEnv, uiExports.getAllApps());
if (bundle) bundles.add(bundle);
}

Expand All @@ -47,8 +47,8 @@ module.exports = async (kbnServer, server, config) => {
path: '/app/{id}',
method: 'GET',
handler: function (req, reply) {
let id = req.params.id;
let app = uiExports.apps.byId[id];
const id = req.params.id;
const app = uiExports.apps.byId[id];
if (!app) return reply(Boom.notFound('Unknown app ' + id));

if (kbnServer.status.isGreen()) {
Expand Down

0 comments on commit e683b1d

Please sign in to comment.