Fork me on GitHub
#shadow-cljs
<
2021-04-22
>
mbertheau03:04:34

What's the correct workflow when adding a dependency to shadow-cljs.edn? When I run just shadow-cljs , it updates package.json and yarn.lock by calling yarn, and then it tells me "specify which action to run". I get what I want because package.json and yarn.lock are updated, but I think I may have not used the intended workflow. :target is :react-native if that's relevant

mbertheau03:04:05

Also, I call shadow-cljs with npx, and I don't install npm packages globally, in particular yarn isn't installed globally. Consequently when shadow-cljs calls yarn, it complains IOException: Cannot run program "yarn" (in directory "."): error=2, No such file or directory. I work around that by calling shadow-cljs through yarn through npx: npx yarn shadow-cljs. Is that the intended way? Update: I guess the correct answer to this is don't mix npm/npx and yarn like this. Use npm and package-lock.json and npx, or use yarn by installing it globally and use yarn.lock.

thheller06:04:10

yeah don't mix. shadow-cljs wants to infer which tool you are using look looking for the lock files. so if there is a yarn.lock it'll attempt to use yarn.

šŸ‘ 2
Vincent Cantin05:04:15

Using shadow-cljs v2.12.5, I run into a very weird bug where functions in a long namespace (5 namespace segments) are resolved at runtime to nil . Did it happen to anyone before?

thheller06:04:04

not enough information to comment. it is rather unlikely that the number of namespace segments is the cause here. much more likely to be related to something else.

Vincent Cantin06:04:55

I will try to reproduce on a smaller project after work. I am using shorter namespaces (4 namespace segments) as a workaround.

thheller07:04:34

never had an issue

Vincent Cantin12:04:36

Ok. I guess the bug appears as a side effect of something else. I will still investigate.

Vincent Cantin11:04:40

@thheller I could reproduce 2 of the bugs we encountered with the latest version of shadow-cljs https://github.com/thheller/shadow-cljs/issues/874

mbertheau06:04:11

When I add reagent as a cljs dependency to shadow-cljs.edn and run shadow-cljs, it calls npm to add react and react-dom as deps to package.json. What's the mechanism here that triggers this? Looking at the reagent source code, there's deps in package.json to react and react-dom, but there's also prop-types and cljs-oss/module-deps there, which shadow-cljs doesn't add to package.json. What happens here?

thheller07:04:29

shadow-cljs will attempt to install those unless they are already in package.json

thheller07:04:13

you can set :npm-deps {:install false} in your shadow-cljs.edn to disable to automatic install

oliver13:04:24

Can closure defines be used within macros? I want to configure a build against various configuration files by specifying their path as a closure-define. I want a macro read the specified file at compile time and bind its contents to a var. Here's the macro I use:

(defmacro def-from-file [var path-to-file f]
  `(def ~var
     (~f ~(read-string (slurp path-to-file)))))  
I've been unable to call the macro with file being the value bound to a closure define. With the shadow-cljs guide stating that closure defines ā€œare essentially compile time constantsā€ I thought there must be a way to eval them inside macrosā€¦ is that actually possible? If not, are there other ways to do what I'm looking for here?

thheller13:04:00

you can look at the compiler environment to get the value

oliver18:04:46

Many thanksā€¦ that library look great, but for now I'll keep it simple and just access cljs.env/*compiler*directly. Thanks for pointing me at it!

thheller18:04:32

thats what I meant. just wanted to show an example of a library doing that.

haywood14:04:32

Hey friends, wanted to ask if Iā€™m thinking about this correctly: I have a clojure codebase and I want to add a coupleĀ `.cljc`Ā namespaces to it and create a jar thatĀ onlyĀ includes those namespaces using a separate profile for consumption as a library in a clojurescript project. Is that necessary or should I just create a single jar for the whole thing?

thheller14:04:18

imho just create a jar with everything

haywood14:04:37

:thumbsup::skin-tone-2:, does it need to be an uberjar? I donā€™t know how dependencies all resolve

thheller14:04:55

no uberjar, just your sources

thheller14:04:13

might make sense to make a separate library that both use, your clj code won't be used by cljs project I assume

ghaskins14:04:01

I have this snippet

(defn copy-to-clipboard [val]
  (let [c (.-clipboard js/navigator)]
    (-> (.writeText c val)
        (.then (fn [] (debug "copied to clipboard")))
        (.catch (fn [e] (error "clipboard error:" e))))))

ghaskins14:04:12

which works fine in dev build, and fails in release build

ghaskins14:04:30

i suspect I need to properly require the navigator stuff, but im not quite sure of the mechanics

ghaskins14:04:46

any suggestions?

šŸ˜† 1
ghaskins14:04:30

release build throws

Uncaught TypeError: navigator.clipboard is undefined

ghaskins14:04:12

or maybe I need a ^js hint?

thheller15:04:13

^js hint you only need if things are getting renamed but it doesn't seem to be renamed

ghaskins15:04:38

yeah, its like js/navigator isnt available in release build

thheller15:04:34

it should be. hard to say without seeing code.

ghaskins15:04:51

hmm, generated code looks ok, I think

ghaskins15:04:55

function eNa(a){return navigator.clipboard.writeText(a).then(...

thheller15:04:42

yes but in which context does it execute

thheller15:04:48

pretty sure you are only allowed to access that after asking permissions first? did you do that?

ghaskins15:04:11

yeah, that is a distinct possibilityā€¦i havent got that far yet, but i would have expected an exception over permissions, not a seemingly symbol undefined error

ghaskins15:04:21

ill keep plugging

thheller15:04:02

just for sanity try logging js/navigator and see what that is. maybe it is redeclared somewhere locally or so

ghaskins15:04:15

good idea, ill try that

ghaskins15:04:19

The navigator object is there, but it doesnt have the clipboard property, giving legs to your theory on permissions

ghaskins15:04:43

ill follow that rabbit hole, ty

ghaskins15:04:31

ah, i think I figured it out, completely uninteresting

ghaskins15:04:47

its only supported from secure-contexts with https, heh

šŸ‘ 2
ghaskins15:04:51

forest for the trees

ghaskins15:04:55

ty for the help, though

apt17:04:10

Hey folks. Iā€™m trying to connect to socket repl in a shadow project. My project is based on this template, I didnā€™t change too much stuff: https://github.com/day8/re-frame-template Iā€™m doing the following: 1. lein watch 2. In Emacs, I use inf-clojure-connect with localhost and the port in .shadow-cljs/socket-repl.port. The repl opens fine. 3. Then, when I try to eval any require, I get errors such as:

Could not locate timeline/test_utils__init.class, timeline/test_utils.clj or timeline/test_utils.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
Iā€™ve tried to have a look at shadowā€™s manual but Iā€™m not too familiar with cljs and front-end. Am I missing something?

dpsutton17:04:47

when that repl opens up, type (help). I think there's a small banner indicating this. You get a clojure repl and you can start your repl with (shadow/repl :your-build)

shadow-cljs - REPL - see (help)
To quit, type: :repl/quit
shadow.user=> 

thheller17:04:31

or (shadow/browser-repl) or (shadow/node-repl) if you don't have a build configured yet and just want a REPL

apt17:04:12

Ooops, I missed (help) . Thanks šŸ™‡

apt17:04:01

A more general issue: Thereā€™s one test that passes in the repl, but it fails with karma . What would be a good approach of debugging that? :thinking_face: I guess I can bisect and run karma, just wondering if thereā€™s a more efficient way

apt18:04:16

Well, yeah, already found the issue (bisecting)