Skip to content

Removing lodash from CITGM dependencies - #1240

Open
pacostas wants to merge 10 commits into
nodejs:mainfrom
pacostas:removing-lodash
Open

pacostas wants to merge 10 commits into
nodejs:mainfrom
pacostas:removing-lodash

Conversation

@pacostas

Copy link
Copy Markdown
Contributor

Summary

The majority of lodash functions, can be replaced from the Node.js native ones. Here is a reference which helped me with the lodash replacement process, and it can also help with the review process https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore

On this PR, we remove lodash from the dependencies of the CITGM, this means:

  • Less Mbs to download while installing citgm ~1.4mb
  • One less dependency to update on package.json, each time there is a new lodash version release

Lodash is a good candidate to be removed from the citgm dependencies as:

  • Is already included on the lookup.json file, so there is no need for testing it implicitly (by using it on citgm)
  • The replacement of the lodash functions, with the Node.js native ones, is almost a 1-1 replacement, which makes it very easy to review and safe to replace e.g. const modulesTap = _.map(modules, generateTest).join('\n'); --- converts - to ---> modules.map(generateTest).join('\n');

Its commit, has the class of the functions that it replaces e.g one commit replaces the _.fliter with the array.filter, the other the _.map with the array.map etc.

In addition, I'll add below comments, on each change that is not so obvious.

Last but not least, all the tests pass, without needing any adjustment, this is expected.

Checklist
  • npm test passes
  • contribution guidelines followed
    here

Comment thread lib/reporter/util.js
/* eslint-enable no-control-regex */
// $1 matches the valid-range char if captured, or '' otherwise
// So this removes all invalid UTF-8
return _(output.replace(validUtf8, '$1').split(/[\r\n]+/))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we just remove the lodash wrapper. This was never necessary for the code to work.

@codecov-commenter

codecov-commenter commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.08%. Comparing base (7005bf1) to head (a3610f6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1240      +/-   ##
==========================================
- Coverage   96.09%   96.08%   -0.02%     
==========================================
  Files          29       29              
  Lines        2201     2195       -6     
==========================================
- Hits         2115     2109       -6     
  Misses         86       86              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread lib/check-tags.js
if (!mod.tags) mod.tags = [];
mod.tags.push(name);

let excludeTagMatches = _.intersection(options.excludeTags, mod.tags);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lodash code uses the intersection. In our case, due to we have only two sets, with a filder and include, we can easily find the common parts

Comment thread lib/create-options.js
}

if (context.module && context.module.envVar) {
_.forEach(context.module.envVar, (val, key) => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could also be a for loop. Nothing tricky, we just iterate over the values of the object, and we assigned them to the options.env object.

Comment thread lib/match-conditions.js
}

isObjectMatch(obj) {
return _.some(obj, (value, key) => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is no check if it is actually an object or not from the .some function, first we set a default value {} which will return false in that case. Its the same as if we had an if statement before the .some, which would check whether is an object or not and continue or return a false value accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants