Skip to content

Instantly share code, notes, and snippets.

@humorless
Forked from theronic/deps.clj
Created October 31, 2022 10:08
Show Gist options
  • Save humorless/7c21b6550ad19a3ba4575c0a013d715b to your computer and use it in GitHub Desktop.
Save humorless/7c21b6550ad19a3ba4575c0a013d715b to your computer and use it in GitHub Desktop.
Convert Clojure project.clj :dependencies to deps.edn style
; using Clojure 1.9
(require '[clojure.pprint :as pprint])
(defn xform-dep [[lib version & korks]]
(let [args (into {} (apply hash-map korks))]
[lib (merge {:mvn/version version} args)]))
(defn xform-deps
"deps.edn utility function by @theronic 2018-02-28
Transforms a collection of project.clj :dependencies to deps.edn style
'[[org.clojure/clojurescript \"1.9.946\" :exclusions [org.clojure/clojure com.google.guava/guava]]
...]
=> {:deps {org.clojure/clojurescript {:mvn/version \" 1.9.946\", :exclusions [org.clojure/clojure com.google.guava/guava]}}
...}"
[coll]
(binding [*print-namespace-maps* false
pprint/*print-right-margin* 300]
(pprint/pprint (into {} (map xform-dep coll)))))
(comment
(xform-deps '[[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.9.946" :exclusions [org.clojure/clojure com.google.guava/guava]]
[pandeiro/boot-http "0.8.3" :scope "test"]])
; => {org.clojure/clojure {:mvn/version "1.9.0"}
; org.clojure/clojurescript {:mvn/version "1.9.946", :exclusions [org.clojure/clojure com.google.guava/guava]}
; pandeiro/boot-http {:mvn/version "0.8.3", :scope "test"}}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment