forked from node-cube/cube
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcycle_check.js
More file actions
37 lines (35 loc) · 805 Bytes
/
cycle_check.js
File metadata and controls
37 lines (35 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var RTREE = {};
exports.setRequires = function (module, requires) {
requires.forEach(function (name) {
if (!RTREE[name]) {
RTREE[name] = {};
}
RTREE[name][module] = true;
});
};
exports.check = function (name, parents) {
if (!parents) {
parents = [name];
}
var tmp = RTREE[name];
var tmpParent;
var flags;
if (!tmp) {
return false;
}
var res = [];
Object.keys(tmp).forEach(function (i) {
if (parents.indexOf(i) !== -1) {
parents.unshift(i);
console.warn('[WARNNING]', 'cycle require : ' + parents.join(' > '));
return parents;
}
tmpParent = parents.slice(0);
tmpParent.unshift(i);
flags = this.check(i, tmpParent);
if (flags) {
res = res.concat(flags);
}
});
return flags.length ? flags : false;
};