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

[Telemetry Tools] update lodash to 4.17 #77317

Merged
merged 4 commits into from
Sep 14, 2020
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
4 changes: 2 additions & 2 deletions packages/kbn-telemetry-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-telemetry-tools/src/tools/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import * as ts from 'typescript';
import { uniq } from 'lodash';
import { uniqBy } from 'lodash';
import {
getResolvedModuleSourceFile,
getIdentifierDeclarationFromSource,
Expand Down Expand Up @@ -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.');
Expand Down
80 changes: 48 additions & 32 deletions packages/kbn-telemetry-tools/src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)) {
Expand All @@ -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);

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;
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;
}
});
} 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);
}
Expand Down
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down