Skip to content
trace the dependency graph of a javascript file
JavaScript
Find file
Latest commit 1d8a97f May 27, 2012 @substack using travis
Failed to load latest commit information.
bin subdeps command but it's super slow May 27, 2012
example more examples! Oct 3, 2011
test include and exclude core tests Oct 3, 2011
.travis.yml using travis May 27, 2012
README.markdown using travis May 27, 2012
index.js subdeps command but it's super slow May 27, 2012
package.json

README.markdown

subdeps

Trace the dependency graph of a javascript file using detective and resolve.

build status

examples

tree.js

var subdeps = require('../');
var deps = subdeps.sync(__dirname + '/tree/start.js');
console.dir(deps);

output:

substack : node-subdeps $ node example/tree.js 
[ '/home/substack/projects/node-subdeps/example/tree/start.js',
  '/home/substack/projects/node-subdeps/node_modules/detective/index.js',
  '/home/substack/projects/node-subdeps/node_modules/detective/node_modules/burrito/index.js',
  '/home/substack/projects/node-subdeps/node_modules/detective/node_modules/burrito/node_modules/uglify-js/uglify-js.js',
  '/home/substack/projects/node-subdeps/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/parse-js.js',
  '/home/substack/projects/node-subdeps/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/process.js',
  '/home/substack/projects/node-subdeps/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/squeeze-more.js',
  '/home/substack/projects/node-subdeps/node_modules/detective/node_modules/burrito/node_modules/traverse/index.js',
  '/home/substack/projects/node-subdeps/example/tree/lib/util.js',
  '/home/substack/projects/node-subdeps/example/tree/x.js' ]
substack : node-subdeps $ 

memory.js

var subdeps = require('../');
var deps = subdeps.sync('/a.js', { sources : {
    '/a.js' : "var b = require('./b');",
    '/b.js' : "var c = require('f')",
    '/c.js' : "var d = require('./lib/d.js')",
    '/lib/d.js' : "var e = require('e');",
    '/node_modules/e/index.js' : '55',
    '/node_modules/f/beep.js' : '"boop"',
    '/node_modules/f/package.json' : JSON.stringify({ main : "beep.js" })
} });
console.dir(deps);

output:

[ '/a.js', '/b.js', '/node_modules/f/beep.js' ]

methods

var subdeps = require('subdeps');

subdeps.sync(filename, opts)

Return an array of dependencies starting from the file filename and expanding out recursively and synchronously.

Overload resolve's normal behavior with:

  • opts.isFile
  • opts.readFileSync

If you have an object mapping filenames to string contents, pass it in as opts.sources and the file will be used for dependency analysis entirely in-memory.

install

With npm do:

npm install subdeps

and for the CLI tool do:

npm install -g subdeps

licence

MIT/X11

Something went wrong with that request. Please try again.