mirror of
https://github.com/flynx/features.js.git
synced 2025-10-29 10:20:09 +00:00
fix + refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
25cef0dbec
commit
c997962d47
52
features.js
52
features.js
@ -311,6 +311,12 @@ var FeatureSetProto = {
|
|||||||
// feature in exclusive set (i.e. exclusive tag can be used as
|
// feature in exclusive set (i.e. exclusive tag can be used as
|
||||||
// a dependency)
|
// 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:
|
// Algorithm:
|
||||||
// - expand features:
|
// - expand features:
|
||||||
@ -388,6 +394,30 @@ var FeatureSetProto = {
|
|||||||
|
|
||||||
var that = this
|
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)...
|
// Expand feature references (recursive)...
|
||||||
//
|
//
|
||||||
// NOTE: closures are not used here as we need to pass different
|
// NOTE: closures are not used here as we need to pass different
|
||||||
@ -562,6 +592,8 @@ var FeatureSetProto = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
sortExclusive()
|
||||||
|
|
||||||
return features
|
return features
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,26 +634,6 @@ var FeatureSetProto = {
|
|||||||
|
|
||||||
//-------------------------------- Exclusive groups/aliases ---
|
//-------------------------------- Exclusive groups/aliases ---
|
||||||
// Handle exclusive feature groups and 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 conflicts = {}
|
||||||
var done = []
|
var done = []
|
||||||
loaded
|
loaded
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-features",
|
"name": "ig-features",
|
||||||
"version": "3.1.9",
|
"version": "3.1.10",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "features.js",
|
"main": "features.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user