Skip to content

Instantly share code, notes, and snippets.

@oleics
Created June 28, 2012 15:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oleics/3011868 to your computer and use it in GitHub Desktop.
Save oleics/3011868 to your computer and use it in GitHub Desktop.
module of module
var foo = require('./foo')
, barOfFoo = moduleOfModule('./bar', './foo')
function moduleOfModule(module, ofModule) {
var c = require.cache[require.resolve(ofModule)]
, f = require.resolve(module, c)
, r
c.children.some(function(c) {
if(c.filename === f) {
r = c.exports
return true
}
})
return r
}
@oleics
Copy link
Author

oleics commented Jun 28, 2012

WARNING This is Black Magic. It will break your application tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment