powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

Maintenance: Replace `lodash.merge` with a custom deep merge utility function

Open sdangol opened this issue 2 weeks ago • 6 comments

Summary

We're using a third party dependency, lodash.merge on our Logger utility. We would want to replace the dependency on this library and implement our own deep merge utility function.

Why is this needed?

We would ideally want minimal dependency on other third party libraries

Which area does this relate to?

Logger

Solution

No response

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

sdangol avatar Dec 04 '25 00:12 sdangol

Good idea, this will also remove the last CJS only dependency from Logger, as well as the last 3P one.

dreamorosi avatar Dec 04 '25 00:12 dreamorosi

[!note] For those interested in contributing, please leave a comment below so that we can assign the issue to you and make sure we don't duplicate efforts. If you have any further questions, please don't hesitate to ask below or on our Discord server.

happy to help with this, any clue on implementation details?

jaimellamasi avatar Dec 04 '25 09:12 jaimellamasi

Sure @jaimellamasi, thanks for the offer. I'll assign it to you.

Regarding the implementation details, I'd assume, for primitives, merging would just be an override from the source to the destination. For arrays/objects, we'd need to merge them recursively preventing circular reference. Our common utilities functions reside in the commons package, which we then use to replace the current lodash.merge implementations on the Logger utility.

sdangol avatar Dec 04 '25 10:12 sdangol

Let's make sure we add defences against prototype pollution in this function. In addition to the checks listed here, we should explicitly check for __proto__ and constructor keys and ignore them.

svozza avatar Dec 04 '25 20:12 svozza

IMO, you're better off implementing with something modern like https://remedajs.com/docs/#mergeDeep

rcaughtlaf avatar Dec 05 '25 06:12 rcaughtlaf

Hi @jaimellamasi, are you still working on this PR? If not, that's perfectly fine - we'll put the issue back in the backlog for someone else to pick up.

dreamorosi avatar Dec 16 '25 17:12 dreamorosi

I am planning to do it in the next days if that is fine for you.

On Tue, Dec 16, 2025, 18:07 Andrea Amorosi @.***> wrote:

dreamorosi left a comment (aws-powertools/powertools-lambda-typescript#4846) https://github.com/aws-powertools/powertools-lambda-typescript/issues/4846#issuecomment-3661550693

Hi @jaimellamasi https://github.com/jaimellamasi, are you still working on this PR? If not, that's perfectly fine - we'll put the issue back in the backlog for someone else to pick up.

— Reply to this email directly, view it on GitHub https://github.com/aws-powertools/powertools-lambda-typescript/issues/4846#issuecomment-3661550693, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUQ3DJUTAQJ2EHH5QK3JI34CA36HAVCNFSM6AAAAACN7HX7UGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTMNRRGU2TANRZGM . You are receiving this because you were mentioned.Message ID: @.*** .com>

jaimellamasi avatar Dec 16 '25 20:12 jaimellamasi

Yes, that's perfectly fine - I just wanted to make sure to follow up, but the timeline is ok.

Let us know if you encounter any problems or have any questions when you start.

dreamorosi avatar Dec 17 '25 09:12 dreamorosi

As @dreamorosi said, lodash.merge is a CJS only dependency and this is also a nuisance (e.g. we must install the @rollup/plugin-commonjs Rollup plugin is some projects simply for the Powertools Logger).

It would be great news if lodash.merge is gone!

albertodiazdorado avatar Dec 18 '25 09:12 albertodiazdorado