From e0a303c484387eb4c565b1892f10eed5d7b3aa99 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 12 Sep 2024 16:41:27 +0200 Subject: [PATCH] Fix #1719: add new clojure 1.12 `clojure.repl.deps` namespace (#1724) --- CHANGELOG.md | 1 + resources/src/babashka/clojure/repl/deps.clj | 31 ++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 resources/src/babashka/clojure/repl/deps.clj diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c179a0b..e6c5d0ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ A preview of the next release can be installed from - Upgrade Clojure to `1.12.0` - Fix [#1722](https://github.com/babashka/babashka/issues/1722): add new clojure 1.12 vars - [#1720](https://github.com/babashka/babashka/issues/1720): Include new clojure 1.12's `clojure.java.process` +- [#1719](https://github.com/babashka/babashka/issues/1719): add new clojure 1.12 `clojure.repl.deps` namespace. Only calls with explicit versions are supported. - [#1598](https://github.com/babashka/babashka/issues/1598): use Rosetta on CircleCI to build x64 images - Bump SCI - Bump `fs` diff --git a/resources/src/babashka/clojure/repl/deps.clj b/resources/src/babashka/clojure/repl/deps.clj new file mode 100644 index 00000000..d81f58ab --- /dev/null +++ b/resources/src/babashka/clojure/repl/deps.clj @@ -0,0 +1,31 @@ +(ns clojure.repl.deps + (:require [babashka.deps :as deps])) + +(defn add-libs + "Given lib-coords, a map of lib to coord, will resolve all transitive deps for the libs + together and add them to the repl classpath, unlike separate calls to add-lib." + {:added "1.12"} + [lib-coords] + (deps/add-deps {:deps lib-coords}) + nil) + +(defn add-lib + "Given a lib that is not yet on the repl classpath, make it available by + downloading the library if necessary and adding it to the classloader. + Libs already on the classpath are not updated. Requires a valid parent + DynamicClassLoader. + + lib - symbol identifying a library, for Maven: groupId/artifactId + coord - optional map of location information specific to the procurer, + or latest if not supplied + + Returns coll of libs loaded, including transitive (or nil if none). + + For info on libs, coords, and versions, see: + https://clojure.org/reference/deps_and_cli" + {:added "1.12"} + ([lib coord] + (add-libs {lib coord})) + ([lib] + (throw (ex-info "add-lib without explicit version isn't supported in babashka (yet)" {:lib lib})))) +