Last active
March 1, 2016 22:47
-
-
Save kfranqueiro/4238675 to your computer and use it in GitHub Desktop.
Functions to find what's depending on a loaded Dojo module or what a module depends on (uses ES5 methods)
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
function findDep(depid) { | |
return Object.keys(require.modules).map(function(mid) { | |
return require.modules[mid]; | |
}).filter(function(m) { | |
return m.deps && m.deps.map(function(dep) { | |
return dep.mid; | |
}).indexOf(depid) > -1; | |
}).map(function(m) { | |
return m.mid; | |
}); | |
} |
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
function getDeps(mid, depsMap) { | |
depsMap = depsMap || {}; | |
depsMap[mid] = true; | |
var module = require.modules[mid]; | |
if (module.deps) { | |
module.deps.forEach(function (module) { | |
getDeps(module.mid, depsMap); | |
}); | |
} | |
return Object.keys(depsMap); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment