nicoespeon / sass-graph-viz

Draw a visual graph of Sass dependencies
https://medium.com/@nicoespeon/i-built-a-tool-to-work-with-complicated-sass-codebases-b5c909e269fb
MIT License
26 stars 2 forks source link

Using `parseFile` instead of `parseDir` for single file targets #11

Open nicoespeon opened 5 years ago

nicoespeon commented 5 years ago

[…]

So parseFile documented in their API. The reason I suggest it is because the graph can be smaller if your sass/scss/less/css in your directory would have created a bipartite graph, or more generalized multipartite.

parseDir globs the whole directory for files with matching extensions, so you can get two sets of graphs. By adding less and css support, if you have a directory with both less and sass, you can get both a less and sass graph. Now, this might not be something you are worried about since less is not this project's focus. But sass can be affected too. For example, if you have files which aren't imported. I know you said:

orphan partials which are not imported are suspicious, so they are red

But, that can still work if you pass in a directory. If a file is passed in, the user is saying they only care about dependencies linked to that specified file. So passing in a file can guarantee a 1-partite graph, if that's the correct terminology.

sassgraph's CLI only uses parseDir but that is fine because they are only outputting text. Since you are drawing a graph, this is a useful optimization to provide the user. If I get the time, maybe I can look into creating a PR.

Originally posted by @dosentmatter in https://github.com/nicoespeon/sass-graph-viz/issues/10#issuecomment-513335031

nicoespeon commented 5 years ago

I created a new issue from the comment, so I can keep track of it 😉

nicoespeon commented 5 years ago

If a file is passed in, the user is saying they only care about dependencies linked to that specified file.

Indeed, makes sense to me.

parseDir globs the whole directory for files with matching extensions, so you can get two sets of graphs.

Thanks for the detailed explanation. Now I clearly understand the benefit of using parseFile if given path is a single file.

I agree that could be a nice improvement, reducing noise and false positives.

If I get the time, maybe I can look into creating a PR.

That would be awesome. I'll take a stab at it at some point if you don't have time to do, but I'm currently working on another project.

Ideally, I'd love to have a showcase of the problem in the examples/ (with an associated command) so we can check the working behaviour—and essentially see the before/after effect, validating the use-case.