@@ -12,62 +12,64 @@ const IGNORE_PATH_PREFIX: &str = "_";
1212/// It uses glob patterns to detect the workers and
1313/// provide utilities to work with public folders and
1414/// other related resources.
15- pub struct Files {
15+ pub struct Files < ' t > {
1616 /// Root path
1717 root : PathBuf ,
1818 /// Defines pattern for files considered as workers
19- include_pattern : String ,
19+ include_pattern : Glob < ' t > ,
2020 /// Defines patterns to exclude when traversing for workers
21- ignore_patterns : Vec < String > ,
21+ ignore_patterns : Vec < Glob < ' t > > ,
2222}
2323
24- impl Files {
24+ impl < ' t > Files < ' t > {
25+ const PUBLIC_ASSETS_FOLDER : & str = "public" ;
2526 const DEFAULT_EXTENSIONS : [ & str ; 2 ] = [ "js" , "wasm" ] ;
2627
2728 /// Initializes a new files instance. It will detect
2829 /// relevant resources for WWS like the public folder.
2930 pub fn new ( root : & Path , file_extensions : Vec < String > , ignore_patterns : Vec < String > ) -> Self {
3031 Self {
3132 root : root. to_path_buf ( ) ,
32- include_pattern : Self :: construct_include_pattern ( file_extensions) ,
33- ignore_patterns : Self :: construct_ignore_patterns ( ignore_patterns) ,
33+ include_pattern : Self :: build_include_pattern ( file_extensions) ,
34+ ignore_patterns : Self :: build_ignore_patterns ( ignore_patterns) ,
3435 }
3536 }
3637
3738 /// Walk through all the different files associated to this
3839 /// project using a Glob pattern
3940 pub fn walk ( & self ) -> Vec < WalkEntry > {
40- let include_pattern = Glob :: from_str ( self . include_pattern . as_str ( ) ) . expect (
41- "Failed to parse include pattern when processing files in the current directory" ,
42- ) ;
43-
44- return include_pattern
41+ return self
42+ . include_pattern
4543 . walk ( & self . root )
46- . not ( self . ignore_patterns . iter ( ) . map ( |s| s. as_str ( ) ) )
47- . expect (
48- "Failed to parse ignore patterns when processing files in the current directory" ,
49- )
44+ . not ( self . ignore_patterns . clone ( ) )
45+ . expect ( "Failed to walk the tree when processing files in the current directory" )
5046 . map ( |e| e. unwrap ( ) )
5147 . collect ( ) ;
5248 }
5349
54- fn construct_include_pattern ( file_extensions : Vec < String > ) -> String {
50+ fn build_include_pattern ( file_extensions : Vec < String > ) -> Glob < ' t > {
5551 let mut file_extensions = file_extensions;
5652 for default_extension in Self :: DEFAULT_EXTENSIONS {
5753 file_extensions. push ( default_extension. to_string ( ) ) ;
5854 }
5955
60- format ! ( "**/*.{{{}}}" , file_extensions. join( "," ) )
56+ let include_pattern = format ! ( "**/*.{{{}}}" , file_extensions. join( "," ) ) ;
57+ Glob :: from_str ( include_pattern. as_str ( ) ) . expect ( "Failed to parse include pattern!" )
6158 }
6259
63- fn construct_ignore_patterns ( ignore_patterns : Vec < String > ) -> Vec < String > {
64- let mut result = vec ! [
65- "**/public /**" . to_string ( ) ,
60+ fn build_ignore_patterns ( ignore_patterns : Vec < String > ) -> Vec < Glob < ' t > > {
61+ let default_ignore_patterns = vec ! [
62+ format! ( "**/{} /**" , Self :: PUBLIC_ASSETS_FOLDER ) ,
6663 format!( "**/{}/**" , STORE_FOLDER ) ,
6764 format!( "**/{}*/**" , IGNORE_PATH_PREFIX ) ,
6865 ] ;
66+
67+ let mut result = default_ignore_patterns;
6968 result. extend ( ignore_patterns) ;
7069 result
70+ . iter ( )
71+ . map ( |s| Glob :: from_str ( s. as_str ( ) ) . expect ( "Failed to parse ignore pattern" ) )
72+ . collect ( )
7173 }
7274}
7375
@@ -177,7 +179,7 @@ mod tests {
177179 }
178180
179181 #[ test]
180- fn walk_ignore2 ( ) {
182+ fn walk_ignore_multiple_patterns ( ) {
181183 let files = Files :: new (
182184 Path :: new ( "tests/data/files" ) ,
183185 vec ! [ "ext" . to_string( ) , "none" . to_string( ) ] ,
0 commit comments