shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
2021-04-22T03:29:34.415800Z

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

2021-04-22T03:31:05.417400Z

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.

2021-04-22T05:20:15.419Z

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?

thheller 2021-04-22T07:11:28.424600Z

FWIW pretty much all my projects have 5 or more segments. even the shadow-cljs UI has 5 https://github.com/thheller/shadow-cljs/blob/bbbac5ede9b0cefb48224050a06c673203431685/src/main/shadow/cljs/ui/components/inspect.cljs#L1

thheller 2021-04-22T07:11:34.424900Z

never had an issue

2021-04-22T12:52:36.425700Z

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

thheller 2021-04-22T06:21:32.419800Z

no, it can't see those

đź‘Ť 1
thheller 2021-04-22T06:23:10.420Z

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.

đź‘Ť 1
thheller 2021-04-22T06:24:04.420200Z

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.

2021-04-22T06:34:11.423100Z

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?

2021-04-22T06:58:55.423300Z

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

thheller 2021-04-22T07:08:03.423900Z

reagent declares its npm dependencies via deps.cljs https://github.com/reagent-project/reagent/blob/master/src/deps.cljs

thheller 2021-04-22T07:08:29.424500Z

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

thheller 2021-04-22T07:13:13.425400Z

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

oliver 2021-04-22T13:18:24.426Z

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?

thheller 2021-04-22T13:35:00.426400Z

you can look at the compiler environment to get the value

thheller 2021-04-22T13:35:43.426900Z

something like this https://github.com/binaryage/cljs-devtools/blob/master/src/lib/devtools/prefs.clj#L8-L12

âś… 1
haywood 2021-04-22T14:39:32.427900Z

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?

thheller 2021-04-22T14:40:18.428100Z

imho just create a jar with everything

haywood 2021-04-22T14:40:37.428500Z

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

thheller 2021-04-22T14:41:55.429200Z

no uberjar, just your sources

thheller 2021-04-22T14:43:13.430200Z

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

ghaskins 2021-04-22T14:51:01.430500Z

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))))))

ghaskins 2021-04-22T14:51:12.430800Z

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

ghaskins 2021-04-22T14:51:30.431300Z

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

ghaskins 2021-04-22T14:51:46.431500Z

any suggestions?

ghaskins 2021-04-22T14:52:30.431700Z

release build throws

Uncaught TypeError: navigator.clipboard is undefined

ghaskins 2021-04-22T14:53:12.432Z

or maybe I need a ^js hint?

ghaskins 2021-04-22T14:55:13.432200Z

in reference to: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard

thheller 2021-04-22T15:00:13.432800Z

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

ghaskins 2021-04-22T15:00:38.433200Z

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

thheller 2021-04-22T15:01:34.433600Z

it should be. hard to say without seeing code.

ghaskins 2021-04-22T15:06:51.433900Z

hmm, generated code looks ok, I think

ghaskins 2021-04-22T15:06:55.434200Z

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

thheller 2021-04-22T15:08:42.434400Z

yes but in which context does it execute

thheller 2021-04-22T15:09:48.435Z

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

ghaskins 2021-04-22T15:16:11.435900Z

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

ghaskins 2021-04-22T15:16:21.436100Z

ill keep plugging

thheller 2021-04-22T15:17:02.436800Z

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

ghaskins 2021-04-22T15:17:15.437Z

good idea, ill try that

ghaskins 2021-04-22T15:31:19.437500Z

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

ghaskins 2021-04-22T15:31:43.437900Z

ill follow that rabbit hole, ty

ghaskins 2021-04-22T15:49:31.438200Z

ah, i think I figured it out, completely uninteresting

ghaskins 2021-04-22T15:49:47.438600Z

its only supported from secure-contexts with https, heh

đź‘Ť 1
ghaskins 2021-04-22T15:49:51.438800Z

forest for the trees

ghaskins 2021-04-22T15:49:55.439Z

ty for the help, though

2021-04-22T17:17:10.439400Z

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?

dpsutton 2021-04-22T17:19:47.440500Z

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=> 

thheller 2021-04-22T17:21:31.441Z

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

2021-04-22T17:34:12.441400Z

Ooops, I missed (help) . Thanks 🙇

2021-04-22T17:38:01.443600Z

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

2021-04-22T18:20:16.443700Z

Well, yeah, already found the issue (bisecting)

oliver 2021-04-22T18:24:46.444Z

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!

thheller 2021-04-22T18:35:32.444300Z

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