diff --git a/lib/dynamic-cache.js b/lib/dynamic-cache.js index 9ffbd31..3a34507 100644 --- a/lib/dynamic-cache.js +++ b/lib/dynamic-cache.js @@ -3,13 +3,15 @@ var fs = require('fs'); function objectValues(obj) { - if (typeof obj !== 'object') { - return []; + var values = []; + if (typeof obj === 'object') { + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + values.push(obj[key]); + } + } } - - return Object.keys(obj).map(function (key) { - return obj[key]; - }); + return values } module.exports = DynamicCache; @@ -35,15 +37,31 @@ DynamicCache.prototype.update = function (cb) { this._queue = []; } }.bind(this); + var getDeps = function (filename) { - if (this._files[filename]) { - return [[filename]].concat(this._files[filename].map(getDeps)).reduce(function (a, b) { - return a.concat(b); - }); - } else { - return [filename]; + var dependencies = this._files[filename]; + var dependenciesSet = {}; + + dependenciesSet[filename] = true; + + var getSubDeps = function(deps){ + deps.forEach(function (dep, index) { + if (!dependenciesSet[dep]) { + dependenciesSet[dep] = true; + var subDeps = this._files[deps[index]]; + if (subDeps){ + getSubDeps(subDeps); + } + } + }, this); + }.bind(this) + + if (dependencies) { + getSubDeps(dependencies); } + return Object.keys(dependenciesSet); }.bind(this); + files.forEach(function (filename) { fs.stat(filename, function (err, stats) { if (err || stats.mtime.getTime() !== this._time[filename]) { diff --git a/package.json b/package.json index 1b830bc..7eb1d70 100644 --- a/package.json +++ b/package.json @@ -30,11 +30,11 @@ "require-test": "1.0.0" }, "dependencies": { - "browserify": "^8.1.3", + "browserify": "^9.0.8", "mold-source-map": "0.3.0", "ms": "^0.7.0", "once": "^1.3.1", "prepare-response": "^1.1.2", "uglify-js": "^2.4.16" } -} \ No newline at end of file +}