8000 fix(core): handle .nxignore properly for the native hasher (#15420) · nrwl/nx@87b1a73 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87b1a73

Browse files
CammisuliFrozenPandaz
authored andcommitted
fix(core): handle .nxignore properly for the native hasher (#15420)
(cherry picked from commit b0ab036)
1 parent ee0c88f commit 87b1a73

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

packages/nx/src/native/native_hasher.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ fn hash_file(file: String) -> Option<FileData> {
2828

2929
#[napi]
3030
fn hash_files(workspace_root: String) -> HashMap<String, String> {
31-
let mut walker = WalkBuilder::new(&workspace_root);
3231
let workspace_root = Path::new(&workspace_root);
33-
walker.add_ignore(workspace_root.join(".nxignore"));
34-
32+
let nx_ignore = workspace_root.join(".nxignore");
3533
let git_folder = workspace_root.join(".git");
36-
// We should make sure to always ignore node_modules
3734
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
3841
walker.filter_entry(move |entry| {
3942
!(entry.path().starts_with(&git_folder) || entry.path().starts_with(&node_folder))
4043
});
4144

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>)>();
4646

4747
let receiver_thread = thread::spawn(move || {
4848
let mut collection: HashMap<String, String> = HashMap::new();
49-
for (path, content) in reciever {
49+
for (path, content) in receiver {
5050
collection.insert(path, xxh3::xxh3_64(&content).to_string());
5151
}
5252
collection
@@ -56,7 +56,6 @@ fn hash_files(workspace_root: String) -> HashMap<String, String> {
5656

5757
walker.threads(cpus).build_parallel().run(|| {
5858
let tx = sender.clone();
59-
let workspace_root = workspace_root.clone();
6059
Box::new(move |entry| {
6160
use ignore::WalkState::*;
6261

@@ -69,7 +68,7 @@ fn hash_files(workspace_root: String) -> HashMap<String, String> {
6968
return Continue;
7069
};
7170

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 {
7372
return Continue;
7473
};
7574

@@ -155,18 +154,33 @@ mod tests {
155154
fn handles_nx_ignore() {
156155
let temp_dir = setup_fs();
157156

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+
158167
// 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();
160177

161178
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();
162181
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")
170184
);
171185
}
172186
}

0 commit comments

Comments
 (0)
0