This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-14
Channels
- # aleph (10)
- # announcements (2)
- # beginners (228)
- # calva (18)
- # cider (6)
- # clara (5)
- # cljdoc (25)
- # cljs-dev (22)
- # clojure (78)
- # clojure-dev (30)
- # clojure-europe (2)
- # clojure-finland (1)
- # clojure-italy (32)
- # clojure-nl (21)
- # clojure-uk (126)
- # clojurescript (34)
- # cursive (5)
- # data-science (2)
- # datascript (2)
- # datomic (26)
- # defnpodcast (1)
- # emacs (5)
- # figwheel (5)
- # figwheel-main (3)
- # fulcro (14)
- # graphql (5)
- # jobs (1)
- # keechma (4)
- # nrepl (5)
- # off-topic (35)
- # onyx (3)
- # pedestal (12)
- # random (1)
- # re-frame (35)
- # reagent (8)
- # reitit (20)
- # remote-jobs (5)
- # ring-swagger (20)
- # shadow-cljs (166)
- # sql (43)
- # vim (6)
- # yada (15)
Hi, is there a way I can get a list of the source files that were compiled in the build-state
from within a :flush
build hook?
each id will have (get-in build-state [:sources resource-id])
and [:output resource-id]
for the source and generated output
And from that I can get the files that were touched and recompiled in that incremental compile step?
https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/build.clj#L55-L66
:shadow.build/build-info
is what the websocket uses to decide which code to reload and stuff so that might be most useful
Yep I can see (get-in build-state [:shadow.build/info :compiled])
contains exactly what I need.
Another related question: if I wanted to modify the source files before compilation, will writing to the source files directly be sufficient? Or do I need to update the strings in the build state?
modify in what way? most reliable option is to just modify the files directly on disk
I want to change references to assets in my source files, so that they are fingerprinted.
I agree that is a better solution. I've already written a library that does it the 'search and replace' way, so was planning to reuse that.
you can modifiy sources in a :compile-prepare
hook but getting correct caching is tricky enough as it is
I have plans to integrate something like this fingerprinting for assets directly but didn't get to it yet
I'm just thinking about how I could make the img->hashed-img-path
map available to the implementation of get-img-src
.
doing it via hooks is gonna be trickier since you need to tinker with some internals
Sure, but the compiled JS needs the updated map? IIRC if we write a file then we'll need a macro to slurp the contents of that file?
the idea is to just use the path directly if it was not overridden with a hashed value
Cool, that makes sense. And where in the build-state
can I prepend to the top of main.js
?
There are some edge cases to take care of. e.g. changing an asset involves a recompilation of the source file that references it.
I mean, if I changed ponys.png
will the browser receive a message to reload that asset?
Well typically we don't want to hash assets in dev mode anyway, so it's kind of a moot point.
just make get-img-src
return the original either via a :closure-define
or some logic that checks if the path was overridden
I'll try and knock something up. And whereabouts can I prepend the lookup map to the main.js file?
b) do it in :configure
by basically setting :modules {:main {:prepend-js "var lookup$map = <json>;\n"}}}
(update-in build-state [:shadow.build.modules/config <module-id> :prepend-js] str "var lookup$map = " (json/write-str {"foo" "bar"}))
:prepend-js
will go through :advanced
so the closure compiler may be smart enough to directly inline the strings
One advantage of the dumb regex search-and-replace approach is the same mechanism works for assets referenced in index.html and CSS files. Luckily for us we generate the page frame in hiccup and CSS in garden. Still, we need to generate a manifest file for use on the server.
@thheller it seems we have another problem like yesterday in our build D:\home\.shadow-cljs\builds\az\dev\out\cljs-runtime\goog.debug.error.js
az
is the name of target :azure-app
it seems like it is again trying to skip a folder
and read from the parent of our project
:app-dir "azure/build"
could it be somewhere in the code?
(checking in the meantime)
we can tweak no prob...let's see where the problem is 😄
I am checking the output file but I don't see anything like the SHADOW-IMPORT
like yesterday
maybe not 😄
i'll be back
@thheller so this is what my colleague sees:
var SHADOW_IMPORT_PATH = __dirname + '/../../../.shadow-cljs/builds/az/dev/out/cljs-runtime';
if (__dirname == '.') { SHADOW_IMPORT_PATH = "/Users/user/github-ep/laputa/commit-event-fn/.shadow-cljs/builds/az/dev/out/cljs-runtime"; }
global.$CLJS = global;
like yesterday, the first points outside the project folder
but this time we don't have ./
I see in the code this happens:
{:exports fn-map
;; FIXME: can't have a {:cljs some.ns/fn} function when using cljs dir
:output-to (str app-dir "/cljs/shared.js")}`
so that looks good to me
@richiardiandrea you posted a d:\home
windows location and the code snippet above is clearly not windows
uhm ok thanks, there must be something going on here
the snippet above came from a deployed lambda, this latest from a laptop
something is not right, I will get a better understanding first
then get back to you
yep it seems like something like deploy a compile
d thing happened
@thheller it looks like the culprit on my colleague's MacOsX machines is:
<- Cache read: cljs/core.cljs (151 ms)
-> Compile CLJS: cljs/core.cljs
------ ERROR -------------------------------------------------------------------
File: jar:file:/Users/user/.m2/repository/org/clojure/clojurescript/1.10.439/clojurescript-1.10.439.jar!/cljs/core.cljs
NullPointerException:
cljs.compiler/emit/fn--3144 (compiler.cljc:189)
clojure.lang.Atom.swap (Atom.java:37)
clojure.core/swap! (core.clj:2344)
clojure.core/swap! (core.clj:2337)
cljs.compiler/emit (compiler.cljc:187)
cljs.compiler/emit (compiler.cljc:182)
shadow.build.compiler/eval12942/fn--12943 (compiler.clj:238)
clojure.lang.MultiFn.invoke (MultiFn.java:234)
shadow.build.compiler/default-compile-cljs/fn--12969 (compiler.clj:289)
shadow.build.compiler/default-compile-cljs (compiler.clj:288)
shadow.build.compiler/default-compile-cljs (compiler.clj:274)
clojure.core/partial/fn--5739 (core.clj:2617)
shadow.build.compiler/do-compile-cljs-string/fn--12930 (compiler.clj:227)
it compiles fine on linux though
ooooooo
ok now that makes sense
my colleague did not do yarn install
after updating to 2.7.3
we are using yarn shadow-cljs
for launching things but I am interesting in knowing more about deps.edn
case
I assume you are using deps.edn
because the version conflict above can't happen with pure shadow-cljs.edn
it enforces the CLJS version used based on the version of shadow-cljs in package.json
if you use deps.edn
that can't be enforced so whatever you have in there will be used
oh I see what you mean
oh yea, do I not need to declare it in package.json if I'm adding shadow to my deps? had been cargo culting that without knowing if I needed it
yeah ClojureScript is taken from deps.edn
so you are saying I should get rid of that in deps.edn
basically
@haywood yes. it is recommended so your project doesn't rely on some global install in the system
oh, but I guess if I remove it from package.json, my npm run
scripts will stop working
@richiardiandrea no. I guess its fine. forgot that shadow-cljs injects itself into deps.edn
on startup
@richiardiandrea I was just wrong. it actually does matter that the proper version is installed via yarn/npm
oh ok good to know thanks
I know we should move away from using yarn shadow-cljs
but haven't had the time to figure out the replacement
ideally we should be able to do clojure -A:shadow watch
as a replacement
uhm ok then good that you've just told me that 😄
oh no we don't want that 😄
could maybe add a clojure version that does that check but it would be way slower and launcher a full JVM just to connect to a remote socket is a bit overkill
yeah actually for one-off tasks in CI we don't want a shared JVM anyways
HI. I am using shadow-cljs with re-frame. What can I do to prevent reseting app-db after each file chenge?
well lets start with your setup. do you have any :after-load
or :before-load
hooks configured?
there are a couple example repos here and plenty of them use re-frame https://github.com/thheller/shadow-cljs#examples
shadow-cljs: load JS herman/pages/observations.cljs browser.cljs:25 shadow-cljs: load JS herman/views.cljs browser.cljs:25 shadow-cljs: call herman.core/mount-root browser.cljs:25 shadow-cljs: call herman.core/init