Api.use vs api.imply?

In package.js , whether to use api.use or api.imply or both?
What are the advantages or disadvantages?

Say we are using some other package in our package. Isn’t it always better to api.imply and make that package available for entire project?

Thank you

That depends. api.use makes a dependency available to the package, while api.imply makes a dependency available to packages which depend on the the package that implies the dependency.

So when to use what? I always create a base package which all other packages depend on. It implies a router, collection2, collection-helpers and all other packages which are used in more than one of my packages. If a dependency is just used in one package, api.use it in that package.

IIRC, api.imply doesn’t auto-include or register a dependancy on the specified package.

It only makes it’s exports available to packages which depend on it.

So both should be used if the package is required and if you want other packages (which depend on your package) to see it’s exports.

you can read this article.