Permalink
Browse files

add cljs-compat plugin dependency/subproject, fixes gh-266

  • Loading branch information...
1 parent 2317582 commit c51ab6c5756de5f250d09a9ee1e42f2a89560af1 @cemerick cemerick committed Nov 7, 2013
View
@@ -1,4 +1,8 @@
+pushd cljs-compat
+lein do clean, deploy clojars
+popd
+
pushd support
lein do clean, deploy clojars
popd
View
@@ -11,8 +11,11 @@ projects="$@"
project_root=$(dirname $(realpath $0))/..
pushd $project_root
+# needed to allow for post-release updates to cljs-compat
+export LEIN_SNAPSHOTS_IN_RELEASE=true
+
rm -rf ~/.m2/repository/lein-cljsbuild ~/.m2/repository/cljsbuild/
-for d in support plugin; do
+for d in cljs-compat support plugin; do
pushd $d
lein do clean, install, test
popd
View
@@ -0,0 +1,11 @@
+;; this is _meant_ to be a SNAPSHOT forever so that updates can always percolate
+;; down to users. Necessary because cljs compiler API is very volatile, and it
+;; doesn't use anything like a semver scheme. See
+;; https://github.com/emezeske/lein-cljsbuild/issues/266
+(defproject lein-cljsbuild/cljs-compat "1.0.0-SNAPSHOT"
+ :description "Matrix of cljsbuild/ClojureScript compatibility"
+ :url "http://github.com/emezeske/lein-cljsbuild"
+ :license
+ {:name "Eclipse Public License - v 1.0"
+ :url "http://www.eclipse.org/legal/epl-v10.html"
+ :distribution :repo})
@@ -0,0 +1,19 @@
+(ns cljsbuild.compat
+ (:use clojure.test))
+
+(def matrix {"1.0.0-SNAPSHOT" {:cljs ["0.0-2014"]}
+ "1.0.0-alpha2" {:cljs ["0.0-2014"]}})
+
+(defn parse-version
+ [version-string]
+ (if-let [[_ major minor patch git-commit-number]
+ (re-matches #"(\d*)(?:\.(\d+))?(?:\.(\d+))?(?:-(.+))?" version-string)]
+ [major minor patch (when git-commit-number (format "%05d" (Long/parseLong git-commit-number)))]
+ (throw (IllegalArgumentException. (str "Unparseable version: " version-string)))))
+
+(defn version-in-range?
+ [version [low high]]
+ (let [[version low high] (map parse-version [version low (or high "9.9.9-99999")])]
+ (and (<= (compare low version) 0)
+ (<= 0 (compare high version)))))
+
@@ -0,0 +1,13 @@
+(ns cljsbuild.compat-test
+ (:use clojure.test
+ cljsbuild.compat))
+
+(deftest test-version-in-range?
+ (are [version range] (version-in-range? version range)
+ "0.0-1500" ["0.0-1500"]
+ "0.0-1500" ["0.0-1500" "0.0-1500"]
+ "0.0-1500" ["0.0-1400" "0.0-2014"]
+ "0.0-1500" ["0.0-1500" "0.1-0"])
+ (are [version range] (not (version-in-range? version range))
+ "0.0-1500" ["0.0-1501"]
+ "0.0-1500" ["0.1-0"]))
View
@@ -5,7 +5,9 @@
{:name "Eclipse Public License - v 1.0"
:url "http://www.eclipse.org/legal/epl-v10.html"
:distribution :repo}
- :dependencies [[fs "1.1.2"]]
+ :dependencies [; SNAPSHOT is intentional here, https://github.com/emezeske/lein-cljsbuild/issues/266
+ [lein-cljsbuild/cljs-compat "1.0.0-SNAPSHOT"]
+ [fs "1.1.2"]]
:profiles {
:dev {
:dependencies [
@@ -1,6 +1,8 @@
(ns leiningen.cljsbuild.subproject
"Utilities for running cljsbuild in a subproject"
(:require
+ [leiningen.core.main :as lmain]
+ [cljsbuild.compat :as cljs-compat]
[clojure.java.io :refer (resource)]
[clojure.string :as string]))
@@ -42,23 +44,42 @@
(if-let [clojure-dependency ('org.clojure/clojure project-dependencies)]
(let [version (first clojure-dependency)]
(when (not (version-satisfies? version required-clojure-version))
- (throw
- (Exception.
- (str "The ClojureScript compiler requires Clojure version >= " required-clojure-version)))))))
+ (lmain/abort (str "The ClojureScript compiler requires Clojure version >= "
+ required-clojure-version))))))
(defn dependency-map [dependency-vec]
(into {} (map (juxt first rest) dependency-vec)))
(defn merge-dependencies [project-dependencies]
(let [project (dependency-map project-dependencies)
- cljsbuild (dependency-map cljsbuild-dependencies)]
+ desired-cljs-version ('org.clojure/clojurescript project)
+ cljsbuild (dependency-map cljsbuild-dependencies)
+ {acceptable-cljs-range :cljs} (cljs-compat/matrix cljsbuild-version)
+ cljs-version-message [(format "You're using [lein-cljsbuild \"%s\"]," cljsbuild-version)
+ "which is known to work"
+ "well with ClojureScript" (first acceptable-cljs-range)
+ "-" (str (or (second acceptable-cljs-range) "*") ".")]]
(check-clojure-version project)
- (when-not ('org.clojure/clojurescript project)
- (println "\033[33mWARNING: It appears your project does not contain a ClojureScript"
- "dependency. One will be provided for you by lein-cljsbuild, but it"
- "is strongly recommended that you add your own. You can find a list"
- "of all ClojureScript releases here:")
- (println "http://search.maven.org/#search|ga|1|g%3A%22org.clojure%22%20AND%20a%3A%22clojurescript%22\033[0m"))
+ (if desired-cljs-version
+ (when-not (cljs-compat/version-in-range? (first desired-cljs-version) acceptable-cljs-range)
+ (print "\033[31m")
+ (apply println (concat cljs-version-message
+ ["You are attempting to use ClojureScript"
+ (str (first desired-cljs-version) ",")
+ "which is not within this range. You can either change your"
+ "ClojureScript dependency to fit in the range, or change your"
+ "lein-cljsbuild plugin dependency to one that supports"
+ "ClojureScript" (str (first desired-cljs-version) ".")]))
+ (lmain/abort "\033[0m"))
+ (do
+ (println "\033[33mWARNING: It appears your project does not contain a ClojureScript"
+ "dependency. One will be provided for you by lein-cljsbuild, but it"
+ "is strongly recommended that you add your own. You can find a list"
+ "of all ClojureScript releases here:")
+ (println "http://search.maven.org/#search|ga|1|g%3A%22org.clojure%22%20AND%20a%3A%22clojurescript%22")
+ (when acceptable-cljs-range (apply println cljs-version-message))
+ (println "\033[0m")))
+
(map (fn [[k v]] (vec (cons k v)))
(merge cljsbuild project))))

3 comments on commit c51ab6c

Collaborator

cemerick replied Nov 7, 2013

True, thanks!

Apologies if you've covered this elsewhere - but why not have a dependency from lein-cljsbuild to ClojureScript at a particular known-good version and let people use the normal dependency exclusion mechanism if they want to use something different?

Please sign in to comment.