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

feat: replace lodash with ramda #1242

Merged
merged 8 commits into from
Sep 13, 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
8 changes: 8 additions & 0 deletions .changeset/rare-tips-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@fuel-ts/abi-typegen": patch
"@fuel-ts/hasher": patch
"@fuel-ts/providers": patch
"@fuel-ts/utils": patch
---

Replace lodash with ramda for ESM support
10 changes: 4 additions & 6 deletions packages/abi-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@
"commander": "^9.4.1",
"glob": "^10.2.6",
"handlebars": "^4.7.7",
"lodash.uniq": "^4.5.0",
"lodash.upperfirst": "^4.3.1",
"mkdirp": "^1.0.4",
"ramda": "^0.29.0",
"rimraf": "^3.0.2"
},
"devDependencies": {
"@types/lodash.uniq": "^4.5.7",
"@types/lodash.upperfirst": "^4.3.7",
"@fuel-ts/forc": "workspace:*",
"@types/mkdirp": "^1.0.2",
"@types/rimraf": "^3.0.2",
"@fuel-ts/forc": "workspace:*"
"@types/ramda": "^0.29.3",
"@types/rimraf": "^3.0.2"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import uniq from 'lodash.uniq';
import { uniq } from 'ramda';

import type { IType } from '../../types/interfaces/IType';

Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/utils/validateBinFile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import upperFirst from 'lodash.upperfirst';

import { ProgramTypeEnum } from '../types/enums/ProgramTypeEnum';

const upperFirst = (s: string): string => s[0].toUpperCase() + s.slice(1);

export function validateBinFile(params: {
abiFilepath: string;
binFilepath: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/hasher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"@fuel-ts/math": "workspace:*",
"@fuel-ts/providers": "workspace:*",
"@fuel-ts/transactions": "workspace:*",
"lodash.clonedeep": "^4.5.0"
"ramda": "^0.29.0"
},
"devDependencies": {
"@fuel-ts/testcases": "workspace:*",
"@types/lodash.clonedeep": "^4.5.7"
"@types/ramda": "^0.29.3"
}
}
6 changes: 3 additions & 3 deletions packages/hasher/src/hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { TransactionRequestLike } from '@fuel-ts/providers';
import { transactionRequestify, TransactionType } from '@fuel-ts/providers';
import type { UtxoId } from '@fuel-ts/transactions';
import { OutputType, InputType, TransactionCoder } from '@fuel-ts/transactions';
import cloneDeep from 'lodash.clonedeep';
import { clone } from 'ramda';

/**
* hash string messages with sha256
Expand Down Expand Up @@ -48,7 +48,7 @@ export function hashTransaction(transactionRequestLike: TransactionRequestLike,

// Zero out input fields
transaction.inputs = transaction.inputs.map((input) => {
const inputClone = cloneDeep(input);
const inputClone = clone(input);

switch (inputClone.type) {
// Zero out on signing: txPointer, predicateGasUsed
Expand Down Expand Up @@ -85,7 +85,7 @@ export function hashTransaction(transactionRequestLike: TransactionRequestLike,
});
// Zero out output fields
transaction.outputs = transaction.outputs.map((output) => {
const outputClone = cloneDeep(output);
const outputClone = clone(output);

switch (outputClone.type) {
// Zero out on signing: balanceRoot, stateRoot
Expand Down
8 changes: 4 additions & 4 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@
"@ethersproject/sha2": "^5.7.0",
"@fuel-ts/abi-coder": "workspace:*",
"@fuel-ts/address": "workspace:*",
"@fuel-ts/interfaces": "workspace:*",
"@fuel-ts/crypto": "workspace:*",
"@fuel-ts/errors": "workspace:*",
"@fuel-ts/interfaces": "workspace:*",
"@fuel-ts/math": "workspace:*",
"@fuel-ts/transactions": "workspace:*",
"@fuel-ts/errors": "workspace:*",
"graphql": "^16.6.0",
"graphql-request": "^5.0.0",
"graphql-tag": "^2.12.6",
"lodash.clonedeep": "^4.5.0"
"ramda": "^0.29.0"
},
"devDependencies": {
"@fuel-ts/utils": "workspace:*",
"@graphql-codegen/cli": "^2.13.7",
"@graphql-codegen/typescript": "^2.8.0",
"@graphql-codegen/typescript-graphql-request": "^4.5.7",
"@graphql-codegen/typescript-operations": "^2.5.5",
"@types/lodash.clonedeep": "^4.5.7",
"@types/ramda": "^0.29.3",
"get-graphql-schema": "^2.1.2",
"typescript": "^4.8.4"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/providers/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
TransactionCoder,
} from '@fuel-ts/transactions';
import { GraphQLClient } from 'graphql-request';
import cloneDeep from 'lodash.clonedeep';
import { clone } from 'ramda';

import { getSdk as getOperationsSdk } from './__generated__/operations';
import type {
Expand Down Expand Up @@ -526,7 +526,7 @@ export default class Provider {
transactionRequestLike: TransactionRequestLike,
tolerance: number = 0.2
): Promise<TransactionCost> {
const transactionRequest = transactionRequestify(cloneDeep(transactionRequestLike));
const transactionRequest = transactionRequestify(clone(transactionRequestLike));
const { minGasPrice, gasPerByte, gasPriceFactor, maxGasPerTx } = await this.getNodeInfo();
const gasPrice = max(transactionRequest.gasPrice, minGasPrice);
const margin = 1 + tolerance;
Expand Down
4 changes: 2 additions & 2 deletions packages/providers/src/utils/json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-param-reassign */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { hexlify } from '@ethersproject/bytes';
import cloneDeep from 'lodash.clonedeep';
import { clone } from 'ramda';

// When parsing a Transaction to JSON we need
// to convert special types into each respective
Expand Down Expand Up @@ -42,5 +42,5 @@ export function normalizeJSON(root: any) {
// Do a single deep clone before normalizing
// to avoid mutating the original object
// and doing extra clones on each iteration
return normalize(cloneDeep(root));
return normalize(clone(root));
}
5 changes: 2 additions & 3 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@
},
"license": "Apache-2.0",
"dependencies": {
"lodash.upperfirst": "^4.3.1",
"ramda": "^0.29.0",
"rimraf": "^3.0.2"
},
"devDependencies": {
"@ethersproject/bytes": "^5.7.0",
"@types/lodash.upperfirst": "^4.3.7"
"@ethersproject/bytes": "^5.7.0"
}
}
4 changes: 1 addition & 3 deletions packages/utils/src/utils/normalizeString.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import upperFirst from 'lodash.upperfirst';

/**
* Converts `some.string-value` into `SomeStringValue`.
*
Expand All @@ -16,7 +14,7 @@ export const normalizeString = (str: string): string => {
(s) => s.replace(/-[a-z]/g, (match) => match.slice(-1).toUpperCase()), // delete '-' and capitalize the letter after them
(s) => s.replace(/-/g, ''), // delete any '-' left
(s) => s.replace(/^\d+/, ''), // removes leading digits
(s) => upperFirst(s),
(s) => s[0].toUpperCase() + s.slice(1), // capitalize first letter
];

const output = transformations.reduce((s, t) => t(s), str);
Expand Down
101 changes: 41 additions & 60 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading