-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ad9b22c
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.cpcache/* | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# lein-add-libs | ||
|
||
Use the [add-lib](https://clojure.github.io/clojure/branch-master/clojure.repl-api.html#clojure.repl.deps/add-lib) function in your repl from within a lein project. | ||
|
||
# Installation as a Tool | ||
|
||
Make sure you have the latest Clojure CLI version installed. | ||
|
||
```sh | ||
clj -Ttools install-latest :lib io.github.nubank/lein-add-libs :as lein-add-libs | ||
``` | ||
|
||
# Invoking the tool from a REPL | ||
|
||
```clojure | ||
(clojure.tools.deps.interop/invoke-tool {:tool-name "lein-add-libs" :fn 'lein-add-libs.core/bootstrap}) | ||
``` | ||
|
||
Now that the bootstrap function has been successfully run. You can proceed to use `add-lib` function as you would in a deps.edn base project. | ||
|
||
For example: | ||
```clojure | ||
(add-lib 'org.clojure/data.json) | ||
(require '[clojure.data.json :as json]) | ||
(json/read-str "{\"a\":1,\"b\":2}" :key-fn keyword) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{:paths ["src"] | ||
|
||
:deps {org.clojure/clojure {:mvn/version "1.12.0"} | ||
leiningen-core/leiningen-core {:mvn/version "2.9.1"}} | ||
|
||
:tools/usage {:ns-default lein-add-libs.core} | ||
|
||
:aliases {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(ns lein-add-libs.core | ||
(:require | ||
[clojure.string :as str] | ||
[clojure.java.basis.impl :refer [update-basis!]] | ||
[leiningen.core.project :as project] | ||
[leiningen.core.classpath :refer [get-classpath]])) | ||
|
||
(defn update-lein-basis [current-basis derived-basis] | ||
(if current-basis current-basis derived-basis)) | ||
|
||
(defn bootstrap [& args] | ||
(let [cp (get-classpath (project/read)) | ||
deps (filter #(str/includes? % "/.m2/") cp) | ||
dep-parts (map (fn [dep] (butlast (drop 2 (drop-while #(not= ".m2" %) (str/split dep #"/"))))) deps) | ||
libs (reduce (fn [res dep] | ||
(let [formatted-dep (symbol (str (str/join "." (drop-last 2 dep)) "/" (last (drop-last dep))))] | ||
(assoc res formatted-dep {:mvn/version (last dep) :deps/manifest :mvn}))) {} dep-parts) | ||
repos (reduce (fn [res [repo url]] (assoc res repo url)) {} (:repositories (project/read))) | ||
bootstrapped-basis {:libs libs :mvn/repos repos}] | ||
(update-basis! update-lein-basis bootstrapped-basis))) |