Fork me on GitHub
#shadow-cljs
<
2018-10-22
>
vigilancetech06:10:06

Now I'm trying to take the shadow-cljs electron example code (https://github.com/shadow-cljs/examples/tree/master/electron) and connect to the main and renderer processes with emacs cider-connect-cljs (renderer first) then with cider-connect-sibling-cljs (main). When I do the renderer everything looks okay (other than a middleware mismatch error cuz I'm using the latest snapshot) but when I do the sibling it appears to give me the same repl and it has a bunch of errors:

...
;;
;; You can remove this message with the <M-x cider-repl-clear-help-banner> command.
;; You can disable it from appearing on start by setting
;; ‘cider-repl-display-help-banner’ to nil.
;; ======================================================================
shadow.user>
WARNING: clj-refactor and refactor-nrepl are out of sync.
Their versions are 2.4.0 (package: 20180826.2149) and n/a, respectively.
You can mute this warning by changing cljr-suppress-middleware-warnings. To quit, type: :cljs/quit
[:selected :renderer]
WARNING: No such namespace: shadow, could not locate shadow.cljs, shadow.cljc, or JavaScript source providing "shadow" (<stdin> at 1:55)
WARNING: Use of undeclared Var shadow/watch (<stdin> at 1:55)
WARNING: No such namespace: shadow, could not locate shadow.cljs, shadow.cljc, or JavaScript source providing "shadow" (<stdin> at 1:76)
WARNING: Use of undeclared Var shadow/nrepl-select (<stdin> at 1:76)
cljs.user> 
there's a 2nd repl buffer that is created with similar, but not quite exactly the same, results:
...
;;
;; You can remove this message with the <M-x cider-repl-clear-help-banner> command.
;; You can disable it from appearing on start by setting
;; ‘cider-repl-display-help-banner’ to nil.
;; ======================================================================
WARNING: clj-refactor and refactor-nrepl are out of sync.
Their versions are 2.4.0 (package: 20180826.2149) and n/a, respectively.
You can mute this warning by changing cljr-suppress-middleware-warnings.
shadow.user> TypeError: shadow.watch is not a function
    at eval (eval at <anonymous> (file:///home/kevin/0work/examples/electron/app/js/cljs-runtime/shadow.cljs.devtools.client.browser.js:829:8), <anonymous>:4:8)
    at eval (eval at <anonymous> (file:///home/kevin/0work/examples/electron/app/js/cljs-runtime/shadow.cljs.devtools.client.browser.js:829:8), <anonymous>:7:3)
    at file:///home/kevin/0work/examples/electron/app/js/cljs-runtime/shadow.cljs.devtools.client.browser.js:829:8
    at Object.shadow$cljs$devtools$client$env$repl_call [as repl_call] (file:///home/kevin/0work/examples/electron/app/js/cljs-runtime/shadow.cljs.devtools.client.env.js:139:108)
    at Object.shadow$cljs$devtools$client$browser$repl_invoke [as repl_invoke] (file:///home/kevin/0work/examples/electron/app/js/cljs-runtime/shadow.cljs.devtools.client.browser.js:827:46)
    at shadow$cljs$devtools$client$browser$handle_message (file:///home/kevin/0work/examples/electron/app/js/cljs-runtime/shadow.cljs.devtools.client.browser.js:907:44)
    at Object.shadow$cljs$devtools$client$env$process_ws_msg [as process_ws_msg] (file:///home/kevin/0work/examples/electron/app/js/cljs-runtime/shadow.cljs.devtools.client.env.js:258:102)
    at WebSocket.<anonymous> (file:///home/kevin/0work/examples/electron/app/js/cljs-runtime/shadow.cljs.devtools.client.browser.js:1002:40)
shadow.user> 
The 2nd repl's buffer status says it's only pending. The renderer repl doesn't initially have those (non-middleware) errors until after the sibling is created. From the terminal(s) the repls work perfectly. The renderer can do things like (js/alert "foo") and it works. The main issues an error when trying to do that (as it should because its only the launcher). Help!?!?

thheller07:10:56

@vigilancetech sounds like emacs is not capable of managing two connections?

kwladyka07:10:14

@thheller hi, why EPL-1.0 vs MIT or EPL-2.0? I am trying to learn about licences 🙂

kwladyka07:10:55

haha thanks to be honest 🙂

thheller07:10:02

EPL is the default license set when you create a new project with lein new

thheller07:10:12

and clojure is using it so that sounded ok to me

kwladyka07:10:07

“disclose source” - do you know what does it mean in practice? It force to public sorce when modify “program” / use “program”? Public source of EPL licensed “program” or whole app using this “program” as a dependency.

thheller07:10:51

as far as I understand the source must be "open" when you modify it

kwladyka07:10:13

but the question is: for example if somebody will write wrapper on shadadow-cljs will be forced to public source or not? It is dependency, not modification of the code itself.

kwladyka07:10:25

understanding licenses is harder than coding 😉

thheller07:10:21

hehe yeah ... to be honest I just looked at the summary on github and that looked ok

thheller07:10:19

basically anyone can do anything they want as long as they publish the source. and I can't be sued for bugs 😛

kwladyka07:10:01

just thinking if there is any risk for developers if they use source code with EPL license they will have to public app / part of they app

kwladyka07:10:39

And for myself if I have to add some extra informations to my app about ALL deps license…

kwladyka07:10:09

maybe i break the law everyday and I don’t know 🙂

kwladyka07:10:47

because the question is if using “program” as dependencies force me to license conditions. Or as long as it is deps only it doesn’t matter.

kwladyka07:10:38

Sorry, I know it is not the topic for this channel. Just blowing my mind and nobody really understand and can answer 🙂

thheller08:10:50

yeah its tough. I also have no clue how to do include licenses from libs properly

thheller08:10:27

from my perspective you can do whatever you like with shadow-cljs BUT if you make a commercial profit I expect you to contribute back any actual changes you make

thheller08:10:41

if you just use it as a lib without modifications that is fine

kwladyka09:10:12

yeah, but I am talking about license not shadow-cljs directly. It seems everybody don’t care about licenses, but I have some experience about law. I really expect the worst always. Bad things happening however you try be legal 🙂

thheller09:10:55

yeah its annoying

emil0r12:10:07

shadow-cljs - starting ... [:app] Compiling ... The required namespace “infinitor.collector.core” is not available.

emil0r12:10:23

Any idea why that happens? Got src/infinitor/collector/core.cljs

emil0r12:10:28

with a -main function

thheller12:10:50

and you have :source-paths ["src"]?

vigilancetech12:10:17

@thheller have you ever looked into what it would take to have a system-wide shadow-cljs compile server rather than having to spin up a JVM for each project?

emil0r12:10:48

Ah… a bit too used to how lein sets it up I see 🙂

thheller12:10:12

@vigilancetech yes I have but it would be too much work and probably not worth the effort

emil0r12:10:19

Why does shadow-cljs as default split the source paths up as src/dev, src/main and src/test?

thheller12:10:32

because its my recommended setup

emil0r12:10:44

What’s the reasoning behind it?

thheller12:10:15

I like it and most projects use a setup like that?

thheller12:10:40

just change it to ["src"] if you do not need or want it

thheller12:10:10

the reasoning is that you'll often have sources that are only for tests or development

thheller12:10:16

and you want to split those from your main sources

emil0r12:10:22

between main and test sure. Bit different from how lein sets it up, but I’m not fussed about it. Trying to fit src/dev into the mental model

thheller12:10:36

rather than having dev at the root I prefer to put it in src/dev

emil0r12:10:37

ok. fair enough

thheller12:10:04

lein puts src and test at the root

thheller12:10:12

and most people add dev later on

thheller13:10:30

@vigilancetech the problem really is classpath isolation. each project has its own set of dependencies and those do not always match. can only load one version of a lib at a time

👍 4
vigilancetech13:10:16

@thheller could Stewart Sierra's components help with that?

thheller14:10:49

just trust me when I say that I tried various different approaches and all of them had too many drawbacks to be worth the trouble

vigilancetech15:10:58

not meaning to pester you about it, but it sounds like boot has something in it that may provide that sort of isolation if you ever want to check it out sometime. Having a bunch of people developing on one server isn't that common nowadays, however maybe there might be a use for it in CI

thheller15:10:02

please ... I thought about this for a very long time ... there is nothing to be gained

thheller15:10:44

IF I want full classloader isolation then each "pod" (when using boot terminology) will load its own clojure version and dependencies

thheller15:10:51

which means you pay the full startup cost

thheller15:10:09

if you account for that having separate vms is actually faster and easier to manage

thheller15:10:36

sure if you don't care about classloader isolation then you can optimize a few things

thheller15:10:54

but I care very much about that since dealing with dependency conflicts is already complicated enough

thheller15:10:24

clojure just isn't built for multiple runtimes in the same VM

thheller15:10:36

the upcoming launcher UI will make it easier to manage multiple shadow-cljs instances so you don't have to have a terminal open for each

thheller15:10:17

but running multiple projects in the same JVM is a not something I'm going to pursue further

royalaid15:10:28

@thheller just following up on previous discussion I have filled the issue for the 206 http codes here:https://github.com/thheller/shadow-cljs/issues/396.

thheller16:10:40

yeah I took a look this morning. unfortunately I can't easily use the undertow handler directly

thheller16:10:02

might just modify default ring middleware a bit

vigilancetech16:10:51

@thheller well, I wasn't so much concerned about the start up time as the memory footprint of multiple servers. I happen to be running on a pretty small machine (which is why I'm looking at moving to bootstrap). Although my situation is unusual, I'd think that in a build farm it would also be a concern.

thheller16:10:31

same situation again. memory footprint would not change.

thheller16:10:43

if the default memory setting are problematic you can always tune them

thheller16:10:12

add :jvm-opts ["-Xmx1G"] to you shadow-cljs.edn to limit the amount of memory to 1gb

thheller16:10:21

can go lower if you want

thheller16:10:50

depending on your project really. closure needs the most memory when optimizing so I wouldn't go lower than 512M

vigilancetech16:10:59

yeah, well, soon enough I'll probably have a bigger machine, but I've got this little ARM TV box I'd just love to see being able to be turned into a professional development system for up and coming, but otherwise impoverished programming apprentices

vigilancetech16:10:00

IIRC, when I started multiple servers, each was taking about 700MB of resident memory

thheller16:10:18

yeah because the the default JVM memory settings are greedy

vigilancetech16:10:02

Well, thanks for your help/info @thheller, and I really love what you've done with this tool. Back when I was on boot it was hell to try and get a reliable REPL going, much less connect to it with cider. Plus I think it was a bit of overkill for what I needed (that may change in the future, IDK). Can you think of a situation where shadow would be vulnerable to the problems boot's pod isolation solves? Like a resident dependency in the development machine that gets overlooked in the config file that doesn't exist in the target machine throwing an error?

thheller16:10:56

well dependency issues are always possible depending on how complicated you make your setup

thheller16:10:47

but no .. nothing but your config can add stuff to the classpath

thheller16:10:58

I never had this problem though so I'm not sure how you'd even get into that situation

👍 4
vigilancetech16:10:35

fortunately I haven't either, but the boot documentation seems to make it sound like a serious concern. Not sure if its enough of a threat to have to deal with the extra complexity of getting it all configured though. Certainly not for me, right now.

emil0r17:10:27

What am I missing?

(require ["Buffer" :as Buffer])

(Buffer/alloc 1024)

emil0r17:10:45

getting TypeError: shadow.js.shim.module$Buffer.alloc is not a function

thheller17:10:59

well what is Buffer? try to print it (js/console.log Buffer)

emil0r17:10:55

hmm… getting a nil

emil0r17:10:59

not what i expected

thheller18:10:16

whats your build target?

thheller18:10:54

in node you can just cheat and use (js/Buffer.alloc ...)

emil0r18:10:47

argh… sorry. the stdout is not connected to the REPL in emacs

thheller18:10:36

so it exports multiple objects

thheller18:10:57

then you need (:require ["Buffer" :refer (Buffer)])

emil0r18:10:46

nah. was just me logging to the console twice

emil0r18:10:58

ah, i see what you mean

thheller18:10:08

its still exporting multiple objects 😉

emil0r18:10:31

yeah. (Buffer/Buffer.alloc 1024) works

emil0r18:10:57

any good way of handling UUIDs in cljs? using the npm module uuid only gives me strings as opposed to an object reflecting the UUID

thheller18:10:28

no idea. they all seem to be using strings only

emil0r18:10:23

wow… so bad

emil0r19:10:14

@thheller thumbs up for shadow-cljs 🙂. very smooth once i got it up and running

👍 12
kanwei22:10:21

amen to that... went from boot to tools.deps and shadow works perfect now 🙂

kanwei22:10:33

thanks for all the amazing work @thheller

❤️ 4