Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shows all cyclic dependencies in project #2

Open
Venryx opened this issue Jun 30, 2017 · 2 comments
Open

Shows all cyclic dependencies in project #2

Venryx opened this issue Jun 30, 2017 · 2 comments

Comments

@Venryx
Copy link

Venryx commented Jun 30, 2017

Would be nice if this showed all the cyclic dependencies in the project instead of just the first one found.

@Venryx
Copy link
Author

Venryx commented Jun 30, 2017

A simple solution, which I'm currently using:

cli.js

const statsJson = require( filePath );

+global.statsJson = statsJson;

const dependencyGraph = cyclicUtils.getDependencyGraphFromStats(
    statsJson, options[ 'include-node-modules' ]
);

index.js

  } else if (recStack.indexOf(dependencyId.toString()) > -1) {
    recStack.push(dependencyId.toString());

+    console.log("Cycle found: " + recStack.map(id=> {
+      const mod = global.statsJson.modules.find(mod=>mod.id.toString() == id.toString());
+      if (mod) {
+        return '(' + id + ') ' + mod.name;
+      }
+    }).filter(m =>!!m).join(' -> '));

    return true;
   }
});

// Return the recursion stack (walk of ids through the graph) if a
// cycle detected

-if (found) {
-  return found;
-}

@Venryx
Copy link
Author

Venryx commented Jun 30, 2017

Hmm, the above does show more than cyclic dependency. However, it seems to be showing fewer (7) than the other plugin here (70): https://github.com/aackerman/circular-dependency-plugin

For now I'll probably just use the other plugin, but thought I would mention it. (not sure if it's a problem with the plugin itself, or just with my modifications to it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant