Fork me on GitHub

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:

| └-core.cljs
| └-...
| └-deps.edn
| └-deps.cljs
| └-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


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?


It works. 😃


You also said > Or one deps.edn at the root 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)]
       (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?


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)
       :title ~title
       :component (factory->class ~component)
       :decorators (into-array ~decorators))))


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

eccentric J21:02:32 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