Skip to content

Commit

Permalink
fixed a bug causing to fail rekuiring coffee files without extensions…
Browse files Browse the repository at this point in the history
… specified
  • Loading branch information
nadav-dav committed Aug 9, 2013
1 parent a16fe11 commit 759d492
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
13 changes: 3 additions & 10 deletions lib/main.js
Expand Up @@ -49,16 +49,14 @@ function getModule(requirement){
var modulePath = null;
var error = "";

var requirementJs = hasKnownExtension( requirement ) ? requirement : requirement+".js";

if (ambiguousFileNames[requirement] !== undefined){
throw new Error('Ambiguity Error: There are more then one files that is named '+requirement);
}

if ( filesInProject[requirementJs] !== undefined){
if ( filesInProject[requirement] !== undefined){
// User typed in a relative path
retModule = parentReq(filesInProject[requirementJs]);
modulePath = filesInProject[requirementJs];
retModule = parentReq(filesInProject[requirement]);
modulePath = filesInProject[requirement];
}else{
// User typed in a module name
modulePath = path.normalize(calleePath+"/"+requirement);
Expand All @@ -84,8 +82,3 @@ function getModule(requirement){
}
return { module: retModule, path: modulePath};
}

function hasKnownExtension( requirement ){
return requirement.toLowerCase().match( new RegExp( extensions.join( "|" ) + "$" ) );
}

8 changes: 8 additions & 0 deletions test/rekuire.spec.js
Expand Up @@ -55,6 +55,14 @@ describe("Testing 'rekuire'",function(){
expect(imported).toEqual({"someKey":"someValue"});
});

it("should retrieve it according to the file name (*.coffee)",function(){
var rek = require('rekuire');
var withExt = rek('cup.coffee');
var withoutExt = rek('cup');
expect(withExt ).toEqual("cup of coffee")
expect(withExt ).toEqual(withoutExt );
});

it("should get module by name even if extension not present",function(){
var rek = require('rekuire');
var jsModule = rek('someModule');
Expand Down
1 change: 1 addition & 0 deletions test/testResources/nestedPackage/cup.coffee
@@ -0,0 +1 @@
module.exports = "cup of coffee"

0 comments on commit 759d492

Please sign in to comment.