Created
November 16, 2011 02:13
-
-
Save natecavanaugh/1369064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RESOLVE = function() { | |
var seen = {}; | |
var resolved = {}; | |
var aui_mods = YUI.AUI_config.groups.alloy.modules; | |
var yui_mods = YUI.Env[YUI().version].modules; | |
var A = AUI(); | |
var all_mods = A.merge(aui_mods, yui_mods); | |
var mods = all_mods; | |
// var mods = aui_mods; | |
for (var i in mods) { | |
var subs = mods[i].submodules; | |
if (subs) { | |
for (var j in subs) { | |
var reqs = subs[j].requires; | |
var subm = {}; | |
mods[j] = subm; | |
if (reqs) { | |
submreqs = []; | |
subm.requires = submreqs; | |
for (var k = 0; k < reqs.length; k++) { | |
submreqs[k] = reqs[k]; | |
} | |
} | |
} | |
} | |
} | |
var resolve_dep = function(name, mods) { | |
var mod = mods[name]; | |
if (!mod) { | |
console.info('no module found for: ', name); | |
return; | |
} | |
var requires = mod.requires; | |
var use = mod.use; | |
var sub; | |
seen[name] = true; | |
if (requires && requires.length) { | |
for (var i = 0; i < requires.length; i++) { | |
sub = requires[i]; | |
if (!(sub in mods)) { | |
continue; | |
} | |
if (!(sub in resolved)) { | |
if (sub in seen) { | |
console.warn('REQUIRES: module: %s%a, submodule: %s%a', name, mod.requires, sub, mods[sub].requires); | |
throw 'Circular dependency: ' + sub + ' -> ' + name; | |
} | |
resolve_dep(sub, mods); | |
} | |
} | |
} | |
if (use && use.length) { | |
for (var i = 0; i < use.length; i++) { | |
sub = use[i]; | |
if (!(sub in mods)) { | |
continue; | |
} | |
if (!(sub in resolved)) { | |
if (sub in seen) { | |
console.info('USE', 'Circular dependency: ' + sub + ' -> ' + name, mod, mods[sub].requires); | |
} | |
// resolve_dep(sub, mods); | |
} | |
} | |
} | |
resolved[name] = true; | |
}; | |
for (var i in mods) { | |
resolve_dep(i, mods); | |
} | |
return resolved; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment