Fork me on GitHub
#tools-build
<
2021-12-29
>
sashton19:12:23

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}

borkdude19:12:47

@sashton You can create a java process which invokes cljs.main with args`"-m" "clojure.main" "-m" "cljs.main"`

borkdude19:12:38

and this java process takes a basis argument.

borkdude19:12:09

but you can also just shell out to clojure and call cljs.main like that

borkdude19:12:37

this would be similar for invoking shadow-cljs

sashton19:12:14

Is there a way to do it without shelling out?

borkdude19:12:10

you are starting a new process either way, compile-clj is also starting a new clojure process

sashton19:12:26

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?

sashton19:12:26

I could certainly roll my own compile-cljs, but I wanted to check if there was already something like that out there

Alex Miller (Clojure team)19:12:25

I would be happy to have a contribution towards that

sashton20:12:31

If I come up with something workable, I’ll reach back out to you about it

Alex Miller (Clojure team)20:12:31

Or maybe it makes sense as a separate lib, not sure

Alex Miller (Clojure team)19:12:43

There is not anything I'm aware of

borkdude19:12:54

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}

borkdude19:12:26

but then use :main-args ["-m" "cljs.main"] instead

sashton19:12:50

Ok, I’ll explore that idea.

sashton19:12:10

Thanks for the suggestions!