:node-script target exists, and this cljs is intended to be executed on the server side. It depends on resources/schema.graphql and is being loaded via shadow.resource/inline. When schema.graphql changes, watch will automatically recompile, but in cases where the schema.graphql is being edited and may be corrupted, I want to interrupt the build rather than replacing the new output with it. I considered using :build-hooks, but throwing an exception here would cause shadow-cljs to endlessly retry. Is there any way to tell shadow-cljs to interrupt the build in such cases?
there is not no and I would recommend solving this outside shadow-cljs. for example save to a different file, validate it and only when validated copy it to the included location. or just do not include it in the build at all. doesn't seem like something that needs to be inlined. just load if the (fs/readFileSync ...) into node at runtime?
Since loading a broken schema.graphql at runtime causes the server to crash, we must maintain a backup of a previous, valid schema.graphql. Running this at runtime would be cumbersome, so we want to handle this during the build phase instead. Is there a configuration method for specifying prerequisites required for the build process?
well, you can just write your own macro. inline is just a very small wrapper around the slurp-resource helper function. https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/resource.clj#L73
so something like
(defmacro inline-gql [path]
(let [text (slurp-resource &env path)]
(when (invalid-graphql? text)
(throw (ana/error &env "graphql is invalid!")))
text))that'll throw and exception and thus cause a build error
see https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html on how to write a macro. ana/error is cljs.analyzer/error, make sure to only require that in the .clj part of the macro. otherwise it'll make your build huge if part of the .cljs compile
you can just throw any exception, but using ana/error the error will at least point to the correct location.
thanks! I'll try it after get home.