Fork me on GitHub
#shadow-cljs
<
2019-11-02
>
tekacs03:11:08

I… assume that I shouldn’t be doing this:

:closure-defines
 {"shadow.cljs.devtools.client.env.ssl" true}
This configuration works perfectly for me. I’m doing this because whilst I have an SSL section in my shadow-cljs.edn (my dev-http at https://<hostname>:3000 works), my REPL/devtools connection was using ws://<hostname>:9630 rather than wss://<hostname>:9630. I’m reverse port forwarding onto the real host. Any chance that someone could point out the error in my config? I tried reading a bunch of places in the shadow-cljs source, but wasn’t sure how to pull off this behaviour in particular. https://gist.github.com/tekacs/95e2e78f806bc72c9695504426c930a4 Intended behaviour: - Bind to localhost:3000 over SSL for my dev-http - Bind to localhost:9630 over SSL for my main server - Visit https://<hostname>:443 for my dev-http server (due to ssh -R '*:443:localhost:3000 <hostname>` - Have the client use wss://<hostname>:9630 for devtools connections (due to another -R to that SSH)

jorda0mega05:11:43

has anyone been successful in loading a custom font through AppLoading Font.loadAsync in expo?

thheller08:11:22

the dev-http server is completely separate and isn't involved in the websockets setup

thheller08:11:10

I didn't know ssh could be used for https proxying

Filipe Silva12:11:24

is it possible to connect a repl to a :node-test target?

Filipe Silva12:11:59

the repl needs a running process, but when I try to connect node to the output (e.g. node out/test.js) it will run the tests and exit immediately, leaving no running process for the repl to use

Filipe Silva12:11:54

my usecase is that I would like to develop tests with editor support (vscode+calva), and the tooling needs to connect a repl

thheller12:11:38

no that is not supported and also pointless

thheller12:11:05

shadow-cljs node-repl (require 'your.test-ns) (cljs.test/run-tests 'your.test-ns)

thheller12:11:28

doesn't even need a build config

thheller12:11:40

:node-test is meant to run all tests and then exit the process

thheller12:11:03

a REPL would prohibit that exit

thheller12:11:16

which effectively turns it into just a node-repl, but you had to run the process manually

Filipe Silva12:11:57

ok, I suppose that I can use the repl directly

Filipe Silva12:11:23

but that doesn't make for a very smooth development flow, at least with my current knowledge

Filipe Silva12:11:49

in Calva, I would like to jack in to a certain build, and connect to that builds repl

Filipe Silva12:11:03

so I guess I want a node-script target with a main that does (cljs.test/run-tests 'your.test-ns)

thheller12:11:10

no you don't

thheller12:11:25

you want to jack into node-repl

thheller12:11:35

otherwise you have to run the actual node process

thheller12:11:45

which isn't "very smooth"

Filipe Silva12:11:26

if I jack into the node-repl, I have to still do (require 'your.test-ns) (cljs.test/run-tests 'your.test-ns) right?

thheller12:11:25

yes. maybe I just don't understand what you are actually trying to do

thheller12:11:38

with :node-test the tests run ONCE and then exit

thheller12:11:47

suppose it doesn't exit and just waits for REPL stuff

thheller12:11:02

what else is it supposed to do now?

thheller12:11:29

what exactly do you want to do at the REPL?

Filipe Silva12:11:10

I don't want to do anything specific at the repl myself, but to have tooling support in the editor I need to connect a running repl

Filipe Silva12:11:29

otherwise I don't get code completions, or repl execution, etc

Filipe Silva12:11:32

the total steps seem the same the repl way: - jack in - select the a build? (not sure if this is always needed in calva) - select node-repl - input (require 'your.test-ns) (cljs.test/run-tests 'your.test-ns) - have tooling support in vscode the node-script way: - jack in - select node-script target - select node-script target repl - run node the-output.js and leave running - have tooling support in vscode

thheller12:11:00

node-script way is missing node the-output.js

Filipe Silva12:11:06

yes, you are right

Filipe Silva12:11:23

I have to do that in a console somewhere and leave it running

thheller12:11:43

and that part you skip with node-repl

thheller12:11:47

no extra console

thheller12:11:50

no extra command

Filipe Silva12:11:03

there is one less console command, but one more command in a repl

thheller12:11:05

and it lets you run tests selectively

thheller12:11:16

vs. always everything

thheller12:11:34

I run almost all my tests from the REPL

Filipe Silva12:11:39

the calva extension has some helpers for that

Filipe Silva12:11:02

I don't know if they'll work though, because I was still setting it up and got hung on the repl bit

thheller12:11:18

embrace the REPL. it is the clojure way. 🙂

thheller12:11:14

the calva stuff may actually be dependent on some nrepl middleware so it might not work with CLJS

thheller12:11:15

not sure what exactly it does

thheller12:11:55

you can also just jack into node-repl and run the tests separately (if you just want completion and stuff)

thheller12:11:20

or just use Cursive which has all the tooling even without the REPL 😉

Filipe Silva12:11:46

it might be the clojure way but it's also one of those things that isn't obvious and that requires you to figure out how to plug everything together in a unfamiliar way

Filipe Silva12:11:28

maybe cursive is better, but if I have to leave my day to day editor for another way, and configure that from scratch, before I can start being productive... well that's an extra overhead

thheller12:11:48

so the problem is that calva needs a REPL connection for its tooling support

Filipe Silva12:11:51

I can do all that, and it might be better. But does it mean there's no point to trying to use Calva? There must be a point

thheller12:11:02

but you are only working on :node-test so you don't have an actual REPL?

thheller12:11:28

:node-test is only meant to be supplemental to an actual other build that does stuff

thheller12:11:34

why not connect to that REPL?

thheller12:11:57

Calva is great, totally fine to use it

thheller12:11:12

I'm just not convinced that building all tooling on top of the REPL is the best way to go

thheller12:11:09

I'm trying to understand what workflow you are actually trying to achieve

thheller12:11:49

(mine is likely very different, I barely "test" at all, I run code at the REPL)

Filipe Silva12:11:08

ok, let me try and describe the workflow I was going for

Filipe Silva12:11:18

I have some tests that are meant to be ran on node

Filipe Silva12:11:24

I would like to: - open vs code - jack in use calva - get tooling in the test namespaces (completions, eval code) - use the calva commands to run tests (sometimes all of them, sometimes only some of them)

thheller12:11:51

I don't know what the calva test commands do

thheller12:11:03

do they work over the REPL or do they run a separate process?

Filipe Silva12:11:44

that's a good question, let me try to figure it out

thheller12:11:28

ok I don't like Calva anymore. It is still mostly typescript 😛

thheller12:11:49

though it was more CLJS these days 😛

thheller12:11:36

ok from the looks of it uses the REPL

thheller12:11:43

and as expected some nrepl middleware

thheller12:11:50

but that middleware doesn't support CLJS

thheller12:11:54

so I guess you are out of luck and can't really run the tests using calva commands

Filipe Silva12:11:03

so, having this config:

{:builds
 {:test-dev
  {:main async-interop.interop-tests/main
   :output-to "out/test-dev.js"
   :target :node-script}
  :test
  {:ns-regexp "async-interop.*-tests$"
   :output-to "out/test.js"
   :target :node-test}}
 :dependencies [[org.clojure/core.async "0.4.500"]]
 :dev-http {3000 "public"}
 :nrepl {:port 3333}
 :source-paths ["src/main" "src/test"]}
and this namespace with tests
(ns async-interop.interop-tests
  (:require
   [async-interop.interop :refer [p->c]]
   [async-interop.interop :refer-macros [<p!]]
   [cljs.test :refer-macros [deftest is]]))

(deftest interop
  (is true))

(defn main [])
I jack in, select test-dev to build, select the test-dev repl connection

Filipe Silva12:11:25

I run the Calva: run all tests command

Filipe Silva12:11:44

I get this error in the calva pane

Filipe Silva12:11:17

maybe thats related to the middleware you just mentioned

thheller12:11:55

that is an odd error

Filipe Silva12:11:02

if I try to use the node-repl as you mentioned, I can run the tests and get results

Filipe Silva12:11:04

kamik@RED-X1C6 MINGW64 /d/sandbox/async-interop (master)
$ yarn shadow-cljs node-repl
yarn run v1.17.3
$ D:\sandbox\async-interop\node_modules\.bin\shadow-cljs node-repl
shadow-cljs - config: D:\sandbox\async-interop\shadow-cljs.edn  cli version: 2.8.69  node: v10.16.0
shadow-cljs - connected to server
cljs.user=> (require 'async-interop.interop-tests)
nil
cljs.user=> (cljs.test/run-tests 'async-interop.interop-tests)

Testing async-interop.interop-tests

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
nil
cljs.user=>

Filipe Silva12:11:26

but if instead of the node-repl I connect to a cljs-repl for the target, I do not see test results

Filipe Silva12:11:29

kamik@RED-X1C6 MINGW64 /d/sandbox/async-interop (master)
$ yarn shadow-cljs cljs-repl test-dev
yarn run v1.17.3
$ D:\sandbox\async-interop\node_modules\.bin\shadow-cljs cljs-repl test-dev
shadow-cljs - config: D:\sandbox\async-interop\shadow-cljs.edn  cli version: 2.8.69  node: v10.16.0
shadow-cljs - connected to server
async-interop.interop-tests=> (require 'async-interop.interop-tests)
nil
async-interop.interop-tests=> (cljs.test/run-tests 'async-interop.interop-tests)
nil
async-interop.interop-tests=>

thheller12:11:40

I'm unsure what is causing that error above

thheller12:11:06

that is expected. the output goes to whereever test-dev is running

Filipe Silva12:11:45

yes that is what is happening

Filipe Silva12:11:48

kamik@RED-X1C6 MINGW64 /d/sandbox/async-interop (master)
$ node out/test-dev.js

Testing async-interop.interop-tests

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Testing async-interop.interop-tests

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Testing async-interop.interop-tests

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Filipe Silva12:11:16

I suppose that's the whole story

Filipe Silva12:11:34

> This is due to that cider-nrepl doesn't yet support running cljs tests. Something that might not be fixed all that soon. clojure-emacs/cider-nrepl#555

thheller12:11:13

to me it looks like that works directly with clojure.test. so no CLJS support

Filipe Silva12:11:49

I'll add this context to the calva issue, and use the node-repl to run tests manually

Filipe Silva13:11:00

is there a way to run a single test via the node-repl?

thheller13:11:01

tests are callable functions

thheller13:11:12

so (deftest some-test ...) is callable as (some-test)

thheller13:11:43

I'm not a fan of cljs.test. I think it is implemented in a needlessly complex way which makes it really annoying to use

thheller13:11:01

everything is done via macros

Filipe Silva13:11:34

hm.... I didn't know, that, but it opens up another approach

thheller13:11:12

lots of the problems with tooling is that most of it pretends that clojurescript is like clojure

thheller13:11:29

so it tries to treat them the same .. which they simply aren't

Filipe Silva13:11:42

I was trying this approach instead: - open vs code - jack in using calva to a node-test target, then use node-repl - got tooling in the test namespaces (completions, eval code) - then tried to run the individual test functions in the calva repl window

Filipe Silva13:11:41

that got me another odd Calva error

thheller13:11:07

I thought I fixed that error. which verison are you on?

Filipe Silva13:11:40

$ yarn list shadow-cljs
yarn list v1.17.3
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ [email protected]
Done in 0.18s.

thheller13:11:58

that is only the npm package

thheller13:11:03

do you use deps.edn/project.clj?

thheller13:11:21

(if you do they might have a different version)

Filipe Silva13:11:24

I am using a shadow-cljs.edn

{:builds
 {:test-dev
  {:main async-interop.interop-tests/main
   :output-to "out/test-dev.js"
   :target :node-script}
  :test
  {:ns-regexp "async-interop.*-tests$"
   :output-to "out/test.js"
   :target :node-test}}
 :dependencies [[org.clojure/core.async "0.4.500"]]
 :dev-http {3000 "public"}
 :nrepl {:port 3333}
 :source-paths ["src/main" "src/test"]}

Filipe Silva13:11:45

when shadow-cljs starts it lists these versions

Filipe Silva13:11:47

shadow-cljs - config: d:\sandbox\async-interop\shadow-cljs.edn  cli version: 2.8.69  node: v10.16.0
shadow-cljs - socket connect failed, server process dead?
shadow-cljs - HTTP server available at 
shadow-cljs - server version: 2.8.69 running at 
shadow-cljs - nREPL server started on port 3333
shadow-cljs - watching build :test-dev

thheller13:11:12

hmm yeah I thought I fixed that issue but I guess I didn't

thheller13:11:22

happens when (ns foo.bar) is first eval'd at the REPL

thheller13:11:27

and then loaded from a file

Filipe Silva13:11:25

yes I think that's what happens in my editor, because I have Calva configured to automatically load the namespace on save

Filipe Silva13:11:45

so I guess it loads the NS at the repl, then shadowcljs detects the file changed and loads from the file?

thheller13:11:58

ah right. the bug I fixed was require itself

thheller13:11:01

didn't fix load-file

Filipe Silva13:11:32

subscribed to it, thank you for all of your help on this

Filipe Silva13:11:49

I'll do a write-up on the calva issue with the test I did today

calva 4
pez14:11:50

> ok I don’t like Calva anymore. I heard that! 😃

pez14:11:29

> - jack in using calva to a node-test target, then use node-repl @filipematossilva: curious, how did you “use node-repl”?

Filipe Silva15:11:28

I used jack in, selected a target, then selected node-repl from this window

pez15:11:11

Cool. That's what you're supposed to do. 😎 You can then switch between the build you started at jack-in and node-repl at will. (In case that is not made clear enough by Calva)

Filipe Silva15:11:31

I didn't know I could, I often just reloaded the vscode window... but I did notice I could do something of the sort on the buttons in the status bar, just never tried much

pez15:11:26

The command is Calva; Select CLJS Build Connection. Maybe not the best name for it… but, yeah, the status bar has a button for it as well.

Filipe Silva15:11:23

I tested several approaches

Filipe Silva15:11:29

and logged the results here

Filipe Silva15:11:43

that repo can be used to test

Filipe Silva15:11:05

on calva's side, the test commands don't work on cljs: https://github.com/BetterThanTomorrow/calva/issues/311

Filipe Silva15:11:08

on shadow cljs's side two bad interactions happen with calvas repl window - the test output isn't shown for node repls (https://github.com/thheller/shadow-cljs/issues/373) - running a test build without autoron and with node-repl fails to load the namespace https://github.com/thheller/shadow-cljs/issues/587

pez15:11:56

I’m painfully aware that test commands do not work for clks…

pez15:11:40

From the calva-testing repo: > running tests by name in Calva repl shows nil return, must check separate calva output pane Not sure what the nil results are about, but you can use the Calva setting for async output routing to get Calva to show that output in the REPL window instead of the Output pane. (So at least one inconvenience less.)

Filipe Silva15:11:15

but maybe that's not the whole story

Filipe Silva15:11:44

atm the best shot seems to be running tests on a autorun node-test build to get around https://github.com/thheller/shadow-cljs/issues/587

pez15:11:38

I use auto-run but stay connected to my app-build. So I start both my app build and my test build at jack-in and then connect to the app build. auto-run keeps watching the files and reruns the tests when the files change.

Filipe Silva16:11:16

yeah for browser apps I do something similar

dpsutton17:11:11

@thheller can you confirm that its never valid to use shadow.cljs.devtools.api/nrepl-select on browser-repl or node-repl? This is meant only for a named build?

thheller17:11:42

@dpsutton that is valid for :browser-repl and :node-repl yes

dpsutton17:11:19

ah so i was incorrect.

thheller17:11:17

they need to be running though

thheller17:11:49

so maybe there should be a separate op for starting a browser-repl/node-repl but not switching to it

thheller17:11:15

but when they are running you can select them like any other build repl

thheller17:11:29

they are regular builds after all, just with a hardcoded config and some extras

dpsutton17:11:08

and by running there needs to be a shadow-cljs server browser-repl ?

thheller17:11:28

thats not a command

thheller17:11:47

there needs to be a running server instance yes

thheller17:11:49

shadow-cljs server

thheller17:11:15

to start a browser REPL you can run (shadow.cljs.devtools.api/browser-repl)

thheller17:11:26

that will start it and switch

dpsutton17:11:14

but there can only be on server running at a time?

dpsutton17:11:42

it seems that CIDER always starts a server so there's no good way for it to do this kind of stuff

thheller17:11:34

I thought it starts the server and connects to it? that is all you need?

dpsutton17:11:30

yeah. there's two repl types for shadow in CIDER. the normal one and then one called shadow-select which doesn't start a watch. I'm trying to figure out how the select version works and what needs to be running for that to make sense.

This kind of CLJS REPL is very helpful for cases when you are already watching
one or more shadow builds in shadow either after having launched the server in
a terminal or from within Cider.
This patch also refactors option normalization out of figwheel-main so that it
can be reused by every other function.

thheller17:11:17

whats the normal one?

thheller17:11:54

select only switches the nrepl session to CLJS. it doesn't do anything regarding shadow-cljs itself. it is strictly for nrepl purposes.

dpsutton17:11:17

/usr/bin/npx shadow-cljs -d nrepl:0.6.0 -d cider/piggieback:0.4.2 -d cider/cider-nrepl:0.23.0-SNAPSHOT server and then running (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch <build>) (shadow/nrepl-select <build>))

dpsutton17:11:42

so in this case, if you choose browser-repl, it doesn't watch and select, just shadow/browser-repl

thheller17:11:58

ok that is start the watch and switch the nrepl to it (two commands)

thheller17:11:09

browse-repl is basically watch+select in one

thheller17:11:53

if you call browser-repl repeatedly it'll just select

thheller17:11:18

can you remove that require btw?

thheller17:11:40

or well it doesn't matter much I guess

thheller17:11:17

the first session you connect to is a regular CLJ REPL

thheller17:11:42

is that used for anything else other than clone+select to CLJS?

dpsutton17:11:33

let me back up and show the problem that I'm trying to solve. If you choose :browser-repl the above startup command doesn't work. So I understood that you had to not do watch and nrepl-select for the built in repls but just call shadow.cljs.devtools.api/special-repl instead

dpsutton17:11:37

npx shadow-cljs -d nrepl:0.6.0 -d cider/piggieback:0.4.2 -d cider/cider-nrepl:0.23.0-SNAPSHOT clj-repl

(shadow.cljs.devtools.api/watch :browser-repl)
Execution error (ExceptionInfo) at shadow.cljs.devtools.config/get-build! (config.clj:153).
no bulid with id: :browser-repl

dpsutton17:11:49

and this confirms that this behavior doesn't work for the built in repl types i think

thheller17:11:28

as I said ... you cannot watch the "special" builds

thheller17:11:34

so you run them via separate commands

dpsutton17:11:57

right. so i need spacial behavior for when the user uses a special repl. But you can nrepl-select the "special" builds?

thheller17:11:36

I'm confused. if you call the special REPL is will already switch

thheller17:11:51

if the use switches out of it you CAN nrepl-select it again yes

thheller17:11:10

(do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :browser-repl) (shadow/nrepl-select :browser-repl))

thheller17:11:17

that is not valid and is replaced by

thheller17:11:26

(do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/browser-repl))

thheller17:11:33

the end result is the same

thheller17:11:58

the user can send :cljs/quit which will drop the session back to CLJ

thheller18:11:07

it will not actually terminate the REPL though

thheller18:11:17

you can nrepl-select :browser-repl to get back to it

dpsutton18:11:54

awesome. thanks

dpsutton18:11:46

hmm. (shadow.cljs.devtools.api/nrepl-select :browser-repl) -> [:no-worker :browser-repl]

thheller18:11:25

did you run (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/browser-repl)) first?

thheller18:11:46

nrepl-select is ONLY for switching

dpsutton18:11:07

to an already running build?

dpsutton18:11:42

gotcha. ok.

dpsutton18:11:44

thanks much