Comparing version 0.1.0 to 0.1.1
26
index.js
const promise = require('bluebird'); | ||
const request = promise.promisify(require('request').get); | ||
const githubUrlFromGit = require('github-url-from-git'); | ||
var Deptrace = module.exports = function Deptrace(opts) { | ||
var Deptrace = module.exports = function Deptrace (opts) { | ||
opts = opts || {}; | ||
@@ -13,4 +10,4 @@ if (opts.depsFor) { | ||
} | ||
if (opts.lookup) { | ||
this.lookup = opts.lookup; | ||
if (opts.resolve) { | ||
this.resolve = opts.resolve; | ||
} | ||
@@ -23,14 +20,13 @@ if (opts.format) { | ||
// extract dependencies from something into an array of objects | ||
Deptrace.prototype.depsFor = function(input) { | ||
// extract an array of dependencies from some input | ||
Deptrace.prototype.depsFor = function (input) { | ||
throw new Error('Implement a method to return an array of dependencies.'); | ||
}; | ||
// resolve an individual dependency into a dependency object | ||
Deptrace.prototype.lookup = function(dep, parents) { | ||
// resolve an individual dependency into a more detailed form | ||
Deptrace.prototype.resolve = function (dep, parents) { | ||
return promise.resolve(dep); | ||
}; | ||
// format the result of a dependency after it's associated deps | ||
// have been resolved | ||
// format a node in a dependency graph after all dependencies are resolved | ||
Deptrace.prototype.format = function (input, deps) { | ||
@@ -43,3 +39,3 @@ return promise.resolve({ | ||
Deptrace.prototype.graph = function(input, parents) { | ||
Deptrace.prototype.graph = function (input, parents) { | ||
if (!parents) { | ||
@@ -52,3 +48,3 @@ parents = []; | ||
.map(function (dep) { | ||
return this.lookup(dep, parents); | ||
return this.resolve(dep, parents); | ||
}.bind(this)) | ||
@@ -58,3 +54,3 @@ .then(this._recurse.bind(this, input, parents)); | ||
Deptrace.prototype._recurse = function(input, parents, deps) { | ||
Deptrace.prototype._recurse = function (input, parents, deps) { | ||
return promise.resolve(deps) | ||
@@ -61,0 +57,0 @@ .map(function (dep) { |
const promise = require('bluebird'); | ||
module.exports = function (key) { | ||
if (!key) { | ||
throw new Error('Please specify a dependency key.'); | ||
} | ||
return function (input) { | ||
@@ -5,0 +8,0 @@ var deps = input[key] || []; |
{ | ||
"name": "deptrace", | ||
"description": "A tool for tracing recursive dependency trees asynchronously.", | ||
"version": "0.1.0", | ||
"description": "Trace and format recursive dependency trees asynchronously.", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/tkellen/node-deptrace", | ||
"authors": [ | ||
"Tyler Kellen <tyler@sleekcode.net>", | ||
"Michael \"Z\" Goddard <mzgoddard@gmail.com>" | ||
"Tyler Kellen <tyler@sleekcode.net>" | ||
], | ||
@@ -41,4 +40,5 @@ "repository": { | ||
"keywords": [ | ||
"trace dependencies" | ||
"trace dependencies", | ||
"dependency tree" | ||
] | ||
} |
# deptrace [![Build Status](https://secure.travis-ci.org/tkellen/node-deptrace.png)](http://travis-ci.org/tkellen/node-deptrace) | ||
> A tool for tracing recursive dependency trees asynchronously. | ||
> Trace and format recursive dependency trees asynchronously. | ||
@@ -15,10 +15,11 @@ [![NPM](https://nodei.co/npm/deptrace.png)](https://nodei.co/npm/deptrace/) | ||
depsFor: function (input) { | ||
// extract dependencies from something into an array of objects | ||
// extract an array of dependencies from some input | ||
}, | ||
lookup: function (dep, parents) { | ||
// resolve an individual dependency into a dependency object | ||
resolve: function (dep, parents) { | ||
// resolve an individual dependency into a more detailed form | ||
}, | ||
format: function (input, deps) { | ||
// format the result of a dependency after it's associated deps | ||
} | ||
// format a node in a dependency graph after all dependencies are resolved | ||
}, | ||
concurrency: 4 | ||
}); | ||
@@ -56,6 +57,9 @@ ``` | ||
#### opts.lookup(dep, parents) | ||
#### opts.resolve(dep, parents) | ||
Receives each dependency gathered by `depsFor`, as well as an array of all parent dependencies. Must return a promise. This method is optional and can be used to resolve a more detailed version of a dependency. (e.g. converting the named of the dependency in package.json to the actual package.json of *that* dependency). | ||
Receives each dependency gathered by `depsFor`, as well as an array of all parent dependencies. Must return a promise. This method is optional and can be used to resolve a more detailed version of a dependency. (e.g. converting the name of a dependency in package.json to the actual package.json of *that* dependency). | ||
Type: `Function` | ||
Default: [see source](https://github.com/tkellen/node-deptrace/blob/master/index.js#L25-27) | ||
Here is a naive example which can trace dependencies for any npm module for which all dependencies are on github: | ||
@@ -70,3 +74,3 @@ ```js | ||
depsFor: Deptrace.packageJson('dependencies'), | ||
lookup: function (dep, parents) { | ||
resolve: function (dep, parents) { | ||
return request('http://registry.npmjs.org/'+dep.name). | ||
@@ -101,5 +105,8 @@ get(1). | ||
This method can be used to format the result for each node of the dependency after all of its dependencies have been resolved. | ||
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. | ||
The default implementation (show in the example above) formats the dependency tree to be compatible with [archy](https://github.com/substack/node-archy) (as follows): | ||
Type: `Function` | ||
Default: [see source](https://github.com/tkellen/node-deptrace/blob/master/index.js#L30-35) | ||
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): | ||
```js | ||
@@ -122,4 +129,9 @@ { | ||
### packageJson(field) | ||
This helper can be used to generate a `depsFor` method that will extract dependencies from `package.json` files under the provided key. See example for [opts.lookup(deps, parents)](#optslookupdep-parents). | ||
### graph(input) | ||
Asynchronously trace a dependency graph for the provided input. | ||
### Deptrace.packageJson(field) | ||
This helper can be used to generate a [depsFor](#optsdepsforinput) method that will extract an array of name/version dependencies from the specified dependency field in a `package.json` file. See example for [opts.resolve(deps, parents)](#optsresolvedep-parents). |
Sorry, the diff of this file is not supported yet
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
9146
133