typhonjs-node-escomplex / typhonjs-escomplex

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

Question: Why is dependencies an empty array? #10

Closed akshat1 closed 6 years ago

akshat1 commented 6 years ago

The output of escomplex.analyzeModule(source) does not contain dependencies (or rather, the value of dependencies is an empty array). Do I need to supply some configuration value, or a dependency resolver?

typhonrt commented 6 years ago

Can you provide a snippet of code? I gander you are not using ES6 imports?

akshat1 commented 6 years ago

Hey, thanks for responding. You are right, :) I've been playing with typhonjs-escomplex and analyzing https://github.com/es-analysis/plato, which uses require instead of ES6 imports. Do I need to configure something for that, or is that just not supported?

typhonrt commented 6 years ago

Apologies for there not being full documentation available presently.

By default CommonJS / require isn't processed, but you can set commonjs: true in options:

escomplex.analyzeModule(source, { commonjs: true }). You can also set a function for dependencyResolver which takes a string and returns a value.

You can refer to this section of the source code for how CallExpression AST nodes (functions like require) are handled in PluginSyntaxESTree.

akshat1 commented 6 years ago

Please, no apologies required :) Thanks for clarifying the configuration. Is it OK if I mark this question closed now?

sgb-io commented 5 years ago

It would be great to have the full list of options documented (or linked to) in this project, if someone can find time. Thanks both!

typhonrt commented 5 years ago

Indeed. I will definitely try and get the documentation up to par in a pending "0.2.0" update in the coming weeks then I'll patch things into the major downstream consumers (plato mainly). I plan to be back to full time OSS work at the end of January, so it might be until the end of the month.