Fork me on GitHub
#shadow-cljs
<
2018-06-08
>
hlolli00:06:53

I'm haveing diffuculty connecting to a node based nrepl in cider

shadow.user> (shadow.cljs.devtools.api/watch :node)
:already-watching
shadow.user> (shadow.cljs.devtools.api/nrepl-select :node)
To quit, type: :cljs/quit
[:selected :node]
cljs.user> :a
No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
cljs.user> (shadow.cljs.devtools.api/nrepl-select :node)
No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
cljs.user> 
here I already started a watch, also when I start server and manually ignite the watch, I get the same error message.

oscar00:06:34

@hlolli You've only started the build. You need to run the compiled code before you can evaluate cljs. Do $ node <your-build.js> and then try evaling again.

hlolli00:06:46

amazing how fast things change, this is not how I did things in the old days (6-8 weeks ago) 😛

richiardiandrea00:06:36

There is also a node-repl command directly

hlolli00:06:58

@richiardiandrea of course, and that's how I did things in "the old days". That brain cell must have gotten erased on some berlin dancefloor.

richiardiandrea00:06:53

Yeah well I have to say that I prefer to work at the REPL too and have a shadow server always on

hlolli00:06:44

yeh, for a website that I did recently, I got into this rythm, so the environment is the browser when it's opened, so this all makes sense.

richiardiandrea00:06:18

@hlolli do you have completions in emacs + shadow? I think I see them intermittently

hlolli00:06:58

yes, at a quick glance, company-mode is doing its job correctly

richiardiandrea00:06:53

Cool thanks so I will try to check if my config is broken somehow

kwladyka10:06:52

 * I have this symbols instead of * for required fields in material ui

kwladyka10:06:37

Is it possible to solve it in some way in shadow-cljs?

kwladyka10:06:10

Not sure what is the right solution here

thheller11:06:13

@kwladyka you probably just need to set the correct charset for your html <meta charset="utf-8">

🍺 4
jmckitrick14:06:51

Has anyone figured out how to get cider to run (shadow.cljs.devtools.api/repl :app) after connecting?

jmckitrick14:06:09

I’m doing it manually now

colindresj16:06:39

@thheller how do you suggest including dependencies from private maven repos? Currently, I use lein and an s3 wagon to handle it, but hoping to move off of lein entirely

thheller16:06:25

@colindresj I have never used a private maven repo so I don't know what setup is involved. if it just requires a :repository entry you can do that in shadow-cljs.edn just like lein

colindresj17:06:32

So something like:

colindresj17:06:50

:repositories
 [["private-maven"
   {:url "",
    :snapshots false,
    :sign-releases false,
    :username :env/aws_access_key_id,
    :password :env/aws_secret_access_key}]]

colindresj17:06:42

I get a shadow-cljs - dependency update failed - Vector arg to map conj must be a pair with that

thheller17:06:53

I think that should be a map

thheller17:06:02

{"private-maven" {...}}

thheller17:06:43

dunno about the :env/ stuff. that might be something lein does?

colindresj17:06:00

Yeah that’s for reading env variables

thheller17:06:05

:username #shadow/env "aws_access_key_id"

colindresj17:06:24

Ah cool didn’t know there was a reader tag for env vars with shadow

colindresj17:06:27

That’s sweet

colindresj17:06:09

Do I have to specify maven central and clojars in the repositories map as well, or will shadow merge my map with defaults?

thheller17:06:21

will be merged

colindresj17:06:00

Cool thank you

richiardiandrea17:06:54

question about new :exports

richiardiandrea17:06:04

I have :exports-var in my config

richiardiandrea17:06:16

but I receive:

should contain keys: :exports, :exports-fn, :exports-sym

|          key | spec |
|--------------+------|
|     :exports |  nil |
|  :exports-fn |  nil |
| :exports-sym |  nil |

richiardiandrea17:06:33

cli version: 2.3.36

richiardiandrea17:06:56

I see the code has :exports-var in there, so maybe it has not been deployed yet?

richiardiandrea17:06:44

oh, no I think there is a bug, let me fix it

thheller17:06:13

oh yeah the spec is invalid

thheller17:06:11

oh ... already fixed it 🙂

richiardiandrea17:06:26

lol kk no problem 😉

richiardiandrea18:06:06

does :output-to in a :release map?

kwladyka18:06:59

(ns material-ui.colors
  (:require ["@material-ui/core/colors/deepPurple" :default deepPurple]
            ["@material-ui/core/colors/green" :default green]
            ["@material-ui/core/colors/blue" :default blue]))

(def deepPurple deepPurple)
(def green green)
(def blue blue)
Is there any way to do something like that? In that case blue is nil when load from another namespace [material-ui.colors :as colors] In the same namespace blue has value.

kwladyka18:06:34

Sure I can name all colours cblue or something like that, but it would be so ugly

thheller18:06:26

so the (def deepPurple deepPurple) is basically a self-reference

thheller18:06:48

you can do :default mui-deepPurple

thheller18:06:56

(def deepPurple mui-deepPurple)

kwladyka18:06:30

no shortcut to list all colours and def all of them?

thheller18:06:21

don't ask me ... ask the insane JS people making a file per color 😛

kwladyka18:06:29

(def deepPurple (js->clj mui-deepPurple)) - how compiler work? Will it be count in the browser or during compile?

kwladyka18:06:02

this one too?

thheller18:06:14

(def deepPurple (js->clj mui-deepPurple)) whats this supposed to do?

thheller18:06:29

isn't it a string?

kwladyka18:06:38

now I have to get value like that (aget colors/blue "A400")

thheller18:06:12

ah its a JS object

thheller18:06:23

well honestly I would just make a function

kwladyka18:06:35

or maybe it is just stupid to use this colours objects hmm

kwladyka18:06:11

I want to avoid performance waste to count all colour in the web browser

thheller18:06:11

(defn color [x y] ...) so you can do (color :blue 400)

kwladyka18:06:30

this energy could be use for cyrptocurrency instead of counting colours 😛 😉

kwladyka18:06:57

It will work 🙂

kwladyka18:06:27

but if js->clj in this situation will be optimised during build code it will be even better

thheller18:06:40

the js->clj is at runtime

thheller18:06:54

you could just take the color codes and port them to CLJS

thheller18:06:07

DCE will actually remove the colors you don't use then

thheller18:06:34

not sure how material-ui uses the colors internally though?

thheller18:06:48

I guess they sometimes take the color object as arguments somewhere?

kwladyka18:06:29

It can be use to make a them for example:

(def theme (mui/create-mui-theme
             (clj->js
               {:palette {:primary {:main (aget colors/blue "A400")}
                          :secondary {:main (aget colors/deepPurple "500")}}
                :overrides {:MuiAppBar {:root {
                                               ;:color "#00ff00"
                                               ;:background-color "white"
                                               }}
                            :MuiButton {:root {:text-transform "none"}}}})))

thheller18:06:07

so you use it only once ever?

kwladyka18:06:46

I wanted use it in view components also, for example to set colour of the button

thheller18:06:05

then seriously just :palette {:primary {:main "#42a5f5" ...

kwladyka18:06:30

but I start to think maybe it is stupid idea to use this objects…

kwladyka18:06:55

I can rewrite values from there instead

kwladyka18:06:20

just I am not a graphic designer and this pallet of colours help me a little 🙂

thheller18:06:41

yeah the palette is great

thheller18:06:05

but just copying the colors you want seems like a much better solution that dealing with those JS objects

thheller18:06:36

its not like the color blue is suddenly going to change its color code

kwladyka18:06:48

probably you are right. This is the trap of using ready solutions. Start to turn off brain and use it 🙂

kwladyka18:06:52

maybe I will write macro one day or something for that 🙂

richiardiandrea18:06:41

is there a way to add dev folder to shadow's classpath?

thheller18:06:08

:source-paths ["src" "dev"]?

thheller18:06:27

if you want to replace files: no, that is not possible

richiardiandrea18:06:32

yep ok, sorry should have asked better...only in dev mode, not for :release

thheller19:06:00

will need to drop to deps.edn or lein for that

thheller19:06:29

I consider it a horrible anti-pattern so I won't add support for that

thheller19:06:45

you can do it fine via lein or deps.edn though

richiardiandrea19:06:49

@thheller so my next q. would be, is there :aliases in :release

richiardiandrea19:06:01

I see it global only

thheller19:06:07

yes classpath applies globally

thheller19:06:24

shadow-cljs -A:release --force-spawn release your-app

richiardiandrea19:06:43

so if it is an antipattern, maybe I can ask if there a better way to do the following 😄

richiardiandrea19:06:20

I have the classic my-org.dev namespace that uses the dotenv library to load environment variables only when using the REPL

richiardiandrea19:06:50

I don't wont to use it in :release, so I added:

(when goog.DEBUG
  (dev/load-env-vars!))

richiardiandrea19:06:07

but I see that I have to require it...which indeed feels like an anti-pattern

richiardiandrea19:06:23

it is kind of a :preload

thheller19:06:34

dev stuff you can easily load via :preloads

richiardiandrea19:06:58

yeah maybe I should do that

thheller19:06:01

I should really write down my recommended way to inject "runtime" config

thheller19:06:29

browser app?

richiardiandrea19:06:37

no, node server app

thheller19:06:54

ah thats probably the easier solution of them all

thheller19:06:34

(defn main [config-path] (let [config (-> (fs/readFileSync config-path) str (reader/read-string))] ...))

richiardiandrea19:06:43

I use env vars, I just need to load them from somewhere

richiardiandrea19:06:51

yeah...i do something similar

thheller19:06:58

then call with node server.js dev-config.edn

thheller19:06:05

or node server.js prod-config.edn ...

richiardiandrea19:06:19

we prefer env vars here 😄

thheller19:06:19

no nasty env vars in your compiler output

richiardiandrea19:06:24

but I see your point

thheller19:06:37

but with node you can easily access env vars? why include them at compile time?

richiardiandrea19:06:58

yes I can, I just need to load them at runtime for REPL dev

richiardiandrea19:06:06

I think :preloads is fine

richiardiandrea19:06:28

but the dev folder will need to always be on the classpath

thheller19:06:39

I don't understand, why do you need to load them at runtime for REPL dev?

richiardiandrea19:06:02

because I need them for running 😄

richiardiandrea19:06:09

like DB connection and all that

thheller19:06:13

assuming you are using :target :node-script?

richiardiandrea19:06:33

at the moment it is :node-library

thheller19:06:04

same thing ... you are starting the node process do you not?

thheller19:06:14

or are you using (shadow/node-repl)?

richiardiandrea19:06:42

I am starting it with node-repl

richiardiandrea19:06:49

or similar thing 😄

thheller19:06:00

so would (shadow/node-repl {:node-env {"hello" "world"}}) help? (adding extra env vars to the node process so js/process.env.hello works?

richiardiandrea19:06:10

something like that would definitely help...but dotenv is kind of nice because it automagically reads from .env the variables

thheller19:06:47

(shadow/node-repl {:node-env (read-from-dotenv)})?

thheller19:06:09

never heard of dotenv

richiardiandrea19:06:26

yeah I mean it's a JS thing right?

thheller19:06:10

I don't know? what is it?

richiardiandrea19:06:41

probably shadow should have its own way of loading vars and I can use that instead, I can drop dotenv actually. it could be env.edn or something

thheller19:06:03

I'm still trying to understand what problem you are actually trying to solve though

thheller19:06:13

I still have no idea what the actual problem is

richiardiandrea19:06:18

my server has to connect to the db

richiardiandrea19:06:34

at runtime in production, env vars will be set for it

richiardiandrea19:06:44

at runtime in the repl, I need a way to load env vars

thheller19:06:18

so your code uses something like js/process.env.DB?

richiardiandrea19:06:46

we don't like config files here for now 😄

richiardiandrea19:06:54

don't ask me why 😉

thheller19:06:06

you do ... they are just config files for bash or something like that

thheller19:06:29

gotta be written down somewhere 😉

thheller19:06:47

ok assuming that dotenv is just a npm lib I think :preloads is the best option

richiardiandrea19:06:31

yeah, so again the problem would be that that code should not leak to production

richiardiandrea19:06:41

that is why normal clj/cljs you would use an clj alias

thheller19:06:53

:preloads are never included in release builds?

richiardiandrea19:06:26

and i guess the namespace will be trimmed

thheller19:06:51

if its not required anywhere (besides :preloads) then it won't even be compiled in release

thheller19:06:38

{:target :node-library :exports .... :devtools {:preloads [my-org.dev]}}

richiardiandrea19:06:16

perfect sorry if it took so long 😉

thheller19:06:56

I understand why you want to use separate :source-paths in CLJS usually

thheller19:06:11

but that is not an issue in shadow-cljs since it won't just randomly include stuff just because its on the classpath

richiardiandrea19:06:27

oh that's exactly what I need 😄

richiardiandrea20:06:43

Other q. 😄 I connected to a REPL with nrepl-select in emacs, and I have a server in another window that compiles. Is there a way to stop receiving the compilation logs in the nrepl-select-ed buffer?

thheller20:06:45

well the watch messages appear wherever the watch was started

thheller20:06:19

nrepl-select has nothing to do with those messages

thheller20:06:36

I think cider is just setup to always do watch+select

richiardiandrea20:06:08

No I am doing it manually

richiardiandrea20:06:18

I have a watch in the terminal

richiardiandrea20:06:31

Then I connected with a nrepl-select

richiardiandrea20:06:46

The messages are visible in the buffer in emacs

richiardiandrea20:06:04

So you are saying it is not expected?

thheller20:06:01

which messages are we talking about?

thheller20:06:15

it is not expected to get random messages no?

richiardiandrea20:06:22

I receive watch messages in my buffer

thheller20:06:36

please give me an example of a message you get

richiardiandrea20:06:41

Watch was started in a terminal

thheller20:06:45

there are a gazillion messages, no idea what you mean by watch messages

richiardiandrea20:06:54

Oh ok right so compilation warnings

thheller20:06:08

please just paste one example 😛

richiardiandrea20:06:33

Kk I was afk let me go and do it

richiardiandrea20:06:27

user> (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :init-store)(shadow/nrepl-select :init-store))
To quit, type: :cljs/quit
[:selected :init-store]
JS runtime disconnected.
JS runtime connected.
JS runtime disconnected.
JS runtime connected.
JS runtime disconnected.
JS runtime connected.
[:init-store] Compiling ...
[:init-store] Build failure:
------ ERROR -------------------------------------------------------------------
 File: /home/arichiardi/git/laputa/lambda-cqrs/src/ep_cloud/init_store.cljs:23:3
--------------------------------------------------------------------------------
  20 | 
  21 |   This function is idempotent, you can call it multiple times."
  22 |   [ctx request]
  23 |   (let [azure-callback
---------^----------------------------------------------------------------------
Call to cljs.core/let did not conform to spec
-- Spec failed --------------------

  ([... ... (partial ... ...) ... ... ... ...] ... ...)
             ^^^^^^^

should satisfy

  vector?
...

thheller20:06:12

I very clearly see a (shadow/watch :init-store) there?

😱 4
richiardiandrea20:06:23

I was sure I did not use it :(

richiardiandrea20:06:24

Sorry for the noise ;)

richiardiandrea23:06:09

so is there a "watch test" mode in shadow by any chance?

richiardiandrea23:06:52

I have a problem cause the tests are there but it does not seem to pick them up