Skip to content

Commit

Permalink
Set it up so that require(".") returns the main module.
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Mar 18, 2010
1 parent e082cef commit a4d8fdc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/module.js
Expand Up @@ -34,6 +34,9 @@ function requireNative (id, cb) {
// first pass, just local
function require (id, parent, cb) {
if (id in natives) return requireNative(id, cb);
if (id in nativeModuleCache) {
return nativeModuleCache[id];
}
if (parent && parent.uri) {
var base = parent.uri;
} else {
Expand Down Expand Up @@ -212,6 +215,7 @@ function resolve (root, id, parent, cb) {
function main (uri) {
if (process.mainModule) return process.mainModule;
process.mainModule = new Module(uri, null, ".");
nativeModuleCache["."] = process.mainModule;
loadModule(process.mainModule, function (er) {
if (er) throw er;
});
Expand Down Expand Up @@ -260,7 +264,8 @@ function Module (uri, parent, id) {
// bind require's context
var self = this;
this.require = function (id) { return require(id, self) };
this.require.main = process.mainModule;
Object.defineProperty(this.require, "main",
{ get : function () { return process.mainModule }});
this.require.async = function (id, cb) { return require(id, self, cb || noop) };
Object.defineProperty(this.require, "paths",
{ set : function (newPaths) { exports.paths = newPaths }
Expand Down

0 comments on commit a4d8fdc

Please sign in to comment.