This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-21
Channels
- # aleph (2)
- # announcements (2)
- # babashka (10)
- # beginners (117)
- # calva (11)
- # cider (19)
- # clj-kondo (27)
- # cljs-dev (24)
- # cljsjs (1)
- # clojure (73)
- # clojure-europe (3)
- # clojure-italy (2)
- # clojure-nl (47)
- # clojure-spec (23)
- # clojure-uk (28)
- # clojurescript (71)
- # cursive (7)
- # data-science (17)
- # datascript (1)
- # datomic (7)
- # duct (23)
- # emacs (23)
- # fulcro (6)
- # graalvm (41)
- # jobs (2)
- # luminus (1)
- # malli (1)
- # off-topic (151)
- # pathom (1)
- # portkey (10)
- # re-frame (12)
- # reitit (17)
- # shadow-cljs (158)
- # spacemacs (14)
- # sql (8)
- # tools-deps (17)
- # xtdb (9)
I'm using shadow-cljs to compile react-native to an Android emulator (code is forked from https://github.com/PEZ/rn-rf-shadow )
It works fine until I encounter an error. Sometimes they disconnect the CIDER nREPL (started via Emacs M-x cider-jack-in-cljs
) with the runtime in the Android VM, then all REPL commands result in:
example.repl> (js/alert "test")
REPL command timed out.
Is there a way to recover from this state? Reloading the app via CMD+M
(in the emulator) doesn't re-establish the connection from Emacs to the in-process nREPLJust to make sure - does only js/alert
timeout or any command (given that you haven't executed js/alert
before it).
The thing is - js/alert
is blocking. The execution will not continue till you interact with the pop-up dialog.
(note that the hot-reloading part of shadow-cljs still works fine, it's just the REPL connection that gets borked)
the problem is that in android the react-native app does not disconnect the websocket when you reload the app
I added (shadow.cljs.devtools.api/repl-runtime-clear)
to get rid of "stale" connections like that but it has to be called from a CLJ REPL
Thanks @thheller, appreciate that there's a way to do this. I wrote a section for my README.md but wanted to repost here for channel record. Recover disconnected shadow-cljs REPL You might accidentally crash your react-native app on your emulator/browser with a big red error screen. You can hit Reload to restart the app into a working state, but putting any command into your shadow-cljs REPL will time out.
myapp.core> (js/alert "test")
REPL command timed out.
To recover this you'll need to:
1) Quit the CLJS REPL
2) Tell shadow-cljs to clear its REPL connection
3) Reconnect the CLJS REPL
The following commands should achieve this.
cljs.user> :cljs/quit
;; wait at least 5 seconds for session cleanup
user> (shadow.cljs.devtools.api/repl-runtime-clear)
user> (shadow/repl :app)
also only need to wait 5sec after reloading the actual app. so may not need to wait at all depending on how fast you do this 😉
Hmm, my REPL never recovers from the disconnected state after hitting Reload
. That's after I tank the app with something bad like (js/require "foo")
No sweat, gotta sleep soon myself. If you have any recommendations I'll try them tomorrow, but thanks either way 🙂
So @thheller I noted that you mentioned in #cljs-dev that CLJS is stuck at an older version of Google Closure compiler -- is that something that carries over to shadow-cljs too or do you override the google closure dependency?
shadow-cljs uses the latest closure compiler and library. it does override those yes.
I'm having some trouble using the main
option for node-test targets... given this namespace:
(ns app.core-spec
(:require [cljs.test :refer-macros [deftest is]]))
(deftest something (is true))
and config:
:test {:ns-regexp "app.core-spec"
:output-to "out/test.js"
:target :node-test}}
running the tests works:
$ shadow-cljs compile test && node out/test.js
shadow-cljs - config: D:\sandbox\devcards-test\shadow-cljs.edn cli version: 2.8.69 node: v10.16.0
shadow-cljs - socket connect failed, server process dead?
[:test] Compiling ...
[:test] Build completed. (47 files, 2 compiled, 0 warnings, 2.04s)
Testing app.core-spec
Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
Done in 13.20s.
but if instead I require the test runner:
(ns app.core-spec
(:require [cljs.test :refer-macros [deftest is]]
[shadow.test.node :as stn]))
(deftest something (is true))
(defn main []
(stn/main))
and alter the config to use my main
:test {:main app.core-spec/main
:output-to "out/test.js"
:target :node-test}}
no tests will be found:
kamik@RED-X1C6 MINGW64 /d/sandbox/devcards-test (master)
$ yarn test:once
yarn run v1.17.3
$ shadow-cljs compile test && node out/test.js
shadow-cljs - config: D:\sandbox\devcards-test\shadow-cljs.edn cli version: 2.8.69 node: v10.16.0
shadow-cljs - socket connect failed, server process dead?
[:test] Compiling ...
[:test] Build completed. (47 files, 2 compiled, 0 warnings, 1.89s)
Ran 0 tests containing 0 assertions.
0 failures, 0 errors.
Done in 12.60s.
I also tried using both :main
and :ns-regexp
at the same time but that failed with a weird error
I think the issue with par-compile might be that it sets up a circular dependency if your ns-regexp matches your main ns
also do yourself a favor and run shadow-cljs server
separately. waiting 12sec to a test to run is horrible
yeah on the real project I start the server separately, I didn't do it here because I forgot
I'm trying to override main because on my real setup there's some logic I need to run conditionally at the start
so the intended usage is that both main and ns-regexp need to be set?
you can leave it to something that doesn't match and include all the namespaces in the :main ns directly
the user guide mentions that it defaults to "-test$"
so I thought that if I set main without setting ns-regexp it would run the tests in the included namespaces in main, including itself
it doesn't, so it falls into the case you suggested: > you can leave it to something that doesn't match and include all the namespaces in the :main ns directly
ns-regexp didn't match anything but in main there was a test
the future is coming thheller, and it is annoying
drives me mad ... can't type :main
anymore without it trying to make it something else
it does get better though, on my work slack it started last week and everyone had the same reaction, this week no one seems bothered
totally possible this all has a bunch of issues. I basically only tested the default setup
ok, I think I'm starting to understand a bit better... so if I want to both have my own main (for init logic), and not match any ns (because I don't have dedicated test ns), is there an approach I can take?
you mentioned just including the ns in the main ns
will try that
if you write your own main-ns I would suggest copying the default as is and only override what you need
and the :main ns needs https://github.com/thheller/shadow-cljs/blob/0aaa281853d113829d01a6ba09cc328578b969cc/src/main/shadow/test/node.cljs#L2
I tried these ns and it seems to run with main
(ns app.core-spec
(:require [app.core-spec-two]
[shadow.test.node :as stn]))
(defn main []
(stn/main))
(ns app.core-spec-two
(:require [cljs.test :refer-macros [deftest is]]))
(deftest something (is true))
will try the way you just mentioned
hmm, so the above finds and runs the single tests
but using the ns as you said does not
(ns app.core-spec
{:dev/always true}
(:require
[shadow.test.env :as env]
[cljs.test :as ct]
[shadow.test :as st]))
;; FIXME: add option to not exit the node process?
(defmethod ct/report [::ct/default :end-run-tests] [m]
(if (ct/successful? m)
(js/process.exit 0)
(js/process.exit 1)))
(defn main []
(-> (env/get-test-data)
(env/reset-test-data!))
(st/run-all-tests))
$ shadow-cljs compile test && node out/test.js
shadow-cljs - config: D:\sandbox\devcards-test\shadow-cljs.edn cli version: 2.8.69 node: v10.16.0
shadow-cljs - connected to server
[:test] Compiling ...
[:test] Build completed. (46 files, 1 compiled, 0 warnings, 0.82s)
Ran 0 tests containing 0 assertions.
0 failures, 0 errors.
Done in 1.83s.
HN thread (https://news.ycombinator.com/item?id=21589647) says to use /feedback to complain, let's see 🙂
set up a repro, and I think there isn't anything to look into proper
this repo has 2 deftests
in one of them, devcards is also imported, but not used
running yarn test
will run node-test test targets with ns-regexp, main pointing at a import of shadow.test.node, and main pointing at a copy of shadow.test.node
both ns-regexp and main pointing at a copy of shadow.test.node work as expected and show two tests running
main pointing at a import of shadow.test.node only shows one test running (the one in the ns that doesn't import devcards)
I don't know why the devcards import should be relevant, but you told me to use a copy anyway so I suppose it's related
maybe because devcards also declares a deftest
roger, will do
thank you for your time
Thanks @thheller, appreciate that there's a way to do this. I wrote a section for my README.md but wanted to repost here for channel record. Recover disconnected shadow-cljs REPL You might accidentally crash your react-native app on your emulator/browser with a big red error screen. You can hit Reload to restart the app into a working state, but putting any command into your shadow-cljs REPL will time out.
myapp.core> (js/alert "test")
REPL command timed out.
To recover this you'll need to:
1) Quit the CLJS REPL
2) Tell shadow-cljs to clear its REPL connection
3) Reconnect the CLJS REPL
The following commands should achieve this.
cljs.user> :cljs/quit
;; wait at least 5 seconds for session cleanup
user> (shadow.cljs.devtools.api/repl-runtime-clear)
user> (shadow/repl :app)
shadow-cljs has no support for processing html, so yes you copy it manually or with another tool
When trying to host my app, i'm noticing that the the requests by the browser triggered in the index.html to load the other assets (e.g main.js) are returning 404. I assume there is some path issue i need to resolve. I assume this is a function of the hosting service (in this case google bucket) but i wanted to ask here in case there is some configuration concept im missing. I dont think any of the production settings (e.g url hashing) would make a difference and i didnt see anything else listed.
maybe setting homepage in the package.json?
I haven't used the google stuff before. I'm assuming you upload the files somewhere so make sure you upload all the files properly?
Thanks heller. The issue seems to be that the requested url is missing the bucket name e.g. its requesting http://storage.googleapis.com/js/compiled/main.js but the file is at http://storage.googleapis.com/<bucket-name>/js/compiled/main.js
because /js implies relative?
that will be it then
so that it loads <script src="js/main.js">
:asset-path
does nothing for the initial file, only if you use multiple :modules
we do use multiple modules.
ok then :asset-path
is relevant too. still need to change the html for the initial load though
Is it possible to get some sort of debug in compilation process using console flags?
I am trying to debug my configuration of :source-paths ["src" "env/dev"]
(ns-es in "env/dev" are ignored for some reason).
@muhanga do you mean that the namespaces are not found, even though the files exist on disk?
@lilactown Yes.
I have namespace 'tst.cards' declared in "env/dev" dir and it is ignored and not taken into compilation.
I have :lein true
enabled, but i am not sure how those two interract.
@lilactown file path is env/dev/cljs/tst/cards.cljs
. And source paths are defined in leiningen profile and i am able to build using lein.
if you want to nest it in that cljs
directory then you need to add to the source-path instead
Okay, this actually shed some light. Does shadow-cljs actually use :source-paths
declared in lein config when :lein true
is declared? Or it uses :cljsbuild\{build}\source-paths
?
:lein true
will use the source-paths defined in your leiningen config. it does not use anything to do with cljsbuild
Nasty. so if i want to be able to build cljs using both lein and shadow i basially need to disable :lein true
if you prefer to split your config and source paths between CLJ and CLJS, then what I typically do is use leiningen to manage CLJ dependencies and source paths and shadow-cljs.edn to manage CLJS dependencies and source paths
@lilactown Ouch. I need to read docs again. And couple of time more.
@dpsutton as of now i am trying to understand how shadow works so using it on existing lein project help me immensly. So i am trying to make them work in parallel. But more i try, more i think this is not really ideal approach to learning.
i did exactly that and unfortunately we couldn't move over since we serve our front-end over https and local networking hyjinx but figwheel will happily connect an insecure websocket over ws not wss
@dpsutton :devtools-url "
`http://localhost:9630``"` should work and also use ws:// even if you serve the initial page over https?
@muhanga any cljsbuild config is ignored but you can just setup regular :profiles {:dev {:source-paths ["src" "env/dev"]}}
with :lein true
@dpsutton there are some Clojure libraries that only works with lein
I wish I could use shadow-CLJS with that :)
but i'm sure it could be ported over. just no benefit i suppose. i don't think devcards require figwheel just its a bit easier
Basically i am trying to bootstrap spring + reagent + d3 + devcards combo to shadow-cljs (with minimal changes of lein configs) and everyting expect devcards works very nice with shadow. Looks like i will need to bite the bullet and do some rewrites from scratch. Thank you all.
@thheller for some reason devcards can't find react during initialization emiting bunch of "React is not defined"