Fork me on GitHub
#shadow-cljs
<
2021-02-24
>
pez12:02:37

Is there a way to configure the compilation progress output to include the files being compiled? So I have things like this in the log

[:dev] Build completed. (451 files, 3 compiled, 0 warnings, 5.12s)
And would like to have the file paths of the 3 compiled files.

thheller12:02:58

the UI might be a better option for that? as far as the CLI is concerned there is only --verbose which is likely too verbose?

pez12:02:42

Looks like I can grep a bit on the verbose output and get what I want.

thheller12:02:57

what do you want? if you actually want to do something with the "data" a build hook might help? https://shadow-cljs.github.io/docs/UsersGuide.html#build-hooks

pez12:02:27

A build hook might do it too. I have the output from the CLI in a terminal pane in VS Code. When I save a file or unstash something and such I like to see when the compilation is done, and also which files have been recompiled. It’s more “for my information” than anything else.

pez13:02:26

Tried with this hook now, but don’t see anything in the CLI output.

(defn print-compilation-info [build-state & args]
  {:shadow.build/stages #{:compile-finish :flush}}
  (prn [:build-state build-state
        :args args])
  build-state)

pez13:02:56

This in the build conf:

:build-hooks [(env.hooks/print-compilation-info 1 2 3)]

thheller13:02:04

ehm yeah printing the build-state is not a good idea. it will be several hunderd megabytes 😛

😂 1
thheller13:02:26

use tap> and look at it in the UI

thheller13:02:51

also the metadata is misplaced

thheller13:02:57

before the args vector, not after.

pez13:02:56

That inspector. ❤️

pez13:02:45

With the metadata map at the right place things started to work of course.

pez13:02:00

We have just (yesterday) switched to shadow at work for our react native app. I am going to have so much use for the inspector I now realize. Totally wonderful.

👍 1
pez13:02:34

Not sure I can hook myself to the output I want. Using verbose output it looks like I would want the -> Cache write: foo.cljs rows in addition to the non-verbose output. But i don’t find the info I need in the build-state. You think it is there in any of the stages, @thheller?

thheller14:02:10

@pez well you could replace the logger but I think it is enough if you just get the data you need and print what you want

thheller14:02:14

for example

(defn pez-print
  {:shadow.build/state :flush}
  [{:keys [build-sources] :as build-state}]
  
  (let [compiled (get-in build-state [:shadow.build/build-info :compiled])]
    (doseq [src-id build-sources
            :when (contains? compiled src-id)
            :let [rc (get-in build-state [:sources src-id])]]
      (prn [:compiled (:resource-name rc)])))

  build-state)

pez14:02:15

:shadow-build/build-info :compiled! Thanks. I’m tempted to name the hook like that. 😃

😎 1
thheller14:02:19

yeah I need to document the build-state data at some point. kind of a lot of stuff in there 🙂

thheller14:02:16

rc will also contain all the other info. :file will have the .File instance if you need the full path. :resource-name is just the name on the classpath

thheller14:02:01

(not all sources fill have :file though so make sure you are only accessing it if it exist. won't exist for classpath .jar resources for example)

pez14:02:51

I’ll run with this for now. Many thanks for the help!

(defn print-compiled-files
  {:shadow.build/stages #{:flush}}
  [{:keys [build-sources] :as build-state}]
  (let [compiled
        (get-in build-state
                [:shadow.build/build-info
                 :compiled])
        output
        (->> rc
             :resource-name
             (for [src-id build-sources
                   :when (contains? compiled src-id)
                   :let [rc (get-in build-state
                                    [:sources src-id])]])
             (sort)
             (into [:compiled]))]
    (binding [clojure.pprint/*print-right-margin* 20]
      (clojure.pprint/pprint output)))
  build-state)

jimmy16:02:57

Posted in #cider and got no bites. Figured I’d repost here: Anyone else have any issues with cider-doc in a shadow-cljs? It is working fine in my clojure repl and in a different project that uses weasel. It isn’t even working for built-in clojure functions.  Toggled messages and just see a (“done” “no-eldoc”). Any ideas?

thheller16:02:38

shadow-cljs doesn't handle eldoc. the cider-nrepl middleware does. did you install that?

jimmy16:02:20

Yep, got cider nrepl. Works for all the other projects I’m working on. But for some reason not working in my shadow-cljs project. (Posted in cider first because I know it isn’t shadow-cljs’s fault)

thheller16:02:39

if you have the cider-nrepl listed as a proper dependency and a new enough shadow-cljs version it should work

thheller16:02:17

but I don't use emacs or cider so I cannot help much with debugging