Skip to content

Commit 5eef6b7

Browse files
authored
Merge pull request #2481 from itowlson/watch-relative-or-absolute-make-up-your-sodding-mind
Fix `watch` not picking up manifest changes
2 parents 3bd74a2 + 8f575b6 commit 5eef6b7

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/commands/watch/filters.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use std::{
33
sync::Arc,
44
};
55

6-
use anyhow::bail;
6+
use anyhow::Context;
77
use async_trait::async_trait;
8+
use spin_common::ui::quoted_path;
89
use spin_manifest::schema::v2;
910

1011
#[async_trait]
@@ -34,7 +35,7 @@ impl FilterFactory for ArtifactFilterFactory {
3435
manifest: &v2::AppManifest,
3536
) -> anyhow::Result<Arc<watchexec_filterer_globset::GlobsetFilterer>> {
3637
let manifest_glob = if self.skip_build {
37-
vec![stringize_path(manifest_file)?]
38+
vec![manifest_path_to_watch(manifest_file)?]
3839
} else {
3940
vec![] // In this case, manifest changes trigger a rebuild, which will poke the uppificator anyway
4041
};
@@ -95,7 +96,7 @@ impl FilterFactory for BuildFilterFactory {
9596
manifest_dir: &Path,
9697
manifest: &v2::AppManifest,
9798
) -> anyhow::Result<Arc<watchexec_filterer_globset::GlobsetFilterer>> {
98-
let manifest_glob = vec![stringize_path(manifest_file)?];
99+
let manifest_glob = vec![manifest_path_to_watch(manifest_file)?];
99100
let src_globs = manifest
100101
.components
101102
.iter()
@@ -152,7 +153,7 @@ impl FilterFactory for ManifestFilterFactory {
152153
manifest_dir: &Path,
153154
_: &v2::AppManifest,
154155
) -> anyhow::Result<Arc<watchexec_filterer_globset::GlobsetFilterer>> {
155-
let manifest_glob = stringize_path(manifest_file)?;
156+
let manifest_glob = manifest_path_to_watch(manifest_file)?;
156157

157158
let filterer = watchexec_filterer_globset::GlobsetFilterer::new(
158159
manifest_dir,
@@ -167,11 +168,13 @@ impl FilterFactory for ManifestFilterFactory {
167168
}
168169
}
169170

170-
fn stringize_path(path: &Path) -> anyhow::Result<String> {
171-
match path.to_str() {
172-
Some(s) => Ok(s.to_owned()),
173-
None => bail!("Can't represent path {} as string", path.display()),
174-
}
171+
// Although manifest dir must be absolute, and most things are safer with abs
172+
// file paths, the manifest _path_ for the watchers must be relative to manifest dir
173+
fn manifest_path_to_watch(path: &Path) -> anyhow::Result<String> {
174+
let rel_path = path
175+
.file_name()
176+
.with_context(|| format!("resolved manifest {} has no filename", quoted_path(path)))?;
177+
Ok(rel_path.to_string_lossy().to_string())
175178
}
176179

177180
fn standard_ignores() -> Vec<(String, Option<PathBuf>)> {

0 commit comments

Comments
 (0)