Giter Club home page Giter Club logo

depgraph's Introduction

depgraph

Build Status Coverage Status

depgraph provides luadepgraph command-line tool for building, analyzing, and visualizing graph of dependencies between Lua modules within a package. To install it using LuaRocks, open terminal and run luarocks install depgraph or sudo luarocks install depgraph.

luadepgraph scans all passed files, looking for require calls. It distinguishes several types of dependencies based on call context:

  • A dependency is lazy if require is called inside a function;
  • A dependency is conditional if require is called within a branch of an if statement;
  • A dependency is protected if require is called using pcall or xpcall.

Dependency target is inferred from the argument passed to require if it's a literal string or a concatenation of a string and another expression.

Specifying Lua files

luadepgraph needs to know which Lua files are part of the package and have to be included in its dependency graph. It can handle two types of files: regular modules and external files that can't be imported from other files, but can depend on modules, e.g. scripts and test files.

Modules are specified using -m/--modules option and external files are added using -e/--ext-files. Both options accept several files or directories. -m/--modules also accepts rockspecs; if no modules are added but there is a single rockspec in current directory, it will be used automatically.

Unless using a rockspec, pass prefix directory from where Lua modules can be loaded using -p/--prefix.

Graph actions

luadepgraph can perform several actions on the graph:

  • --list: print a listing of modules and external files in the graph. This is the default action.
  • --show <module>: print all information about a module, which includes its location, dependencies and dependents. External files can be passed by file name.
  • --deps: print a listing of all external dependencies of the graph.
  • --cycles: look for circular dependencies and show the shortest ones.
  • --dot [<title>]: export the graph in .dot format, which can be turned into an image using Graphviz.
    • Nodes with black border are modules, blue borders - external files, yellow - unresolved and external dependencies.
    • Solid edges are normal dependencies, dashed edges - conditional dependencies, dotted - lazy ones.
    • Black edges are unprotected dependencies, green ones are protected.

There are some options that can preprocess or filter the graph before executing an action, run luadepgraph -h for more info.

Examples

List all modules in src directory:

luadepgraph -m src -p src

Show dependencies and dependents of module rock.foo:

luadepgraph -m src -p src --show rock.foo

List all modules used by unit test spec/foo_spec.lua:

luadepgraph -m src -p src -e spec --root spec/foo_spec.lua

Show external dependencies of a package given a rockspec:

luadepgraph -m rockspecs/rock-1.0-1.rockspec --deps

Look for circular dependencies:

luadepgraph -m rockspecs/rock-1.0-1.rockspec --cycles

Same, but ignore lazy dependencies:

luadepgraph -m rockspecs/rock-1.0-1.rockspec --cycles --strict

Turn the graph into an image (dot command-line tool is a part of Graphviz):

luadepgraph -m rockspecs/rock-1.0-1.rockspec --dot | dot -Tgif -o rock.gif

depgraph's People

Contributors

mpeterv avatar

Watchers

James Cloos avatar tianchaijz avatar

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.