This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-28
Channels
- # announcements (1)
- # babashka (9)
- # beginners (82)
- # calva (6)
- # cider (3)
- # clj-kondo (69)
- # cljdoc (4)
- # cljs-dev (10)
- # cljsrn (2)
- # clojure (74)
- # clojure-europe (11)
- # clojure-italy (9)
- # clojure-nl (15)
- # clojure-spec (18)
- # clojure-uk (89)
- # code-reviews (8)
- # core-async (42)
- # cursive (22)
- # datomic (26)
- # fulcro (13)
- # graalvm (31)
- # graphql (1)
- # leiningen (20)
- # malli (19)
- # music (1)
- # off-topic (4)
- # pathom (56)
- # re-frame (3)
- # reitit (26)
- # shadow-cljs (40)
- # spacemacs (5)
- # tools-deps (25)
How can a library include EDN resources?
Context: I wrote an internal "model" library that has some .edn files under /resources/definitions
. The library parses these files and generates some Datomic/DataScript schemas + Clojure specs.
I want these files to be included in the library when used by downstream projects, but the way I wrote the "inlining" causes no files to be loaded at all in those projects.
My model library has this in deps.edn
: :paths ["src/main/clojure" "resources"]
It "inlines" resources with the following code:
(defn list-resource-files
"Given a directory included on the classpath, returns seq of filenames"
[directory]
(let [in (.getResourceAsStream (.getContextClassLoader (Thread/currentThread)) directory)
reader (BufferedReader. (InputStreamReader. in))]
(loop [line (.readLine reader)
files []]
(if (some? line)
(recur (.readLine reader) (conj files line))
files))))
(defmacro inline-resources
"Given directory name in resources, returns coll of file contents"
[resources-path]
(->> (list-resource-files resources-path)
(map #(str resources-path "/" %))
(map #(slurp ( %)))
vec))
;; in consuming namespace
(inline-resources "definitions")
I think I can answer why it's failing... In a project that consumes the library, this code is causing it to look at /consuming-project/resources/definitions
, which turns out to have zero files.
What I'm not clear on is how to workaround this. Short of just embedding the library's EDN in a .cljc
file , is there any way to include resources/
from a library?
IIRC lein
did this and it "just worked". Also this might be a deps.edn question, can post there if it's more appropriate.
Worth mentioning is that I need to consume these resources from both clojure & cljs, hence why I was trying to "inline" it in the first place.
Is the relevant directory in the classpath when you run the app as is, not from a jar? If so, try using
.
Ah, right - you're not just reading, you're listing the contents of a directory. Not sure how to do that.
@quest listing the contents of a directory is not supported for .jar
files. you cannot "list" contents. you'll need to create an "index" file of some kind that lists the other files and then load them by name
well you can get fancy and list things by looking for the actual jar file and traversing that but that doesn't exactly respect the classpath
instead make a script for something that takes the definitions and creates actual cljs/clj or cljc files
Figured I might be barking up the wrong tree, thanks for setting me straight. I'll try this approach
oh and not to forgot way easier on the tools since they can actually see the files 😛
@thheller I have a very small feature request, make the color of shadow-cljs log in browser console with dark mode looks nicer?
@doglooksgood you can set :devtools {:log-style "color: white;"}
in your build config
unfortunately you cannot "detect" dark mode so there is no way to adjust dynamically
for the default blue color, maybe there's RGB that looks good on both light and dark background?
but maybe not as sharp as the current in light mode, don't know if the contrast is too low.
maybe bold is a better idea. I think this contrast is not enough for a few peoples. I'm very sensitive on contrast, so it's only okay to me.
Quick note for channel, React-Native Webpack broke on the shadow-cljs 2.8.68 -> 2.8.69 release. If anyone corroborates this see https://github.com/thheller/shadow-cljs/issues/607
Hi, what does mean the following error while building release target? Is it something I should address, or can be safely ignored?
NPM dependency "react" has installed version "^16.12.0"
"16.9.0" was required by jar:file:/C:/Users/pavel/.m2/repository/reagent/reagent/0.9.0-rc3/reagent-0.9.0-rc3.jar!/deps.cljs