@@ -510,9 +510,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
510510 // 2. If X.js is a file, load X.js as JavaScript text. STOP
511511 // 3. If X.json is a file, parse X.json to a JavaScript Object. STOP
512512 // 4. If X.node is a file, load X.node as binary addon. STOP
513- if let Some ( path) =
514- self . load_extensions ( cached_path. path ( ) , & self . options . extensions , ctx) ?
515- {
513+ if let Some ( path) = self . load_extensions ( cached_path, & self . options . extensions , ctx) ? {
516514 return Ok ( Some ( path) ) ;
517515 }
518516 Ok ( None )
@@ -571,11 +569,16 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
571569 Ok ( None )
572570 }
573571
574- fn load_extensions ( & self , path : & Path , extensions : & [ String ] , ctx : & mut Ctx ) -> ResolveResult {
572+ fn load_extensions (
573+ & self ,
574+ path : & CachedPath ,
575+ extensions : & [ String ] ,
576+ ctx : & mut Ctx ,
577+ ) -> ResolveResult {
575578 if ctx. fully_specified {
576579 return Ok ( None ) ;
577580 }
578- let path = path. as_os_str ( ) ;
581+ let path = path. path ( ) . as_os_str ( ) ;
579582 for extension in extensions {
580583 let mut path_with_extension = path. to_os_string ( ) ;
581584 path_with_extension. reserve_exact ( extension. len ( ) ) ;
@@ -637,9 +640,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
637640 // 1. If X/index.js is a file, load X/index.js as JavaScript text. STOP
638641 // 2. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP
639642 // 3. If X/index.node is a file, load X/index.node as binary addon. STOP
640- if let Some ( path) =
641- self . load_extensions ( cached_path. path ( ) , & self . options . extensions , ctx) ?
642- {
643+ if let Some ( path) = self . load_extensions ( & cached_path, & self . options . extensions , ctx) ? {
643644 return Ok ( Some ( path) ) ;
644645 }
645646 }
@@ -972,7 +973,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
972973 Ok ( None )
973974 }
974975
975- /// Given an extension alias map `{".js": [".ts", "js"]}`,
976+ /// Given an extension alias map `{".js": [".ts", ". js"]}`,
976977 /// load the mapping instead of the provided extension
977978 ///
978979 /// This is an enhanced-resolve feature
@@ -996,11 +997,24 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
996997 return Ok ( None ) ;
997998 } ;
998999 let path = cached_path. path ( ) . with_extension ( "" ) ;
999- ctx. with_fully_specified ( false ) ;
1000- if let Some ( path) = self . load_extensions ( & path, extensions, ctx) ? {
1001- return Ok ( Some ( path) ) ;
1000+ let path = path. as_os_str ( ) ;
1001+ ctx. with_fully_specified ( true ) ;
1002+ for extension in extensions {
1003+ let mut path_with_extension = path. to_os_string ( ) ;
1004+ path_with_extension. reserve_exact ( extension. len ( ) ) ;
1005+ path_with_extension. push ( extension) ;
1006+ let cached_path = self . cache . value ( Path :: new ( & path_with_extension) ) ;
1007+ // Bail if path is module directory such as `ipaddr.js`
1008+ if cached_path. is_dir ( & self . cache . fs , ctx) {
1009+ ctx. with_fully_specified ( false ) ;
1010+ return Ok ( None ) ;
1011+ }
1012+ if let Some ( path) = self . load_alias_or_file ( & cached_path, ctx) ? {
1013+ ctx. with_fully_specified ( false ) ;
1014+ return Ok ( Some ( path) ) ;
1015+ }
10021016 }
1003- Err ( ResolveError :: ExtensionAlias )
1017+ Err ( ResolveError :: ExtensionAlias ( cached_path . to_path_buf ( ) ) )
10041018 }
10051019
10061020 /// enhanced-resolve: RootsPlugin
0 commit comments