Code Monkey home page Code Monkey logo

dependo's Introduction

dependo

Visualize your CommonJS, AMD, or ES6 module dependencies in a force directed graph report - powered by D3.js.

NEW MAINTAINER WANTED: This project hasn't been maintained in while, so if you wanna help out, please let me know!

Introduction

Let me introduce dependo - A small visualization tool that draws an force directed graph of JavaScript dependencies pulled from a codebase of CommonJS, AMD, or ES6. Behind the scene Iโ€™m using a wonderful library named node-madge, to extract the dependencies and combined with the power of D3.js I draw a beautiful zoomable directed graph.

You can read the full introduction to the project in my blog post.

Features

  • Draw a graph of nodes, where each module is represented as a node.
  • Google Maps's like zooming, dragging and panning.
  • Connect nodes with it's dependencies via lines.
  • Hovering a node will highlight it's direct dependencies.
  • It's possible to drag a node to a specific position, to re-layout the graph.

Report example

The best way to show something is by example, so here I generated a graph of the official RequireJS multipage example:

Example

See the example here: http://auchenberg.github.com/dependo/example

Installation

To install as a library:

$ npm install dependo

To install the command-line tool:

$ sudo npm -g install dependo

Options

{
    'format': The module format to expect, 'cjs', 'amd', 'es6', or 'json'. AMD (amd) is the default format. If 'json', pass a file formatted like `example.json` in the `example/` directory.
    'optimized': Boolean, True if the parser should read modules from a optimized file (r.js). Defaults to false.
    'exclude': String from which a regex will be constructed for excluding files from the scan.
    'mainRequireModule': Name of the module if parsing an optimized file (r.js), where the main file used require() instead of define. Defaults to ''.
    'requireConfig': Path to RequireJS config used to find shim dependencies and path aliases. Not used by default.
    'reverse': Reverse dependency arrow directions.
    'title': The title of the generated HTML document.
    'extensions': Valid file extensions used to find files in directories e.g. .js,.ts Default: .js
}

API

  var Dependo = require('dependo');

  // Fire up an dependo instance
  var dependo = new Dependo(src, {
    format: 'amd',
    requireConfig: 'optional path to RequireJS config file',
    exclude: '^node_modules',
    transform: function(dep){
        //Apply a transformation on dependencies
        ....

        return dep;

    }
  });

  dependo.generateHtml();
  ...

CLI

Usage: dependo [options] <file|dir ...>

Options:

  -h, --help             output usage information
  -V, --version          output the version number
  -f, --format <name>    format to parse (amd/cjs/es6/json)
  -x, --exclude <regex>  a regular expression for excluding modules
  -t, --title <title>    the title of the generated document (dependo)
  -v, --reverse          reverse direction of arrows
  -e, --extensions       file extensions to use separated by comma

Generate HTML report of all module dependencies (AMD), and save it to /example/report.html

$ dependo -f amd /path/src > example/report.html

Grunt

I also wrote a grunt-task that can be found in this separate repository: https://github.com/auchenberg/grunt-dependo

Roadmap

dependo is still very much in progress, so here is the todo-list:

  • Proper label positioning: Avoid label collisions and make the graph more readable.
  • Testing! Unit tests of D3 render logic, and the grunt-task itself

Thanks to

This project wouldn't have been possible without the great work on node-madge by Patrik Henningson, or wonderful D3.js library.

Inspiration

http://bl.ocks.org/1153292

dependo's People

Contributors

amiram avatar auchenberg avatar jdfreder avatar malys avatar naugtur avatar philfreo avatar wayofthefuture avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dependo's Issues

[idea] tree view from top to bottom.

Would be interesting to have a tree view that shows dependencies from the chosen entry point as a tree from top to bottom, all arrows going downwards, and if a dependency imports th same module as already up higher in the tree then the graph just duplicates that dependency downward in the tree, and hovering on a dependency that is dupplicate (to see what imports it or what it imports) would highlight all instances of that node.

Topological sort of the dependency graph

A top sort (a tree-like layout) of the dependency graph would be helpful. This enhancement would help users understand how the modules are structured.

I say tree-like because,

  1. the modules with no dependencies will form the root(s).
  2. cycles may be formed as well.

Madge dependencies again

Hi! I have the same issue #15
Can you update madge dependencies again?
On my computer [email protected] not display dependency tree, and dependo not display connecctions between modules.
Latest release of Madge (3.0.0) working correctly.

