@@ -303,11 +303,11 @@ module.exports = function resolve(x, options, callback) {
303
303
} ) ;
304
304
}
305
305
306
- function processDirs ( cb , dirs , subpath ) {
306
+ function processDirs ( cb , dirs , subpath , endsWithSubpath ) {
307
307
if ( dirs . length === 0 ) return cb ( null , undefined ) ;
308
308
var dir = dirs [ 0 ] ;
309
309
310
- if ( env . length > 0 && dir . substring ( dir . length - subpath . length ) === subpath ) {
310
+ if ( env . length > 0 && endsWithSubpath ( dir ) ) {
311
311
var pkgDir = dir . substring ( 0 , dir . length - subpath . length ) ;
312
312
loadManifestInDir ( pkgDir , onmanifestWithExports ) ;
313
313
} else {
@@ -337,21 +337,21 @@ module.exports = function resolve(x, options, callback) {
337
337
338
338
function isdir ( err , isdir ) {
339
339
if ( err ) return cb ( err ) ;
340
- if ( ! isdir ) return processDirs ( cb , dirs . slice ( 1 ) , subpath ) ;
340
+ if ( ! isdir ) return processDirs ( cb , dirs . slice ( 1 ) , subpath , endsWithSubpath ) ;
341
341
loadAsFile ( dir , opts . package , onfile ) ;
342
342
}
343
343
344
344
function onfile ( err , m , pkg ) {
345
345
if ( err ) return cb ( err ) ;
346
346
if ( m ) return cb ( null , m , pkg ) ;
347
- if ( ! tryLoadAsDirectory ) return processDirs ( cb , dirs . slice ( 1 ) , subpath ) ;
347
+ if ( ! tryLoadAsDirectory ) return processDirs ( cb , dirs . slice ( 1 ) , subpath , endsWithSubpath ) ;
348
348
loadAsDirectory ( dir , opts . package , ondir ) ;
349
349
}
350
350
351
351
function ondir ( err , n , pkg ) {
352
352
if ( err ) return cb ( err ) ;
353
353
if ( n ) return cb ( null , n , pkg ) ;
354
- processDirs ( cb , dirs . slice ( 1 ) , subpath ) ;
354
+ processDirs ( cb , dirs . slice ( 1 ) , subpath , endsWithSubpath ) ;
355
355
}
356
356
}
357
357
@@ -369,10 +369,16 @@ module.exports = function resolve(x, options, callback) {
369
369
}
370
370
371
371
var thunk = function ( ) { return getPackageCandidates ( x , start , opts ) ; } ;
372
+ var endsWithSubpath = function ( dir ) {
373
+ var endOfDir = dir . substring ( dir . length - subpath . length ) ;
374
+
375
+ return endOfDir === subpath || endOfDir . replace ( / \\ / g, '/' ) === subpath ;
376
+ }
372
377
processDirs (
373
378
cb ,
374
379
packageIterator ? packageIterator ( x , start , thunk , opts ) : thunk ( ) ,
375
- subpath
380
+ subpath ,
381
+ endsWithSubpath
376
382
) ;
377
383
}
378
384
} ;
0 commit comments