How to get a list of component file paths from an Angular ngModule file?

1.1k views Asked by At

I'm trying to look for automation solutions for refactoring an Angular app as it is really tedious to manually refactor.

As we try to lighten our app's shared module by treeshaking components/directives into their own module, there is a need to go through every feature module in the app and check if a directive or component selector exist in the template. If it does, the module the template is in must import the new directive's/component's module that was treeshaken from the shared module. Are there any refactor tools that can help with this? It feels like a very common task.


Alternatively if no general solution exist, I'd still like to find a way to programmatically at least list all absolute paths of components in any given .module.ts file's declarations array.

The resolution issues I'm facing now are,

  • The components file names can be different from the Class
  • They are sometimes in deeply nested in multiple barrels references
  • TsConfig paths is also customizing imports of the project.
1

There are 1 answers

0
nickbullock On

This is a really good question, but I'm sure that at the moment there is no ready-to-go tool that can solve your problem.

What I can suggest: