Permalink
Browse files

Handle node's .node files

Let require errors for non-missing files pass through
  • Loading branch information...
1 parent e095507 commit c0f3f9fd86600cc64eb4078a4ad8d848357ab4c9 @kriszyp committed Jul 15, 2010
Showing with 14 additions and 1 deletion.
  1. +14 −1 lib/nodules.js
View
@@ -231,7 +231,10 @@ function makeRequire(currentId){
try{
return moduleExports[id] || defaultRequire(id);
}catch(e){
- throw new Error("Can not find module " + uri);
+ if(e.message.substring(0,19) == "Can not find module"){
+ throw new Error("Can not find module " + uri);
+ }
+ throw e;
}
};
require.main = main;
@@ -280,6 +283,7 @@ function makeRequire(currentId){
createFactory(uri, rewrittenSource);
deferred.resolve();
}catch(e){
+ e.message += " compiling " + uri;
deferred.reject(e);
}
});
@@ -635,6 +639,15 @@ function readModuleFile(path, uri){
});
}
}
+ }, function(e){
+ if(path.match(/\.js$/)){
+ path = path.replace(/\.js$/,".node");
+ return promiseReadFileSync(path).then(function(){
+ return 'process.dlopen("' + path + '", exports);';
+ }, function(){
+ throw e;
+ });
+ }
});
}
function cachePath(uri){

0 comments on commit c0f3f9f

Please sign in to comment.