Skip to content

Commit d0d983a

Browse files
committed
Fixes watch rebuild loop if empty watch
Signed-off-by: itowlson <[email protected]>
1 parent 66ede35 commit d0d983a

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/commands/watch/filters.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ impl FilterFactory for BuildFilterFactory {
9898
filterers.push(Box::new(manifest_filterer));
9999

100100
for (cid, c) in &manifest.components {
101-
let build_globs = create_source_globs(cid.as_ref(), c);
102-
let build_filterer = globset_filter(manifest_dir, build_globs).await?;
103-
filterers.push(Box::new(build_filterer));
101+
if let Some(build_globs) = create_source_globs(cid.as_ref(), c) {
102+
let build_filterer = globset_filter(manifest_dir, build_globs).await?;
103+
filterers.push(Box::new(build_filterer));
104+
}
104105
}
105106

106107
let filterer = CompositeFilterer { filterers };
@@ -109,17 +110,15 @@ impl FilterFactory for BuildFilterFactory {
109110
}
110111
}
111112

112-
fn create_source_globs(cid: &str, c: &v2::Component) -> Vec<String> {
113-
let Some(build) = &c.build else {
114-
return vec![];
115-
};
113+
fn create_source_globs(cid: &str, c: &v2::Component) -> Option<Vec<String>> {
114+
let build = c.build.as_ref()?;
116115
if build.watch.is_empty() {
117116
eprintln!(
118117
"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"
119118
);
120-
return vec![];
119+
return None;
121120
};
122-
build
121+
let globs = build
123122
.workdir
124123
.as_deref()
125124
.map(|workdir| {
@@ -129,7 +128,13 @@ fn create_source_globs(cid: &str, c: &v2::Component) -> Vec<String> {
129128
.filter_map(|w| Path::new(workdir).join(w).to_str().map(String::from))
130129
.collect()
131130
})
132-
.unwrap_or_else(|| build.watch.clone())
131+
.unwrap_or_else(|| build.watch.clone());
132+
if globs.is_empty() {
133+
// watchexec misinterprets empty list as "match all"
134+
None
135+
} else {
136+
Some(globs)
137+
}
133138
}
134139

135140
#[async_trait]

0 commit comments

Comments
 (0)