From 85d12f57f932241e8d14f71bd91ca68f6cec04aa Mon Sep 17 00:00:00 2001 From: Jinbao1001 Date: Tue, 23 Jul 2024 14:23:01 +0800 Subject: [PATCH] feat: add regexes from node_modules watch --- crates/mako/src/config/config.rs | 3 ++- crates/mako/src/dev/watch.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/mako/src/config/config.rs b/crates/mako/src/config/config.rs index 2ac6601ce..08f38c126 100644 --- a/crates/mako/src/config/config.rs +++ b/crates/mako/src/config/config.rs @@ -446,6 +446,7 @@ pub struct ExperimentalConfig { #[serde(rename_all = "camelCase")] pub struct WatchConfig { pub ignore_paths: Vec, + pub node_modules_regexes: Vec, } #[derive(Deserialize, Serialize, Debug)] @@ -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 } } "#; diff --git a/crates/mako/src/dev/watch.rs b/crates/mako/src/dev/watch.rs index 108d13b62..d7816569e 100644 --- a/crates/mako/src/dev/watch.rs +++ b/crates/mako/src/dev/watch.rs @@ -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; @@ -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| {