Skip to content

Commit

Permalink
only add cljx as a runtime dependency when running a REPL, fixes gh-47
Browse files Browse the repository at this point in the history
  • Loading branch information
cemerick committed Sep 5, 2014
1 parent aea65aa commit be2a633
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/cljx/plugin.clj
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
(ns cljx.plugin
(:require [clojure.java.io :as io]))
(:require [robert.hooke :as hooke]
leiningen.repl
[clojure.java.io :as io]))

(def ^:private cljx-version
(-> (io/resource "META-INF/leiningen/com.keminglabs/cljx/project.clj")
slurp
read-string
(nth 2)))
(def cljx-coordinates
(-> (or (io/resource "META-INF/leiningen/com.keminglabs/cljx/project.clj")
(io/resource "META-INF/leiningen/org.clojars.cemerick/cljx/project.clj"))
slurp
read-string
((fn [[_ artifact version]] [artifact version]))))

(assert (string? cljx-version)
(str "Something went wrong, version of cljx is not a string: "
cljx-version))
(assert (and (symbol? (first cljx-coordinates))
(string? (second cljx-coordinates)))
(str "Something went wrong, cljx coordinates are invalid: "
cljx-coordinates))

(defn middleware
[project]
(-> project
(update-in [:dependencies]
(fnil into [])
[['com.keminglabs/cljx cljx-version]])
(if (or (-> project :cljx :disable-repl-integration)
(not (-> project meta :included-profiles set (contains? :repl))))
project
(-> project
(update-in [:repl-options :nrepl-middleware]
(fnil into [])
'[cljx.repl-middleware/wrap-cljx cemerick.piggieback/wrap-cljs-repl])))
(fnil into [])
'[cljx.repl-middleware/wrap-cljx cemerick.piggieback/wrap-cljs-repl])
(update-in [:dependencies]
(fnil conj [])
cljx-coordinates))))

0 comments on commit be2a633

Please sign in to comment.