Fork me on GitHub
#tools-deps
<
2022-05-28
>
Benjamin12:05:50

How do I include non clj files from an external lib. Specifically the cognitect aws lib depends on service.edn files. I made an intermediate library that depends on com.cognitect.aws/redshift-data

Alex Miller (Clojure team)12:05:12

If you depend on a lib, anything in it will be on the classpath and loadable as a resource

Alex Miller (Clojure team)12:05:29

But not sure if that's what you're asking

Benjamin12:05:07

I see so it should work

Benjamin13:05:43

(ns lambdaisland.classpath.watch-deps
  "Watch deps.edn for changes"
  (:require [clojure.java.classpath :as cp]
            [clojure.string :as str]
            [clojure.tools.deps.alpha :as deps]
            [lambdaisland.classpath :as licp]
            [nextjournal.beholder :as beholder]))

(def watcher (atom nil))

(defn- on-event [opts {:keys [type path]}]
  (when (and (= :modify type)
             ;; On Mac the path will be absolute and include the watched dir,
             ;; e.g. `/Users/x/project/./deps.edn`
             ;; On other systems it seems to be relative, like `./deps.edn`
             (str/ends-with? (str path) "./deps.edn"))
    (println "✨ Reloading deps.edn ✨")
    (let [new-paths (remove (set (map str (cp/system-classpath)))
                            (:classpath-roots (deps/create-basis opts)))]
      (doseq [path new-paths]
        (println "- " path))
      (licp/install-priority-loader! new-paths))))

(defn start!
  "Start a file system watcher to pick up changes in `deps.edn'

  Options are passed on to tools.deps when creating the basis, you probably want
  to at least put the `:aliases` you need in there.

  
(start! {:aliases [:dev :test]})
"
  [opts]
  (swap! watcher
         (fn [w]
           (when w
             (println "Stopping existing `deps.edn' watcher")
             (beholder/stop w))
           (beholder/watch (partial on-event opts) "."))))

(defn stop!
  "Stop a previously started watcher"
  [opts]
  (swap! watcher
         (fn [w]
           (when w
             (beholder/stop w))
           nil)))


(comment
  (start! {:aliases [:dev]}))
there is something about how this tool works that made it so I ended up with the error "could not find redshift-something.service.edn" on the classpath. It worked when I started the program. So I have libA depends on com.cognitect.aws/redshift-data and programB depends on libA and ran into the error