@@ -34,15 +34,10 @@ module.exports = function resolve (x, opts, cb) {
34
34
if ( / ^ (?: \. \. ? (?: \/ | $ ) | \/ | ( [ A - Z a - z ] : ) ? [ \\ \/ ] ) / . test ( x ) ) {
35
35
var res = path . resolve ( y , x ) ;
36
36
if ( x === '..' ) res += '/' ;
37
- loadAsFile ( res , opts . package , function ( err , m , pkg ) {
38
- if ( err ) cb ( err )
39
- else if ( m ) cb ( null , m , pkg )
40
- else loadAsDirectory ( res , function ( err , d , pkg ) {
41
- if ( err ) cb ( err )
42
- else if ( d ) cb ( null , d , pkg )
43
- else cb ( new Error ( "Cannot find module '" + x + "' from '" + y + "'" ) )
44
- } )
45
- } ) ;
37
+ if ( / \/ $ / . test ( x ) && res === y ) {
38
+ loadAsDirectory ( res , opts . package , onfile ) ;
39
+ }
40
+ else loadAsFile ( res , opts . package , onfile ) ;
46
41
}
47
42
else loadNodeModules ( x , y , function ( err , n , pkg ) {
48
43
if ( err ) cb ( err )
@@ -51,21 +46,24 @@ module.exports = function resolve (x, opts, cb) {
51
46
else cb ( new Error ( "Cannot find module '" + x + "' from '" + y + "'" ) )
52
47
} ) ;
53
48
54
- function loadAsFile ( x , pkg , cb , again ) {
49
+ function onfile ( err , m , pkg ) {
50
+ if ( err ) cb ( err )
51
+ else if ( m ) cb ( null , m , pkg )
52
+ else loadAsDirectory ( res , function ( err , d , pkg ) {
53
+ if ( err ) cb ( err )
54
+ else if ( d ) cb ( null , d , pkg )
55
+ else cb ( new Error ( "Cannot find module '" + x + "' from '" + y + "'" ) )
56
+ } )
57
+ }
58
+
59
+ function loadAsFile ( x , pkg , cb ) {
55
60
if ( typeof pkg === 'function' ) {
56
61
cb = pkg ;
57
62
pkg = undefined ;
58
63
}
59
64
60
65
var exts = [ '' ] . concat ( extensions ) ;
61
-
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
- }
68
- else load ( exts , x , pkg )
66
+ load ( exts , x , pkg )
69
67
70
68
function load ( exts , x , pkg ) {
71
69
if ( exts . length === 0 ) return cb ( null , undefined , pkg ) ;
0 commit comments