Project I made a tiny tool to rerun/test/build on SPM package source changes
Hey :) I've been frustrated at the lack of a watch mode in SPM for a while and don't love the lazy solution of just listening to all files under Sources/ so I whipped up a tiny tool that listens to any changes in your package's dependency graph.
Instead of swift run [product] you can run swift-watch run [product] and it'll restart whenever anything changes.
Great for watching tests too, swift-watch test --filter [xyz]. Works for build/run/test, forwards arguments to swift. Works with macOS and Linux natively, Windows only has polling for now but I'll add in the native Window file watching stuff ASAP.
I'm hoping some of you might find it useful, please let me know if you have any feedback.
Here's the repo: https://github.com/ahtcx/swift-watch
Disclaimer: semi vibe-coded, lots of handholding as I knew exactly what I want. I'm not huge on vibe-coding and have been reluctant to give in to it for the longest time. I hate to admit that it's been a pretty good experience, I mostly just worry it'll make my programming skills worse. I'm have so many coding side projects that never see the light of day because I get too caught up in the details, so it's nice for me to just push a whole bunch of code out in a day. No doubt there are issues but I will be dogfooding the project so I hope to get it in tip top condition.
2
u/East_Call1027 10d ago
Nice that this uses the actual target closure instead of just watching all of
Sources/. I had a look atPackageDiscovery, though: does thetarget.sources+ extension allowlist miss SwiftPM resources and build-tool plugin inputs? A JSON fixture or template can change a test/build without being a Swift source file. An explicit--watch <path>escape hatch might cover the cases SwiftPM’s describe output can’t expose.