Fork me on GitHub
#shadow-cljs
<
2019-05-03
>
enn16:05:28

Can somebody help me understand why I need a watch to run a REPL? (Or maybe I'm misunderstanding that requirement?)

enn16:05:52

I'm having difficulty understanding the different options--`clj-repl`, cljs-repl, node-repl

enn16:05:26

node-repl seems like what I want but I don't understand what "It has access to all your code via the usual means." in the docs means.

lilactown16:05:13

@enn what are you trying to do? develop an app? just play at the REPL?

enn16:05:21

@lilactown I am trying to develop an AWS Lambda node function. I need one dependency loaded (the AWS JS SDK).

enn16:05:03

I don't have any Clojurescript background, only Clojure. Most of the documentation I can find presumes a level of familiarity with third-party tools (node, npm, yarn) that I do not have.

enn16:05:15

(In production, the AWS lambda runtime automatically has the AWS SDK available, as I understand it. But I would like to also have it available locally in an instance with a REPL so I can iterate on my code without needing to deploy constantly)

lilactown16:05:04

so CLJS is different than Clojure, in that the process that takes Clojure code and turns it into something the platform executes is separate from the process it actually evaluates in

lilactown16:05:15

so the typical way of working on an application is to have a watch running (which is compiling your ClojureScript code) and a Node.js process running which is connected to that watch.

lilactown16:05:29

your REPL code then would go through that same compilation process before being sent to the Node.js process to be evaluated

enn16:05:41

I think it's that third point that I am most confused about

enn16:05:06

how do I get a REPL where that compilation will happen?

thheller16:05:20

@enn shadow-cljs node-repl and then (require '["aws-sdk" :as aws]) should get you started without any watch

thheller16:05:30

watch is only required if you have an actual build you want to do

thheller16:05:48

if you just want the normal REPL workflow like you'd do in CLJ node-repl is fine

enn16:05:34

I get this error:

[0:0]~cljs.user=> (require '["aws-sdk" :as aws])
repl/require failed { Error: ENOENT: no such file or directory, open '/Users/elinaeher/clubhouse/backend/salesforce-lambda/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow.js.shim.module$aws_sdk.js'

lilactown16:05:41

you will need to run npm i aws-sdk in the local directory

thheller17:05:22

how "wrong" is that path?

thheller17:05:39

/Users/elinaeher/clubhouse/backend/salesforce-lambda is that your project directory?

thheller17:05:49

hmm the node repl should make sure that the file exists before trying to load it?

thheller17:05:13

can you check the contents of the /Users/elinaeher/clubhouse/backend/salesforce-lambda/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime directory? it should have a bunch of .js files?

enn17:05:19

after installing aws-sdk with node I am able to require it in the CLI repl. If I connect with CIDER though I am not in a clojurescript repl and it doesn't work

enn17:05:56

@thheller there is a bunch of js in there but I don't see anything that looks like AWS

thheller17:05:29

shadow.js.shim.module$aws_sdk.js well that would be the only one

enn17:05:29

everything starts with cljs, goog, shadow, or clojure

enn17:05:42

ah I do see that

thheller17:05:21

hmm so the file exists but node doesn't find it?

thheller17:05:58

are you one a weird network drive or some other non-standard filesystem that maybe doesn't like the $?

lilactown17:05:36

but it's working now right?

enn17:05:57

well kind of

enn17:05:02

not in the nrepl

enn17:05:05

only in the CLI repl

enn17:05:22

I'm fine doing the watch workflow if that is a better way to do this

enn17:05:40

just as long as I can get a REPL where I can run my code interactively

thheller17:05:48

thats no different really

thheller17:05:16

what is your nrepl setup? do you use lein/deps.edn or just plain shadow-cljs.edn?

enn17:05:31

in this repo I just have a minimal shadow-cljs.edn

thheller17:05:13

I know basically nothing about CIDER so if things works without it I can't help much

enn17:05:32

I have tried basically that flow ... I don't understand this part though: https://shadow-cljs.github.io/docs/UsersGuide.html#_connect_the_javascript_environment

enn17:05:46

> If you haven’t already done so, connect a JavaScript runtime to the shadow-cljs server. For example, for browser development, browse to http://localhost:8080. What would the node equivalent be?

thheller17:05:29

well ... M-x cider-connect-sibling-cljs I have no clue what that does

thheller17:05:50

you can just run shadow-cljs node-repl separately and select the :node-repl build in cider

thheller17:05:27

or run (shadow.cljs.devtools.api/node-repl) in the cider CLJ REPL

thheller17:05:37

but I have absolutely no clue how cider handles nrepl sessions and such

justinbarclay17:05:32

I don’t think it’s cider-connect-sibling-cljs he wants, but cider-connect-cljs https://cider.readthedocs.io/en/latest/clojurescript/#using-shadow-cljs

enn17:05:33

Leaving CIDER out of it for now, I am still having problems connecting a watch and a repl

enn17:05:10

$ shadow-cljs watch app
shadow-cljs - config: /Users/elinaeher/clubhouse/backend/salesforce-lambda/shadow-cljs.edn  cli version: 2.8.36  node: v8.11.3
shadow-cljs - server version: 2.8.36 running at 
shadow-cljs - nREPL server started on port 61441
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
[:app] Build completed. (44 files, 2 compiled, 0 warnings, 1.24s)
$ shadow-cljs cljs-repl app
shadow-cljs - config: /Users/elinaeher/clubhouse/backend/salesforce-lambda/shadow-cljs.edn  cli version: 2.8.36  node: v11.12.0
shadow-cljs - connected to server
[1:1]~cljs.user=> (require '["aws-sdk" :as aws])
No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
[1:1]~cljs.user=>

thheller17:05:00

watch doesn't manage your node process. so you need to run node <the-output-to>.js manually

enn17:05:58

Do I need to restart node when the output file changes or does node automatically reload?

richiardiandrea21:05:48

What does reload mean in this context, do you want to launch the process again? If that's the case then Thomas' solution is the best (or use nodemon). However if you want more of a REPL-driven development you can keep the process going and shadow will reload the namespaces for you. Am I right @thheller? Hopefully 😃

thheller17:05:54

node doesn't reload anything. you can tell shadow-cljs to reload via the hooks

lilactown17:05:09

to use node-repl with cider: 1. run shadow-cljs node-repl 2. wait for nREPL server started on port <x> 3. In Emacs, M-x cider-connect and do localhost, port <x> 4. Once in the CLJ REPL, run (shadow/repl :node-repl)

enn17:05:33

OK. That works, but CIDER does not register that it is a CLJS REPL. However, if I start it with cider-jack-in-cljs per the link that @emoarmy posted, and run node target/main.js separately, it does work and CIDER does pick on it being a CLJS REPL. Thank you for your help, everyone.

jjttjj18:05:27

I'm using a PixelBook with Google's linux VM "Crostini". I believe I need browsers to use penguin.linux.test as a host instead of localhost for websocket connections. Is there setting that I can use to change the websocket host with shadow-cljs?

thheller18:05:44

the browser build will default to connecting to the host you used to access the page

thheller18:05:04

so if you use it should be using that host as well?

jjttjj18:05:47

ok great, that works, thank you!

thheller18:05:22

you can also configure it but if that works its probably the easiest way

jjttjj18:05:27

yeah this is probably best thank you