Fork me on GitHub
#shadow-cljs
<
2019-11-28
>
Quest01:11:32

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

Quest01:11:14

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?

Quest01:11:29

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.

p-himik10:11:36

Is the relevant directory in the classpath when you run the app as is, not from a jar? If so, try using .

p-himik10:11:39

Ah, right - you're not just reading, you're listing the contents of a directory. Not sure how to do that.

thheller10:11:57

@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

thheller10:11:36

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

thheller10:11:51

and won't work if you need to run in any kind of application server/container

thheller10:11:56

or what I would actually recommend is not doing this as a macro at all

thheller10:11:21

instead make a script for something that takes the definitions and creates actual cljs/clj or cljc files

thheller10:11:37

way easier to debug than a macro, way better from a compiler perspective

👍 4
Quest19:11:03

Figured I might be barking up the wrong tree, thanks for setting me straight. I'll try this approach

thheller11:11:34

oh and not to forgot way easier on the tools since they can actually see the files 😛

tianshu11:11:09

@thheller I have a very small feature request, make the color of shadow-cljs log in browser console with dark mode looks nicer?

thheller11:11:29

@doglooksgood you can set :devtools {:log-style "color: white;"} in your build config

tianshu11:11:54

wow, great. it's configurable!

thheller11:11:12

unfortunately you cannot "detect" dark mode so there is no way to adjust dynamically

thheller11:11:40

actually I just thought of something "better" 😛

tianshu11:11:25

for the default blue color, maybe there's RGB that looks good on both light and dark background?

thheller11:11:01

no clue. happy to take suggestions

thheller11:11:53

it think it might be enough if the messages are just bold

thheller11:11:11

so then dark mode should adjust the color automatically

thheller11:11:42

just want the messages to be a little different from regular console logs

tianshu11:11:38

you mean don't want to use the color as the same as the ()?

thheller11:11:38

color I dont' really care about

thheller11:11:52

only need to be distinguish from regular console.log

thheller11:11:37

maybe an emoji or so

tianshu11:11:23

how about this one

tianshu11:11:29

but maybe not as sharp as the current in light mode, don't know if the contrast is too low.

thheller11:11:34

hmm that still doesn't look great in chrome darkmode

thheller11:11:50

but more readable for sure

thheller11:11:57

I'll add that as the default color. thx.

👍 4
tianshu11:11:08

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.

thheller11:11:09

yeah I just removed color and added bold and 🠶

thheller11:11:37

> 🠶 shadow-cljs: WebSocket connected!

thheller11:11:49

is distinctive enough I think

tianshu12:11:54

this looks great, I can't wait to use the newer version.

Quest21:11:55

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

Pavel Klavík23:11:15

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