I’m trying to build a clojurescript task as part of an uber task, but I’m struggling to come up with a solution which feels fully integrated with tools.build . I was hoping/expecting to use cljs.build.api in my build script, but I don’t see any concept of a basis there as is found in clojure.tools.build.api . So I don’t see a compile-cljs analog to clojure.tools.build.api/compile-clj which operates on a basis . Therefore, I don’t see a clear way to specify the needed classpath for the build. Instead, I’ve ended up shelling out to a new process which can get the correct classpath. But, my solution doesn’t feel fully integrated. Am I missing something?
Here is what I’ve got (I’m using Figwheel here, but would be just as happy for a release build using a cljs compiler):
deps.edn
:figwheel-release {:extra-deps {com.bhauman/figwheel-main {:mvn/version "0.2.15"}}
:main-opts ["-m" "figwheel.main"
"--build-once" "release"]
:extra-paths ["client/src" "resources"]}
build.clj
(defn cljs [_]
(b/process {:command-args ["clojure" "-A:figwheel-release"]}))
release.cljs.edn
{:main ___
:output-to "___"
:output-dir "___"
:optimizations :advanced}
@sashton You can create a java process which invokes cljs.main with args`"-m" "clojure.main" "-m" "cljs.main"`
and this java process takes a basis argument.
but you can also just shell out to clojure and call cljs.main like that
this would be similar for invoking shadow-cljs
Is there a way to do it without shelling out?
you are starting a new process either way, compile-clj is also starting a new clojure process
See https://github.com/clojure/tools.build/blob/f57f3babcff129cf7df7af57c9c462459be1a698/src/main/clojure/clojure/tools/build/tasks/compile_clj.clj#L76-L81. You can do a similar thing for cljs.main
yeah, that’s true. I guess I was interested in an api which already handles error codes, etc. It seems like a little boilerplate to handle it in each build file, rather than via an api call. I guess I’m wondering: if this isn’t already a feature, is it something someone is considering/working on?
I could certainly roll my own compile-cljs, but I wanted to check if there was already something like that out there
I would be happy to have a contribution towards that
If I come up with something workable, I’ll reach back out to you about it
Or maybe it makes sense as a separate lib, not sure
There is not anything I'm aware of
user=> (def j (b/java-command {:main-args ["-e" "(+ 1 2 3)"] :basis (b/create-basis {}) :main 'clojure.main }))
#'user/j
user=> (b/process (assoc j :out :inherit :err :inherit))
6
{:exit 0}but then use :main-args ["-m" "cljs.main"] instead
Ok, I’ll explore that idea.
Thanks for the suggestions!