|
28 | 28 | [nil "--emacs" "Shorthand for --cider-nrepl --refactor-nrepl --cider-connect"] |
29 | 29 | [nil "--go" "Call (user/go) on boot"]]) |
30 | 30 |
|
31 | | -(def default-nrepl-version "1.0.0") |
| 31 | +(def library-versions |
| 32 | + (:deps (edn/read-string (slurp (io/resource "launchpad/deps.edn"))))) |
32 | 33 |
|
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"}) |
47 | 39 |
|
48 | 40 | (def verbose? (some #{"-v" "--verbose"} *command-line-args*)) |
49 | 41 |
|
|
107 | 99 | ;; even though they are not running Emacs. |
108 | 100 | ))) |
109 | 101 |
|
110 | | -(defn emacs-cider-version |
| 102 | +(defn emacs-cider-coords |
111 | 103 | "Find the CIDER version that is currently in use by the running Emacs instance." |
112 | 104 | [] |
113 | 105 | (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))))})) |
118 | 111 |
|
119 | | -(defn emacs-refactor-nrepl-version |
| 112 | +(defn emacs-refactor-nrepl-coords |
120 | 113 | "Find the refactor-nrepl version that is required by the `clj-refactor` version |
121 | 114 | installed in Emacs." |
122 | 115 | [] |
123 | 116 | (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))})) |
126 | 120 |
|
127 | 121 | (defn add-nrepl-middleware [& mws] |
128 | 122 | (fn [ctx] |
|
137 | 131 | (:refactor-nrepl options) |
138 | 132 | ((add-nrepl-middleware 'refactor-nrepl.middleware/wrap-refactor)))) |
139 | 133 |
|
| 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 | + |
140 | 151 | (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)))) |
149 | 159 |
|
150 | 160 | (defn get-nrepl-port [ctx] |
151 | 161 | (assoc ctx :nrepl-port (or (get-in ctx [:options :nrepl-port]) |
|
290 | 300 |
|
291 | 301 | (defn include-hot-reload-deps [{:keys [extra-deps aliases] :as ctx}] |
292 | 302 | (as-> ctx <> |
293 | | - (update <> :extra-deps assoc 'com.lambdaisland/classpath classpath-coords) |
| 303 | + (assoc-extra-dep <> 'com.lambdaisland/classpath) |
294 | 304 | (update <> :requires conj 'lambdaisland.launchpad.deps) |
295 | 305 | (update <> :eval-forms (fnil conj []) |
296 | 306 | `(lambdaisland.launchpad.deps/write-cpcache-file)) |
|
310 | 320 |
|
311 | 321 | (defn watch-dotenv [ctx] |
312 | 322 | (-> ctx |
313 | | - (update :extra-deps assoc 'com.github.jnr/jnr-posix jnr-posix-coords) |
| 323 | + (assoc-extra-dep 'com.github.jnr/jnr-posix) |
314 | 324 | (update :java-args conj |
315 | 325 | "--add-opens=java.base/java.lang=ALL-UNNAMED" |
316 | 326 | "--add-opens=java.base/java.util=ALL-UNNAMED") |
|
338 | 348 | (debug "Starting shadow-cljs builds" build-ids)) |
339 | 349 | (if (seq build-ids) |
340 | 350 | (-> 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) |
341 | 354 | (update :middleware (fnil conj []) 'shadow.cljs.devtools.server.nrepl/middleware) |
342 | 355 | (assoc :shadow-cljs/build-ids build-ids) |
343 | 356 | (assoc :shadow-cljs/connect-ids connect-ids) |
|
350 | 363 | ctx))) |
351 | 364 |
|
352 | 365 | (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]))) |
357 | 368 |
|
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))) |
360 | 371 |
|
361 | 372 | (defn maybe-connect-emacs [{:keys [options nrepl-port project-root] :as ctx}] |
362 | 373 | (when (:cider-connect options) |
|
511 | 522 | (defn process-steps [ctx steps] |
512 | 523 | (reduce #(%2 %1) ctx steps)) |
513 | 524 |
|
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