Fork me on GitHub
#clojurescript
<
2022-02-24
>
pez14:02:22

I'm trying to control which :npm-deps are provided using deps.cljs for diferent versions of a library in a monorepo. Setting up a structure like this:

foo_lib
├-src
| └-core.cljs
| └-...
├-v1
| └-deps.edn
| └-deps.cljs
├-v2
| └-deps.edn
| └-deps.cljs
And in those deps.edn files
:paths ["." "../src"]
This gives me a deprecation warning because the path is outside the project. Anyone see some other layout I can use? (I'm ready to solve it via documentation and telling consumer which npm dependency to install for different versions of the library API, but want to also check what options I have.)

Alex Miller (Clojure team)14:02:49

this is what local deps are for

pez12:03:46

The library is consumed through local deps. Is the suggestion here that I can somehow use local deps in the library to get the shared src directory on the classpath?

pez12:03:11

It works. 😃

pez12:03:09

You also said > Or one deps.edn at the root https://clojurians.slack.com/archives/C03S1L9DN/p1645713410040839 I think I am missing something there, because I struggle to make sense of it.

Alex Miller (Clojure team)13:03:04

you can possibly use one deps.edn at the root, then different aliases to pull different subsets of the subdirs and only work from there (but this probably fights with tooling)

Alex Miller (Clojure team)14:02:31

my/src {:local/root ".."} etc

Alex Miller (Clojure team)14:02:50

or one deps.edn at the root

Karol Wójcik17:02:43

I'm trying to create a macro that creates a var 'default in the ns in which it's used without requiring 'default to be passed as a first argument. I've expressed the idea in the following snippet of code:

(defmacro defpage
  [{:keys [title component decorators arg-types]}]
  (let [ns       (:ns &env)
        ns-name  (:name ns)
        meta     (:meta ns)
        var-name (with-meta (symbol (str ns-name) "default") meta)]
    `(do
       (let [x# (with-meta '~var-name (merge {:export true} ~meta))]
         (def x#
           #js {:title      ~title
                :component  (factory->class ~component)
                :decorators (into-array ~decorators)})))))
However when using the macro it creates a var in the macro ns instead of the ns where it's used. In clojure I would probably use in-ns for this. Do you have an idea how to make it work with Clojurescript?

p-himik17:02:18

Looks like you're overcomplicating things. You can just emit a regular def form without having to generate symbols or altering the namespace. This should work:

(defmacro defpage
  [{:keys [title component decorators]}]
  `(def ~(vary-meta 'default assoc :export true)
     (cljs.core/js-obj
       :title ~title
       :component (factory->class ~component)
       :decorators (into-array ~decorators))))

p-himik17:02:41

Can't use #js because it's expanded during reading and not macro expansion. And Clojure itself doesn't have a #js reader. Though I'm not entirely sure why ^:export is not usable and instead vary-meta has to be used.

Karol Wójcik17:02:02

Huh. You're right! Thanks @U2FRKM4TW!

👍 1
Karol Wójcik18:02:53

Thank you so much!!

jaide21:02:32

https://replit.com/@eccentric-j/Node-Babashka-With-Redefs-Examples#src/cli/core.cljs here's a demo of nbb using the latest version of promesa which includes an async version of with-redefs perfect for mocking out api requests while testing in a live repl

❤️ 2