skott
skott copied to clipboard
View unused modules in a monorepo for dead code elimination
I would like to see unused modules so that I can easily remove dead code from the codebase.
Note: Since the module can be used in NOT production code like tests, storybook and other tooling files, there should be an option to skip them
Hey @ild0tt0re,
Thanks for submitting that feature request.
It is indeed the next feature planned before v1 is released, I'll probably open an issue where we can track the different milestones of that big feature.
Few milestones that I can see without even thinking about it are:
- provide a new API to list all unused modules, with a possibility of filtering the glob pattern (since you were talking about targeting specific sets of tests)
- provide a new API that automatically prunes unused modules using the first API (like 'ts-prune', but for all kind of files, not only typescript ones
Do you have any other ideas that could be valuable for Skott?
Hi, any update on this feature request ? We would be very interested by this feature using it on an angular monolithic codebase in order to split our applications and keep them separated
Hello @dufrenb, there is unfortunately no new update regarding the elimination of local dead code.
However, I have been discussing with the author of knip which is an awesome library, and I will probably end up opening discussions regarding the need of exposing a knip API allowing tools like skott to integrate with it.
For your information, in the future, skott aims to provide dead code elimination for third-party + local modules by analyzing the graph. But if you want to start removing dead code of your own code as of today, I would recommend you to start using knip. Combining it with skott (that checks unused third-party modules) could be a great combination in order to remove most of the dead code (local+third-party) while being able to take full control over your project graph :)
@dufrenb
Just to be 100% sure, when talking about "unused modules" in a monorepo, do you have in mind "unused files" or "unused identifiers (import/export)"? As the time flies by, I don't remember what I initially had in mind, sorry about that.
Identifying "unused files" could be pretty straightforward to implement actually, I could do that in one day.
But knowing if an import/export from a module is being actually used is another game.
So please, could you help me clarify what are your expectations?
Hello @dufrenb and @ild0tt0re,
I just published a new 0.35.0 skott version including a new --showUnusedFiles
CLI option to list unused files (can only be used when not providing any entrypoint). The feature is also available through the API.
Let me know how it goes!