Fork me on GitHub
#shadow-cljs
<
2022-07-04
>
pinkfrog01:07:05

How can I variable names in comment around? I often do some quick experimentation and define variables in comments to hold some results. However, due to the hot load mechanism, these variables will disappear. For example

(ns foo)

(comment 
  (def *a (result-of-some-http-req)) 
*a will disappear after add some change in other parts of the file. How can I disable this behavior? I verified, js/foo.STARa_ still exist. It’s just the access of foo/*a gives the undeclared var error

pinkfrog01:07:50

I can change above to

pinkfrog01:07:20

(ns foo)
(declare *a)
(coment
  (def *a (....))
and it works. But I ’d rather move anything about *a to be inside the comment.

thheller04:07:40

well hot reload and REPL are somewhat at odds with each other sometimes

thheller04:07:45

suppose you have

(defn a [])

(defn b []
  (a))

thheller04:07:05

regularly in a file and rename (defn a []) to (defn x []) without changing b

thheller04:07:38

I want to get a warning for that immediately and not at some arbritrary time later when I restart the build or something

pinkfrog04:07:38

But consider my use case, it is possible to tell shadow to not erase the declaration for vars beginning with a * ?

thheller04:07:41

there is no setting to disable the namespace "reset" for hot-reload

thheller04:07:49

no there is not

pinkfrog04:07:32

Then what’s your workflow regarding this? Hotload is great, but on the other hand, it breaks the interactive testing loop cycle.

thheller04:07:52

I never have these kinds of defs

thheller04:07:24

(comment
  (tap> (result-of-some-http-req)))

thheller04:07:26

is what I would have

thheller04:07:42

but honestly given hot-reload I barely use the REPL for CLJS

thheller04:07:13

I mean if you reload the file via the REPL in the first place

pinkfrog04:07:23

After the tap, what’s the next step? How can you look into some nested data fields of the result? Some tools like portal?

thheller04:07:24

eg. load-file it will not be reset

thheller04:07:33

the shadow-cljs inspect UI

pinkfrog04:07:53

One thing to mention, it does not has much to do with the REPL. I mostly perform evaluation in the comment block with the repl panel closed. It’s just things def-ed in the comment block are resetted.

thheller04:07:25

thats a weird statement. I mean what do you care about it getting reset if you don't look at it anyways?

thheller04:07:13

I mean you can always move things to a namespace not part of the actual build

thheller04:07:20

those won't get reset or touched in any way

pinkfrog04:07:23

(comment
  (def *a (some-stuff))
  (def *b (:key *a))
  )
I do look at it. But it’s the inline result not from repl.

pinkfrog04:07:07

I considered (def x/a (some-stuff) but it’s definitely results in syntax error.

thheller04:07:33

well, not removing the analyzer data hides all sorts of issues

thheller04:07:51

I can add a flag to not do the reset, thats not a big deal

pinkfrog04:07:39

Awesome. One more thing, what part does the magic? I am interested.

thheller04:07:39

please open an issue for this. can't get to it today and might forget otherwise

pinkfrog04:07:35

Btw, will the previously required names, e.g., (require ’[foo :refer [bar]), will the bar be kept around after a reload?

thheller04:07:15

no, the entire analyzer data is reset for that namespace

pinkfrog05:07:48

Just wanna make sure after the new flag, the above bar is also kept.

ingesol09:07:52

We are looking for ways to speed up the advanced compilation of our large CLJS codebase. I thought code splitting might help, so I tried it out by putting a couple of namespaces into my-module. My example setup is main + my-module that depends on main. My expectation was that modifying a file within my-module would only rebuild the my-module.js file, but compile times were the same both for modifying files on main and my-module. My question is: Does shadow skip advanced compilation for modules with no changes on the file system?

thheller16:07:40

:advanced is whole program optimization. :modules just splits the final output into multiple files. it still needs to compile everything all at once.

thheller16:07:54

no, this also cannot be done incrementally in any way

ingesol17:07:27

Ok, thanks for clarifying

wilkerlucio12:07:39

hello, on Shadow I'm seeing a lot of reflection warnings when compiling, not sure the cause:

thheller15:07:18

I guess you are running shadow-cljs in an embedded/repl context somehow that binds *warn-on-reflection* to true globally? normally you shouldn't see those?

wilkerlucio19:07:34

makes sense, gonna dig in, thanks!

souenzzo13:07:48

Hello. I'm using :target :graaljs and getting this error message, while trying to load the cljs into polyglot context:

shadow-cljs - failed to load module$node_modules$react_dom$cjs$react_dom_server_browser_development
shadow-cljs - failed to load module$node_modules$react_dom$server_browser
{:clojure.main/message
 "Execution error (PolyglotException) at <js>/:anonymous (ssr.js:47696).\nReferenceError: TextEncoder is not defined\n",
 :clojure.main/triage
 {:clojure.error/cause "ReferenceError: TextEncoder is not defined",
  :clojure.error/symbol <js>/:anonymous,
  :clojure.error/source "ssr.js",
  :clojure.error/phase :execution},
...
Steps to reproduce: git clone --branch graaljs-ssr ; cd atemoia; npm install && clj -A:dev -X atemoia.server/dev-main

souenzzo13:07:56

Seems that it only occurs in React18. React17 works.

thheller15:07:55

graaljs is rather limited and does not have the common browser features

thheller15:07:11

I guess react just assumes TextEncoder is present and wants to use it?

thheller15:07:45

nothing to do from the shadow-cljs side. this is just graaljs being very limited and honestly I would strongly recommend to just use node instead

souenzzo16:07:44

Yes. I will try to polyfill. I'm just having fun and learning about graaljs

souenzzo16:07:21

btw, graaljs is undocumented because it is unstable/unsupported?

thheller16:07:54

well, I consider it incomplete since you really can't do much with it

thheller16:07:03

but thats really a graaljs problem not a shadow-cljs problem

👌 1
thheller16:07:22

no async support, no common APIs, pretty much nothing

souenzzo16:07:22

That limitations are by design (the don't want to implement it) or it just incomplete because it is in development?

thheller16:07:12

I haven't figured out how you can run the scriptengine with node mode enabled. so far it just seems to be available as a node executable replacement

thheller16:07:55

I don't follow graaljs much. so no clue what their plans are regarding more features

souenzzo16:07:19

(.eval "js" "TextEncoder = class { encode() {} }") is enough 🙈

souenzzo19:07:36

BTW, I just leaned about https://blog.cloudflare.com/introducing-the-wintercg/ Seems that a cool project could be WinterGC compliance to graaljs. It may turn graaljs into a nicer target for shadow-cljs 👀

souenzzo13:07:48

@U05224H0W do you have a list of API's that shadow-cljs need to be able to have a REPL inside graaljs?

thheller16:07:18

that entirely depends on how you use it. it is somewhat possible if you control the JVM side graal context and can just use the java side to eval stuff and so on

thheller16:07:45

the JS side doesn't have any IO built-in so the REPL is pretty much a no-go purely from the JS side

souenzzo17:07:55

I'm working on add fetch/websocket/other missing api's into graaljs 🙂 https://github.com/souenzzo/inverno/blob/fetch/src/test/br/dev/zz/inverno_test.clj#L27

souenzzo17:07:54

Still learning A LOT about polyglot/graaljs, but seems to be "just" hard-working

souenzzo17:07:18

Most of the API's, like textencoder is already present at JDK stdlib.

Karan Ahlawat18:07:27

Hey guys, whenever I setup a new shadow-cljs project, and I try to run the repl/watch the build, it gives me errors about transitive dependencies of the JS packages I have in my package.json. And it does not stop until I manually install them. Today it went as far as making me install packages like base64-js and the like manually. I think this should not be the case, so I'm most likely doing something wrong. Could anyone point me to what though? TLDR; shadow-cljs makes me add transitive deps manually, and I don't think that's the intended behavior.

thheller18:07:08

@ahlawatkaran14 if you have packages in pacakge.json you need to run npm install without specifying a package to install them all. otherwise it only ends up installing whatever package you specified

thheller18:07:25

it should never be necessary to install every single package

thheller18:07:44

unless you mess with npm in some way

Karan Ahlawat18:07:16

I use pnpm, but I don't think that should have any effect?

Karan Ahlawat18:07:34

since pnpm supports the same node_modules resolution to be npm compatible

thheller18:07:10

sorry I haven't tried pnpm so dunno what that looks like

Karan Ahlawat18:07:47

it looks pretty similar tbh. Thanks though, will report back

blogscot10:07:28

I’ve had a similar experience using pnpm, in that not all the dependant libraries get installed as happens with npm. Without fully understanding what the issue is, I found that running pnpm i --shamefully-hoist usually fixes this type of issue. The https://pnpm.io/npmrc:

shamefully-hoist
Default: false
Type: Boolean
By default, pnpm creates a semistrict node_modules, meaning dependencies have access to undeclared dependencies but modules outside of node_modules do not. With this layout, most of the packages in the ecosystem work with no issues. However, if some tooling only works when the hoisted dependencies are in the root of node_modules, you can set this to true to hoist them for you.

Karan Ahlawat16:07:48

That did help, thanks 😄

Karan Ahlawat18:07:50

This is what I'm talking about

thheller16:07:36

can't say., which shadow-cljs version do you use? older versions didn't properly support symlinks and the node resolve rules fully. current version does but I never tried pnpm so no clue what else might be going on

Karan Ahlawat16:07:37

The latest one that is on the npm registry, so 2.19.5

Karan Ahlawat18:07:44

hm, using npm works just fine though. So I suppose it's a pnpm thing then

john23:07:31

So I have this new webworker library I'm working on. It's basically the connection/communication/mesh logic ripped out of tau.alpha, so as to have a lower level lib to build a new version of tau (and other things) on top of. Figwheel uses different build IDs for each build, while Shadow uses modules. So, with Calva and Figwheel, I'm able to focus the repl on a particular set of repl clients, using the option "Select CLJS Build Connection." With Shadow I only have the one build, which is defaulting to the main/screen thread:

john23:07:41

Is there any way to force Shadow to focus on a given module, with its respective clients, in Calva or otherwise?

john23:07:16

I see the docs mention:

(shadow/watch :the-build)
(shadow/repl :the-build)

john23:07:14

Maybe I can still use separate builds, instead of modules? I'd just loose code sharing?

john23:07:26

I'll try to get a repo up tonight so folks can try it. I'm trying to make a lib that normalizes some of the differences across build tools to make working with webworkers easier