I'm looking at tools.build for the first time due to a question on clojureverse. trying to write a blog post how to best run shadow-cljs via tools.build. this is what I'm currently stuck at. using the latest tools.deps cli install, with tools.build 0.10.5
$ clj -T:build cljs-release
Namespace could not be loaded: build:build here is an alias in your deps.edn, presumably it contains a :ns-default or something, I'm guessing build
because of that, it will try to resolve cljs-release as a var in build (`build/cljs-release` ). is there a build.clj in the root of your project?
ah thanks for the hint. I assumed the :paths at the top level would still apply but I guess -T replaces that. added :paths ["src/dev"] to the alias and it works.
that error message could be improved IMHO 😛
yes, -T removes the project :paths and adds ["."]
can you clarify which piece of this was the point of confusion?
I assumed there was just a syntax error or something preventing the load. didn't think of "not found" since for me the file was clearly on the "classpath"
just wasn't aware the -T removed all top level config. first time using that, didn't check any docs for that flag.
would "Namespace not found on classpath: build" have been better?
absolutely. In addition one thing I do in shadow-cljs is list the paths that were checked. So could potentially list the classpath (minus jars, so only actual folders)
well, -T is usually invoking code from a jar
so that is not a good filter here
build.clj is not in a jar?
correct, but -T is often used for tools that are external to the project
ah ok
but I could possibly provide the command that would list the classpath
yeah, all I needed was a little hint. so any option that could provide insight would help. I was just like "hmm, how I debug this" so I asked.
I appreciate it, will at least update the message a little
wonderful. thx.
So executing clj -T:build jar will use an effective classpath here of:
"." (added by -T)
I should have RTFM. it is right there 🙂while I have you here. any thoughts on this? seems to work ok, so seems fine to me.
(defn cljs-release [& args]
(let [basis
(b/create-basis
{:project "deps.edn"
:aliases [:cljs]})
res
(-> (b/java-command
{:basis basis
:main 'clojure.main
:main-args ["-m" "shadow.cljs.devtools.cli" "release" "frontend"]})
(b/process))]
(when-not (zero? (:exit res))
(throw (ex-info "CLJS compilation failed!" {})))))basically the goal is giving people a way to invoke shadow-cljs to make a CLJS release .js file before packing a uberjar (thread: https://clojureverse.org/t/making-a-clojure-clojurescript-project-in-oct-2024-round-2/10991)
lgtm
not sure if :cljs is "standard" but could have an option to override that
yeah people can change that if needed. I'm not intending to make this a library or so. just wanted to have something as a reference to show when people ask how you'd build CLJS in a tools.build context
usually people will have CLJS stuff in an alias I think
how am I supposed to figure out why it could not be loaded? all I did was copy the code from the tutorial and add a (defn cljs-release [] ...) to the ns