console.log(x.a);
+### module.require
+
+The `module.require` method provides a way to load a module as if
+`require()` was called from the original module.
+
+Note that in order to do this, you must get a reference to the `module`
+object. Since `require()` returns the `exports`, and the `module` is
+typically *only* available within a specific module's code, it must be
+explicitly exported in order to be used.
+
+
### All Together...
To get the exact filename that will be loaded when `require()` is called, use
};
+Module.prototype.require = function(path) {
+ return Module._load(path, this);
+};
+
+
// Returns exception if any
Module.prototype._compile = function(content, filename) {
var self = this;
content = content.replace(/^\#\!.*/, '');
function require(path) {
- return Module._load(path, self);
+ return self.require(path);
}
require.resolve = function(request) {
--- /dev/null
+exports.loaded = require('target');
+exports.module = module;
--- /dev/null
+exports.loaded = 'from child';
--- /dev/null
+var child = require('../child');
+//console.log(child.module.require, child.module);
+console.log(child.module.require('target'));
+console.log(child.loaded);
+exports.loaded = child.module.require('target');
--- /dev/null
+exports.loaded = 'from parent';
assert.equal(amdExtraArgs.ok, amdreg.ok, 'amd extra args failed');
+// make sure that module.require() is the same as
+// doing require() inside of that module.
+var parent = require('../fixtures/module-require/parent/');
+var child = require('../fixtures/module-require/child/');
+assert.equal(child.loaded, parent.loaded);
+
+
process.addListener('exit', function() {
assert.ok(common.indirectInstanceOf(a.A, Function));
assert.equal('A done', a.A());