tools-build

thheller 2024-10-28T17:38:33.089789Z

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

Alex Miller (Clojure team) 2024-10-28T17:40:15.424199Z

:build here is an alias in your deps.edn, presumably it contains a :ns-default or something, I'm guessing build

Alex Miller (Clojure team) 2024-10-28T17:40:52.875579Z

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?

thheller 2024-10-28T17:42:57.879799Z

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.

thheller 2024-10-28T17:43:09.049679Z

that error message could be improved IMHO 😛

Alex Miller (Clojure team) 2024-10-28T17:56:37.190739Z

yes, -T removes the project :paths and adds ["."]

Alex Miller (Clojure team) 2024-10-28T17:57:27.715149Z

can you clarify which piece of this was the point of confusion?

thheller 2024-10-28T17:57:49.091579Z

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"

thheller 2024-10-28T17:58:51.000069Z

just wasn't aware the -T removed all top level config. first time using that, didn't check any docs for that flag.

Alex Miller (Clojure team) 2024-10-28T18:00:24.774889Z

would "Namespace not found on classpath: build" have been better?

thheller 2024-10-28T18:00:33.394589Z

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)

Alex Miller (Clojure team) 2024-10-28T18:01:39.061559Z

well, -T is usually invoking code from a jar

Alex Miller (Clojure team) 2024-10-28T18:01:54.616419Z

so that is not a good filter here

thheller 2024-10-28T18:02:11.907909Z

build.clj is not in a jar?

Alex Miller (Clojure team) 2024-10-28T18:02:44.580339Z

correct, but -T is often used for tools that are external to the project

thheller 2024-10-28T18:03:04.453129Z

ah ok

Alex Miller (Clojure team) 2024-10-28T18:03:22.604679Z

but I could possibly provide the command that would list the classpath

thheller 2024-10-28T18:04:25.715739Z

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.

Alex Miller (Clojure team) 2024-10-28T18:04:47.185449Z

I appreciate it, will at least update the message a little

thheller 2024-10-28T18:05:12.695969Z

wonderful. thx.

thheller 2024-10-28T18:06:37.139239Z

So executing clj -T:build jar will use an effective classpath here of:

"." (added by -T)
I should have RTFM. it is right there 🙂

thheller 2024-10-28T18:08:28.332179Z

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!" {})))))

thheller 2024-10-28T18:09:11.669259Z

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)

Alex Miller (Clojure team) 2024-10-28T18:09:30.787849Z

lgtm

❤️ 1
Alex Miller (Clojure team) 2024-10-28T18:14:35.464319Z

not sure if :cljs is "standard" but could have an option to override that

thheller 2024-10-28T18:17:04.198789Z

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

thheller 2024-10-28T18:17:24.332069Z

usually people will have CLJS stuff in an alias I think

thheller 2024-10-28T17:39:10.215499Z

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