Comparing version
23
index.js
@@ -30,6 +30,7 @@ const promise = require('bluebird'); | ||
// format a node in a dependency graph after all dependencies are resolved | ||
Deptrace.prototype.format = function (input, deps) { | ||
Deptrace.prototype.format = function (input, children, allNodes) { | ||
return promise.resolve({ | ||
label: input.name, | ||
nodes: deps | ||
children: children, | ||
nodes: allNodes | ||
}); | ||
@@ -44,17 +45,19 @@ }; | ||
parents.push(input); | ||
return this.depsFor(input) | ||
.map(function (dep) { | ||
return this.depsFor(input). | ||
map(function (dep) { | ||
return this.resolve(dep, parents); | ||
}.bind(this)) | ||
.then(this._recurse.bind(this, input, parents)); | ||
}.bind(this)). | ||
then(this._recurse.bind(this, input, parents)); | ||
}; | ||
Deptrace.prototype._recurse = function (input, parents, deps) { | ||
return promise.resolve(deps) | ||
.map(function (dep) { | ||
// we lose the resolved version of each dep here because we | ||
// replace each dependency with the graphed version of itself | ||
return promise.resolve(deps). | ||
map(function (dep) { | ||
return this.graph(dep, parents); | ||
}.bind(this)) | ||
.then(this.format.bind(this, input)); | ||
}.bind(this)). | ||
then(this.format.bind(this, input, deps)); | ||
}; | ||
Deptrace.packageJson = require('./lib/package_json'); |
{ | ||
"name": "deptrace", | ||
"description": "Trace and format recursive dependency trees asynchronously.", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/tkellen/node-deptrace", | ||
@@ -30,6 +30,6 @@ "authors": [ | ||
"devDependencies": { | ||
"chai": "~1.9.1", | ||
"mocha": "~1.18.2", | ||
"github-url-from-git": "^1.1.1", | ||
"request": "^2.37.0", | ||
"chai": "1.9.1", | ||
"mocha": "1.18.2", | ||
"github-url-from-git": "1.1.1", | ||
"request": "2.37.0", | ||
"archy": "0.0.2" | ||
@@ -36,0 +36,0 @@ }, |
@@ -20,3 +20,3 @@ # deptrace [](http://travis-ci.org/tkellen/node-deptrace) | ||
}, | ||
format: function (input, deps) { | ||
format: function (input, children, tree) { | ||
// format a node in a dependency graph after all dependencies are resolved | ||
@@ -87,8 +87,2 @@ }, | ||
then(JSON.parse); | ||
}, | ||
format: function (input, deps) { | ||
return promise.resolve({ | ||
label: input.name, | ||
nodes: deps | ||
}); | ||
} | ||
@@ -102,5 +96,5 @@ }); | ||
#### opts.format(input, deps) | ||
#### opts.format(input, children, allNodes) | ||
This method can be used to format the result for each node of the dependency graph after all of its direct dependencies have been resolved. | ||
This method can be used to format the result for each node of the graph after all of its direct dependencies have been resolved. | ||
@@ -110,3 +104,3 @@ Type: `Function` | ||
The default implementation (shown in the example above) formats the dependency tree to be compatible with [archy](https://github.com/substack/node-archy) (as follows): | ||
The default implementation formats the dependency graph to be compatible with [archy](https://github.com/substack/node-archy) (as follows): | ||
```js | ||
@@ -113,0 +107,0 @@ { |
Sorry, the diff of this file is not supported yet
9273
1.39%69
4.55%127
-4.51%