version - an easier way

module.exports = JSON.parse(require('fs').readFileSync(__dirname + '/../package.json')).version;

Can also be done as:

module.exports = require('../package.json').version;

inject a module-deps json file produced by browserify to analyse

Hi,
I try to use dependo to analyse my dependency graph.
I think I have understand that --deps of browserify build a json in module-deps format.
Is it currently the json format expected by dependo ? (seems don't)
I prefer to plug dependo on json output instead of the real code, because of browserify transformers applied on my source (babelify for es6 and jsx).

Thanks for any help.

fix absolute paths windows

on windows, dependency graph shows full absolute paths... i.e. c:/a/b/c/d. which causes extreme clutter. would be much nicer if the path was relative to the node application root. thanks.

Specifying RequireJS config file on command line

How can I specify the RequireJS config file on the command line? I've seen this requireConfig option in the API, but it's not mentioned as a command line option. I attempted the following

dependo -f amd --requireConfig subdir/Config.js . >dependencies.html

in the directory under which all source exists, but that had no effect in limiting the dependencies to those rooted in the Config.js file.

-JM

Straight line option?

I like straight lines to connect nodes more than the curved ones. This would be a nice option.

Common js: certain dependencies not registering

Hey there,

I've got an app I'd like to see the dependency tree for. The 'entry point' file is named App.js and the top of App.js looks like:

var React = require('react');
var Router = require('react-router'); // or var Router = ReactRouter; in browsers
var Route = Router.Route;
var RouteHandler = Router.RouteHandler;
var Link = Router.Link;

var Dashboard = require('./Dashboard.js');
var SequenceEditor = require('./SequenceEditor.js');
var Skeleton = require('./Skeleton.js');
etc.

Unfortunately, none of the dependencies are showing up for app.
I've run:

dependo -f cjs ./app/App.js > report.html

With no success:
image

And:
dependo -f cjs ./app > report.html

with some success:
image

I can't tell if there is a pattern of which require() statements it is picking up on and which it isn't. It seems a bit random to me: certain require statements get picked up in some files, but don't in others. Any help debugging this would be greatly appreciated. Thanks so much!

baseUrl

Hi, I'm having trouble getting dependo to read my dependencies beyond the first file. I am passing in a require config file but I'm wondering primarily about the baseUrl. Should the path be relative to the config file, to the main application entry point or the current working directory? Or something else?

Any help appreciated, thanks :)

Add ability to specify a requireJS-style 'config' file, or explain how to specify it

I apologize if this is something you've already added and I just haven't figured out yet, but the reason I never used any of the graphviz-based tools was that our project is heavily dependent on custom paths mapped inside a require.config call. Can dependo use such a file to resolve file mappings, or does it do it automatically assuming you've got the correct "entry point" script? Or is this too specific to requireJS AMD implementations?

[idea] class hierarchies

class syntax is perhaps easy to analyze too, so it might be nice to also show a class inheritance graph. Possibly both can be shown at the same time with different color, or a toggle switch shows one while the other is greyed out, or similar.

npm publish

Could you publish a new version of dependo corresponding to your master branch + pull requests?

Persist hand-made layout

Moving a node makes it stick in one place.

Maybe there's a way to store that information, JSON.stringifyand put in the local storage.
From there there's only one step to printing the string to console and allowing user to put it in a file which would be loaded and interpreted every time the graph is drawn, so you can have some of the graph nodes maintain order between browsers and machines (assuming the file goes to the repository as documentation)

Add option to disable some node from UI

Hi guys,

cheers for this awesome tool. That's a nice start and I would like to see more things in the UI.

I like the D3 graph controls, however I would like to easily "disable" some nodes to visualise more easily my dependencies.

For instance: http://bl.ocks.org/gre/raw/8caa85c90b134f3c8852/ is the graph of my app,
but it is barely readable because basically everyone depends on "react" , "lodash" and "q". I don't want to statically remove those nodes because that's the truth, I just want to disable (delete/or grey out) from the UI a node and all its connection.

Thanks

Recursively Trace Dependencies

dependo is great to see what files a given file depends on, but it doesn't go any levels deeper to show what files those files depend on, and so on.

Cyclic dependency graph

Would it be possible to create a graph of cyclic dependencies?
I can do this in madge but it doesn't have the image capabilities.
I used the command: madge -c

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.