Upgrade to lodash v4 (#660)
* npm install lodash-2 Someone handily published a lodash-2 v4.17.4 - it is exactly the same as lodash v4.17.4, so it is safe to use during the migration. * use lodash-2 in tests * update tests to split utils vs lodash * remove Utils.nextTick usage Utils.nextTick with a single argument is the same as process.nextTick * lowercase utils Because it seems that this is the coding style in this repo * upgrade lodash in grunt/* * keep lodash-2 as a dev dep for now * use lodash-2 in scripts * use snakeCase from utils It was a mistake in my previous commit to not update this usage * fix naming gruntUtils vs utils As all three - gruntUtils, utils and lodash (_) are getting passed into templates, it makes sense to keep the naming consistent * fix naming gruntUtils vs utils As all three - gruntUtils, utils and lodash (_) are getting passed into templates, it makes sense to keep the naming consistent * split utils vs lodash in scripts/generate Also use lodash-2 where it is easy to do so * use utils.get until lodash upgrade * remove lodash.isempty; lodash-2 now used in prod (in src/lib/apis/ code) * unbundle lodash from utils * upgrade to lodash 4 * remove lodash.get and lodash.trimEnd * clean out unused code * clean out unused code * fix a breaking change listed under "notable changes" rather than under "breaking changes"...
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
module.exports = function (done) {
|
||||
var _ = require('../../src/lib/utils');
|
||||
var utils = require('../../grunt/utils');
|
||||
var _ = require('lodash');
|
||||
var gruntUtils = require('../../grunt/utils');
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fromRoot = _.partial(require('path').join, require('find-root')(__dirname));
|
||||
@ -10,13 +10,13 @@ module.exports = function (done) {
|
||||
var browserApiIndex = fromRoot('src/lib/apis/browser_index.js');
|
||||
|
||||
write(nodeApiIndex, require('./templates').apiIndex({
|
||||
branches: utils.branches
|
||||
branches: gruntUtils.branches
|
||||
}), 'utf8');
|
||||
|
||||
console.log(chalk.white.bold('wrote'), 'api index to', nodeApiIndex);
|
||||
|
||||
write(browserApiIndex, require('./templates').apiIndexBrowser({
|
||||
branches: utils.browserBranches
|
||||
branches: gruntUtils.browserBranches
|
||||
}), 'utf8');
|
||||
|
||||
console.log(chalk.white.bold('wrote'), 'browser api index to', browserApiIndex);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
module.exports = function (done) {
|
||||
var _ = require('../../src/lib/utils');
|
||||
var _ = require('lodash');
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fromRoot = _.partial(require('path').join, require('find-root')(__dirname));
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
module.exports = function (done) {
|
||||
var _ = require('../../src/lib/utils');
|
||||
var utils = require('../../grunt/utils');
|
||||
var _ = require('lodash');
|
||||
var gruntUtils = require('../../grunt/utils');
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fromRoot = _.partial(require('path').join, require('find-root')(__dirname));
|
||||
@ -9,8 +9,8 @@ module.exports = function (done) {
|
||||
var outputPath = fromRoot('docs/index.asciidoc');
|
||||
|
||||
write(outputPath, require('./templates').docsIndex({
|
||||
apiFiles: utils.stableBranches.map(function (branch) {
|
||||
return 'api_methods' + utils.branchSuffix(branch) + '.asciidoc';
|
||||
apiFiles: gruntUtils.stableBranches.map(function (branch) {
|
||||
return 'api_methods' + gruntUtils.branchSuffix(branch) + '.asciidoc';
|
||||
})
|
||||
}), 'utf8', done);
|
||||
|
||||
|
||||
@ -29,8 +29,9 @@ var argv = require('optimist')
|
||||
|
||||
var path = require('path');
|
||||
var fromRoot = path.join.bind(path, require('find-root')(__dirname));
|
||||
var utils = require(fromRoot('grunt/utils'));
|
||||
var _ = require(fromRoot('src/lib/utils'));
|
||||
var _ = require('lodash');
|
||||
var utils = require(fromRoot('src/lib/utils'));
|
||||
var gruntUtils = require(fromRoot('grunt/utils'));
|
||||
var esUrl = process.env.ES_REPO
|
||||
? path.resolve(process.cwd(), process.env.ES_REPO)
|
||||
: 'https://github.com/elastic/elasticsearch.git';
|
||||
@ -48,7 +49,7 @@ if (process.env.npm_config_argv) {
|
||||
if (argv.branch) {
|
||||
branches = [argv.branch];
|
||||
} else {
|
||||
branches = utils.branches;
|
||||
branches = gruntUtils.branches;
|
||||
}
|
||||
|
||||
var paths = {
|
||||
@ -59,10 +60,10 @@ var paths = {
|
||||
docsIndex: fromRoot('docs/index.asciidoc'),
|
||||
apiSrc: 'src/lib/apis',
|
||||
getArchiveDir: function (branch) {
|
||||
return fromRoot('src/_elasticsearch_' + _.snakeCase(branch));
|
||||
return fromRoot('src/_elasticsearch_' + utils.snakeCase(branch));
|
||||
},
|
||||
getArchiveTarball: function (branch) {
|
||||
return fromRoot('src/_elasticsearch_' + _.snakeCase(branch) + '.tar');
|
||||
return fromRoot('src/_elasticsearch_' + utils.snakeCase(branch) + '.tar');
|
||||
},
|
||||
getSpecPathInRepo: function (branch) {
|
||||
return /^v?(master|[2-9]\.)/.test(branch) ? 'rest-api-spec/src/main/resources/rest-api-spec' : 'rest-api-spec';
|
||||
@ -98,7 +99,7 @@ function dirRegex(dir, regexp) {
|
||||
function dirOpts(dir, opts) {
|
||||
opts = _.isArray(opts) ? opts : [opts];
|
||||
return dirFilter(dir, function (name) {
|
||||
return _.include(opts, name);
|
||||
return _.includes(opts, name);
|
||||
});
|
||||
}
|
||||
|
||||
@ -137,7 +138,7 @@ function fetchBranchesStep() {
|
||||
function findGeneratedApiFiles() {
|
||||
var anyApiMethodDocs = /^(configuration|index|api_methods).*\.asciidoc$/;
|
||||
var anyApiJsFiled = /^.+\.js$/;
|
||||
var allBranches = _.isEqual(branches, utils.branches);
|
||||
var allBranches = _.isEqual(branches, gruntUtils.branches);
|
||||
|
||||
if (allBranches) {
|
||||
return [
|
||||
@ -147,11 +148,11 @@ function findGeneratedApiFiles() {
|
||||
}
|
||||
|
||||
return branches.reduce(function (files, branch) {
|
||||
var b = _.snakeCase(branch);
|
||||
var b = utils.snakeCase(branch);
|
||||
|
||||
files.push(dirOpts(paths.docs, 'api_methods_' + b + '.asciidoc'));
|
||||
|
||||
var isDefault = branch === utils.branches._default;
|
||||
var isDefault = branch === gruntUtils.branches._default;
|
||||
if (isDefault) {
|
||||
files.push(dirOpts(paths.docs, 'api_methods.asciidoc'));
|
||||
}
|
||||
|
||||
@ -3,8 +3,9 @@ module.exports = function (branch, done) {
|
||||
* Read the API actions form the rest-api-spec repo.
|
||||
* @type {[type]}
|
||||
*/
|
||||
var _ = require('../../src/lib/utils');
|
||||
var utils = require('../../grunt/utils');
|
||||
var _ = require('lodash');
|
||||
var utils = require('../../src/lib/utils');
|
||||
var gruntUtils = require('../../grunt/utils');
|
||||
var fs = require('fs');
|
||||
var async = require('async');
|
||||
var chalk = require('chalk');
|
||||
@ -18,8 +19,8 @@ module.exports = function (branch, done) {
|
||||
var apiSpec; // populated by parseSpecFiles
|
||||
var docVars; // slightly modified clone of apiSpec for the docs
|
||||
|
||||
var branchSuffix = utils.branchSuffix(branch);
|
||||
var esDir = fromRoot('src/_elasticsearch_' + _.snakeCase(branch));
|
||||
var branchSuffix = gruntUtils.branchSuffix(branch);
|
||||
var esDir = fromRoot('src/_elasticsearch_' + utils.snakeCase(branch));
|
||||
|
||||
var version = Version.fromBranch(branch);
|
||||
var overrides = version.mergeOpts(require('./overrides'), {
|
||||
@ -39,7 +40,7 @@ module.exports = function (branch, done) {
|
||||
writeApiFile
|
||||
];
|
||||
|
||||
if (!~utils.unstableBranches.indexOf(branch)) {
|
||||
if (!~gruntUtils.unstableBranches.indexOf(branch)) {
|
||||
steps.push(
|
||||
ensureDocsDir,
|
||||
formatDocVars,
|
||||
@ -137,7 +138,7 @@ module.exports = function (branch, done) {
|
||||
}
|
||||
|
||||
function writeApiFile(done) {
|
||||
var outputPath = fromRoot('src/lib/apis/' + _.snakeCase(branch) + '.js');
|
||||
var outputPath = fromRoot('src/lib/apis/' + utils.snakeCase(branch) + '.js');
|
||||
fs.writeFileSync(outputPath, templates.apiFile(apiSpec));
|
||||
console.log(chalk.white.bold('wrote'), apiSpec.actions.length, 'api actions to', outputPath);
|
||||
done();
|
||||
@ -169,7 +170,7 @@ module.exports = function (branch, done) {
|
||||
'name'
|
||||
);
|
||||
docVars.branch = branch;
|
||||
docVars.branchIsDefault = branch === utils.branches._default;
|
||||
docVars.branchIsDefault = branch === gruntUtils.branches._default;
|
||||
docVars.branchSuffix = branchSuffix.replace(/_/g, '-');
|
||||
done();
|
||||
}
|
||||
@ -194,7 +195,7 @@ module.exports = function (branch, done) {
|
||||
// itterate all of the specs within the file, should only be one
|
||||
_.each(spec, function (def, name) {
|
||||
// camelcase the name
|
||||
name = _.map(name.split('.'), _.camelCase).join('.');
|
||||
name = _.map(name.split('.'), utils.camelCase).join('.');
|
||||
|
||||
if (name === 'cat.aliases') {
|
||||
def.documentation = 'http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat.html';
|
||||
@ -208,7 +209,7 @@ module.exports = function (branch, done) {
|
||||
var steps = name.split('.');
|
||||
|
||||
function transformParamKeys(note, param, key) {
|
||||
var cmlKey = _.camelCase(key);
|
||||
var cmlKey = utils.camelCase(key);
|
||||
if (cmlKey !== key) {
|
||||
param.name = key;
|
||||
}
|
||||
@ -222,7 +223,7 @@ module.exports = function (branch, done) {
|
||||
_.forOwn(allParams, (paramSpec, paramName) => {
|
||||
const toMerge = _.get(overrides, ['mergeConcatParams', name, paramName])
|
||||
if (toMerge) {
|
||||
_.merge(paramSpec, toMerge, (dest, src) => {
|
||||
_.mergeWith(paramSpec, toMerge, (dest, src) => {
|
||||
if (_.isArray(dest) && _.isArray(src)) {
|
||||
return dest.concat(src)
|
||||
}
|
||||
@ -240,7 +241,7 @@ module.exports = function (branch, done) {
|
||||
methods: _.map(def.methods, function (m) { return m.toUpperCase(); }),
|
||||
params: def.url.params,
|
||||
body: def.body || null,
|
||||
path2lib: _.repeat('../', steps.length + 1) + 'lib/'
|
||||
path2lib: utils.repeat('../', steps.length + 1) + 'lib/'
|
||||
};
|
||||
|
||||
if (def.body && def.body.required) {
|
||||
@ -270,17 +271,17 @@ module.exports = function (branch, done) {
|
||||
}
|
||||
|
||||
while (match = urlParamRE.exec(url)) {
|
||||
name = _.camelCase(match[1]);
|
||||
name = utils.camelCase(match[1]);
|
||||
param = def.url.parts[name] || {};
|
||||
target = (param.required || !param.default) ? requiredVars : optionalVars;
|
||||
target[name] = _.omit(param, 'required', 'description', 'name');
|
||||
target[name] = _.omit(param, ['required', 'description', 'name']);
|
||||
}
|
||||
|
||||
urlSignatures.push(_.union(_.keys(optionalVars), _.keys(requiredVars)).sort().join(':'));
|
||||
|
||||
return _.omit({
|
||||
return _.omitBy({
|
||||
fmt: url.replace(urlParamRE, function (full, match) {
|
||||
return '<%=' + _.camelCase(match) + '%>';
|
||||
return '<%=' + utils.camelCase(match) + '%>';
|
||||
}),
|
||||
opt: _.size(optionalVars) ? optionalVars : null,
|
||||
req: _.size(requiredVars) ? requiredVars : null,
|
||||
|
||||
@ -191,7 +191,7 @@ module.exports = [
|
||||
/* eslint-disable */
|
||||
clientActionModifier:
|
||||
function (spec) {
|
||||
return require('../utils').merge(spec, {
|
||||
return require('lodash').merge(spec, {
|
||||
params: {
|
||||
filterPath: {
|
||||
type: 'list',
|
||||
|
||||
@ -15,8 +15,8 @@ _.each(actions, function (action) {
|
||||
.slice(0, -1)
|
||||
.filter(step => step !== 'prototype')
|
||||
.join('.prototype.');
|
||||
|
||||
if (_.include(namespaces, namespace)) {
|
||||
|
||||
if (_.includes(namespaces, namespace)) {
|
||||
_.pull(namespaces, namespace);
|
||||
%>
|
||||
|
||||
|
||||
@ -4,10 +4,10 @@ module.exports = {
|
||||
|
||||
branches.forEach(function (branch, i, list) {
|
||||
function printVersion(name) {
|
||||
print(` get '${name}'() { return require('./${_.snakeCase(branch)}'); },\n`)
|
||||
print(` get '${name}'() { return require('./${utils.snakeCase(branch)}'); },\n`)
|
||||
}
|
||||
|
||||
if (branch === utils.branches._default) printVersion('_default');
|
||||
if (branch === gruntUtils.branches._default) printVersion('_default');
|
||||
printVersion(branch);
|
||||
});
|
||||
|
||||
|
||||
@ -2,8 +2,8 @@ module.exports = {
|
||||
<%
|
||||
|
||||
branches.forEach(function (branch, i, list) {
|
||||
var req = "require('./" + _.snakeCase(branch) + "')";
|
||||
if (branch === utils.branches._default) {
|
||||
var req = "require('./" + utils.snakeCase(branch) + "')";
|
||||
if (branch === gruntUtils.branches._default) {
|
||||
print(" '_default': " + req + ',\n');
|
||||
}
|
||||
|
||||
|
||||
@ -52,12 +52,12 @@ Default in Node:::
|
||||
+
|
||||
WARNING: This default will track the latest version of Elasticsearch, and is only intended to be used during development. It is highly recommended that you set this parameter in all code that is headed to production.
|
||||
|
||||
Default ::: `<%= stringify(utils.branches._default) %>`
|
||||
Default ::: `<%= stringify(gruntUtils.branches._default) %>`
|
||||
<%
|
||||
|
||||
function printBranch(branch, i) {
|
||||
print(' * `' + stringify(branch) + '`');
|
||||
if (utils.unstableBranches.indexOf(branch) >= 0) {
|
||||
if (gruntUtils.unstableBranches.indexOf(branch) >= 0) {
|
||||
print(' (unstable)');
|
||||
}
|
||||
print('\n');
|
||||
@ -65,9 +65,9 @@ function printBranch(branch, i) {
|
||||
|
||||
%>
|
||||
Options in node :::
|
||||
<% utils.branches.forEach(printBranch); %>
|
||||
<% gruntUtils.branches.forEach(printBranch); %>
|
||||
Options in the browser :::
|
||||
<% utils.browserBranches.forEach(printBranch); %>
|
||||
<% gruntUtils.browserBranches.forEach(printBranch); %>
|
||||
|
||||
|
||||
`plugins`[[config-plugins]]:: `Function[]` -- Plugin instantiators that will be called when the Client initializes. Each function is called in order with the arguments `Constructor`, `config`, and `components`.
|
||||
@ -319,7 +319,7 @@ var client = new elasticsearch.Client({
|
||||
// choose the node with the smallest weight.
|
||||
selection = _(nodes).sortBy(function (node) {
|
||||
return node.host.weight;
|
||||
}).first();
|
||||
}).head();
|
||||
}
|
||||
|
||||
return selection;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var utils = require('../../../grunt/utils');
|
||||
var _ = require('lodash');
|
||||
var utils = require('../../../src/lib/utils');
|
||||
var gruntUtils = require('../../../grunt/utils');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
@ -42,9 +43,10 @@ var templateGlobals = {
|
||||
stringify: stringify,
|
||||
|
||||
_: _,
|
||||
utils: utils,
|
||||
|
||||
indent: function (block, spaces) {
|
||||
var indent = _.repeat(' ', spaces);
|
||||
var indent = utils.repeat(' ', spaces);
|
||||
return block.split('\n').map(function (line) {
|
||||
return indent + line;
|
||||
}).join('\n');
|
||||
@ -92,7 +94,7 @@ var templateGlobals = {
|
||||
|
||||
partials: templates,
|
||||
|
||||
utils: utils
|
||||
gruntUtils: gruntUtils
|
||||
};
|
||||
|
||||
fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) {
|
||||
@ -100,7 +102,6 @@ fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) {
|
||||
if (name !== 'index') {
|
||||
templates[name] = _.template(
|
||||
fs.readFileSync(path.resolve(__dirname, filename), 'utf8'),
|
||||
null,
|
||||
{
|
||||
imports: templateGlobals
|
||||
}
|
||||
|
||||
@ -8,10 +8,10 @@ module.exports = function (branch, done) {
|
||||
var chalk = require('chalk');
|
||||
var path = require('path');
|
||||
var fromRoot = path.join.bind(path, require('find-root')(__dirname));
|
||||
var _ = require(fromRoot('src/lib/utils'));
|
||||
var utils = require(fromRoot('src/lib/utils'));
|
||||
var tests = {}; // populated in readYamlTests
|
||||
|
||||
var esDir = fromRoot('src/_elasticsearch_' + _.snakeCase(branch));
|
||||
var esDir = fromRoot('src/_elasticsearch_' + utils.snakeCase(branch));
|
||||
|
||||
// generate the yaml tests
|
||||
async.series([
|
||||
@ -43,14 +43,14 @@ module.exports = function (branch, done) {
|
||||
}
|
||||
|
||||
function writeYamlTests(done) {
|
||||
var testFile = fromRoot('test/integration/yaml_suite/yaml_tests_' + _.snakeCase(branch) + '.json');
|
||||
var testFile = fromRoot('test/integration/yaml_suite/yaml_tests_' + utils.snakeCase(branch) + '.json');
|
||||
fs.writeFileSync(testFile, JSON.stringify(tests, null, ' '), 'utf8');
|
||||
console.log(chalk.white.bold('wrote') + ' YAML tests as JSON to', testFile);
|
||||
done();
|
||||
}
|
||||
|
||||
function writeTestIndex(done) {
|
||||
var file = fromRoot('test/integration/yaml_suite/index_' + _.snakeCase(branch) + '.js');
|
||||
var file = fromRoot('test/integration/yaml_suite/index_' + utils.snakeCase(branch) + '.js');
|
||||
fs.writeFileSync(file, 'require(\'./run\')(\'' + branch + '\');\n', 'utf8');
|
||||
console.log(chalk.white.bold('wrote') + ' YAML index to', file);
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user