Fork me on GitHub
#shadow-cljs
<
2017-11-13
>
cmal03:11:40

Hi, after changed my code, I found that have responsed

java.lang.IllegalArgumentException: No matching clause: :get
	at $files_req.invokeStatic(ws.clj:197)
	at $files_req.invoke(ws.clj:179)
	at $process.invokeStatic(ws.clj:283)
	at $process.invoke(ws.clj:254)
	at clojure.lang.AFn.applyToHelper(AFn.java:154)
	at clojure.lang.AFn.applyTo(AFn.java:144)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$apply.invoke(core.clj:652)
	at shadow.http.router$call_handler.invokeStatic(router.clj:12)
	at shadow.http.router$call_handler.invoke(router.clj:11)
	at shadow.cljs.devtools.server.web$root.invokeStatic(web.clj:20)
	at shadow.cljs.devtools.server.web$root.invoke(web.clj:19)
	at shadow.cljs.devtools.server$get_ring_handler$G__26813__26814.invoke(server.clj:52)
	at ring.middleware.params$wrap_params$fn__14985.invoke(params.clj:67)
	at aleph.http.server$handle_request$fn__13182$f__649__auto____13183.invoke(server.clj:157)
	at clojure.lang.AFn.run(AFn.java:22)
	at io.aleph.dirigiste.Executor$Worker$1.run(Executor.java:62)
	at manifold.executor$thread_factory$reify__541$f__542.invoke(executor.clj:44)
	at clojure.lang.AFn.run(AFn.java:22)
	at java.lang.Thread.run(Thread.java:745)

cmal03:11:37

And the page was not modified with the newest code, though the console have some correct messages.

thheller07:11:59

@oliver.mooney I didn’t touch the create-react-app example in quite a while. I imagine a lot has changed since then.

thheller07:11:17

@cmal the client side for the code reload will send a http POST request to request the new content

thheller07:11:52

somehow that gets turned into a GET request? do you have a proxy or so that rewrites the request?

thheller07:11:39

is there some documentation about this wechat setup you are using?

cmal07:11:13

I changed the source code of shadow-cljs and set the (env/ws-url js/document.location.hostname :browser) to (env/ws-url "localhost" :browser). This enables the hot reload. but got some error in the requests.

cmal07:11:35

The wechat developer tool just uses chrome.

thheller07:11:28

right. so I should allow configuration of the host that is used for the websocket and file updates and it should work?

thheller07:11:51

yeah something must happen to the XHR request that gets sent to download the files

thheller07:11:54

it always sends a POST, there is no way it initially sends a GET.

thheller07:11:12

seems like maybe the wechat developer tools rewrites the request?

cmal07:11:46

I wonder whether this is right:

cmal07:11:27

both 200, but I cannot see the content.

cmal07:11:29

devtools says it has reloaded, but page not reload the new content.

cmal07:11:11

The console got this

thheller07:11:41

yeah that error is from the server handling the request. it does not expect a GET request and fails. don’t know how a GET request ends up there.

thheller08:11:26

but it seems to be loading the JS? how else would it produce those re-frame warnings?

thheller08:11:01

did you maybe try to re-run the request in the devtools? that won’t work.

cmal08:11:50

yes. I tried to re-run the request in the devtools. that did not work.

cmal08:11:26

so ignore the :get error.

cmal08:11:18

But any possibility that the ws sent the data and devtools load the jss but the page is not reloaded?

cmal08:11:28

The updated code seems not injected into the browser html.

cmal08:11:33

DEVTOOLS: load JS doumi/bottomnav_comp.cljs shadow.cljs.devtools.client.browser.js:46
DEVTOOLS: load JS doumi/ua.cljs shadow.cljs.devtools.client.browser.js:46 
DEVTOOLS: load JS doumi/core.cljs shadow.cljs.devtools.client.browser.js:46 

thheller08:11:36

try putting a (js/console.log "foo") at the top-level in the file. it should reload yes.

thheller08:11:01

maybe you have some code that is not reloadable properly? eg. a fn you put into a map somewhere?

thheller08:11:47

there was a bug that the :after-load fn was not loaded properly and was using the old version (from before the code load)

thheller08:11:59

but that only affected the :after-load fn, nothing else.

cmal08:11:28

I will have a try

cmal08:11:56

Yes, the top level code get reloaded. There must be some problems with my code. Thank you @thheller.

OliverM09:11:22

@thheller thanks, I thought as much - the regex you talk about in the create-react-app example is out of date. I'm trying to reproduce the fix in the issue you raised here: https://github.com/facebookincubator/create-react-app/issues/2281

OliverM09:11:49

Is there a way to set the output directory of shadow-cljs, or is that the normal cljsbuild config option?

OliverM09:11:06

I can just do a link between the directories once I figure that bit out

thheller09:11:13

yes you can set :output-dir.

thheller09:11:00

the create-react-app example I made is currently broken because of the relative require it had

thheller09:11:52

I need to add support for that again, works fine if you don’t need relative requires in CLJS though.

OliverM09:11:12

I've to restart yarn start after each cljs change and thought that was the culprit, but I'm not using relative requires, hmmm

thheller09:11:57

there seems to be a bug with watch. it does not recover when a compile failed with an error.

OliverM09:11:09

yeah, I've seen that too, but it's pretty quick to restart - yarn is the slowpoke for me

thheller09:11:16

try running a separate server instance, so restarting the watch is not to painful

thheller10:11:15

the watch problems should go away with [email protected]

pedrorgirardi11:11:44

