This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-18
Channels
- # announcements (4)
- # babashka (13)
- # beginners (8)
- # chlorine-clover (1)
- # cider (5)
- # clj-http (12)
- # clojure (157)
- # clojure-dev (14)
- # clojure-europe (26)
- # clojure-nl (2)
- # clojure-norway (69)
- # clojure-uk (6)
- # clojuredesign-podcast (21)
- # clojurescript (7)
- # core-async (4)
- # datomic (170)
- # editors (1)
- # hyperfiddle (45)
- # java (7)
- # joyride (1)
- # leiningen (43)
- # lsp (7)
- # malli (24)
- # music (1)
- # off-topic (22)
- # pathom (16)
- # portal (31)
- # re-frame (1)
- # releases (1)
- # shadow-cljs (36)
- # squint (4)
Hi all :) I hope someone know about this: I'd like to add a custom transformation to the JS code compiled by shadow-cljs, preferably, before writing to the disk. I was thinking that maybe the best way to do this is by using the Build Hooks. But the info there is really big :thinking_face: idk where to look at. At the end shadow writes many of these things:
SHADOW_ENV.evalLoad("my_ns", "goog.provide(... my compiled JS code ...")
I want to transform ... my compiled js code...
One option is look at all the "goog.provides"'s content and apply my transformation.
Another option is adding metadata to the namespace or functions (so cool!) And only applying the transformation to the namespace/fns having that data.
My questions:
Is it possible to add that transformation as part of the BuildHooks?
Is it possible to look at the metadata and apply the transformation only on certain namespaces/fns?
It would be really good in terms of performance to only apply the transformation to the changed code, not to the whole compiled thing.
Thanks in advance!yes, you can do that in build hooks but you kinda have to be careful about what you are doing as you may potentially break caching. also possibly weird issues when not respecting how watch
works (incremental compiles)
not sure what your intent is though as the generated JS isn't exactly easy to process
Thanks for the reply! Any hint about what are the involved keys? Just want to pass a babel plugin to the JS output.
I'm asking because I want to safe you the time of doing something that is maybe covered elsewhere
Oh yeah, sorry. Involved keys in build hooks to check the metadata, and to apply a babel plugin to the JS code related to that metadata.
I mean have you looked at the actual JS output? are you sure the babel plugin is going to be able to do what you want to do?
About the metadata, nothing specific, it would work just as a flag to apply the plugin
you are being very vague so I'm just gonna tell you want you want to know and skip trying to safe time
And yes, I'm sure about the pluging working as expected, I applied the plugin to the strings passed to evalLoad
in index.js and it works well.
I'll share the plugin link in a sec
the relevant bits are in :sources
which is a map of all the sources revelant to the build
the analyzer data you find in [:compiler-env :cljs.analyzer/namespaces your.ns :defs your-var :meta]
:js
is the field being later generated into the evalLoad
argument, and is the final JS being loaded
you are being very vague so I'm just gonna tell you want you want to know and skip trying to safe time> Sorry, I'm on my phone rn 😅 And also I say nothing concrete/specific because it's something to be created, the metadata can be whatever I find better. The plug-in link (animated babel parser for react-native): https://github.com/software-mansion/react-native-reanimated/tree/main/plugin/src
@thheller Hello again,
I recently tried this approach and it worked as expected! Thanks for your help.
Now I'm wondering if there's a key in the build-state
that lets me know what were the files/namespaces modified by the user, and that need to be recompiled.
I've checked the build-state but I didn't find something meaningful.
I just noticed during :compile-prepare
there's a key (I forgot the name) that has less files listed compared to the same key at :compile-finish
(that has all the files) and I'm getting that difference.
I guess there should be a better way to know it.
Thanks in advance!
so if you want you can keep state in :output
yourself, so for files you have processed you can set a boolean or something
I moved an old codebase from #C1A38UB5X into shadow-cljs Using the shadow-cljs build report I was able to remove 64 files//7kLOC from the repo, of unused namespaces 🙂 Thank you thheller!
@thheller Hello again,
I recently tried this approach and it worked as expected! Thanks for your help.
Now I'm wondering if there's a key in the build-state
that lets me know what were the files/namespaces modified by the user, and that need to be recompiled.
I've checked the build-state but I didn't find something meaningful.
I just noticed during :compile-prepare
there's a key (I forgot the name) that has less files listed compared to the same key at :compile-finish
(that has all the files) and I'm getting that difference.
I guess there should be a better way to know it.
Thanks in advance!