Fork me on GitHub
#shadow-cljs
<
2020-01-27
>
Oz08:01:24

Hi, small question about lifecycle hooks, I have a re-frame app that defines this hook in it's core namespace:

(defn ^:dev/after-load mount-root []
        (re-frame/clear-subscription-cache!)
        (reagent/render [views/main-panel]
                        (.getElementById js/document "app")))

Oz08:01:42

I've added a :workspaces build in shadow-cljs.edn to support https://github.com/nubank/workspaces/ Now, whenever I update the code, the workspaces app goes blank because of this hook. Is there a way to disable it for that build, but keep it for the regular build?

thheller08:01:09

@ozfraier I would recommend splitting the namespaces so this can't happen. there is currently no way to disable hooks per build. you can move the hook config to the build though. so no meta but :devtools {:after-load } in the build config

thheller08:01:29

@royalaid shadow-cljs never even opens the package.json in your project. I assume you want to configure where it looks for actual npm packages and that you can configure per build via :js-options {:js-package-dirs ["addBankAccount/node_modules" ...]}

thheller08:01:00

and structure wise I would probably keep all sources in <project>/src/main and then just have it output separate files to <project>/lambdas/foo/... so each lambda can have its own config and stuff in its own folder

thheller08:01:19

enforcing that structure for everything seems rather cumbersome to me πŸ˜›

royalaid08:01:46

Yeah, it's because the cli tools zip the dir and just upload it after running your build step so it has to be a specific shape πŸ˜•

royalaid08:01:19

I am sure I could make some magic happen but I would rather put that work towards business logic

thheller08:01:23

yes ... but the cljs sources and build related things don't need to be in there?

thheller08:01:57

one deps.edn + shadow-cljs.edn per lamda seems incredibly clunky

royalaid08:01:13

The node_modules and build output have to but that's it

royalaid08:01:19

And it is clunky haha

royalaid08:01:02

When I mentioned a while back about wanting a better way to work with multiple shadow instances this is what I was asking about

royalaid08:01:27

And the lambdas can have separate deps so I am unsure how best to split the config

thheller08:01:33

hmm did I recommend not having multiple shadow instances back then? since that seems entirely unnecessary here πŸ˜›

thheller08:01:49

you can just always load all deps

thheller08:01:02

the build output will only contain whatever you actually used

thheller08:01:25

so unless you need different versions of the same package it is not a problem to always load everything

royalaid08:01:36

This is a very good point

royalaid08:01:46

Then I can pull everything up into a single config

thheller08:01:24

FWIW I do this in shadow-cljs. all build configs in one shadow-cljs.edn and all deps in project.clj. then all the various output going to https://github.com/thheller/shadow-cljs/tree/master/packages

πŸ‘ 1
royalaid08:01:44

I will put in some time moving all this around, thanks for the help

Oz08:01:37

@thheller Thanks! I tried doing it but for some reason it didn't work, probably because I missed a turn somewhere. Eventually my setup had the workspaces app use an "#app" div just like my real app So I renamed it, and with some fiddling it seems to work now ^^;

thheller08:01:56

ideally you would have a or .core or whatever namespace that handles all the initialization logic

thheller08:01:23

and you already have [views/main-panel] so your UI is already separate

thheller08:01:35

so your workspaces build just shouldn't include the main ns

thheller08:01:42

and go directly to views

justinbarclay17:01:13

Is there anyway to force shadow-cljs to bind to 0.0.0.0? I'm running shadow-cljs 2.8.83 and I'm my config is:

;; shadow-cljs configuration
{:source-paths
 ["src"
  "test"]
...
 :builds
 {:dev
  {:target :browser
   :output-dir "resources/dev/public/js/compiled"
   :asset-path "/js/compiled"
   :js-options {:variable-renaming :local}
   :modules {:app {:init-fn app.core/main}}
   :devtools {:http-root "resources/dev/public"
              :http-port 3449}}}}

thheller17:01:44

bind what exactly? the 3449 server?

justinbarclay17:01:05

the shadow-cljs dev http server

thheller17:01:26

or the main server at 9630?

thheller17:01:48

(both should be binding to 0.0.0.0 by default)

justinbarclay17:01:25

I'm not sure exactly, but I am not seeing it bound to 0.0.0.0

✦ ❯ netstat -tulpn | rg LISTEN                                                                                                                                                                                                                                                                                                                                                                                                              09:35:16(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN      1313/puma 3.12.1 (t
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      -
tcp6       0      0 127.0.0.1:36585         :::*                    LISTEN      472/java
tcp6       0      0 127.0.0.1:35625         :::*                    LISTEN      472/java
tcp6       0      0 :::5355                 :::*                    LISTEN      -
tcp6       0      0 :::44179                :::*                    LISTEN      472/java
tcp6       0      0 ::1:3000                :::*                    LISTEN      1313/puma 3.12.1 (t
tcp6       0      0 :::3449                 :::*                    LISTEN      472/java
tcp6       0      0 :::3451                 :::*                    LISTEN      472/java
tcp6       0      0 :::9630                 :::*                    LISTEN      472/java

thheller17:01:09

tcp6 0 0 :::3449 :::* LISTEN 472/java?

justinbarclay17:01:54

yeah, I thought that would have worked too. My work has a kind of complicated dev set-up and I am trying to get it to work on Windows + WSL. I have shadow-cljs running on WSL and I can connect to it when using localhost:3449 from Windows. But generally my work uses and has code set-up to handle our dev environment from the url *. (for info on https://readme.localtest.me/). And when I try to connect to shadow-cljs on Windows from it can't find it. I'm trying to debug this and see if it's because it's not listening specifically on 0.0.0.0. The thought that led me down that path is because a rails webserver listening on port 3000 and bound to 0.0.0.0 is able to be reached by on Windows.

thheller17:01:18

hmm yeah the 3000 seems to have an extra listen on 127.0.0.1

thheller17:01:37

I'm on windows/wsl too but never tried http://localtest.me

thheller17:01:09

seems to run fine when started in windows

justinbarclay18:01:05

Just a heads up, I've done some more testing on this using just node and both WSL and WSL2. With node, binding to port :: and 0.0.0.0 behaves the same on WSL. IE They're both accessible from . However, in WSL2 (which is what I run) only 0.0.0.0 is accessible from . So it looks like WSL2 is not correctly handling :: . Thanks again, talking to someone else running WSL really helped narrow this down.

thheller18:01:30

hmm that makes sense. I'm not on wsl2

thheller17:01:27

hmm also works fine for me when started in wsl?

thheller17:01:35

I don't really know. the default is to listen on 0.0.0.0 and thats I all pass into it

thheller17:01:52

I'm not specifying anythings related to ipv4/6 or further

justinbarclay17:01:09

Ok it must be something on my end then. I just tried recreating the acme-app from https://github.com/thheller/shadow-cljs#quick-start, and again I could connect on localhost:8080 but not

justinbarclay17:01:35

Thanks for the help πŸ™‚

lilactown20:01:41

what’s the appropriate way to emit a compiler warning?

thheller20:01:18

cljs.analyzer/warning