Skip to content

Commit 07ecd90

Browse files
committed
Improve deps handling
1 parent bc39c2f commit 07ecd90

File tree

5 files changed

+90
-57
lines changed

5 files changed

+90
-57
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
## Added
44

5+
- Inject shadow-cljs deps when needed and not already present
6+
57
## Fixed
68

79
## Changed
810

11+
- Check deps before injecting extra deps (cider, nrepl, shadow, etc). Declared
12+
deps versions always get precedence.
13+
914
# 0.22.110-alpha (2024-01-17 / 95c22dc)
1015

1116
## Added
@@ -169,4 +174,4 @@ Initial release
169174
- lambdaisland.classpath integration
170175
- Support for cider-nrepl, refactor-nrepl
171176
- Basic support for shadow-cljs cljs nREPL-base REPL
172-
- Auto-connect for Emacs
177+
- Auto-connect for Emacs

bb.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{:deps
1+
{:paths ["src" "resources"]
2+
:deps
23
{lambdaisland/open-source {:git/url "https://github.com/lambdaisland/open-source"
34
:git/sha "7ce125cbd14888590742da7ab3b6be9bba46fc7a"}
45
com.lambdaisland/launchpad {:local/root "."}}}

deps.edn

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55
com.lambdaisland/dotenv {:mvn/version "0.2.5"}}
66

77
:aliases
8-
{:clojure { :extra-deps {babashka/babashka {:mvn/version "1.3.187" :scope "provided"}
9-
org.clojure/tools.deps.alpha {:mvn/version "0.15.1254"}
10-
com.nextjournal/beholder {:mvn/version "1.0.2"}
11-
thheller/shadow-cljs {:mvn/version "2.26.3"}
12-
;; prevent tools.deps.alpha from dragging in an old guava
13-
com.google.guava/guava {:mvn/version "33.0.0-jre"}
14-
com.lambdaisland/classpath {:mvn/version "0.5.48"}}}
8+
{:clojure
9+
{:extra-deps {babashka/babashka {:mvn/version "1.3.188" :scope "provided"}
10+
org.clojure/tools.deps.alpha {:mvn/version "0.15.1254"}
11+
com.nextjournal/beholder {:mvn/version "1.0.2"}
12+
thheller/shadow-cljs {:mvn/version "2.26.5"}
13+
;; prevent tools.deps.alpha from dragging in an old guava
14+
com.google.guava/guava {:mvn/version "33.0.0-jre"}
15+
com.lambdaisland/classpath {:mvn/version "0.5.48"}}}
1516
:dev
1617
{:extra-paths ["dev"]
1718
:extra-deps {djblue/portal {:mvn/version "RELEASE"}}}
1819

1920
:test
2021
{:extra-paths ["test"]
21-
:extra-deps {lambdaisland/kaocha {:mvn/version "1.87.1366"}}}}}
22+
:extra-deps {lambdaisland/kaocha {:mvn/version "1.87.1366"}}}
23+
24+
:self-deps
25+
{:extra-deps {com.lambdaisland/launchpad-deps {:local/root "resources/launchpad"}}}
26+
}}

resources/launchpad/deps.edn

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
;; This file is just a lookup file for Launchpad to find the version of various
2+
;; things to use. We keep it in deps.edn format so antq can automatically
3+
;; upgrade versions.
4+
{:deps
5+
{com.lambdaisland/launchpad {:mvn/version "0.22.110-alpha"}
6+
com.lambdaisland/classpath {:mvn/version "0.5.48"}
7+
com.github.jnr/jnr-posix {:mvn/version "3.1.18"}
8+
thheller/shadow-cljs {:mvn/version "2.26.5"}
9+
com.google.guava/guava {:mvn/version "33.0.0-jre"}
10+
cider/cider-nrepl {:mvn/version "0.45.0"}
11+
nrepl/nrepl {:mvn/version "1.1.0"}
12+
refactor-nrepl/refactor-nrepl {:mvn/version "3.9.1"}}}

src/lambdaisland/launchpad.clj

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,14 @@
2828
[nil "--emacs" "Shorthand for --cider-nrepl --refactor-nrepl --cider-connect"]
2929
[nil "--go" "Call (user/go) on boot"]])
3030

