File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -1173,11 +1173,11 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
11731173 }
11741174 }
11751175 // Bail if path is module directory such as `ipaddr.js`
1176- if !cached_path. is_file ( & self . cache . fs , ctx) . await {
1176+ if !cached_path. is_file ( & self . cache . fs , ctx) . await
1177+ || !self . check_restrictions ( cached_path. path ( ) )
1178+ {
11771179 ctx. with_fully_specified ( false ) ;
11781180 return Ok ( None ) ;
1179- } else if !self . check_restrictions ( cached_path. path ( ) ) {
1180- return Ok ( None ) ;
11811181 }
11821182 // Create a meaningful error message.
11831183 let dir = path. parent ( ) . unwrap ( ) . to_path_buf ( ) ;
Original file line number Diff line number Diff line change @@ -91,3 +91,22 @@ async fn should_try_to_find_alternative_3() {
9191 let resolution = resolver1. resolve ( & f, "pck2" ) . await . map ( |r| r. full_path ( ) ) ;
9292 assert_eq ! ( resolution, Ok ( f. join( "node_modules/pck2/index.css" ) ) ) ;
9393}
94+
95+ #[ tokio:: test]
96+ async fn should_try_to_find_alternative_4 ( ) {
97+ let f = super :: fixture ( ) . join ( "restrictions" ) ;
98+
99+ let re = Regex :: new ( r"\.(sass|scss|css)$" ) . unwrap ( ) ;
100+ let resolver1 = Resolver :: new ( ResolveOptions {
101+ extensions : vec ! [ ".css" . into( ) ] ,
102+ main_fields : vec ! [ "main" . into( ) ] ,
103+ extension_alias : vec ! [ ( ".js" . into( ) , vec![ ".js" . into( ) , ".jsx" . into( ) ] ) ] ,
104+ restrictions : vec ! [ Restriction :: Fn ( Arc :: new( move |path| {
105+ path. as_os_str( ) . to_str( ) . map_or( false , |s| re. is_match( s) )
106+ } ) ) ] ,
107+ ..ResolveOptions :: default ( )
108+ } ) ;
109+
110+ let resolution = resolver1. resolve ( & f, "pck2" ) . await . map ( |r| r. full_path ( ) ) ;
111+ assert_eq ! ( resolution, Ok ( f. join( "node_modules/pck2/index.css" ) ) ) ;
112+ }
You can’t perform that action at this time.
0 commit comments