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

refactor: remove not used utils and prefer using lodash #6643

Merged
merged 7 commits into from
Feb 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ export class CompositionsMain {

if (!maybeFiles) return [];
const [, files] = maybeFiles;
return files
.map((file) => {
return this.computeCompositions(component, file);
})
.flat();
return files.map((file) => this.computeCompositions(component, file)).flat();
}

getCompositionFilePattern() {
Expand Down
2 changes: 1 addition & 1 deletion src/bit-id/bit-ids.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import R from 'ramda';
import { forEach } from 'lodash';

import BitId, { BitIdStr } from '../bit-id/bit-id';
import { LATEST_BIT_VERSION } from '../constants';
import forEach from '../utils/object/foreach';
import getLatestVersionNumber from '../utils/resolveLatestVersion';

export default class BitIds extends Array<BitId> {
Expand Down
5 changes: 3 additions & 2 deletions src/cli/commands/private-cmds/_scope-cmd.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isEmpty } from 'lodash';
import { describeScope } from '../../../api/scope';
import { buildCommandMessage, empty, fromBase64, packCommand, unpackCommand } from '../../../utils';
import { buildCommandMessage, fromBase64, packCommand, unpackCommand } from '../../../utils';
import clientSupportCompressedCommand from '../../../utils/ssh/client-support-compressed-command';
import { LegacyCommand } from '../../legacy-command';

Expand All @@ -19,7 +20,7 @@ export default class Prepare implements LegacyCommand {
}

report(scopeObj: any): string {
if (empty(scopeObj)) return '';
if (isEmpty(scopeObj)) return '';
return packCommand(buildCommandMessage(scopeObj, undefined, compressResponse), true, compressResponse);
}
}
4 changes: 2 additions & 2 deletions src/cli/commands/public-cmds/remote-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import chalk from 'chalk';
import Table from 'cli-table';
import { forEach, isEmpty } from 'lodash';

import { remoteAdd, remoteList, remoteRm } from '../../../api/consumer';
import { BASE_DOCS_DOMAIN } from '../../../constants';
import { empty, forEach } from '../../../utils';
import { Group } from '../../command-groups';
import { CommandOptions, LegacyCommand } from '../../legacy-command';
import RemoteUndefined from '../exceptions/remote-undefined';
Expand Down Expand Up @@ -63,7 +63,7 @@ export default class Remote implements LegacyCommand {
}

