Skip to content

Commit

Permalink
Merge pull request #2642 from itowlson/fix-watch-nothing-watching-all
Browse files Browse the repository at this point in the history
Fixes watch rebuild loop if empty watch
  • Loading branch information
itowlson authored Jul 15, 2024
2 parents 086ded6 + d0d983a commit 3fc4f6f
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/commands/watch/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ impl FilterFactory for BuildFilterFactory {
filterers.push(Box::new(manifest_filterer));

for (cid, c) in &manifest.components {
let build_globs = create_source_globs(cid.as_ref(), c);
let build_filterer = globset_filter(manifest_dir, build_globs).await?;
filterers.push(Box::new(build_filterer));
if let Some(build_globs) = create_source_globs(cid.as_ref(), c) {
let build_filterer = globset_filter(manifest_dir, build_globs).await?;
filterers.push(Box::new(build_filterer));
}
}

let filterer = CompositeFilterer { filterers };
Expand All @@ -109,17 +110,15 @@ impl FilterFactory for BuildFilterFactory {
}
}

fn create_source_globs(cid: &str, c: &v2::Component) -> Vec<String> {
let Some(build) = &c.build else {
return vec![];
};
fn create_source_globs(cid: &str, c: &v2::Component) -> Option<Vec<String>> {
let build = c.build.as_ref()?;
if build.watch.is_empty() {
eprintln!(
"You haven't configured what to watch for the component: '{cid}'. Learn how to configure Spin watch at https://developer.fermyon.com/common/cli-reference#watch"
);
return vec![];
return None;
};
build
let globs = build
.workdir
.as_deref()
.map(|workdir| {
Expand All @@ -129,7 +128,13 @@ fn create_source_globs(cid: &str, c: &v2::Component) -> Vec<String> {
.filter_map(|w| Path::new(workdir).join(w).to_str().map(String::from))
.collect()
})
.unwrap_or_else(|| build.watch.clone())
.unwrap_or_else(|| build.watch.clone());
if globs.is_empty() {
// watchexec misinterprets empty list as "match all"
None
} else {
Some(globs)
}
}

#[async_trait]
Expand Down

0 comments on commit 3fc4f6f

Please sign in to comment.