typhonjs-node-escomplex / typhonjs-escomplex

Next generation complexity reporting for Javascript & Typescript based on the Babel parser.
Other
110 stars 9 forks source link

adjacencyList not containing all adjacencies #12

Open llamadeus opened 5 years ago

llamadeus commented 5 years ago

The adjacencyList key does not contain all adjacencies for projects which use webpack aliases to resolve files from another path.

Given the following webpack config:

resolve: {
    extensions: ['*', '.js', '.jsx'],
    alias: {
        app: 'src/js;,
    },
},

And the following file src/js/app.js:

import 'app/bootstrap';

The adjacency will not be discovered. However, the dependency is listed correctly.

typhonrt commented 5 years ago

I'm away this week, so can give you an abbreviated answer. typhonjs-escomplex has no idea about dependency resolvers. Look an ImportDeclaration(settings) in this file and see that you can provide a dependencyResolver function to modify things here. This needs to have examples in the forthcoming documentation.

llamadeus commented 5 years ago

Thanks for your explanation. I understand that it's not really possible to resolve aliases, because they depend on the webpack config. Also, there can be multiple different webpack configs, having different aliases (which wouldn't make too much sense).

The only two options I see here would be a heuristic approach, which assumes, aliases should resolve to a file in the project folder, and therefore tries to figure out the alias itself. The second approach would need the webpack config itself to extract the alias key. Both not 100% satisfying as they have their pros and cons.

I'm willing to invest some time to write a plugin which helps resolving dependencies, but I'd like to discuss first, which approach is the more promising.