@@ -37,7 +37,7 @@ module.exports = function resolve (x, opts, cb) {
37
37
loadAsFile ( res , opts . package , function ( err , m , pkg ) {
38
38
if ( err ) cb ( err )
39
39
else if ( m ) cb ( null , m , pkg )
40
- else loadAsDirectory ( path . resolve ( y , x ) , function ( err , d , pkg ) {
40
+ else loadAsDirectory ( res , function ( err , d , pkg ) {
41
41
if ( err ) cb ( err )
42
42
else if ( d ) cb ( null , d , pkg )
43
43
else cb ( new Error ( "Cannot find module '" + x + "' from '" + y + "'" ) )
@@ -51,20 +51,21 @@ module.exports = function resolve (x, opts, cb) {
51
51
else cb ( new Error ( "Cannot find module '" + x + "' from '" + y + "'" ) )
52
52
} ) ;
53
53
54
- function loadAsFile ( x , pkg , cb ) {
54
+ function loadAsFile ( x , pkg , cb , again ) {
55
55
if ( typeof pkg === 'function' ) {
56
56
cb = pkg ;
57
57
pkg = undefined ;
58
58
}
59
59
60
60
var exts = [ '' ] . concat ( extensions ) ;
61
61
62
- if ( x === y ) {
63
- return loadAsDirectory ( y , pkg , cb ) ;
64
- }
65
- else {
66
- return load ( exts , x , pkg ) ;
62
+ if ( x === y && ! again ) {
63
+ loadAsDirectory ( y , pkg , function ( err , d , pkg ) {
64
+ if ( d ) cb ( err , d , pkg )
65
+ else loadAsFile ( x , pkg , cb , true )
66
+ } ) ;
67
67
}
68
+ else load ( exts , x , pkg )
68
69
69
70
function load ( exts , x , pkg ) {
70
71
if ( exts . length === 0 ) return cb ( null , undefined , pkg ) ;
0 commit comments