Welldone Software
Published in

Welldone Software

Clever Library Wrapping

A Small Tip That Will Save You a Lot of Time, Bugs, and Rage.

Let’s say you work on a huge project with many people and it is important to you that a library will be called from a wrapper you created around it or at least they know about the existence of such a wrapper.

For example, let’s take a logging library like winston.

After it’s initialization:

Any developer can just import it and use it as they wish:

But what if you have a fancy wrapper around it that reports errors to a remote server, and formats and standardizes the logs?

You wouldn’t want developers to use it directly but to use your module instead. And they will use it directly. In some point, they will. Trust me.

A similar issue can arise if you add a library that provides you with some kind of component. After styling and wrapping it, developers can technically still import both the styled component and the raw one.

This scenario is actually pretty common because when developers will look in “package.json” they will only see the raw library.

This means you are in danger of someone styling and wrapping a library again instead of using a ready wrapper.

In short, my answer is to use no-restricted-imports linter rule or an equivalent rule in other linters to notify the user that the library is restricted:

Being restricted by the linter will lead the user to look at the linter configuration where an explanation about the restriction will be given:

To still use these imports a linter suppression comment should be added:

Happy programming and let me know if you have other solutions or tips regarding this issue.




The leading full-stack software solutions company. Creating amazing frontends and rock-solid backends using top-notch technologies and practices. Visit us at https://welldone.software/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vitali Zaidman

Vitali Zaidman

https://twitter.com/vzaidman ⎝(•ω•)⎠ https://vzaidman.com

More from Medium

What is the NestJS Runtime

Integrate geocoding the right way

Managing source code with a monorepo

Isolate the architecture from the framework using a monorepo tool like Nx