Fork me on GitHub
#shadow-cljs
<
2022-05-08
>
Patrick Brown00:05:30

The documentation for Shadow is so good I'm having trouble finding something simple 👍. Where can I find the keys for the opts map that shadow.cljs.devtools. server/start!, api/watch, and repl? Also if anyone has any reason why I shouldn't launch them from integrant repl, let me know.

neilyio03:05:20

I’m noticing a weird edge case with shadow-cljs compilation. When a (ns…) form is wrapped in a (do..) block, compilation fails with odd errors. Here’s a minimal example:

(do
  (ns cljs.user
   (:require [cljs.core.async :refer [chan <! go-loop]])))

(def wait-chan (chan 1))

(go-loop []
  (<! wait-chan)
  (recur))
…results in this error:
[:app] Build failure:
------ ERROR -------------------------------------------------------------------
 File: /Users/neilhansen/Documents/quickstart-browser/src/cljs/user.cljs:9:3
--------------------------------------------------------------------------------
   6 | 
   7 | (go-loop []
   8 |   (<! wait-chan)
   9 |   (recur))
---------^----------------------------------------------------------------------
null
Can't recur here at line 9 cljs/user.cljs
--------------------------------------------------------------------------------
  10 | 
--------------------------------------------------------------------------------
…why am I doing this in the first place? I was working on some custom editor tooling that involved evaluating the whole buffer. I thought I would be clever and wrap the buffer string in a (do…) block. Ran into this issue, so thought I’d ask about it!

thheller05:05:12

@neil.hansen.31 don't wrap ns in a do. that is not supported. ns is a special form that needs to be the first form in the file. this isn't supported in regular CLJS either.

p-himik10:05:02

Just out of interest - shadow.cljs.devtools.server.config-watch doesn't use shadow.cljs.devtools.server.fs-watch but instead busy-loops with (Thread/sleep 1000). Is it just a historical artifact or is there some deliberate decision behind this?

thheller15:05:07

fs-watch only watches directories recursively. overkill for a single file.

👍 1
zimablue17:05:02

does shadow-cljs do any hashing or comparison of modification times on files or pure file-event-watching? Skimming the code it looks like the latter, was wondering whether hashing files or storing last-modification dates was considered/done in an extension or something

thheller17:05:40

the 3rd implies the 2nd so I'm not sure what you are asking? what is the problem or concern?

zimablue17:05:04

not problem or concern, design question

zimablue17:05:47

in theory one can use hashes of files to work out what needs to be recompiled and what doesn't one AFAIK could also use file modification times or filesystem events, but that's not persistent across "watch" sessions

thheller17:05:11

cache takes care of that, which indeed does a md5 hash of the file

zimablue17:05:19

checking that shadow-cljs doesn't do the first and wondering why that choice was made as considering writing a tool for a different purpose that does do that

zimablue17:05:30

how does cache know when it's invalidated?

zimablue17:05:49

is this the "hash-optimized-module" code?

thheller17:05:00

no, not related in any way

zimablue17:05:44

sorry, I am just searching for md5 in the source code