Skip to content

chore(ramda) - remove ramda from entire workspace #9484

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

Merged
merged 9 commits into from
Jan 21, 2025
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
8 changes: 4 additions & 4 deletions components/legacy/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fork } from 'child_process';
import hashObj from 'object-hash';
import os from 'os';
import * as path from 'path';
import R from 'ramda';
import { isNil, isEmpty, filter } from 'lodash';
import { serializeError } from 'serialize-error';
import uniqid from 'uniqid';
import yn from 'yn';
Expand Down Expand Up @@ -75,7 +75,7 @@ class Analytics {
if (cmd.length && cmd[0] !== 'config' && !process.env.CI) {
const analyticsReporting = getSync(CFG_ANALYTICS_REPORTING_KEY);
const errorReporting = getSync(CFG_ANALYTICS_ERROR_REPORTS_KEY);
return R.isNil(analyticsReporting) && R.isNil(errorReporting);
return isNil(analyticsReporting) && isNil(errorReporting);
}
return false;
}
Expand Down Expand Up @@ -119,8 +119,8 @@ class Analytics {
}
static _hashFlags(flags: Record<string, any>) {
const hashedFlags = {};
const definedFlags = R.filter((flag) => typeof flag !== 'undefined', flags);
if (this.anonymous && !R.isEmpty(definedFlags)) {
const definedFlags = filter(flags, (flag) => typeof flag !== 'undefined');
if (this.anonymous && !isEmpty(definedFlags)) {
Object.keys(definedFlags).forEach((key) => {
hashedFlags[key] = this._hashLightly(flags[key]);
});
Expand Down
13 changes: 6 additions & 7 deletions components/legacy/bit-map/bit-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import objectHash from 'object-hash';
import json from 'comment-json';
import fs from 'fs-extra';
import * as path from 'path';
import { compact, uniq } from 'lodash';
import R from 'ramda';
import { compact, uniq, differenceWith, isEmpty, isString, unionWith, get } from 'lodash';
import { LaneId } from '@teambit/lane-id';
import { BitError } from '@teambit/bit-error';
import { ComponentID, ComponentIdList } from '@teambit/component-id';
Expand Down Expand Up @@ -135,7 +134,7 @@ export class BitMap {
}

isEmpty() {
return R.isEmpty(this.components);
return isEmpty(this.components);
}

static mergeContent(rawContent: string, otherRawContent: string, opts: MergeOptions = {}): string {
Expand Down Expand Up @@ -585,7 +584,7 @@ export class BitMap {
* search for a similar id in the bitmap and return the full BitId
*/
getExistingBitId(id: BitIdStr, shouldThrow = true, searchWithoutScopeInProvidedId = false): ComponentID | undefined {
if (!R.is(String, id)) {
if (!isString(id)) {
throw new TypeError(`BitMap.getExistingBitId expects id to be a string, instead, got ${typeof id}`);
}

Expand Down Expand Up @@ -634,7 +633,7 @@ export class BitMap {
_areFilesArraysEqual(filesA: ComponentMapFile[], filesB: ComponentMapFile[]): boolean {
if (filesA.length !== filesB.length) return false;
const cmp = (x, y) => x.relativePath === y.relativePath;
const diff = R.differenceWith(cmp, filesA, filesB);
const diff = differenceWith(filesA, filesB, cmp);
if (!diff.length) return true;
return false;
}
Expand All @@ -643,7 +642,7 @@ export class BitMap {
* add files from filesB that are not in filesA
*/
mergeFilesArray(filesA: ComponentMapFile[], filesB: ComponentMapFile[]): ComponentMapFile[] {
return R.unionWith(R.eqBy(R.prop('relativePath')), filesA, filesB);
return unionWith(filesA, filesB, (file1, file2) => get(file1, 'relativePath') === get(file2, 'relativePath'));
}

addComponent({
Expand Down Expand Up @@ -871,7 +870,7 @@ export class BitMap {
}

_populateAllPaths() {
if (R.isEmpty(this.paths)) {
if (isEmpty(this.paths)) {
this.components.forEach((component) => {
component.files.forEach((file) => {
const relativeToConsumer = component.rootDir
Expand Down
14 changes: 6 additions & 8 deletions components/legacy/bit-map/component-map.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import globby from 'globby';
import ignore from 'ignore';
import R from 'ramda';
import { pickBy, isNil, sortBy, isEmpty } from 'lodash';
import { ComponentID } from '@teambit/component-id';
import { BIT_MAP, Extensions, PACKAGE_JSON, IGNORE_ROOT_ONLY_LIST } from '@teambit/legacy.constants';
import { ValidationError } from '@teambit/legacy.cli.error';
Expand Down Expand Up @@ -127,7 +127,7 @@ export class ComponentMap {
}

toPlainObject(): Record<string, any> {
let res = {
let res: Record<string, any> = {
name: this.name,
scope: this.scope,
version: this.version,
Expand All @@ -144,10 +144,8 @@ export class ComponentMap {
localOnly: this.localOnly || null, // if false, change to null so it won't be written
config: this.configToObject(),
};
const notNil = (val) => {
return !R.isNil(val);
};
res = R.filter(notNil, res);

res = pickBy(res, (value) => !isNil(value));
return res;
}

Expand Down Expand Up @@ -346,7 +344,7 @@ export class ComponentMap {
}

sort() {
this.files = R.sortBy(R.prop('relativePath'), this.files);
this.files = sortBy(this.files, 'relativePath');
}

clone() {
Expand Down Expand Up @@ -381,7 +379,7 @@ export class ComponentMap {
}
});
const foundMainFile = this.files.find((file) => file.relativePath === this.mainFile);
if (!foundMainFile || R.isEmpty(foundMainFile)) {
if (!foundMainFile || isEmpty(foundMainFile)) {
throw new ValidationError(`${errorMessage} mainFile ${this.mainFile} is not in the files list.
if you renamed the mainFile, please re-add the component with the "--main" flag pointing to the correct main-file`);
}
Expand Down
4 changes: 2 additions & 2 deletions components/legacy/cli/error/clone-error-object.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import R from 'ramda';
import { cloneDeep } from 'lodash';

export const systemFields = ['stack', 'code', 'errno', 'syscall'];

Expand All @@ -11,7 +11,7 @@ export default function cloneErrorObject(error: Error): Error {
if (error[field]) err[field] = error[field];
});
Object.keys(error).forEach((key) => {
err[key] = R.clone(error[key]);
err[key] = cloneDeep(error[key]);
});
return err;
}
4 changes: 2 additions & 2 deletions components/legacy/component-diff/components-diff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk from 'chalk';
import tempy from 'tempy';
import R from 'ramda';
import { uniq } from 'lodash';
import { ComponentID } from '@teambit/component-id';
import { diffFiles } from './diff-files';
import { PathOsBased } from '@teambit/toolbox.path.path';
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function getFilesDiff(
): Promise<FileDiff[]> {
const filesAPaths = filesA.map((f) => f[fileNameAttribute]);
const filesBPaths = filesB.map((f) => f[fileNameAttribute]);
const allPaths = R.uniq(filesAPaths.concat(filesBPaths));
const allPaths = uniq(filesAPaths.concat(filesBPaths));
const fileALabel = filesAVersion === filesBVersion ? `${filesAVersion} original` : filesAVersion;
const fileBLabel = filesAVersion === filesBVersion ? `${filesBVersion} modified` : filesBVersion;
const filesDiffP = allPaths.map(async (relativePath) => {
Expand Down
26 changes: 13 additions & 13 deletions components/legacy/component-diff/components-object-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { ComponentIdList } from '@teambit/component-id';
import Table from 'cli-table';
import normalize from 'normalize-path';
import diff from 'object-diff';
import R from 'ramda';
import { compact } from 'lodash';
import { compact, find, get, isEmpty, isNil, union } from 'lodash';
import { lt, gt } from 'semver';
import { ConsumerComponent as Component } from '@teambit/legacy.consumer-component';
import { ExtensionDataList } from '@teambit/legacy.extension-data';
Expand All @@ -26,13 +25,13 @@ type DepDiff = {
export function componentToPrintableForDiff(component: Component): Record<string, any> {
const obj: Record<string, any> = {};
const parsePackages = (packages: Record<string, string>): string[] | null => {
return !R.isEmpty(packages) && !R.isNil(packages)
return !isEmpty(packages) && !isNil(packages)
? Object.keys(packages).map((key) => `${key}@${packages[key]}`)
: null;
};

const parseExtensions = (extensions?: ExtensionDataList) => {
if (!extensions || R.isEmpty(extensions)) return null;
if (!extensions || isEmpty(extensions)) return null;
return extensions.toConfigArray().map((extension) => extension.id);
};

Expand Down Expand Up @@ -80,11 +79,12 @@ export function componentToPrintableForDiff(component: Component): Record<string
obj.peerDependencies = peerPackageDependencies.length ? peerPackageDependencies : undefined;

obj.files =
files && !R.isEmpty(files) && !R.isNil(files)
files && !isEmpty(files) && !isNil(files)
? files.filter((file) => !file.test).map((file) => normalize(file.relative))
: null;

obj.specs =
files && !R.isEmpty(files) && !R.isNil(files) && R.find(R.propEq('test', true))(files)
files && !isEmpty(files) && !isNil(files) && find(files, (file) => get(file, 'test') === true)
? files.filter((file) => file.test).map((file) => normalize(file.relative))
: null;
obj.extensions = parseExtensions(extensions);
Expand All @@ -102,7 +102,7 @@ export function prettifyFieldName(field: string): string {

function comparator(a, b) {
if (a instanceof Array && b instanceof Array) {
return R.isEmpty(arrayDifference(a, b));
return isEmpty(arrayDifference(a, b));
}
return a === b;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ export async function diffBetweenComponentsObjects(
if (!verbose) return [];
const dependenciesLeft = componentLeft.getAllDependencies();
const dependenciesRight = componentRight.getAllDependencies();
if (R.isEmpty(dependenciesLeft) || R.isEmpty(dependenciesRight)) return [];
if (isEmpty(dependenciesLeft) || isEmpty(dependenciesRight)) return [];
return dependenciesLeft.reduce((acc, dependencyLeft) => {
const idStr = dependencyLeft.id.toString();
const dependencyRight = dependenciesRight.find((dep) => dep.id.isEqual(dependencyLeft.id));
Expand All @@ -186,7 +186,7 @@ export async function diffBetweenComponentsObjects(
const title =
titleLeft(fieldName, leftVersion, rightVersion) + chalk.bold(titleRight(fieldName, leftVersion, rightVersion));
const getValue = (fieldValue: Record<string, any>, left: boolean) => {
if (R.isEmpty(fieldValue)) return '';
if (isEmpty(fieldValue)) return '';
const sign = left ? '-' : '+';
const jsonOutput = JSON.stringify(fieldValue, null, `${sign} `);
return `${jsonOutput}\n`;
Expand Down Expand Up @@ -249,7 +249,7 @@ export async function diffBetweenComponentsObjects(
const packageDependenciesOutput = (fieldName: string): string | null => {
const dependenciesLeft = componentLeft[fieldName];
const dependenciesRight = componentRight[fieldName];
if (R.isEmpty(dependenciesLeft) && R.isEmpty(dependenciesRight)) return null;
if (isEmpty(dependenciesLeft) && isEmpty(dependenciesRight)) return null;
const diffsLeft = Object.keys(dependenciesLeft).reduce<DepDiff[]>((acc, dependencyName) => {
const dependencyLeft = dependenciesLeft[dependencyName];
const dependencyRight = dependenciesRight[dependencyName];
Expand Down Expand Up @@ -283,7 +283,7 @@ export async function diffBetweenComponentsObjects(
const componentDependenciesOutput = (fieldName: string): string | null => {
const dependenciesLeft: ComponentIdList = componentLeft.depsIdsGroupedByType[fieldName];
const dependenciesRight: ComponentIdList = componentRight.depsIdsGroupedByType[fieldName];
if (R.isEmpty(dependenciesLeft) && R.isEmpty(dependenciesRight)) return null;
if (isEmpty(dependenciesLeft) && isEmpty(dependenciesRight)) return null;
const diffsLeft = dependenciesLeft.reduce<DepDiff[]>((acc, dependencyLeft) => {
const dependencyRight = dependenciesRight.searchWithoutVersion(dependencyLeft);
if (dependencyRight && dependencyLeft.isEqual(dependencyRight)) return acc;
Expand Down Expand Up @@ -336,7 +336,7 @@ export async function diffBetweenComponentsObjects(
...getAllDepsOutput(),
];

return R.isEmpty(allDiffs) ? undefined : allDiffs;
return isEmpty(allDiffs) ? undefined : allDiffs;
}

async function getExtensionsConfigOutput(componentLeft: Component, componentRight: Component): Promise<ConfigDiff[]> {
Expand All @@ -347,7 +347,7 @@ async function getExtensionsConfigOutput(componentLeft: Component, componentRigh

// const mutualIds = R.intersection(rightExtensionsIds, rightExtensionsIds);
// const onlyOnOneIds = R.symmetricDifference(leftExtensionsIds, rightExtensionsIds);
const allIds = R.union(leftExtensionsIds, rightExtensionsIds);
const allIds = union(leftExtensionsIds, rightExtensionsIds);

const allIdsOutput = await Promise.all(
allIds.map((extId) => {
Expand Down
27 changes: 18 additions & 9 deletions components/legacy/component-list/components-list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pFilter from 'p-filter';
import { ComponentID, ComponentIdList } from '@teambit/component-id';
import R from 'ramda';
import { uniqBy } from 'lodash';
import { LATEST } from '@teambit/legacy.constants';
import { ModelComponent, Lane } from '@teambit/objects';
import { Scope } from '@teambit/legacy.scope';
Expand Down Expand Up @@ -392,10 +392,13 @@ export class ComponentsList {
static sortComponentsByName<T>(components: T): T {
const getName = (component) => {
let name;
if (R.is(ModelComponent, component)) name = component.id();
else if (R.is(Component, component)) name = component.componentId.toString();
else if (R.is(ComponentID, component)) name = component.toString();
else name = component;
if (component instanceof ModelComponent) {
name = component.id();
} else if (component instanceof Component) {
name = component.componentId.toString();
} else if (component instanceof ComponentID) {
name = component.toString();
} else name = component;
if (typeof name !== 'string')
throw new Error(`sortComponentsByName expects name to be a string, got: ${name}, type: ${typeof name}`);
return name.toUpperCase(); // ignore upper and lowercase
Expand All @@ -418,9 +421,15 @@ export class ComponentsList {

static filterComponentsByWildcard<T>(components: T, idsWithWildcard: string[] | string): T {
const getBitId = (component): ComponentID => {
if (R.is(ModelComponent, component)) return component.toComponentId();
if (R.is(Component, component)) return component.componentId;
if (R.is(ComponentID, component)) return component;
if (component instanceof ModelComponent) {
return component.toComponentId();
}
if (component instanceof Component) {
return component.componentId;
}
if (component instanceof ComponentID) {
return component;
}
throw new TypeError(`filterComponentsByWildcard got component with the wrong type: ${typeof component}`);
};
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
Expand All @@ -431,6 +440,6 @@ export class ComponentsList {
}

static getUniqueComponents(components: Component[]): Component[] {
return R.uniqBy((component) => JSON.stringify(component.componentId), components);
return uniqBy(components, (component) => JSON.stringify(component.componentId));
}
}
6 changes: 3 additions & 3 deletions components/legacy/consumer-component/consumer-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ComponentID, ComponentIdList } from '@teambit/component-id';
import fs from 'fs-extra';
import { v4 } from 'uuid';
import * as path from 'path';
import R from 'ramda';
import { flatten } from 'lodash';
import { IssuesList } from '@teambit/component-issues';
import { BitId } from '@teambit/legacy-bit-id';
import { BitError } from '@teambit/bit-error';
Expand Down Expand Up @@ -338,7 +338,7 @@ export class Component {
}

getAllDependenciesIds(): ComponentIdList {
const allDependencies = R.flatten(Object.values(this.depsIdsGroupedByType));
const allDependencies = flatten(Object.values(this.depsIdsGroupedByType));
return ComponentIdList.fromArray(allDependencies);
}

Expand Down Expand Up @@ -539,7 +539,7 @@ export class Component {
const packageJsonChangedProps = componentFromModel ? componentFromModel.packageJsonChangedProps : undefined;
const docsP = _getDocsForFiles(files, consumer.componentFsCache);
const docs = await Promise.all(docsP);
const flattenedDocs = docs ? R.flatten(docs) : [];
const flattenedDocs = docs ? flatten(docs) : [];
// probably componentConfig.defaultScope is not needed. try to remove it.
// once we changed BitId to ComponentId, the defaultScope is always part of the id.
const defaultScope = id.hasScope() ? componentConfig.defaultScope : id.scope;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { ComponentID } from '@teambit/component-id';
import R from 'ramda';
import { cloneDeep } from 'lodash';
import { Dependencies } from './';

const dependenciesFixture = [
Expand Down Expand Up @@ -29,8 +29,10 @@ describe('Dependencies', () => {
let dependencies;
let validateFunc;
beforeEach(() => {
const dependenciesFixtureCloned = R.clone(dependenciesFixture);
const dependenciesFixtureCloned = cloneDeep(dependenciesFixture);
// @ts-expect-error we want to change the type here explicitly
dependenciesFixtureCloned.forEach((d) => (d.id = ComponentID.fromString(d.id)));
// @ts-expect-error that's good enough for testing
dependencies = new Dependencies(dependenciesFixtureCloned);
validateFunc = () => dependencies.validate();
});
Expand Down
Loading