Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: watch files change of module_graph in node_modules #1385

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading