Fork me on GitHub
#shadow-cljs
<
2023-12-27
>
mikerod16:12:45

I see this exception as an INFO log that doesn’t appear to cause any issues (in thread). I’m curious if it is anything worth looking into.

mikerod16:12:52

[2023-12-27 10:13:39.133 - INFO] :shadow.build.classpath/jar-cache-read-ex - {:file #object[java.io.File 0x34a53af9 "target/.shadow-cljs/jar-manifest/riddley-0.1.12.jar.033bd1610a8ef50a6347cd571eaef76182ca50b0.manifest"]}
RuntimeException java.io.EOFException
	com.cognitect.transit.impl.ReaderFactory$ReaderImpl.read (ReaderFactory.java:114)
	cognitect.transit/read (transit.clj:323)
	cognitect.transit/read (transit.clj:319)
	shadow.build.cache/read-cache (cache.clj:49)
	shadow.build.cache/read-cache (cache.clj:33)
	shadow.build.classpath/find-jar-resources/fn--23022 (classpath.clj:543)
	shadow.build.classpath/find-jar-resources (classpath.clj:542)
	shadow.build.classpath/find-jar-resources (classpath.clj:528)
	shadow.build.classpath/find-resources (classpath.clj:699)
	shadow.build.classpath/find-resources (classpath.clj:690)
	shadow.build.classpath/index-path* (classpath.clj:919)
	shadow.build.classpath/index-path* (classpath.clj:916)
Caused by:
EOFException
	com.cognitect.transit.impl.JsonParser.parse (JsonParser.java:44)
	com.cognitect.transit.impl.ReaderFactory$ReaderImpl.read (ReaderFactory.java:112)
	cognitect.transit/read (transit.clj:323)

thheller18:12:21

can be ignored I guess. it'll just recreate it on next start

👍 1
mikerod17:12:00

I had a macro for cljs that does something like:

(defmacro find-all-namespaces []
  (let [all (->> @env/*compiler* :cljs.analyzer/namespaces keys (mapv str))]
    `~all))
Basically, I was doing compiler introspection to find all namespaces to do other things (not that relevant now). I have some :require in a ns ahead of expanding this macro later on:
(ns my.stuff (:require [my.a] [my.b]))

(def all-of-them (find-all-namespaces))
For the same shadow-cljs build, I end up with the namespaces I expect in all-of-them (ie. my.a and my.b) when doing shadow.cljs.devtools.cli compile. However, I do not find the namespaces expected when I do shadow.cljs.devtools.cli release. Is there something about release and optimizations etc that makes this not work?

thheller18:12:02

how are you checking if they are "found"? I mean this is just an unused def and :advanced will have removed that because it is not used?

mikerod18:12:07

I use it for other things. So I know it’s empty in release mode only.

mikerod18:12:04

I mean the namespace names just aren’t there when release mode. I use this var to do other things and I see them missing at runtime.

thheller18:12:56

what does that mean. please be more precise. :advanced collapses all namespaces and vars, so are the names missing or the things they are supposed to look up?

thheller18:12:08

a repro would help for sure

thheller18:12:14

the above is fine and should work without issue

thheller18:12:28

whatever else you might be doing might not be

mikerod18:12:49

The analyzer gives me the ns i expect when in dev but not when in advanced.

mikerod18:12:16

I figured if it isn’t obvious would need to try to recreate a mini example. Will try it out in a bit.

mikerod18:12:44

I’ve debugged this sort of stuff with cljs compiler before. But shadow does things differently. So didn’t know where to really start

thheller18:12:49

the analyzer data is the same in release, no difference to dev. so everything should be fine.

mikerod18:12:11

I’m seeing differences. 😢

mikerod18:12:35

Hopefully it can be recreated in a minimal way.

thheller18:12:41

if you have a repro I'm happy to take a look

thheller18:12:30

accessing the analyzer data in macros is weird, so there are a couple gotchas

thheller19:12:48

one thing that might be relevant is caching

thheller19:12:15

since the my.stuff maybe isn't always recompiled the analyzer data just may be incomplete

thheller19:12:06

you can try (ns ^:dev/always my.stuff) to prevent that cache

mikerod20:12:46

Been working on recreated. A bit tricky to setup. I think what I’ve found is that it isn’t that the namespaces are missing perhaps, instead it is that I am filtering the namespaces from the analyzer based on details of their :defs.

mikerod20:12:36

In one case, I was looking for test vars, by doing something like (-> ns-entry val :defs vals (filterv :test)) for example.

mikerod20:12:04

I don’t think any caching is going on. I am clearing the whole .shadow-cljs every time with this

thheller21:12:49

tests aren't included in release builds?

thheller21:12:31

unless you set :compiler-options {:load-tests true} (or this is any of the test targets, which set this by default)

mikerod21:12:48

It’s a test runner thing. What is excluding tests?

mikerod21:12:56

I use lein for source paths

thheller21:12:10

that doesn't matter for anything

mikerod21:12:19

And my main export is in a test path in this case

thheller21:12:33

and with which build target is this?

mikerod21:12:46

So shadow removes deftest vars?

thheller21:12:03

cljs removes deftests ...

mikerod21:12:17

I have all of this basically in my “main app” in this case. It’s test helper stuff for something complicated.

mikerod21:12:32

I didn’t have any issue here with cljs and figwheel main.

mikerod21:12:39

This is me switching to shadow

thheller21:12:49

yes, and which build :target do you use?

thheller21:12:22

I'm guessing your config in figwheel had :load-tests true .. which you are probably just missing in shadow

thheller21:12:36

otherwise figwheel removes tests too

mikerod21:12:03

Only way that could be is if fig did so implicitly .

mikerod21:12:17

Oh browser target too

thheller21:12:14

yes :browser is not a test target, so test are removed unless configured not to

thheller21:12:26

:browser-test would keep them

thheller21:12:18

that binding is controlled by the :load-tests compiler option

mikerod23:12:09

Weird. I don’t know how I never had trouble with fig main. I’ll have to look. I’ll try this out though soon. Thanks for the pointers

mikerod01:12:30

So makes sense. Shadow sets this flag to false sometimes while fig and cljs did not

thheller08:12:48

shadow in general sets many defaults that you otherwise need to set manually. easy to forget something like load-tests and then have tests in your optimized browser build where you'd never use them normally

thheller08:12:04

I thought :load-tests defaulted to false but I guess that was wrong

mikerod16:12:33

I was surprised to learn that this feature even existed in deftest. What makes test vars any different than other test sources you wouldn’t want to include? I thought DCE would be the mechanism being relied on for all of that if you were compiling with this sort of thing in the source paths being compiled.

mikerod16:12:53

Is there something special about why deftest wouldn’t be DCE’d the same as other things?

mikerod16:12:15

Anyways, in this specific case. I’ll just look into changing this flag in shadow for this sort of build - hopefully it allows it

thheller16:12:35

hmm? I told you how to change it

thheller16:12:48

:compiler-options {:load-tests true}

mikerod16:12:59

Sorry. Didn’t see that one.

thheller16:12:47

in theory DCE will take care of the tests ... that is however just theory. even if it removes all the tests it can still leave more code alive than it otherwise would

thheller16:12:18

best not having to worry about it in the first place

mikerod16:12:20

My preferred approach is to just not have test stuff on the same compilation path. I don’t rely on DCE for these things really.

mikerod16:12:31

For test builds, I just have an entry point that ends up requiring more stuff.

thheller16:12:39

well that problem doesn't exist in the first place in shadow

thheller16:12:09

you are fine to keep all source files on the classpath at all times, even tests and stuff

thheller16:12:25

it won't affect the builds in any way, unless specifically required by the build namespaces

mikerod16:12:02

I think I did read this one. I’ll read again though. And coming from lein, we just used different :source-paths for different profiles - still will for clj. For cljs though, we did have an alternative app entry point anyways that loaded things we wouldn’t do in the prod app.

thheller16:12:11

also the test builds can require namespaces by regexp, so that you don't need a specific namespace to require them all https://shadow-cljs.github.io/docs/UsersGuide.html#_testing

mikerod16:12:15

Yeah, I read this. Seemed like you had an alternative philosophy on this. I think for cljs that is fine from what I can think of.

mikerod16:12:01

I saw that testing docs too. I’m not sure if I can smoothly switch to shadow testing right now. We have something pretty crazy going on.

thheller16:12:50

I still have src/main src/test etc for my projects too, I just don't worry about having them active and that affecting my project 😛

thheller16:12:16

separating them is still useful, just not build affecting

mikerod16:12:45

I think in clj it matters more to me. We don’t want our jars having dependencies that we only need for test in them. We don’t want things on the classpath that shouldn’t be there, etc. We don’t want source files in the jar included if we don’t need them (eg. they were for tests). In cljs for this type of compilation, you are just coming away with the DCE js and don’t bring along other potential baggage of sources existing.

thheller16:12:23

thats not at all what I'm talking about. you should not rely on DCE for stuff that shouldn't be in the build in the first place.

mikerod16:12:51

I know. I think I already agreed with where you were coming from.

mikerod16:12:18

One downside to the shadow approach I think is it is easier to mistakenly require a ns that you didn’t want to - or didn’t plan out well.

mikerod16:12:33

If your source-paths just didn’t have it on the classpath to begin with - it’d be more of a red flag

mikerod16:12:52

I work with larger teams a lot. I see a lot of mistakes.

thheller16:12:56

thats what https://shadow-cljs.github.io/docs/UsersGuide.html#build-report is for, so you can actually verify what you have in your build

mikerod16:12:29

that’s pretty cool. Never got to that section.