@@ -28,25 +28,25 @@ fn hash_file(file: String) -> Option<FileData> {
28
28
29
29
#[ napi]
30
30
fn hash_files ( workspace_root : String ) -> HashMap < String , String > {
31
- let mut walker = WalkBuilder :: new ( & workspace_root) ;
32
31
let workspace_root = Path :: new ( & workspace_root) ;
33
- walker. add_ignore ( workspace_root. join ( ".nxignore" ) ) ;
34
-
32
+ let nx_ignore = workspace_root. join ( ".nxignore" ) ;
35
33
let git_folder = workspace_root. join ( ".git" ) ;
36
- // We should make sure to always ignore node_modules
37
34
let node_folder = workspace_root. join ( "node_modules" ) ;
35
+
36
+ let mut walker = WalkBuilder :: new ( & workspace_root) ;
37
+ walker. hidden ( false ) ;
38
+ walker. add_custom_ignore_filename ( & nx_ignore) ;
39
+
40
+ // We should make sure to always ignore node_modules and the .git folder
38
41
walker. filter_entry ( move |entry| {
39
42
!( entry. path ( ) . starts_with ( & git_folder) || entry. path ( ) . starts_with ( & node_folder) )
40
43
} ) ;
41
44
42
- // dot files are hidden by default. We want to make sure we include those here
43
- walker. hidden ( false ) ;
44
-
45
- let ( sender, reciever) = unbounded :: < ( String , Vec < u8 > ) > ( ) ;
45
+ let ( sender, receiver) = unbounded :: < ( String , Vec < u8 > ) > ( ) ;
46
46
47
47
let receiver_thread = thread:: spawn ( move || {
48
48
let mut collection: HashMap < String , String > = HashMap :: new ( ) ;
49
- for ( path, content) in reciever {
49
+ for ( path, content) in receiver {
50
50
collection. insert ( path, xxh3:: xxh3_64 ( & content) . to_string ( ) ) ;
51
51
}
52
52
collection
@@ -56,7 +56,6 @@ fn hash_files(workspace_root: String) -> HashMap<String, String> {
56
56
57
57
walker. threads ( cpus) . build_parallel ( ) . run ( || {
58
58
let tx = sender. clone ( ) ;
59
- let workspace_root = workspace_root. clone ( ) ;
60
59
Box :: new ( move |entry| {
61
60
use ignore:: WalkState :: * ;
62
61
@@ -69,7 +68,7 @@ fn hash_files(workspace_root: String) -> HashMap<String, String> {
69
68
return Continue ;
70
69
} ;
71
70
72
- let Ok ( file_path) = dir_entry. path ( ) . strip_prefix ( & workspace_root) else {
71
+ let Ok ( file_path) = dir_entry. path ( ) . strip_prefix ( workspace_root) else {
73
72
return Continue ;
74
73
} ;
75
74
@@ -155,18 +154,33 @@ mod tests {
155
154
fn handles_nx_ignore ( ) {
156
155
let temp_dir = setup_fs ( ) ;
157
156
157
+ temp_dir
158
+ . child ( "nested" )
159
+ . child ( "child.txt" )
160
+ . write_str ( "data" ) ;
161
+ temp_dir
162
+ . child ( "nested" )
163
+ . child ( "child-two" )
164
+ . child ( "grand_child.txt" )
165
+ . write_str ( "data" ) ;
166
+
158
167
// add nxignore file with baz/
159
- temp_dir. child ( ".nxignore" ) . write_str ( "baz/" ) . unwrap ( ) ;
168
+ temp_dir
169
+ . child ( ".nxignore" )
170
+ . write_str (
171
+ r"baz/
172
+ nested/child.txt
173
+ nested/child-two/
174
+ " ,
175
+ )
176
+ . unwrap ( ) ;
160
177
161
178
let content = hash_files ( temp_dir. display ( ) . to_string ( ) ) ;
179
+ let mut file_names = content. iter ( ) . map ( |c| c. 0 ) . collect :: < Vec < _ > > ( ) ;
180
+ file_names. sort ( ) ;
162
181
assert_eq ! (
163
- content,
164
- HashMap :: from( [
165
- ( "foo.txt" . into( ) , "8455857314690418558" . into( ) ) ,
166
- ( "test.txt" . into( ) , "6193209363630369380" . into( ) ) ,
167
- ( "bar.txt" . into( ) , "1707056588989152788" . into( ) ) ,
168
- ( ".nxignore" . into( ) , "5786346484289078730" . into( ) )
169
- ] )
182
+ file_names,
183
+ vec!( ".nxignore" , "bar.txt" , "foo.txt" , "test.txt" )
170
184
) ;
171
185
}
172
186
}
0 commit comments