Remove lodash from bitcore-lib#4149
Open
MichaelAJay wants to merge 115 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request removes the lodash runtime dependency from packages/bitcore-lib by replacing lodash helpers with equivalent native JavaScript implementations across the library and its test suite.
Changes:
- Replaced lodash type checks, collection helpers, cloning, and object extension with native JS (
typeof,Array.isArray,map/filter/reduce,Object.assign, etc.). - Updated transaction sorting/shuffling and various loops to avoid
.forEachand lodash utilities. - Removed
lodashfrombitcore-libdependencies and stopped exporting it viabitcore.deps._.
Reviewed changes
Copilot reviewed 45 out of 46 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/bitcore-lib/test/transaction/unspentoutput.js | Drops lodash usage in tests; uses structuredClone for deep copy. |
| packages/bitcore-lib/test/transaction/transaction.js | Replaces lodash shuffle stubbing with Math.random stubbing; minor test cleanups. |
| packages/bitcore-lib/test/transaction/signature.js | Removes unused lodash/chai should imports from test file. |
| packages/bitcore-lib/test/transaction/output.js | Removes unused imports (expect/lodash/errors) after cleanup. |
| packages/bitcore-lib/test/transaction/input/publickeyhash.js | Removes lodash/chai imports (relies on existing test environment setup). |
| packages/bitcore-lib/test/transaction/input/multisigscripthash.js | Replaces lodash-based assertions with native array mapping + chai members checks. |
| packages/bitcore-lib/test/transaction/input/multisig.js | Replaces lodash checks with native array mapping + chai members checks. |
| packages/bitcore-lib/test/transaction/input/input.js | Replaces lodash iteration with for...of; adds lint suppressions for bitwise ops. |
| packages/bitcore-lib/test/script/interpreter.js | Removes lodash and replaces array checks/iteration with native constructs. |
| packages/bitcore-lib/test/opcode.js | Replaces _.size with Object.keys(...).length. |
| packages/bitcore-lib/test/hdpublickey.js | Removes lodash/assert usage; modernizes to const + chai deep equality. |
| packages/bitcore-lib/test/hdprivatekey.js | Removes lodash/assert usage; replaces lodash iteration with for...of. |
| packages/bitcore-lib/test/hdkeys.js | Replaces _.each with for...of; removes unused imports. |
| packages/bitcore-lib/test/crypto/signature.js | Replaces lodash iteration with loops; updates fixture runner implementation. |
| packages/bitcore-lib/package.json | Removes lodash dependency; pins elliptic to an exact version. |
| packages/bitcore-lib/package-lock.json | Updates lockfile to reflect dependency removal and related resolution changes. |
| packages/bitcore-lib/lib/util/preconditions.js | Replaces lodash string checks with typeof. |
| packages/bitcore-lib/lib/util/js.js | Replaces lodash checks and forEach with native checks/loops; simplifies try/catch. |
| packages/bitcore-lib/lib/uri.js | Removes lodash; switches to Object.assign and native loops; replaces URL variable usage. |
| packages/bitcore-lib/lib/unit.js | Removes lodash; replaces object checks and iteration with native constructs. |
| packages/bitcore-lib/lib/transaction/unspentoutput.js | Removes lodash; replaces undefined/number/object checks with native equivalents. |
| packages/bitcore-lib/lib/transaction/transaction.js | Removes lodash; replaces sum/difference/without/shuffle with native implementations. |
| packages/bitcore-lib/lib/transaction/output.js | Removes lodash type checks; adds bitwise lint suppression and minor cleanup. |
| packages/bitcore-lib/lib/transaction/input/multisigscripthash.js | Replaces _.sortBy with explicit array copy + comparator sort. |
| packages/bitcore-lib/lib/transaction/input/multisig.js | Replaces lodash collection helpers with native map/filter/reduce/sort and loops. |
| packages/bitcore-lib/lib/transaction/input/input.js | Removes lodash; replaces type checks; adds bitwise lint suppressions. |
| packages/bitcore-lib/lib/script/script.js | Removes lodash; replaces object checks and sorting with native equivalents. |
| packages/bitcore-lib/lib/script/interpreter.js | Removes lodash; replaces undefined checks with nullish checks; adds JSUtil usage. |
| packages/bitcore-lib/lib/publickey.js | Removes lodash; replaces isUndefined patterns with explicit === undefined checks. |
| packages/bitcore-lib/lib/privatekey.js | Removes lodash; replaces null/undefined and string/object checks with native checks. |
| packages/bitcore-lib/lib/opcode.js | Removes lodash; replaces type checks and _.extend with Object.assign. |
| packages/bitcore-lib/lib/message.js | Removes lodash; replaces string checks with typeof. |
| packages/bitcore-lib/lib/hdpublickey.js | Removes lodash; replaces collection/type helpers with native equivalents. |
| packages/bitcore-lib/lib/hdprivatekey.js | Removes lodash; replaces includes/some/every/type checks with native equivalents. |
| packages/bitcore-lib/lib/errors/index.js | Removes lodash; replaces _.each and type checks with native equivalents. |
| packages/bitcore-lib/lib/encoding/bufferreader.js | Removes lodash; replaces undefined/string/object checks with native equivalents. |
| packages/bitcore-lib/lib/encoding/base58check.js | Removes lodash; replaces string checks with typeof. |
| packages/bitcore-lib/lib/encoding/base58.js | Removes lodash; rewrites validCharacters with native checks/iteration. |
| packages/bitcore-lib/lib/crypto/signature.js | Removes lodash; introduces helper for DER sign-bit checks; adjusts strict defaulting. |
| packages/bitcore-lib/lib/crypto/point.js | Removes unused catch variable; minor import order tweak. |
| packages/bitcore-lib/lib/crypto/bn.js | Removes lodash; replaces type checks; adds bitwise lint suppressions. |
| packages/bitcore-lib/lib/block/merkleblock.js | Removes lodash; replaces extend/array checks/undefined checks with native equivalents. |
| packages/bitcore-lib/lib/block/blockheader.js | Removes lodash; replaces type checks; replaces noop setter. |
| packages/bitcore-lib/lib/block/block.js | Removes lodash; replaces extend and array building with native equivalents. |
| packages/bitcore-lib/lib/address.js | Removes lodash; replaces array/object/number checks and mapping with native equivalents. |
| packages/bitcore-lib/index.js | Stops exporting lodash via bitcore.deps._. |
Files not reviewed (1)
- packages/bitcore-lib/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
packages/bitcore-lib/test/crypto/signature.js:262
- Inside the
forloop, non-hex fixture vectors should be skipped, butreturn;exitstest_sigsearly and prevents generating the rest of the fixture tests. This changes the semantics compared to the priorforEachcallback (wherereturnonly skipped the current element).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+508
to
510
| // eslint-disable-next-line @typescript-eslint/no-unused-expressions | ||
| Interpreter.SCRIPT_VERIFY_CLEANSTACK = (1 << 8), | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Remove lodash from bitcore-lib. Also some general cleanup, and especially 'forEach' fixing.
Changelog
Testing Notes
Checklist