Open Deraen opened 9 years ago
With the warnings on fileset metadata this could even be a separate task. Not sure if there is much value in that besides keeping code out of the regular cljs
task though. edit: Would be a nice example of what fileset metadata enables.
Yes, warning/error info on the fileset would be a great way to solve this. If we could draft a standard for this (perhaps functions in boot.core) then we could make completely separate tasks that could fail on error, print messages in some preferred format, send messages to other services, etc.
The way it would work is the task that catches the error/warning/etc would attach that info to the fileset as metadata and passit down the pipeline. If a subsequent task handles it that task can remove the metadata from the fileset before it passes it on to the next task. Thus, when the fileset bubbles back up to the task where the error originated it can handle it in some default way if the metadata is still on the fileset.
We have the following task in a project:
(defn throw-when-cljs-warnings []
(b/with-pre-wrap fileset
(let [warnings (->> fileset
all-cljs-builds
(map :adzerk.boot-cljs/warnings)
(apply merge)
(remove empty?))]
(when (seq warnings)
(throw (Exception. "There were warnings from the cljs compile step!")))
fileset)))
It works for us, helped catching some warnings :)
@nberger thanks for the snippet, looks great.
Adding this as a boot-cljs option would be a great addition however. I asked elsewhere if a "strict mode" (like -Werror
, fail on warning) could be added to the clojurescript compiler. I got a negative answer, which I take to mean that tooling is the place to do this. I'd like to use it even for dev builds.
@nberger @pesterhazy any of you up for making a PR? :)
@martinklepsch, would love to but don't know when I'll get a chance
See http://jakemccrary.com/blog/2015/12/19/clojurescript-treat-warnings-as-errors/ as an example of how to do this, with lein-cljsbuild.
Boot-cljs overwrites the warning-handler to store the warnings in the fileset metadata, so that is not going to work with Boot-cljs current: https://github.com/adzerk-oss/boot-cljs/blob/master/src/adzerk/boot_cljs/impl.clj#L91
Boot-cljs could add the handler to those set by user, but I'm not sure if this is very useful. A separate task or option is good idea for this.
For production builds it would be useful to have Cljs task fail completely if there are any warnings.
I think this should be a separate option.