better dependency loop detection...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-05-20 03:56:00 +03:00
parent 11f1c08456
commit 48bb6b2746
2 changed files with 31 additions and 4 deletions

View File

@ -553,6 +553,10 @@ var FeatureSetProto = {
// complexity is far better... // complexity is far better...
var max = l * l var max = l * l
var moved = []
var chain = []
var chains = []
for(var i=0; i < lst.length; i++){ for(var i=0; i < lst.length; i++){
var k = lst[i] var k = lst[i]
var depends = (that[k].depends || []).slice() var depends = (that[k].depends || []).slice()
@ -584,8 +588,31 @@ var FeatureSetProto = {
// move the dependencies after k... // move the dependencies after k...
// NOTE: this will keep the order within the dependencies... // NOTE: this will keep the order within the dependencies...
move.length > 0 if(move.length > 0){
&& lst.splice.apply(lst, [i+1, 0].concat(move)) lst.splice.apply(lst, [i+1, 0].concat(move))
// unseen feature -> new chain...
if(moved.indexOf(k) < 0){
chain = []
}
moved.push(k)
// chain completed -> check and store...
if(chain.indexOf(k) >= 0){
var c = JSON.stringify(chain)
// repeating chain -> loop detected...
if(chains.indexOf(c) >= 0){
console.error('Feature cyclic dependency:', chain)
break
}
chains.push(c)
// add item to chain...
} else {
chain.push(k)
}
}
// check for cyclic dependencies... // check for cyclic dependencies...
// XXX loop signs: // XXX loop signs:
@ -597,7 +624,7 @@ var FeatureSetProto = {
// - ... // - ...
if(lst.length >= max){ if(lst.length >= max){
// XXX get the actual cycle... // XXX get the actual cycle...
console.error('Feature cyclic dependency...') console.error('Feature cyclic dependency:', chain)
break break
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "ig-features", "name": "ig-features",
"version": "2.2.4", "version": "2.2.5",
"description": "", "description": "",
"main": "features.js", "main": "features.js",
"scripts": { "scripts": {