31-
(def default-nrepl-version "1.0.0")
31+
(def library-versions
32+
(:deps (edn/read-string (slurp (io/resource "launchpad/deps.edn")))))
3233

33-
;; Unless we have a mechanism of automatically updating these I would use
34-
;; `RELEASE` here, so non-emacs user always default to the latest version. This
35-
;; is a good candidate for making this configurable, for explicitness.
36-
(def default-cider-version "RELEASE")
37-
(def default-refactor-nrepl-version "RELEASE")
38-
39-
(def classpath-coords {:mvn/version "0.5.48"})
40-
(def jnr-posix-coords {:mvn/version "3.1.18"})
41-
42-
(def default-launchpad-coords
43-
"Version coordinates for Launchpad, which we use to inject ourselves into the
44-
project dependencies for runtime support. Only used when we are unable to find
45-
the current version in `bb.edn`"
46-
{:mvn/version "RELEASE"})
34+
;; (def default-launchpad-coords
35+
;; "Version coordinates for Launchpad, which we use to inject ourselves into the
36+
;; project dependencies for runtime support. Only used when we are unable to find
37+
;; the current version in `bb.edn`"
38+
;; {:mvn/version "RELEASE"})
4739

4840
(def verbose? (some #{"-v" "--verbose"} *command-line-args*))
4941

@@ -107,22 +99,24 @@
10799
;; even though they are not running Emacs.
108100
)))
109101

110-
(defn emacs-cider-version
102+
(defn emacs-cider-coords
111103
"Find the CIDER version that is currently in use by the running Emacs instance."
112104
[]
113105
(when (emacs-require 'cider)
114-
(read-string
115-
(eval-emacs '(if (boundp 'cider-required-middleware-version)
116-
cider-required-middleware-version
117-
(upcase cider-version))))))
106+
{:mvn/version
107+
(read-string
108+
(eval-emacs '(if (boundp 'cider-required-middleware-version)
109+
cider-required-middleware-version
110+
(upcase cider-version))))}))
118111

