babashka / obb

Ad-hoc ClojureScript scripting of Mac applications via Apple's Open Scripting Architecture.
Eclipse Public License 1.0
241 stars 5 forks source link

Don't use enable-console-print in projects built with shadow #31

Open borkdude opened 2 years ago

borkdude commented 2 years ago

https://github.com/babashka/obb/blob/d8e5245dc3927527e89ce793f7fb2c57266e47f1/src/obb/impl/core.cljs#L62

See: https://github.com/BetterThanTomorrow/calva/issues/1468#issuecomment-1014781194

I still have to read the entire issue to find out why, when I have time.

PEZ commented 2 years ago

That comment is all there is to read about it on this issue (which is about other, also interesting things). In fact you don't even need to read the full comment. Only this part, from Thomas Heller:

Never call this with shadow-cljs anywhere. It is never required in any setup and it will interfere with printing.

borkdude commented 2 years ago

Sure, but why? I'd like to understand the details. Is there a way to have the same code behave well in both shadow and cljs.main?

PEZ commented 2 years ago

I mainly wanted to hep you not have to read the whole issue. 😄 I don't know the details and haven't found any further info on this. Ping @thheller.

borkdude commented 2 years ago

Fair enough :)

thheller commented 2 years ago

If you look at the implementation of enable-console-print! you'll see that it unconditionally sets *print-fn* and *print-err-fn*. shadow-cljs does set its own print-fn on load which will not only print to the console but also send all messages back to the shadow-cljs instances so it can send them futher along to the nrepl client or so.

As a safeguard I actually replace enable-console-print! with a noop. I actually forgot that I did that but I did it because too many people called this and wondered why they were getting no more prints in the REPL. ;)

In essence you can call it but you shouldn't.