├── .gitignore ├── README.md ├── package.json └── browserify-graph /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # browserify-graph(1) 2 | 3 | [![Dependency Status](https://gemnasium.com/conradz/browserify-graph.png)](https://gemnasium.com/conradz/browserify-graph) 4 | 5 | Output a graph of all the files that are required by a JS source file, using 6 | the same dependency resolution as 7 | [browserify](https://github.com/substack/node-browserify). This will 8 | recursively search for required files. 9 | 10 | ## Installation 11 | 12 | npm install -g browserify-graph 13 | 14 | ## Usage 15 | 16 | browserify-graph 17 | 18 | Outputs a graph of all required files, starting at ``. 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "browserify-graph", 3 | "version": "0.0.0", 4 | "description": "Print a graph of all modules a file depends on", 5 | "dependencies": { 6 | "archy": "~0.0.2", 7 | "async": "~0.2.9", 8 | "browser-resolve": "~1.2.0", 9 | "detective": "~2.2.0" 10 | }, 11 | "devDependencies": {}, 12 | "bin": { 13 | "browserify-graph": "browserify-graph" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/conradz/browserify-graph.git" 18 | }, 19 | "keywords": [ 20 | "browserify", 21 | "dependencies", 22 | "dependency", 23 | "graph" 24 | ], 25 | "author": "Conrad Zimmerman ", 26 | "license": "BSD", 27 | "bugs": { 28 | "url": "https://github.com/conradz/browserify-graph/issues" 29 | }, 30 | "homepage": "https://github.com/conradz/browserify-graph" 31 | } 32 | -------------------------------------------------------------------------------- /browserify-graph: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var detective = require('detective'), 4 | resolve = require('browser-resolve'), 5 | fs = require('fs'), 6 | path = require('path'), 7 | async = require('async'), 8 | archy = require('archy'); 9 | 10 | if (process.argv.length < 3) { 11 | console.error('Usage: browserify-graph '); 12 | console.error('Prints out a graph of all modules a file depends on'); 13 | console.error('Uses the same dependency resolution as browserify'); 14 | process.exit(1); 15 | } 16 | 17 | var IS_CORE = /^[^\\\/]+$/, 18 | file = path.resolve(process.argv[2]), 19 | basedir = path.dirname(file); 20 | 21 | get(file, done); 22 | 23 | function get(file, callback) { 24 | if (IS_CORE.test(file)) { 25 | return callback(null, { label: file + ' - builtin', nodes: [] }); 26 | } 27 | 28 | file = path.resolve(file); 29 | fs.readFile(file, 'utf8', read); 30 | 31 | function read(err, contents) { 32 | if (err) { 33 | return callback(err); 34 | } 35 | 36 | var requires = detective(contents); 37 | async.map(requires, getDep, gotDeps); 38 | } 39 | 40 | function getDep(name, callback) { 41 | resolve(name, { filename: file }, resolved); 42 | 43 | function resolved(err, p) { 44 | if (err) { 45 | return callback(err); 46 | } 47 | 48 | return get(p, callback); 49 | } 50 | } 51 | 52 | function gotDeps(err, deps) { 53 | if (err) { 54 | return callback(err); 55 | } 56 | 57 | callback(null, { label: path.relative(basedir, file), nodes: deps }); 58 | } 59 | } 60 | 61 | function done(err, data) { 62 | if (err) throw err; 63 | console.log(archy(data)); 64 | } 65 | --------------------------------------------------------------------------------