Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created September 22, 2016 22:47
Show Gist options
  • Save isaacs/a055e49e90c405b9920e75feaacea492 to your computer and use it in GitHub Desktop.
Save isaacs/a055e49e90c405b9920e75feaacea492 to your computer and use it in GitHub Desktop.
var Module = require('module')
Module.prototype.require = function (orig) { return function (id) {
console.trace(this, id)
return orig.apply(this, arguments)
}}(Module.prototype.require)
require('./b.js')
require('./c.js')
require('./d.js')
console.log('d.js')
$ node a.js
Trace: Module {
id: '.',
exports: {},
parent: null,
filename: '/Users/isaacs/dev/npm/product/a.js',
loaded: false,
children: [],
paths:
[ '/Users/isaacs/dev/npm/product/node_modules',
'/Users/isaacs/dev/npm/node_modules',
'/Users/isaacs/dev/node_modules',
'/Users/isaacs/node_modules',
'/Users/node_modules',
'/node_modules' ] } './b.js'
at Module.require (/Users/isaacs/dev/npm/product/a.js:3:11)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/isaacs/dev/npm/product/a.js:7:1)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
Trace: Module {
id: '/Users/isaacs/dev/npm/product/b.js',
exports: {},
parent:
Module {
id: '.',
exports: {},
parent: null,
filename: '/Users/isaacs/dev/npm/product/a.js',
loaded: false,
children: [ [Circular] ],
paths:
[ '/Users/isaacs/dev/npm/product/node_modules',
'/Users/isaacs/dev/npm/node_modules',
'/Users/isaacs/dev/node_modules',
'/Users/isaacs/node_modules',
'/Users/node_modules',
'/node_modules' ] },
filename: '/Users/isaacs/dev/npm/product/b.js',
loaded: false,
children: [],
paths:
[ '/Users/isaacs/dev/npm/product/node_modules',
'/Users/isaacs/dev/npm/node_modules',
'/Users/isaacs/dev/node_modules',
'/Users/isaacs/node_modules',
'/Users/node_modules',
'/node_modules' ] } './c.js'
at Module.require (/Users/isaacs/dev/npm/product/a.js:3:11)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/isaacs/dev/npm/product/b.js:1:63)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at Module.require (/Users/isaacs/dev/npm/product/a.js:4:15)
Trace: Module {
id: '/Users/isaacs/dev/npm/product/c.js',
exports: {},
parent:
Module {
id: '/Users/isaacs/dev/npm/product/b.js',
exports: {},
parent:
Module {
id: '.',
exports: {},
parent: null,
filename: '/Users/isaacs/dev/npm/product/a.js',
loaded: false,
children: [Object],
paths: [Object] },
filename: '/Users/isaacs/dev/npm/product/b.js',
loaded: false,
children: [ [Circular] ],
paths:
[ '/Users/isaacs/dev/npm/product/node_modules',
'/Users/isaacs/dev/npm/node_modules',
'/Users/isaacs/dev/node_modules',
'/Users/isaacs/node_modules',
'/Users/node_modules',
'/node_modules' ] },
filename: '/Users/isaacs/dev/npm/product/c.js',
loaded: false,
children: [],
paths:
[ '/Users/isaacs/dev/npm/product/node_modules',
'/Users/isaacs/dev/npm/node_modules',
'/Users/isaacs/dev/node_modules',
'/Users/isaacs/node_modules',
'/Users/node_modules',
'/node_modules' ] } './d.js'
at Module.require (/Users/isaacs/dev/npm/product/a.js:3:11)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/isaacs/dev/npm/product/c.js:1:63)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at Module.require (/Users/isaacs/dev/npm/product/a.js:4:15)
d.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment