[Telemetry Tools] update lodash to 4.17 (#77317)

This commit is contained in:
Ahmad Bamieh 2020-09-14 17:14:57 +03:00 committed by GitHub
parent 520d348bf8
commit 9dfa20acd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 45 deletions

View file

@ -10,12 +10,12 @@
"kbn:watch": "yarn build --watch"
},
"devDependencies": {
"lodash": "npm:@elastic/lodash@3.10.1-kibana4",
"lodash": "^4.17.20",
"@kbn/dev-utils": "1.0.0",
"@kbn/utility-types": "1.0.0",
"@types/normalize-path": "^3.0.0",
"normalize-path": "^3.0.0",
"@types/lodash": "^3.10.1",
"@types/lodash": "^4.14.159",
"moment": "^2.24.0",
"typescript": "4.0.2"
}

View file

@ -18,7 +18,7 @@
*/
import * as ts from 'typescript';
import { uniq } from 'lodash';
import { uniqBy } from 'lodash';
import {
getResolvedModuleSourceFile,
getIdentifierDeclarationFromSource,
@ -148,7 +148,7 @@ export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor |
.map((typeNode) => getDescriptor(typeNode, program))
.filter(discardNullOrUndefined);
const uniqueKinds = uniq(kinds, 'kind');
const uniqueKinds = uniqBy(kinds, 'kind');
if (uniqueKinds.length !== 1) {
throw Error('Mapping does not support conflicting union types.');

View file

@ -18,7 +18,18 @@
*/
import * as ts from 'typescript';
import { pick, isObject, each, isArray, reduce, isEmpty, merge, transform, isEqual } from 'lodash';
import {
pick,
pickBy,
isObject,
forEach,
isArray,
reduce,
isEmpty,
merge,
transform,
isEqual,
} from 'lodash';
import * as path from 'path';
import glob from 'glob';
import { readFile, writeFile } from 'fs';
@ -186,17 +197,17 @@ export function getPropertyValue(
}
}
export function pickDeep(collection: any, identity: any, thisArg?: any) {
const picked: any = pick(collection, identity, thisArg);
const collections = pick(collection, isObject, thisArg);
export function pickDeep(collection: any, identity: any) {
const picked: any = pick(collection, identity);
const collections = pickBy(collection, isObject);
each(collections, function (item, key) {
forEach(collections, function (item, key) {
let object;
if (isArray(item)) {
object = reduce(
item,
function (result, value) {
const pickedDeep = pickDeep(value, identity, thisArg);
const pickedDeep = pickDeep(value, identity);
if (!isEmpty(pickedDeep)) {
result.push(pickedDeep);
}
@ -205,7 +216,7 @@ export function pickDeep(collection: any, identity: any, thisArg?: any) {
[] as any[]
);
} else {
object = pickDeep(item, identity, thisArg);
object = pickDeep(item, identity);
}
if (!isEmpty(object)) {
@ -230,33 +241,38 @@ export const flattenKeys = (obj: any, keyPath: any[] = []): any => {
return { [keyPath.join('.')]: obj };
};
type ObjectDict = Record<string, any>;
export function difference(actual: any, expected: any) {
function changes(obj: { [key: string]: any }, base: { [key: string]: any }) {
return transform(obj, function (result, value, key) {
if (key && /@@INDEX@@/.test(`${key}`)) {
// The type definition is an Index Signature, fuzzy searching for similar keys
const regexp = new RegExp(`${key}`.replace(/@@INDEX@@/g, '(.+)?'));
const keysInBase = Object.keys(base)
.map((k) => {
const match = k.match(regexp);
return match && match[0];
})
.filter((s): s is string => !!s);
function changes(obj: ObjectDict, base: ObjectDict) {
return transform(
obj,
function (result, value, key) {
if (key && /@@INDEX@@/.test(`${key}`)) {
// The type definition is an Index Signature, fuzzy searching for similar keys
const regexp = new RegExp(`${key}`.replace(/@@INDEX@@/g, '(.+)?'));
const keysInBase = Object.keys(base)
.map((k) => {
const match = k.match(regexp);
return match && match[0];
})
.filter((s): s is string => !!s);
if (keysInBase.length === 0) {
// Mark this key as wrong because we couldn't find any matching keys
result[key] = value;
}
keysInBase.forEach((k) => {
if (!isEqual(value, base[k])) {
result[k] = isObject(value) && isObject(base[k]) ? changes(value, base[k]) : value;
if (keysInBase.length === 0) {
// Mark this key as wrong because we couldn't find any matching keys
result[key] = value;
}
});
} else if (key && !isEqual(value, base[key])) {
result[key] = isObject(value) && isObject(base[key]) ? changes(value, base[key]) : value;
}
});
keysInBase.forEach((k) => {
if (!isEqual(value, base[k])) {
result[k] = isObject(value) && isObject(base[k]) ? changes(value, base[k]) : value;
}
});
} else if (key && !isEqual(value, base[key])) {
result[key] = isObject(value) && isObject(base[key]) ? changes(value, base[key]) : value;
}
},
{} as ObjectDict
);
}
return changes(actual, expected);
}

View file

@ -4123,11 +4123,6 @@
"@types/node" "*"
"@types/webpack" "*"
"@types/lodash@^3.10.1":
version "3.10.3"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-3.10.3.tgz#aaddec6a3c93bf03b402db3acf5d4c77bce8bdff"
integrity sha512-b9zScBKmB/RJqETbxu3YRya61vJOik89/lR+NdxjZAFMDcMSjwX6IhQoP4terJkhsa9TE1C+l6XwxCkhhsaZXg==
"@types/lodash@^4.14.116", "@types/lodash@^4.14.159":
version "4.14.159"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.159.tgz#61089719dc6fdd9c5cb46efc827f2571d1517065"
@ -18971,11 +18966,6 @@ lodash@^3.10.1:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
integrity sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=
"lodash@npm:@elastic/lodash@3.10.1-kibana4":
version "3.10.1-kibana4"
resolved "https://registry.yarnpkg.com/@elastic/lodash/-/lodash-3.10.1-kibana4.tgz#d491228fd659b4a1b0dfa08ba9c67a4979b9746d"
integrity sha512-geQqXd9ZedRCL+kq5cpeahYWYaYRV0BMXhCwzq4DpnGCVs430FTMS3Wcot3XChZZhCvkwHm15bpNjB312vPxaA==
log-ok@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/log-ok/-/log-ok-0.1.1.tgz#bea3dd36acd0b8a7240d78736b5b97c65444a334"