tools-build

sashton 2021-12-29T19:00:23.369400Z

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}

borkdude 2021-12-29T19:22:47.370700Z

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

borkdude 2021-12-29T19:23:38.371100Z

and this java process takes a basis argument.

borkdude 2021-12-29T19:24:09.371600Z

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

borkdude 2021-12-29T19:24:37.371900Z

this would be similar for invoking shadow-cljs

sashton 2021-12-29T19:27:14.372200Z

Is there a way to do it without shelling out?

borkdude 2021-12-29T19:28:10.372800Z

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

sashton 2021-12-29T19:33:26.376500Z

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?

sashton 2021-12-29T19:34:26.377300Z

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) 2021-12-29T19:35:25.377700Z

I would be happy to have a contribution towards that

sashton 2021-12-29T20:02:31.380100Z

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

Alex Miller (Clojure team) 2021-12-29T20:08:31.380800Z

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

Alex Miller (Clojure team) 2021-12-29T19:35:43.378100Z

There is not anything I'm aware of

borkdude 2021-12-29T19:37:54.378400Z

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}

borkdude 2021-12-29T19:38:26.378600Z

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

sashton 2021-12-29T19:44:50.379700Z

Ok, I’ll explore that idea.

sashton 2021-12-29T19:46:10.380Z

Thanks for the suggestions!