119-
(defn emacs-refactor-nrepl-version
112+
(defn emacs-refactor-nrepl-coords
120113
"Find the refactor-nrepl version that is required by the `clj-refactor` version
121114
installed in Emacs."
122115
[]
123116
(when (emacs-require 'clj-refactor)
124-
(read-string
125-
(eval-emacs 'cljr-injected-middleware-version))))
117+
{:mvn/version
118+
(read-string
119+
(eval-emacs 'cljr-injected-middleware-version))}))
126120

127121
(defn add-nrepl-middleware [& mws]
128122
(fn [ctx]
@@ -137,15 +131,31 @@
137131
(:refactor-nrepl options)
138132
((add-nrepl-middleware 'refactor-nrepl.middleware/wrap-refactor))))
139133

134+
(defn library-in-deps? [ctx libname]
135+
(or (contains? (get-in ctx [:deps-edn :deps]) libname)
136+
(some
137+
(fn [extra-deps]
138+
(contains? extra-deps libname))
139+
(map (comp :extra-deps val)
140+
(select-keys (get-in ctx [:deps-edn :aliases])
141+
(:aliases ctx))))))
142+
143+
(defn assoc-extra-dep [ctx libname & [version]]
144+
(if (library-in-deps? ctx libname)
145+
ctx
146+
(update ctx :extra-deps
147+
assoc libname
148+
(or version
149+
(get library-versions libname)))))
150+
140151
(defn compute-extra-deps [{:keys [options] :as ctx}]
141-
(let [assoc-dep #(update %1 :extra-deps assoc %2 %3)]
142-
(cond-> ctx
143-
true
144-
(assoc-dep 'nrepl/nrepl {:mvn/version default-nrepl-version})
145-
(:cider-nrepl options)
146-
(assoc-dep 'cider/cider-nrepl {:mvn/version (or (emacs-cider-version) default-cider-version)})
147-
(:refactor-nrepl options)
148-
(assoc-dep 'refactor-nrepl/refactor-nrepl {:mvn/version (or (emacs-refactor-nrepl-version) default-refactor-nrepl-version)}))))
152+
(cond-> ctx
153+
true
154+
(assoc-extra-dep 'nrepl/nrepl)
155+
(:cider-nrepl options)
156+
(assoc-extra-dep 'cider/cider-nrepl (emacs-cider-coords))
157+
(:refactor-nrepl options)
158+
(assoc-extra-dep 'refactor-nrepl/refactor-nrepl (emacs-refactor-nrepl-coords))))
149159

150160
(defn get-nrepl-port [ctx]
151161
(assoc ctx :nrepl-port (or (get-in ctx [:options :nrepl-port])
@@ -290,7 +300,7 @@
290300

291301
(defn include-hot-reload-deps [{:keys [extra-deps aliases] :as ctx}]
292302
(as-> ctx <>
293-
(update <> :extra-deps assoc 'com.lambdaisland/classpath classpath-coords)
303+
(assoc-extra-dep <> 'com.lambdaisland/classpath)
294304
(update <> :requires conj 'lambdaisland.launchpad.deps)
295305
(update <> :eval-forms (fnil conj [])
296306
`(lambdaisland.launchpad.deps/write-cpcache-file))
@@ -310,7 +320,7 @@
310320

311321
(defn watch-dotenv [ctx]
312322
(-> ctx
313-
(update :extra-deps assoc 'com.github.jnr/jnr-posix jnr-posix-coords)
323+
(assoc-extra-dep 'com.github.jnr/jnr-posix)
314324
(update :java-args conj
315325
"--add-opens=java.base/java.lang=ALL-UNNAMED"
316326
"--add-opens=java.base/java.util=ALL-UNNAMED")
@@ -338,6 +348,9 @@
338348
(debug "Starting shadow-cljs builds" build-ids))
339349
(if (seq build-ids)
340350
(-> ctx
351+
(assoc-extra-dep 'thheller/shadow-cljs)
352+
;; tools.deps pulls in an old Guava, which causes issues with shadow-cljs
353+
(assoc-extra-dep 'com.google.guava/guava)
341354
(update :middleware (fnil conj []) 'shadow.cljs.devtools.server.nrepl/middleware)
342355
(assoc :shadow-cljs/build-ids build-ids)
343356
(assoc :shadow-cljs/connect-ids connect-ids)
@@ -350,13 +363,11 @@
350363
ctx)))
351364

352365
(defn find-launchpad-coords []
353-
(or
354-
(when (.exists (io/file "bb.edn"))
355-
(get-in (edn/read-string (slurp "bb.edn")) [:deps 'com.lambdaisland/launchpad]))
356-
default-launchpad-coords))
366+
(when (.exists (io/file "bb.edn"))
367+
(get-in (edn/read-string (slurp "bb.edn")) [:deps 'com.lambdaisland/launchpad])))
357368

358-
(defn include-launchpad-deps [{:keys [extra-deps] :as ctx}]
359-
(update ctx :extra-deps assoc 'com.lambdaisland/launchpad (find-launchpad-coords)))
369+
(defn include-launchpad-deps [ctx]
370+
(assoc-extra-dep ctx 'com.lambdaisland/launchpad (find-launchpad-coords)))
360371

361372
(defn maybe-connect-emacs [{:keys [options nrepl-port project-root] :as ctx}]
362373
(when (:cider-connect options)
@@ -511,11 +522,10 @@
511522
(defn process-steps [ctx steps]
512523
(reduce #(%2 %1) ctx steps))
513524

514-
(defn main
515-
([{:keys [steps] :or {steps default-steps} :as opts}]
516-
(let [ctx (process-steps (initial-context opts) steps)
517-
processes (:processes ctx)]
518-
(.addShutdownHook (Runtime/getRuntime)
519-
(Thread. (fn [] (run! #(.destroy %) processes))))
520-
(System/exit (apply min (for [p processes]
521-
(.waitFor p)))))))
525+
(defn main [{:keys [steps] :or {steps default-steps} :as opts}]
526+
(let [ctx (process-steps (initial-context opts) steps)
527+
processes (:processes ctx)]
528+
(.addShutdownHook (Runtime/getRuntime)
529+
(Thread. (fn [] (run! #(.destroy %) processes))))
530+
(System/exit (apply min (for [p processes]
531+
(.waitFor p))))))

0 commit comments

Comments
 (0)