Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to show unnecessary module imports #55

Open
jmcdo29 opened this issue Mar 13, 2024 · 0 comments
Open

Provide a way to show unnecessary module imports #55

jmcdo29 opened this issue Mar 13, 2024 · 0 comments

Comments

@jmcdo29
Copy link
Owner

jmcdo29 commented Mar 13, 2024

This request came from the NestJS Discord server

TLDR: Is there a tool to list Modules that were imported within a Module, but there is not a single Provider using any of the Exported Providers from that Module?

Over the years working on a project written in NestJS, I've refactored many of the providers, split some providers into smaller ones, extracted them to own modules, etc.

My IDE tells me when I have an unused variable/property and sometimes I clean them up, when I'm in the file. Rarely I remember to try and remove the module from the imports of the module though.

I.e. I've just noticed I no-longer use AccountsService in my CartsService. I removed accountsService from my constructor. The CartsService was the only place within CartsModule which depended on AccountsService, so I have safely removed AccountsModule from my imports.
As a side-effect, next time I eventually need to work with CartsModule from within AccountsModule, I possibly can, without introducing a cyclic import.

I'd like to check that there are no modules that have leftover imports which are not required. I'd guess there's no huge memory or performance impact of having them, but I'd feel better knowing I don't have them.

A simple CLI tool I'd run manually every now and then would suffice, I don't need to monitor that or have an online tool set up for that. But again, maybe such feature exists in NestJS Devtools?

Thanks in advance


While not thinking about a CLI, this could be implemented into the DebugModule (probably) as it will have everything already loaded into their maps and introspection can then be done. It'll also help out with #45 as we'll need to see what is and isn't used

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

No branches or pull requests

1 participant