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
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.
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?
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
never had an issue
Ok. I guess the bug appears as a side effect of something else. I will still investigate.
no, it can't see those
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
.
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.
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?
I will try to reproduce on a smaller project after work. I am using shorter namespaces (4 namespace segments) as a workaround.
reagent declares its npm dependencies via deps.cljs https://github.com/reagent-project/reagent/blob/master/src/deps.cljs
shadow-cljs will attempt to install those unless they are already in package.json
you can set :npm-deps {:install false}
in your shadow-cljs.edn
to disable to automatic install
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?you can look at the compiler environment to get the value
something like this https://github.com/binaryage/cljs-devtools/blob/master/src/lib/devtools/prefs.clj#L8-L12
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?
imho just create a jar with everything
:thumbsup::skin-tone-2:, does it need to be an uberjar? I don’t know how dependencies all resolve
no uberjar, just your sources
might make sense to make a separate library that both use, your clj code won't be used by cljs project I assume
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))))))
which works fine in dev build, and fails in release build
i suspect I need to properly require the navigator stuff, but im not quite sure of the mechanics
any suggestions?
release build throws
Uncaught TypeError: navigator.clipboard is undefined
or maybe I need a ^js hint?
in reference to: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard
^js
hint you only need if things are getting renamed but it doesn't seem to be renamed
yeah, its like js/navigator isnt available in release build
it should be. hard to say without seeing code.
hmm, generated code looks ok, I think
function eNa(a){return navigator.clipboard.writeText(a).then(...
yes but in which context does it execute
pretty sure you are only allowed to access that after asking permissions first? did you do that?
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
ill keep plugging
just for sanity try logging js/navigator
and see what that is. maybe it is redeclared somewhere locally or so
good idea, ill try that
The navigator object is there, but it doesnt have the clipboard property, giving legs to your theory on permissions
ill follow that rabbit hole, ty
ah, i think I figured it out, completely uninteresting
its only supported from secure-contexts with https, heh
forest for the trees
ty for the help, though
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?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=>
or (shadow/browser-repl)
or (shadow/node-repl)
if you don't have a build configured yet and just want a REPL
Ooops, I missed (help)
. Thanks 🙇
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
Well, yeah, already found the issue (bisecting)
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!
thats what I meant. just wanted to show an example of a library doing that.