Skip to content

Instantly share code, notes, and snippets.

@ilearnio
Last active March 18, 2016 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilearnio/53edec6936181852f31c to your computer and use it in GitHub Desktop.
Save ilearnio/53edec6936181852f31c to your computer and use it in GitHub Desktop.
List children imported modules (paths) of a module
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