shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
frankitox 2021-01-03T01:37:44.245900Z

I use it to show a little OS notification if I get a warning (usually I keep shadow's term hidden).

👍 1
2021-01-03T09:55:05.248100Z

Using Shadow-cljs, is there a way to run a hook inside the context of the reloaded cljc source files? From my test on the hooks, it seems that the source code is only loaded once.

2021-01-03T09:57:10.248500Z

This is my use case: https://clojurians.slack.com/archives/C07UQ678E/p1609647836133300

thheller 2021-01-03T10:19:01.248800Z

scanning for generic things like that is difficult but build hooks receive the entire build state and can inspect it however they need

2021-01-03T10:20:44.249Z

I took a look at the build-state and made the mistake of printing its content 😛

thheller 2021-01-03T10:20:56.249200Z

the best option I have found so far however is using a dedicated css macro or so that collects these things during compilation. much easier to extract but slightly more verbose in the code

(def button-style (css :border :p-2 :shadow :lg/p-4))
or so

thheller 2021-01-03T10:21:14.249600Z

(tap> build-state) and look at it in the inspect UI

2021-01-03T10:21:31.249800Z

oh, good idea (for the tap>)

thheller 2021-01-03T10:21:55.250100Z

:sources has all the sources

thheller 2021-01-03T10:22:29.250300Z

:output has all the outputs of those sources (in :flush) stage, otherwise might still be empty

2021-01-03T10:22:50.250500Z

I made a macro which adds the css in the metadata attached to the clojure var already. I am looking at how to read it from the hook.

thheller 2021-01-03T10:28:39.250900Z

you can take a look at this macro I wrote https://clojureverse.org/t/using-none-code-resources-in-cljs-builds/3745

thheller 2021-01-03T10:28:54.251200Z

it stores state in the analyzer data for the namespace

thheller 2021-01-03T10:29:23.251400Z

you could read that out later in the build hook via [:compiler-env :cljs.analyzer/namespaces your.ns :your.thing/key] or so

2021-01-03T10:33:21.251600Z

Thx, I am taking a look now.

2021-01-03T12:09:25.251800Z

@thheller this worked !

(tap> (get-in build-state
                [:compiler-env
                 :cljs.analyzer/namespaces
                 '<http://acme.frontend.app|acme.frontend.app>
                 :defs
                 'my-fn
                 :css]))
Big thank you !

thheller 2021-01-03T12:47:15.252Z

when you add custom keys to the analyzer data make sure they are namespaced

thheller 2021-01-03T12:47:26.252200Z

otherwise you might at some point clash with implementation details

👌 1