Hi there! I added this dependency "rmwc": "0.0.1-beta10" to my package.json and I’m getting a funny error message: ReferenceError: Unknown plugin “react-hot-loader/babel” specified in “/Users/pedro/Developer/rmwc-cljs/node_modules/rmwc/package.json” at 0, attempted to resolve relative to “/Users/pedro/Developer/rmwc-cljs/node_modules/rmwc”

pedrorgirardi11:11:02

The whole package.json is:

{
  "dependencies": {
    "create-react-class": "^15.6.2",
    "react": "^16.1.0",
    "react-dom": "^16.1.0",
    "rmwc": "0.0.1-beta10"
  },
  "devDependencies": {
    "shadow-cljs": "^2.0.74"
  }
}

thheller11:11:45

hmm thats babel

thheller11:11:52

you can edit the node_modules/rmwc/package.json and just rename the babel entry to xbabel or so

thheller11:11:07

projects usually remove the babel entry when publishing to npm, this one doesn’t it seems

thheller11:11:04

let me adjust my babel interop so that it ignores those settings

pedrorgirardi12:11:24

Giving it a try right now 🙂

thheller12:11:57

meh doesn’t work

thheller12:11:16

will do some tests with rmwc

thheller12:11:29

see what strange things they do 😉

pedrorgirardi12:11:12

It did work! 😉

thheller12:11:46

ah hehe … I tested with the old version … doh 🙂

pedrorgirardi12:11:07

Everything working, so good! Thank you again @thheller!

mhuebert15:11:29

@thheller is there a way to set :closure-defines dynamically from the cli? eg. if i want to build a release of a build where the closure variable server-env is set to dev or staging or whatever

thheller15:11:39

that sounds more like an env variable the process would read?

thheller15:11:55

but no, currently there is no way to set this dynamically

thheller15:11:05

you can set env variables for the node process and access it per js/process.env

thheller15:11:11

THING=foo node
> process.env.THING
'foo'

mhuebert16:11:47

it’s a server that will build the cljs :release itself, so the app itself is not running on node and has no access to js/process.env

mhuebert16:11:24

am thinking it will end up being a Clojure macro

thheller16:11:02

hmm not a fan of that

thheller16:11:09

it breaks caching 😛

thheller16:11:52

what does the the env variable do? where is it used?

mhuebert16:11:26

hm. which kind of caching? it would eg/ read an “API_URL” to know which backend to send ajax requests to, localhost:PORT or test-server.x or prod-server.y

mhuebert16:11:36

so static, build-time stuff

thheller16:11:13

hmm I typically keep those things out of my build and in actual config

thheller16:11:43

and then pass in this config when calling from HTML

thheller16:11:35

do you have a suggestions on how the env thing could look? I can’t think of a good way to do this right now

thheller16:11:57

ah hehe .. just thought of something

mhuebert16:11:58

i’m not entirely sure. by ‘actual config’ what do you mean?

thheller16:11:15

this is the basic setup I have in all the things I build

thheller16:11:38

there is a init fn that is called from HTML

thheller16:11:05

if I have any runtime configuration that may change due the which user is accessing it

thheller16:11:10

or which server is running on

thheller16:11:15

I pass that config to the init fn

mhuebert16:11:09

ah i see. so this is a case where index.html is generated by a server vs. static file

thheller16:11:23

<script>starter.browser.init({api_url: "foo"});</script>

thheller16:11:21

well you could also use 2 separate static html files

thheller16:11:55

I just added something that you could use for this as well though

thheller16:11:02

(ns demo.run-test
  (:require [shadow.cljs.devtools.config :as config]
            [shadow.cljs.devtools.api :as api]))

(defn build [& args]
  (let [config
        (-> (config/get-build! :your-build)
            (assoc-in [:compiler-options :closure-defines 'some.ns/define] (System/getenv "FOO")))]
    (api/release* config {})
    ))

thheller16:11:27

shadow-cljs clj-run demo.run-test/build

thheller16:11:49

scripted the build process more or less

mhuebert16:11:51

hah that is almost exactly the code I was just writing as an example 🙂

thheller16:11:41

clj-run I just added, lets you call any clojure fn from the CLI

thheller16:11:58

same as lein run -m ...

mhuebert16:11:13

that was my next question 🙂

mhuebert16:11:22

which version was this added in?

thheller16:11:31

I should add a get-build-config fn to the api namespace but besides that it should work

mhuebert16:11:43

that was fast 👀

thheller16:11:21

already had it implemented when you asked 😛

thheller16:11:47

its pretty rough and probably needs some tweaking but it should do the job

mhuebert16:11:50

should that be clj-eval?

mhuebert16:11:02

Invalid action "clj-run"

Usage:
  shadow-cljs <action> <zero or more build ids>

thheller16:11:48

hmm no clj-run

thheller16:11:28

shadow-cljs clj-run demo.run-test/fn1 1 2 3
shadow-cljs - config: /Users/zilence/code/shadow-cljs/shadow-cljs.edn version: 2.0.76
shadow-cljs - connected to server
[:fn1 ("1" "2" "3")]

thheller16:11:40

server process not restarted?

mhuebert16:11:19

ah correct. that is a bit confusing because it still shows 2.0.76 even though it’s not actually running that version

thheller16:11:40

yeah I should add a check for that

thheller17:11:02

@mhuebert btw did you sort out the circleci issues?

mhuebert18:11:13

I have not.. I got stuck sorting out the node/Java docker image and haven’t had time to finish

mhuebert21:11:07

this clj-run command, super useful

mhuebert21:11:26

it seems to sometimes get stuck on a particular version of a file

mhuebert21:11:54

ie. editing the file and clj-run’ing it again, it evaluates the old version