Skip to content

Conversation

@jdalrymple
Copy link
Contributor

@jdalrymple jdalrymple commented Jan 30, 2026

What: Remove dependency on lodash

Why: In the attempt to move to esm, lodash is a blocker. There are alternatives such as lodash-esm, but alot of the use cases (except for template) are supported by native js. Additional benefit is the reduction in pkg size since lodash is massive!

How: Migrate all lodash usages to native logic, and migrate template to use eta

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

Related #412

@jdalrymple jdalrymple marked this pull request as ready for review January 30, 2026 04:55
@JoshuaKGoldberg
Copy link
Contributor

I'm generally in favor of moving off of Lodash - or at least the parts of it that are now built into JS. But:

In the attempt to move to esm, lodash is a blocker

Why does Lodash block ESM? As of Node.js v20.19.0+, require(esm) is a thing - so we should be fine to use it regardless of CJS/ESM?

@jdalrymple
Copy link
Contributor Author

I'm generally in favor of moving off of Lodash - or at least the parts of it that are now built into JS. But:

In the attempt to move to esm, lodash is a blocker

Why does Lodash block ESM? As of Node.js v20.19.0+, require(esm) is a thing - so we should be fine to use it regardless of CJS/ESM?

New info to me! haha I had to brush back up on the spec. I think eslint/prettier fires off an error about it since its recommended that you do not use require in esm.

That being said, we probably shouldnt be mixing ways to load modules if possible.

Let me see if i can get the exact issue i saw and post it in the PR

@jdalrymple
Copy link
Contributor Author

@JoshuaKGoldberg It might have been this eslint error:

Cannot use import declarations in modules that export using CommonJS (module.exports = 'foo' or exports.bar = 'hi')

When i tried to perform the import _ from 'lodash/fp'. So yea, using require should be "ok". If thats something youd like to do, i can kill this pr?

@JoshuaKGoldberg
Copy link
Contributor

Cannot use import declarations ...

Weird, that doesn't look like an ESLint error. Where did you see it / how did you get that to happen? Can you paste the full error? (I don't reproduce locally)

kill this pr

Well, removing a large dependency is always nice 😄 I'm not against the PR if you want to keep it going! But I just don't think we need it for the yargs update or otherwise.

@jdalrymple
Copy link
Contributor Author

Weird, that doesn't look like an ESLint error. Where did you see it / how did you get that to happen? Can you paste the full error? (I don't reproduce locally)

How i create it is by setting the module type in the pkg json, and then switching the import to use "import" instead of require:

Screenshot 2026-01-31 at 11 42 12 AM

@lwasser
Copy link
Member

lwasser commented Jan 31, 2026

@jdalrymple, My apologies, I just broke your PR with merge conflicts when we merged my ESLINT config pr. 🙃
this will likely happen again in both directions 🤣

@jdalrymple
Copy link
Contributor Author

hahah no worries, ill sort out the conflicts over the next couple days

@jdalrymple
Copy link
Contributor Author

@JoshuaKGoldberg I was able to bump yargs without doing all the esm things in one ticket, see #431

@JoshuaKGoldberg
Copy link
Contributor

setting the module type in the pkg json

Aha there's an issue! I think you discovered this in the PR, but just to say it here: there shouldn't be a need to do that. The only entries that should need to be changed in the package.json are under dependencies/devDependencies/similar.

@jdalrymple
Copy link
Contributor Author

jdalrymple commented Feb 2, 2026

setting the module type in the pkg json

Aha there's an issue! I think you discovered this in the PR, but just to say it here: there shouldn't be a need to do that. The only entries that should need to be changed in the package.json are under dependencies/devDependencies/similar.

Not quite sure I follow. Are you saying that nothing* needs to be changed in the package.json to have the library be recognized as esm?

@JoshuaKGoldberg
Copy link
Contributor

Depends what you mean by "have the library be recognized as esm"?

  • If by "library" you mean lodash: correct, we can just change the version range as you did in chore: Update yargs to v18 #431
  • If by "library" you mean all-contributors/cli: we'd have to add "type": "module" in package.json, which is definitely out of scope for dropping a dependency like lodash

@jdalrymple
Copy link
Contributor Author

Anything missing in this that i should add/cover?

"async": "^3.1.0",
"chalk": "^5.6.2",
"didyoumean": "^1.2.1",
"eta": "^4.5.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

[Praise] TIL that eta is the recommended replacement for _.template. Cool! https://www.npmjs.com/package/lodash.template

Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

LGTM, what a great contribution - thanks for doing all this manual work! 🙌

Because this touches a lot of tricky stuff, I'd definitely want another review from a maintainer. I think it'd be good to double-check sure CI is working & tests are running well before merging. But no blockers that I can see.

@lwasser
Copy link
Member

lwasser commented Feb 9, 2026

thanks for the review @JoshuaKGoldberg !! @jdalrymple two questions - are you interested in becoming a part of our maintainer team here? you've been helping so so much!

second, I will review this in the next few days. i'll test things locally - and give it a closer review. My apologies for the delays!!

@lwasser
Copy link
Member

lwasser commented Feb 10, 2026

hey there @jdalrymple i'm curious - did you run an all-contributors add command locally? I just tried to run a simple command to add (init works fine)

all-contributors add lwasser code

i'm getting a TypeError

{
                             ^

TypeError: util.template is not a function
    at /Users/leahawasser/Documents/GitHub/allcontributors/cli/dist/util/git.js:57:30
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Node.js v22.22.0

but then when I try to fix that I get another error - circular reference. So i'm wondering if you see the same thing? Thank you!!

git: require('./git'),
markdown: require('./markdown'),
url: require('./url'),
template: require('./template'),
Copy link
Member

Choose a reason for hiding this comment

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

I ran into a problem here with template loading in time. So moving git to the end helped with that issue.

i'm a bit confused as there seems to be a circular import involved here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weirdddddd, ill give it a look and follow up 🫡

@jdalrymple jdalrymple marked this pull request as draft February 10, 2026 15:32
@jdalrymple
Copy link
Contributor Author

hey there @jdalrymple i'm curious - did you run an all-contributors add command locally? I just tried to run a simple command to add (init works fine)

all-contributors add lwasser code

i'm getting a TypeError

{
                             ^

TypeError: util.template is not a function
    at /Users/leahawasser/Documents/GitHub/allcontributors/cli/dist/util/git.js:57:30
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Node.js v22.22.0

but then when I try to fix that I get another error - circular reference. So i'm wondering if you see the same thing? Thank you!!

Ill check this one as well, and write a test so its not missed again 🫡

@jdalrymple
Copy link
Contributor Author

thanks for the review @JoshuaKGoldberg !! @jdalrymple two questions - are you interested in becoming a part of our maintainer team here? you've been helping so so much!

second, I will review this in the next few days. i'll test things locally - and give it a closer review. My apologies for the delays!!

No apology needed! Were all running on little time here 😂 I'm down! though time commitment might be hit and miss, I'm game to help regardless.

# Conflicts:
#	src/util/git.js

# Conflicts:
#	src/generate/index.js
#	src/init/init-content.js
@jdalrymple
Copy link
Contributor Author

Converted to a draft until i have time to check the above notes

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.

3 participants