Skip to content

Commit

Permalink
fix: watch files change of module_graph in node_modules (#1385)
Browse files Browse the repository at this point in the history
* fix: watch files change of module_graph in node_modules

* chore: extends overrides_ingore_list
  • Loading branch information
Jinbao1001 authored Jul 17, 2024
1 parent 32d7d8c commit 3a74d28
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
55 changes: 41 additions & 14 deletions crates/mako/src/dev/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ pub struct Watcher<'a> {
pub watched_dirs: HashSet<PathBuf>,
}

pub struct IgnoreListArgs {
with_output_dir: bool,
with_node_modules: bool,
}

impl<'a> Watcher<'a> {
pub fn new(
root: &'a PathBuf,
Expand All @@ -39,7 +44,13 @@ impl<'a> Watcher<'a> {
pub fn watch(&mut self) -> anyhow::Result<()> {
let t_watch = Instant::now();

self.watch_dir_recursive(self.root.into(), &self.get_ignore_list(true))?;
self.watch_dir_recursive(
self.root.into(),
&self.get_ignore_list(IgnoreListArgs {
with_output_dir: true,
with_node_modules: false,
}),
)?;

let module_graph = self.compiler.context.module_graph.read().unwrap();
let mut dirs = HashSet::new();
Expand All @@ -57,10 +68,23 @@ impl<'a> Watcher<'a> {
dirs.insert(dir);
}
}
let _ = self.watch_file_or_dir(
resource.0.path().to_path_buf(),
&self.get_ignore_list(IgnoreListArgs {
with_output_dir: false,
with_node_modules: true,
}),
);
}
});
dirs.iter().try_for_each(|dir| {
self.watch_dir_recursive(dir.into(), &self.get_ignore_list(false))?;
self.watch_dir_recursive(
dir.into(),
&self.get_ignore_list(IgnoreListArgs {
with_output_dir: false,
with_node_modules: false,
}),
)?;
Ok(())
})?;

Expand Down Expand Up @@ -92,20 +116,23 @@ impl<'a> Watcher<'a> {
Ok(())
}

fn get_ignore_list(&self, with_output_dir: bool) -> Vec<PathBuf> {
let mut ignore_list = vec![".git", "node_modules", ".DS_Store", ".node"];
if with_output_dir {
fn get_ignore_list(&self, ignore_list_args: IgnoreListArgs) -> Vec<PathBuf> {
let mut ignore_list: Vec<&str> = vec![".git", ".DS_Store", ".node"];
let overrides_ignore_list = vec!["node_modules"];
if ignore_list_args.with_output_dir {
ignore_list.push(self.compiler.context.config.output.path.to_str().unwrap());
}
ignore_list.extend(
self.compiler
.context
.config
.watch
.ignore_paths
.iter()
.map(|p| p.as_str()),
);
let config_ignore_path = &self.compiler.context.config.watch.ignore_paths;
if config_ignore_path.is_empty() {
ignore_list.extend(overrides_ignore_list);
} else {
ignore_list.extend(config_ignore_path.iter().map(|p: &String| p.as_str()));
}

if ignore_list_args.with_node_modules {
ignore_list.retain(|&item| item != "node_modules");
return ignore_list.into_iter().map(PathBuf::from).collect();
}

// node_modules of root dictionary and root dictionary's parent dictionaries should be ignored
// for resolving the issue of "too many files open" in monorepo
Expand Down
4 changes: 0 additions & 4 deletions packages/mako/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

/* auto-generated by NAPI-RS */

export interface TransformOutput {
code: string;
map?: string;
}
export interface JsHooks {
name?: string;
load?: (
Expand Down

0 comments on commit 3a74d28

Please sign in to comment.