Skip to content

Commit 7e2d93a

Browse files
committed
Fix function to retrieve dependencies (prevents stackoverflow)
1 parent 0bb3a31 commit 7e2d93a

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

lib/dynamic-cache.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,31 @@ DynamicCache.prototype.update = function (cb) {
3737
this._queue = [];
3838
}
3939
}.bind(this);
40+
4041
var getDeps = function (filename) {
41-
if (this._files[filename]) {
42-
return [[filename]].concat(this._files[filename].map(getDeps)).reduce(function (a, b) {
43-
return a.concat(b);
44-
});
45-
} else {
46-
return [filename];
42+
var dependencies = this._files[filename];
43+
var dependenciesSet = {};
44+
45+
dependenciesSet[filename] = true;
46+
47+
var getSubDeps = function(deps){
48+
deps.forEach(function (dep, index) {
49+
if (!dependenciesSet[dep]) {
50+
dependenciesSet[dep] = true;
51+
var subDeps = this._files[deps[index]];
52+
if (subDeps){
53+
getSubDeps(subDeps);
54+
}
55+
}
56+
}, this);
57+
}.bind(this)
58+
59+
if (dependencies) {
60+
getSubDeps(dependencies);
4761
}
62+
return Object.keys(dependenciesSet);
4863
}.bind(this);
64+
4965
files.forEach(function (filename) {
5066
fs.stat(filename, function (err, stats) {
5167
if (err || stats.mtime.getTime() !== this._time[filename]) {

0 commit comments

Comments
 (0)