diff --git a/packages/hot-reload/src/lib.rs b/packages/hot-reload/src/lib.rs index 1ddd32bb1..20cc70a9a 100644 --- a/packages/hot-reload/src/lib.rs +++ b/packages/hot-reload/src/lib.rs @@ -129,9 +129,30 @@ pub fn init(cfg: Config) { } = cfg; if let Ok(crate_dir) = PathBuf::from_str(root_path) { + // try to find the gitingore file + let gitignore_file_path = crate_dir.join(".gitignore"); + let (gitignore, _) = ignore::gitignore::Gitignore::new(gitignore_file_path); + + // convert the excluded paths to absolute paths + let excluded_paths = excluded_paths + .iter() + .map(|path| crate_dir.join(PathBuf::from(path))) + .collect::>(); + let temp_file = std::env::temp_dir().join("@dioxusin"); let channels = Arc::new(Mutex::new(Vec::new())); - let file_map = Arc::new(Mutex::new(FileMap::::new(crate_dir.clone()))); + let file_map = Arc::new(Mutex::new(FileMap::::new_with_filter( + crate_dir.clone(), + |path| { + // skip excluded paths + excluded_paths.iter().any(|p| path.starts_with(p)) || + // respect .gitignore + gitignore + .matched_path_or_any_parents(path, path.is_dir()) + .is_ignore() + }, + ))); + if let Ok(local_socket_stream) = LocalSocketListener::bind(temp_file.as_path()) { let aborted = Arc::new(Mutex::new(false)); @@ -177,10 +198,6 @@ pub fn init(cfg: Config) { // watch for changes std::thread::spawn(move || { - // try to find the gitingore file - let gitignore_file_path = crate_dir.join(".gitignore"); - let (gitignore, _) = ignore::gitignore::Gitignore::new(gitignore_file_path); - let mut last_update_time = chrono::Local::now().timestamp(); let (tx, rx) = std::sync::mpsc::channel(); @@ -198,11 +215,6 @@ pub fn init(cfg: Config) { } } - let excluded_paths = excluded_paths - .iter() - .map(|path| crate_dir.join(PathBuf::from(path))) - .collect::>(); - let mut rebuild = { let aborted = aborted.clone(); let channels = channels.clone(); @@ -242,7 +254,7 @@ pub fn init(cfg: Config) { matches!( path.extension().and_then(|p| p.to_str()), Some("rs" | "toml" | "css" | "html" | "js") - )&& + ) && // skip excluded paths !excluded_paths.iter().any(|p| path.starts_with(p)) && // respect .gitignore diff --git a/packages/rsx/src/hot_reload/hot_reloading_file_map.rs b/packages/rsx/src/hot_reload/hot_reloading_file_map.rs index be4f5d828..156d64ce4 100644 --- a/packages/rsx/src/hot_reload/hot_reloading_file_map.rs +++ b/packages/rsx/src/hot_reload/hot_reloading_file_map.rs @@ -25,14 +25,22 @@ pub struct FileMap { impl FileMap { /// Create a new FileMap from a crate directory pub fn new(path: PathBuf) -> Self { + Self::new_with_filter(path, |_| false) + } + + /// Create a new FileMap from a crate directory + pub fn new_with_filter(path: PathBuf, mut filter: impl FnMut(&Path) -> bool) -> Self { fn find_rs_files( root: PathBuf, + filter: &mut impl FnMut(&Path) -> bool, ) -> io::Result>)>> { let mut files = HashMap::new(); if root.is_dir() { for entry in (fs::read_dir(root)?).flatten() { let path = entry.path(); - files.extend(find_rs_files(path)?); + if !filter(&path) { + files.extend(find_rs_files(path, filter)?); + } } } else if root.extension().and_then(|s| s.to_str()) == Some("rs") { if let Ok(mut file) = File::open(root.clone()) { @@ -45,7 +53,7 @@ impl FileMap { } let result = Self { - map: find_rs_files(path).unwrap(), + map: find_rs_files(path, &mut filter).unwrap(), phantom: std::marker::PhantomData, }; result