report(remotes: { [key: string]: string }): string {
if (empty(remotes)) return chalk.red('no configured remotes found in scope');
if (isEmpty(remotes)) return chalk.red('no configured remotes found in scope');

const table = new Table({ head: ['scope name', 'host'], style: { head: ['cyan'] } });
forEach(remotes, (host, name) => {
Expand Down
3 changes: 2 additions & 1 deletion src/remotes/remotes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { groupBy, prop } from 'ramda';
import { forEach } from 'lodash';
import pMap from 'p-map';
import { CURRENT_FETCH_SCHEMA, FETCH_OPTIONS } from '../api/scope/lib/fetch';
import { BitId } from '../bit-id';
Expand All @@ -7,7 +8,7 @@ import logger from '../logger/logger';
import { ScopeNotFound } from '../scope/exceptions';
import DependencyGraph from '../scope/graph/scope-graph';
import Scope from '../scope/scope';
import { forEach, prependBang } from '../utils';
import { prependBang } from '../utils';
import { PrimaryOverloaded } from './exceptions';
import Remote from './remote';
import remoteResolver from './remote-resolver/remote-resolver';
Expand Down
18 changes: 9 additions & 9 deletions src/scope/models/model-component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clone, equals, forEachObjIndexed } from 'ramda';
import { isEmpty, pickBy } from 'lodash';
import { forEach, isEmpty, pickBy, mapValues } from 'lodash';
import { Mutex } from 'async-mutex';
import * as semver from 'semver';
import { versionParser, isHash, isTag } from '@teambit/component-version';
Expand All @@ -22,7 +22,7 @@ import GeneralError from '../../error/general-error';
import ShowDoctorError from '../../error/show-doctor-error';
import ValidationError from '../../error/validation-error';
import logger from '../../logger/logger';
import { empty, forEach, getStringifyArgs, mapObject, sha1 } from '../../utils';
import { getStringifyArgs, sha1 } from '../../utils';
import findDuplications from '../../utils/array/find-duplications';
import ComponentObjects from '../component-objects';
import { SnapsDistance } from '../component-ops/snaps-distance';
Expand Down Expand Up @@ -356,7 +356,7 @@ export default class Component extends BitObject {
}

isEmpty() {
return empty(this.versions) && !this.hasHead();
return isEmpty(this.versions) && !this.hasHead();
}

/**
Expand All @@ -366,7 +366,7 @@ export default class Component extends BitObject {
getHeadRegardlessOfLaneAsTagOrHash(returnVersionZeroForNoHead = false): string {
const head = this.getHeadRegardlessOfLane();
if (!head) {
if (!empty(this.versions))
if (!isEmpty(this.versions))
throw new Error(`error: ${this.id()} has tags but no head, it might be originated from legacy`);
if (returnVersionZeroForNoHead) return VERSION_ZERO;
throw new Error(`getHeadRegardlessOfLaneAsTagOrHash() failed finding a head for ${this.id()}`);
Expand Down Expand Up @@ -399,12 +399,12 @@ export default class Component extends BitObject {
}

latestVersion(): string {
if (empty(this.versions)) return VERSION_ZERO;
if (isEmpty(this.versions)) return VERSION_ZERO;
return getLatestVersion(this.listVersions());
}

latestVersionIfExist(): string | undefined {
if (empty(this.versions)) return undefined;
if (isEmpty(this.versions)) return undefined;
return getLatestVersion(this.listVersions());
}

Expand Down Expand Up @@ -439,7 +439,7 @@ export default class Component extends BitObject {
* @memberof Component
*/
latestExisting(repository: Repository): string {
if (empty(this.versions)) return VERSION_ZERO;
if (isEmpty(this.versions)) return VERSION_ZERO;
const versions = this.listVersions('ASC');
let version = null;
let versionStr = null;
Expand Down Expand Up @@ -1107,13 +1107,13 @@ consider using --ignore-missing-artifacts flag if you're sure the artifacts are
return Component.from({
name: rawComponent.box ? `${rawComponent.box}/${rawComponent.name}` : rawComponent.name,
scope: rawComponent.scope,
versions: mapObject(rawComponent.versions, (val) => Ref.from(val)),
versions: mapValues(rawComponent.versions as Record<string, string>, (val) => Ref.from(val)),
lang: rawComponent.lang,
deprecated: rawComponent.deprecated,
bindingPrefix: rawComponent.bindingPrefix,
local: rawComponent.local,
state: rawComponent.state,
orphanedVersions: mapObject(rawComponent.orphanedVersions || {}, (val) => Ref.from(val)),
orphanedVersions: mapValues(rawComponent.orphanedVersions || {}, (val) => Ref.from(val)),
scopesList: rawComponent.remotes,
head: rawComponent.head ? Ref.from(rawComponent.head) : undefined,
schema: rawComponent.schema || (rawComponent.head ? SchemaName.Harmony : SchemaName.Legacy),
Expand Down
10 changes: 0 additions & 10 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ import isDirEmptySync from './is-dir-empty-sync';
import isAutoGeneratedFile from './is-file-auto-generated';
import isRelativeImport from './is-relative-import';
import isValidPath from './is-valid-path';
import mapObject from './map-object';
import mapToObject from './map/to-object';
import isNumeric from './number/is-numeric';
import cleanObject from './object-clean';
import objectToStringifiedTupleArray from './object-to-stringified-tuple-array';
import empty from './object/empty';
import forEach from './object/foreach';
import hasOwnProperty from './object/has-own-property';
import sortObject from './object/sort';
import resolveGroupId from './os-resolve-group-id';
import resolveHomePath from './os-resolve-home-path';
Expand All @@ -44,7 +40,6 @@ import cleanChar from './string/clean-char';
import fromBase64 from './string/from-base64';
import generateRandomStr from './string/generate-random';
import getStringifyArgs from './string/get-stringify-args';
import isString from './string/is-string';
import removeChalkCharacters from './string/remove-chalk-characters';
import stripTrailingChar from './string/strip-trailing-char';
import toBase64 from './string/to-base64';
Expand All @@ -61,7 +56,6 @@ export {
resolveGroupId,
mapToObject,
sortObject,
isString,
removeChalkCharacters,
getStringifyArgs,
isNumeric,
Expand All @@ -71,7 +65,6 @@ export {
toBase64ArrayBuffer,
fromBase64,
glob,
empty,
cleanChar,
checksum,
checksumFile,
Expand All @@ -82,11 +75,8 @@ export {
createSymlinkOrCopy,
cleanBang,
prependBang,
forEach,
hasOwnProperty,
isBitUrl,
isDir,
mapObject,
resolveHomePath,
propogateUntil,
pathHas,
Expand Down
25 changes: 0 additions & 25 deletions src/utils/map-object.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils/object-clean.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import forEach from './object/foreach';
import { forEach } from 'lodash';

/**
* Cleans all object's properties that contains a falsy value
Expand Down
2 changes: 1 addition & 1 deletion src/utils/object-to-stringified-tuple-array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import forEach from './object/foreach';
import { forEach } from 'lodash';

export default function objectToStringifiedTupleArray(obj: { [key: string]: any }): [string | number][] {
const arr: any[] = [];
Expand Down
20 changes: 0 additions & 20 deletions src/utils/object/empty.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/utils/object/foreach.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/utils/object/has-own-property.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/utils/string/is-string.ts

This file was deleted.