From c997962d47c202122987459ea589a9f84c846aee Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 28 Jun 2017 03:36:58 +0300 Subject: [PATCH] fix + refactoring... Signed-off-by: Alex A. Naanou --- features.js | 52 ++++++++++++++++++++++++++++++++-------------------- package.json | 2 +- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/features.js b/features.js index c906d9a..3e26446 100755 --- a/features.js +++ b/features.js @@ -311,6 +311,12 @@ var FeatureSetProto = { // feature in exclusive set (i.e. exclusive tag can be used as // a dependency) // + // NOTE: an exclusive group name can be used as an alias. + // NOTE: if an alias is used and no feature from that exclusive group + // is explicitly included then the actual loaded feature will + // depend on the load order, which in an async world is not + // deterministic... + // // // Algorithm: // - expand features: @@ -388,6 +394,30 @@ var FeatureSetProto = { var that = this + // Pre-sort exclusive feature by their occurrence in dependency + // tree... + // + // NOTE: there can be a case when an exclusive alias is used but + // no feature in a group is loaded, in this case which + // feature is actually loaded depends on the load order... + var sortExclusive = function(){ + var loaded = Object.keys(features) + Object.keys(exclusive) + .forEach(function(k){ + exclusive[k] = exclusive[k] + .map(function(e, i){ return [e, i] }) + .sort(function(a, b){ + var i = loaded.indexOf(a[0]) + var j = loaded.indexOf(b[0]) + // keep the missing at the end... + i = i < 0 ? Infinity : i + j = j < 0 ? Infinity : j + // NOTE: Infinity - Infinity is NaN, so we need + // to guard against it... + return i - j || 0 }) + .map(function(e){ return e[0] }) }) + } + // Expand feature references (recursive)... // // NOTE: closures are not used here as we need to pass different @@ -562,6 +592,8 @@ var FeatureSetProto = { } }) + sortExclusive() + return features } @@ -602,26 +634,6 @@ var FeatureSetProto = { //-------------------------------- Exclusive groups/aliases --- // Handle exclusive feature groups and aliases... - // - // pre-sort exclusive feature by their occurrence in dependency - // tree... - var loaded = Object.keys(features) - Object.keys(exclusive) - .forEach(function(k){ - var l = exclusive[k].length - exclusive[k] = exclusive[k] - .map(function(e, i){ return [e, i] }) - .sort(function(a, b){ - var i = loaded.indexOf(a[0]) - var j = loaded.indexOf(b[0]) - // keep the missing at the end... - i = i < 0 ? Infinity : i - j = j < 0 ? Infinity : j - // NOTE: Infinity - Infinity is NaN, so we need - // to guard against it... - return i - j || 0 }) - .map(function(e){ return e[0] }) }) - // do the actual handling... var conflicts = {} var done = [] loaded diff --git a/package.json b/package.json index 7e4cf35..f3c0467 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-features", - "version": "3.1.9", + "version": "3.1.10", "description": "", "main": "features.js", "scripts": {