Last active
March 18, 2016 13:53
-
-
Save ilearnio/53edec6936181852f31c to your computer and use it in GitHub Desktop.
List children imported modules (paths) of a module
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 listModuleChildren (parent_path) { | |
const parent_mod = require.cache[parent_path] | |
let children = [] | |
;(function run (mod) { | |
if (mod.children.length) { | |
for (let i = 0; i < mod.children.length; i++) { | |
const id = mod.children[i].id | |
if (!children.includes(id)) { | |
children.push(id) | |
run(mod.children[i]) | |
} | |
} | |
} | |
})(parent_mod) | |
return children | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment