Fork me on GitHub
#shadow-cljs
<
2019-07-25
>
Nolan01:07:29

does anyone have any experience exporting npm packages that work in the browser as well?

Nolan01:07:43

i apologize if this question is misguided. the manual is a painstaking cliff hanger (https://shadow-cljs.github.io/docs/UsersGuide.html#_creating_code_npm_code_packages). i guess im primarily curious whether a webpack workflow would appropriately handle making a :node-library output browser compatible

lilactown02:07:36

Yes it should

lilactown02:07:32

Rather, node-library should output a webpack-compatible bundle

Nolan02:07:00

right, getting more familiar with it. seems like its working well. using this tool has never stopped being positively delightful

tianshu09:07:46

@isak I'm trying to write style in cljs, with runtime insertion by library like cljss or herb. not know how will it work in the end yet.

isak13:07:44

interesting 馃憤:skin-tone-2:

Karol W贸jcik11:07:32

Does shadow-cljs fully supports macro system?

(ns infrastructure.util
  (:require
   [clojure.tools.macro :as macro]
   [promesa.core :as p]))

(defmacro defn-handler
  [name & attrs]
  (let [[aname [fn-args & fn-body]] (macro/name-with-attributes name attrs)
        args-count (count fn-args)
        afn `(fn ~fn-args [email protected])]
    `(def ~aname
       (fn [req1# res1# next1#]
         (-> (p/promise (if (= ~args-count 3)
                          (~afn req1# res1# next1#)
                          (~afn req1# res1#)))
             (p/catch #(next1# %)))))))
I've just created macro which is used to define the express.js handlers.
(defn-handler get-login-status
  [req res] 
  (println req res))
For some reason code works perfectly fine but the shadow-cljs outputs a warning:

tianshu11:07:01

I've seen a lot of times like something is undeclared but actually it exists. usually cased by how the namespace is created. is it created by file require or by repl evaluation.

Karol W贸jcik11:07:32

@doglooksgood Ok found one bug. The last warning about undeclared is fixed. So there is one left about "wrong number of args passed".

tianshu11:07:55

try a macro expand?

Karol W贸jcik11:07:14

Ok I see why 馃槢

stask11:07:46

Is there olical/depot or lein-ancient equivalent for shadow-cljs managed projects?

tianshu11:07:38

you can use deps.edn or leiningen to manage dependencies, is easy for shadow-cljs to use them. so all the tools are available now.

stask11:07:26

@doglooksgood yeah, was hoping there is something shadow-cljs specific, thanks

thheller11:07:27

@karol.wojcik that is not how macros work in CLJS. they need to be declared in a CLJ namespace (.clj or .cljc)

Vincent Cantin13:07:32

Hi, does shadow-cljs supports dynamic require() in the JS code? I have problem with this JS code that does not work well (not sure yet how):

const required = require(`../vectors/${name}`);
    vector = required.default || required;

Vincent Cantin13:07:57

It works fine when used from a JS project.

thheller13:07:41

@vincent.cantin no that is not supported. you can do it when building for node by just using js/require directly but it is not supported otherwise

馃憤 4
lilactown16:07:47

I鈥檝e been thinking about a way to include and instrument specs that wouldn鈥檛 have production runtime cost

lilactown16:07:14

if each ns my-project.thing had a corresponding my-project.thing-spec, we could watch for the creation of those files and add their require to a ns that was included via a preloads-like method at dev-time

lilactown16:07:39

I鈥檓 thinking of building this as a standalone tool but could be nice as a shadow-cljs feature too

thheller16:07:05

you could build it as a simple shadow-cljs build hook

lilactown16:07:50

hmm interesting. does the build state have information about files on the classpath that aren鈥檛 included in the dependency graph?

wilkerlucio18:07:09

@lilactown had you tried #ghostwheel? it has a stub thing that can pretty elide all specs and fdefs in prod, both for Clj and CLJS

wilkerlucio18:07:22

(the spec part is coming on the next release, but the alpha of it works fine so far)

lilactown18:07:18

I haven鈥檛

lilactown18:07:38

does it also elide clojure.spec itself?

lilactown18:07:58

atm I see cljs.spec.alpha + cljs.spec.gen.alpha + cljs.spec.test.alpha taking a combined ~100kb

Chase18:07:57

yesterday I was advised to switch my dependency from cider/cider-nrepl "0.21.0" to nrepl "0.6.0" which worked in letting me hook vim into the running nrepl. But I now don't have access to cider and all it gives me, including functionality from other plugins that require cider. The folks at #cider tell me they are very different dependencies but I can't get both the nrepl and the cider-nrepl dependencies in this shadow-cljs to work together. Any advice on how to get Cider working right (outside of emacs, I'm using vim)?

thheller19:07:23

@chase-lambert nrepl and cider-nrepl are 2 different things so you need both

thheller19:07:28

just need to match the proper versions

thheller19:07:49

but that'll break a bunch of stuff is something actually needs to use spec at runtime

thheller19:07:07

otherwise you can always include "extra" stuff during dev via :preloads

thheller20:07:00

I kinda like your idea of automatically include *.thing-spec namespaces for dev builds but instrumentation is tricky enough. automating it entirely and getting that right reliably might be tricky

lilactown21:07:47

馃榿 yeah. I was thinking of having it enabled via a config flag like:

:auto-spec true
;; or
:auto-spec {:only #{app.foo-spec app.bar-spec}}
;; or
:auto-spec {:except #{app.baz-spec}}

;; additional
:auto-spec {:include #{app.specs}}

lilactown21:07:09

maybe have a parameter for controlling whether it included libs or not too

lilactown21:07:33

depending on how it actually shakes out in practice