Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
var helpers = require('broccoli-kitchen-sink-helpers');
var crypto = require('crypto');
var statPathsFor = require('./lib/stat-paths-for');
var timing = require('./lib/timing');
var debug = require('debug')('hash-for-dep:index');

/* @public
*
Expand All @@ -12,8 +14,18 @@ var statPathsFor = require('./lib/stat-paths-for');
* @return {String} a hash representing the stats of this module and all its descendents
*/
module.exports = function hashForDep(name, dir, _hashTreeOverride) {
var start = timing.start();
var inputHashes = statPathsFor(name, dir).map(_hashTreeOverride || helpers.hashTree).join(0x00);
debug('inputHashes stats: %o', {
hashes: inputHashes.length,
elapsedTime: timing.end(start)
});

return crypto.createHash('md5').
update(inputHashes).digest('hex');
start = timing.start();
var hash = crypto.createHash('md5').update(inputHashes).digest('hex');
debug('hash stats: %o', {
elapsedTime: timing.end(start)
});

return hash;
};
11 changes: 9 additions & 2 deletions lib/deps-for.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';
var pkg = require('./pkg');
var debug = require('debug')('hash-for-dep:deps-for');
var time = require('./timing');

/* @private
*
*
* constructs a set of all dependencies recursively
*
* @method depsFor
Expand All @@ -13,6 +15,7 @@ var pkg = require('./pkg');
module.exports = function depsFor(name, dir) {
var dependencies = [];
var visited = Object.create(null);
var start = time.start();

(function again(name, dir) {
var thePackage = pkg(name, dir);
Expand All @@ -28,6 +31,10 @@ module.exports = function depsFor(name, dir) {
});
}(name, dir));

debug('dep discovery stats: %o', {
dependencies: dependencies.length,
elapsedTime: time.end(start)
});

return dependencies;
};

11 changes: 11 additions & 0 deletions lib/timing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = {
start: function() {
return process.hrtime();
},
end: function(start) {
var elapsed = process.hrtime(start)[1] / 1000000;
return process.hrtime(start)[0] + 's ' + elapsed.toFixed(3) + 'ms';
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"homepage": "https://github.com/stefanpenner/hash-for-dep#readme",
"dependencies": {
"broccoli-kitchen-sink-helpers": "^0.2.6",
"debug": "^2.2.0",
"resolve": "^1.1.6"
},
"devDependencies": {
Expand Down