Fork me on GitHub
#shadow-cljs
<
2024-06-30
>
danielcompton03:06:59

I want to be able to send notifications when an incremental build completes, either with a success or a failure. In my case I want to play a sound with a shell script, but you could imagine also sending a macOS notification as well. Is the best place to do this in :build-hooks ? I took a look at the build-hooks documentation but it wasn’t clear to me whether build failures would get called in the hooks.

thheller05:06:21

build hooks are not called for failures currently. there is another option if you do not mind a bit of clojure code. its undocumented so let me make you an example

thheller06:06:53

this would be one way via the undocumented plugin system. basically the :start fn is called when shadow-cljs starts, it depends on the system-bus "service/component" shadow-cljs has and subscribes to the ::m/worker-broadcast core.async topic, i.e. internal pub/sub system. https://github.com/thheller/shadow-cljs/blob/master/src/dev/demo/notify_plugin.clj

thheller06:06:29

plugin is activated via :plugins [demo.notify-plugin] in shadow-cljs.edn

thheller06:06:04

this only receives watch updates though, it does not work for release/compile builds

thheller06:06:39

added the prn as examples, you can run anything you want there. this is just clojure code after all.

thheller06:06:40

I could change things so that build failures are still called for build hooks in some way, if this doesn't work for you

danielcompton18:06:57

Nice, thanks! This is only needed for watch builds so that is perfect