@@ -303,11 +303,11 @@ module.exports = function resolve(x, options, callback) {
303303 } ) ;
304304 }
305305
306- function processDirs ( cb , dirs , subpath ) {
306+ function processDirs ( cb , dirs , subpath , endsWithSubpath ) {
307307 if ( dirs . length === 0 ) return cb ( null , undefined ) ;
308308 var dir = dirs [ 0 ] ;
309309
310- if ( env . length > 0 && dir . substring ( dir . length - subpath . length ) === subpath ) {
310+ if ( env . length > 0 && endsWithSubpath ( dir ) ) {
311311 var pkgDir = dir . substring ( 0 , dir . length - subpath . length ) ;
312312 loadManifestInDir ( pkgDir , onmanifestWithExports ) ;
313313 } else {
@@ -337,21 +337,21 @@ module.exports = function resolve(x, options, callback) {
337337
338338 function isdir ( err , isdir ) {
339339 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 ) ;
341341 loadAsFile ( dir , opts . package , onfile ) ;
342342 }
343343
344344 function onfile ( err , m , pkg ) {
345345 if ( err ) return cb ( err ) ;
346346 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 ) ;
348348 loadAsDirectory ( dir , opts . package , ondir ) ;
349349 }
350350
351351 function ondir ( err , n , pkg ) {
352352 if ( err ) return cb ( err ) ;
353353 if ( n ) return cb ( null , n , pkg ) ;
354- processDirs ( cb , dirs . slice ( 1 ) , subpath ) ;
354+ processDirs ( cb , dirs . slice ( 1 ) , subpath , endsWithSubpath ) ;
355355 }
356356 }
357357
@@ -369,10 +369,16 @@ module.exports = function resolve(x, options, callback) {
369369 }
370370
371371 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+ }
372377 processDirs (
373378 cb ,
374379 packageIterator ? packageIterator ( x , start , thunk , opts ) : thunk ( ) ,
375- subpath
380+ subpath ,
381+ endsWithSubpath
376382 ) ;
377383 }
378384} ;
0 commit comments