Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions tools.deps/src/cider/enrich_classpath/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
(apply vector clojure)
(string/join " ")))

(defn- prepend-arg
"Returns udpated `args` vector where `prepend-with` is inserted before
`arg` if `arg` exists, otherwise returns the original `args`
vector."
[arg prepend-with args]
(when (seq args)
(let [args-vec (vec args)
idx (.indexOf args arg)]
(if-not (neg? idx)
(into (conj (subvec args-vec 0 idx) prepend-with)
(subvec args-vec idx))
args-vec))))

(defn impl ^String [clojure deps-edn-filename pwd args shorten?]
{:pre [(vector? args)]} ;; for conj
(let [aliases (into #{}
Expand Down Expand Up @@ -78,15 +91,16 @@
(conj acc x))))
[]
args)
main-opts (reduce-kv (fn [acc ^long i x]
(let [j (dec i)]
(conj acc (cond-> x
(and (>= j 0)
(#{"-e" (pr-str "-e")} (nth main-opts j))
x)
pr-str))))
[]
main-opts)
main-opts (->> main-opts
(prepend-arg "-m" "-M")
(reduce-kv (fn [acc ^long i x]
(let [j (dec i)]
(conj acc (cond-> x
(and (>= j 0)
(#{"-e" (pr-str "-e")} (nth main-opts j))
x)
pr-str))))
[]))
classpath-overrides-keys (-> classpath-overrides keys set)
classpath-overrides-vector (vec classpath-overrides-keys)
;; a dep like `incanter` with :exclusions can expand to :children like `incanter-<blah>` without inheriting those :exclusions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"clojure -Sforce -Srepro -J-XX:-OmitStackTraceInFastThrow -J-Dclojure.main.report=stderr -Scp")
"Looks like a well-formed `clojure` invocation")
(is (string/ends-with? v
"-m nrepl.cmdline --middleware [refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]")
"-M -m nrepl.cmdline --middleware [refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]")
"Adds cider-nrepl's --main program based on the -Sdeps and -M args")
(is (string/includes? v
".m2/repository/cider/cider-nrepl/0.36.0/cider-nrepl-0.36.0.jar")
Expand Down