Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added errors if the module was not found

  • Loading branch information...
commit 0bd7aeec95498b594b9710b66cf761385376e8ee 1 parent 044e0cf
= authored
Showing with 26 additions and 4 deletions.
  1. +12 −3 lib/main.js
  2. +1 −1  package.json
  3. +13 −0 test/rekuire.spec.js
View
15 lib/main.js
@@ -20,20 +20,29 @@ if(!scanned) { scan(baseDir); }
function rekuire(requirement){
var calleePath = path.dirname(module.parent.filename);
var retModule = null;
+ var error = "";
var requirementjs = requirement.toLowerCase().substr(-3,3) === '.js' ? requirement : requirement+".js";
if ( filesInProject[requirementjs] !== undefined){
retModule = require(filesInProject[requirementjs]);
}else{
+ var modulePath = path.normalize(calleePath+"/"+requirement);
try{
- retModule = require( path.normalize(calleePath+"/"+requirement));
- }catch(e){}
+ retModule = require(modulePath);
+ }catch(e){
+ error += e +"\n";
+ }
if (retModule === null){
try{
retModule = require(requirement);
- }catch(e){}
+ }catch(e){
+ error += e +"\n";
+ }
}
}
+ if(!retModule){
+ throw error;
+ }
return retModule;
}
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "rekuire",
- "version": "0.0.2",
+ "version": "0.0.3",
"description": "'rekuire' is basically node's 'require' without the relative paths",
"repository": {
"type": "git",
View
13 test/rekuire.spec.js
@@ -62,6 +62,19 @@ describe("Testing 'rekuire'",function(){
expect(fse).not.toBeNull();
})
});
+
+ it("should throw an error if not found", function(){
+ runs(function(){
+ var rekuire = require('rekuire');
+ var error = null;
+ try{
+ rekuire('no-such-package');
+ }catch(e){
+ error = e;
+ }
+ expect(error).not.toBeNull();
+ });
+ })
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.