Skip to content

Commit c22e910

Browse files
committed
Merge tag 'v0.5.48'
2 parents 8d2aaab + a77ccb9 commit c22e910

File tree

6 files changed

+81
-24
lines changed

6 files changed

+81
-24
lines changed

.VERSION_PREFIX

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3
1+
0.5

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
# Unreleased
1+
# 0.5.48 (2024-01-10 / 2228a54)
2+
3+
## Changed
4+
5+
- Upgraded dependencies
6+
7+
# 0.4.44 (2022-09-08 / 0c66dda)
8+
9+
## Added
10+
11+
- [watcher] Add a `:watch-paths` option, to watch additional files. Presumable
12+
in combination with a custom `:basis-fn`
13+
14+
# 0.3.40 (2022-09-08 / 73c9529)
215

316
## Added
417

18+
- [watcher] Support for custom basis-fn
19+
- [watcher] Check for aliases in `:extra` deps file
20+
521
## Fixed
622

23+
- [watcher] Fix watcher stop! function
24+
725
## Changed
826

927
# 0.3.43 (2024-12-04 / df15f2e)

bb.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{:deps
22
{lambdaisland/open-source {:git/url "https://github.com/lambdaisland/open-source"
3-
:sha "7f39ffb76d47e2ff83d4478957c2ca4fd180f3e5"
3+
:sha "7ce125cbd14888590742da7ab3b6be9bba46fc7a"
44
#_#_:local/root "../open-source"}}}

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
com.lambdaisland/shellutils {:mvn/version "0.3.20"}
77
org.clojure/java.classpath {:mvn/version "1.0.0"}
88
com.nextjournal/beholder {:mvn/version "1.0.2"}
9-
io.methvin/directory-watcher {:mvn/version "0.16.1"}}}
9+
io.methvin/directory-watcher {:mvn/version "0.18.0"}}}

repl_session/poke.clj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns poke
22
(:require [lambdaisland.classpath :as licp]
3-
[clojure.string :as str])
3+
[clojure.string :as str]
4+
[clojure.java.io :as io])
45
(:import clojure.lang.DynamicClassLoader))
56

67
(licp/classpath-chain)
@@ -28,3 +29,10 @@
2829
(recur (.getParent loader))))))
2930

3031
(has-dcl? (licp/parent (licp/root-loader)))
32+
33+
(keep (fn [{:local/keys [root]}]
34+
(when (and root (.exists (io/file root "shadow-cljs.edn")))
35+
root))
36+
(vals (:libs (licp/read-basis))))
37+
38+
(io/resource "public/index.html")

src/lambdaisland/classpath/watch_deps.clj

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,41 @@
88
[nextjournal.beholder :as beholder])
99
(:import java.util.regex.Pattern
1010
java.nio.file.LinkOption
11-
java.nio.file.Paths))
11+
java.nio.file.Paths
12+
java.nio.file.Path))
1213

1314
(def watcher (atom nil))
1415

16+
(defn path ^Path [root & args]
17+
(if (and (instance? Path root) (not (seq args)))
18+
root
19+
(Paths/get (str root) (into-array String args))))
20+
1521
(defn canonical-path [p]
16-
(.toRealPath (Paths/get p (into-array String [])) (into-array LinkOption [])))
22+
(.toRealPath (path p) (into-array LinkOption [])))
23+
24+
(defn parent-path [p]
25+
(.getParent (path p)))
1726

1827
(def process-root-path (canonical-path "."))
1928

20-
(defn- on-event [deps-path opts {:keys [type path]}]
29+
(defn basis
30+
"Default function for (re-)computing the tools.deps basis, which we then use to
31+
update the classpath. Delegates to [[deps/create-basis]], with one addition:
32+
if you include an `:extra` option which points at a file (string), then we
33+
also look in that file for a `:lambdaisland.classpath/aliases`, which are
34+
additional alias keys to load. This allows having a `deps.local.edn`, where
35+
you can change the aliases in use without restarting."
36+
[opts]
37+
(if-let [f (:basis-fn opts)]
38+
(f opts)
39+
(deps/create-basis
40+
(if (string? (:extra opts))
41+
(update opts :aliases into (:lambdaisland.classpath/aliases
42+
(deps/slurp-deps (io/file (:extra opts)))))
43+
opts))))
44+
45+
(defn- on-event [deps-paths opts {:keys [type path]}]
2146
(locking watcher
2247
(when (and (= :modify type)
2348
;; Before we used "." as the watch path, resulting in a
@@ -28,13 +53,13 @@
2853
;; We now turn `"."` into a canonical path before starting the
2954
;; watcher, which means we get fully qualified filenames for both
3055
;; in this equality check.
31-
(= path deps-path))
56+
(some #{path} deps-paths))
3257
(try
3358
(println "[watch-deps] ✨ Reloading"
3459
(str (.relativize process-root-path path))
3560
"")
3661
(let [added-paths (remove (set (map str (cp/system-classpath)))
37-
(:classpath-roots (deps/create-basis opts)))]
62+
(:classpath-roots (basis opts)))]
3863
(when (not (seq added-paths))
3964
(println "[watch-deps] No new libraries to add."))
4065
(doseq [path added-paths]
@@ -60,31 +85,37 @@
6085
(when w
6186
(println "Stopping existing `deps.edn' watchers")
6287
(run! beholder/stop w))
63-
(let [basis (deps/create-basis opts)
64-
roots (cons (str process-root-path)
65-
(when (:include-local-roots? opts)
66-
(->> (vals (:libs basis))
67-
(keep :local/root)
68-
(map canonical-path)
69-
(map str))))]
88+
(let [basis (basis opts)
89+
deps-paths (cond-> [(path process-root-path "deps.edn")]
90+
(:include-local-roots? opts)
91+
(into (->> (vals (:libs basis))
92+
(keep :local/root)
93+
(map canonical-path)
94+
(map #(path % "deps.edn"))))
95+
(string? (:extra opts))
96+
(conj (canonical-path (:extra opts)))
97+
:always
98+
(concat (:watch-paths opts)))
99+
roots (group-by parent-path deps-paths)]
70100
(doall
71-
(for [root roots]
101+
(for [[root deps-paths] roots]
72102
(beholder/watch
73-
(partial #'on-event (Paths/get root (into-array String ["deps.edn"])) opts)
74-
root)))))))
103+
(partial #'on-event deps-paths opts)
104+
(str root))))))))
75105

76106
(defn stop!
77107
"Stop a previously started watcher"
78-
[opts]
108+
[& _]
79109
(swap! watcher
80110
(fn [w]
81-
(when w
82-
(beholder/stop w))
111+
(run! beholder/stop w)
83112
nil)))
84113

85114
(comment
86-
(start! {:aliases [:dev]})
115+
(start! {:aliases [:dev]
116+
:extra "deps.local.edn"})
87117

118+
(stop!)
88119
(deps/create-basis {:aliases [:backend]
89120
:extra '{cider/cider-nrepl #:mvn{:version "0.28.5"}
90121
refactor-nrepl/refactor-nrepl #:mvn{:version "3.5.2"}}})

0 commit comments

Comments
 (0)