Skip to content

Commit

Permalink
feat: add regexes from node_modules watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinbao1001 committed Jul 23, 2024
1 parent e8a1748 commit 85d12f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/mako/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ pub struct ExperimentalConfig {
#[serde(rename_all = "camelCase")]
pub struct WatchConfig {
pub ignore_paths: Vec<String>,
pub node_modules_regexes: Vec<String>,
}

#[derive(Deserialize, Serialize, Debug)]
Expand Down Expand Up @@ -719,7 +720,7 @@ const DEFAULT_CONFIG: &str = r#"
},
"useDefineForClassFields": true,
"emitDecoratorMetadata": false,
"watch": { "ignorePaths": [] },
"watch": { "ignorePaths": [], "nodeModulesRegexes": [] },
"devServer": { "host": "127.0.0.1", "port": 3000 }
}
"#;
Expand Down
14 changes: 14 additions & 0 deletions crates/mako/src/dev/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anyhow::{self, Ok};
use colored::Colorize;
use notify::{self, EventKind, Watcher as NotifyWatcher};
use notify_debouncer_full::DebouncedEvent;
use regex::Regex;
use tracing::debug;

use crate::compiler::Compiler;
Expand Down Expand Up @@ -57,6 +58,19 @@ impl<'a> Watcher<'a> {
dirs.insert(dir);
}
}
let node_modules_regexes = &self.compiler.context.config.watch.node_modules_regexes;
if !node_modules_regexes.is_empty() {
let regexes = node_modules_regexes.iter().map(|s| Regex::new(s).unwrap());
let is_match = regexes
.into_iter()
.any(|regex| regex.is_match(resource.0.path().to_str().unwrap()));
if is_match {
let _ = self.watcher.watch(
resource.0.path().to_path_buf().as_path(),
notify::RecursiveMode::NonRecursive,
);
}
}
}
});
dirs.iter().try_for_each(|dir| {
Expand Down

0 comments on commit 85d12f5

Please sign in to comment.