Comparing version 0.0.5 to 0.1.0
'use strict'; | ||
/** | ||
* Get path to the circular dependency. | ||
* @param {Object} unresolved | ||
* @return {Array} | ||
*/ | ||
function getPath(unresolved) { | ||
return Object.keys(unresolved).filter(function (module) { | ||
return unresolved[module]; | ||
}); | ||
} | ||
/** | ||
* A circular dependency is occurring when we see a software package | ||
@@ -19,3 +30,3 @@ * more than once, unless that software package has all its dependencies resolved. | ||
if (unresolved[dependency]) { | ||
circular[id] = dependency; | ||
circular.push(getPath(unresolved)); | ||
return; | ||
@@ -38,3 +49,3 @@ } | ||
module.exports = function (modules) { | ||
var circular = {}, | ||
var circular = [], | ||
resolved = {}, | ||
@@ -47,3 +58,25 @@ unresolved = {}; | ||
return circular; | ||
return { | ||
/** | ||
* Expose the circular dependency array. | ||
* @return {Array} | ||
*/ | ||
getArray: function () { | ||
return circular; | ||
}, | ||
/** | ||
* Check if the given module is part of a circular dependency. | ||
* @return {Boolean} | ||
*/ | ||
isCyclic: function (id) { | ||
var cyclic = false; | ||
circular.forEach(function (path) { | ||
if (path.indexOf(id) >= 0) { | ||
cyclic = true; | ||
} | ||
}); | ||
return cyclic; | ||
} | ||
}; | ||
}; |
@@ -60,3 +60,3 @@ 'use strict'; | ||
noDependencyNode(nodes[id], colors.noDependencies); | ||
} else if (circular[id]) { | ||
} else if (circular.isCyclic(id)) { | ||
nodeColor(nodes[id], (colors.circular || '#ff6c60')); | ||
@@ -101,3 +101,3 @@ } | ||
var nodes = {}; | ||
checkGraphvizInstalled(); | ||
@@ -104,0 +104,0 @@ |
@@ -67,12 +67,19 @@ 'use strict'; | ||
*/ | ||
module.exports.circular = function (modules, opts) { | ||
module.exports.circular = function (circular, opts) { | ||
var arr = circular.getArray(); | ||
if (opts.output === 'json') { | ||
return process.stdout.write(toJSON(modules)); | ||
return process.stdout.write(toJSON(arr)); | ||
} | ||
if (!Object.keys(modules).length) { | ||
if (!arr.length) { | ||
console.log(c('No circular references found', 'green', opts.colors)); | ||
} else { | ||
Object.keys(modules).forEach(function (id) { | ||
console.log(c(id, 'grey', opts.colors) + c(' -> ', 'cyan', opts.colors) + c(modules[id], 'grey', opts.colors)); | ||
arr.forEach(function (path, idx) { | ||
path.forEach(function (module, idx) { | ||
if (idx) { | ||
process.stdout.write(c(' -> ', 'cyan', opts.colors)); | ||
} | ||
process.stdout.write(c(module, 'grey', opts.colors)); | ||
}); | ||
process.stdout.write('\n'); | ||
}); | ||
@@ -79,0 +86,0 @@ } |
{ | ||
"name": "madge", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"author": "Patrik Henningsson <patrik.henningsson@gmail.com>", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com/pahen/node-madge", |
@@ -5,3 +5,3 @@ # MaDGe - Module Dependency Graph | ||
Create graphs from your [CommonJS](http://nodejs.org/api/modules.html) or [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) module dependencies. Could also be useful for finding circular dependencies in your code. Tested on [Node.js](http://nodejs.org/) and [RequireJS](http://requirejs.org/) projects. Dependencies are calculated using static code analysis. CommonJS dependencies are found using James Halliday's [detective](https://github.com/substack/node-detective) and for AMD I'm using some parts copied from James Burke's [RequireJS](https://github.com/jrburke/requirejs) (both are using [UglifyJS](https://github.com/mishoo/UglifyJS)). | ||
Create graphs from your [CommonJS](http://nodejs.org/api/modules.html) or [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) module dependencies. Could also be useful for finding circular dependencies in your code. Tested on [Node.js](http://nodejs.org/) and [RequireJS](http://requirejs.org/) projects. Dependencies are calculated using static code analysis. CommonJS dependencies are found using James Halliday's [detective](https://github.com/substack/node-detective) and for AMD I'm using some parts copied from James Burke's [RequireJS](https://github.com/jrburke/requirejs) (both are using [UglifyJS](https://github.com/mishoo/UglifyJS)). Modules written in [CoffeeScript](http://coffeescript.org/) with extension .coffee are supported and will automatically be compiled on-the-fly. | ||
@@ -21,2 +21,6 @@ ## Examples | ||
And some terminal usage. | ||
![](https://github.com/pahen/node-madge/raw/master/examples/terminal.png) | ||
# Installation | ||
@@ -133,2 +137,5 @@ | ||
## v0.1.0 (September 3, 2012) | ||
Complete path in circular dependencies is now printed (and marked as red in image graphs). | ||
## v0.0.5 (August 8, 2012) | ||
@@ -135,0 +142,0 @@ Added support for CoffeeScript. Files with extension .coffee will automatically be compiled on-the-fly. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54480
1380
176