diff --git a/bb.edn b/bb.edn index 57a3e40..4a720ef 100644 --- a/bb.edn +++ b/bb.edn @@ -19,13 +19,13 @@ (run 'test))} lint (shell "clj-kondo --lint .") test {:depends [gen-script] - :extra-deps {io.github.cognitect-labs/test-runner - {:git/tag "v0.5.1" :git/sha "dfb30dd"} - ring/ring-core {:mvn/version "1.12.1"}} + :extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"} + http-kit/http-kit {:mvn/version "2.8.0"} + ring/ring-core {:mvn/version "1.13.0"}} :task cognitect.test-runner/-main} + test:clj (apply clojure "-M:test" *command-line-args*) gen-script {:doc "Build the bbin script" - :extra-deps {org.clojure/tools.namespace - {:mvn/version "1.5.0"}} + :extra-deps {org.clojure/tools.namespace {:mvn/version "1.5.0"}} :requires ([babashka.bbin.gen-script :as gen-script]) :task (gen-script/gen-script)} render-templates {:requires ([clojure.string :as str] diff --git a/bbin b/bbin index d3f8554..7c554df 100755 --- a/bbin +++ b/bbin @@ -740,12 +740,15 @@ WARNING: (We won't make any changes without asking you first.) (defn snake-case [s] (str/replace s "_" "-")) +(defmacro whenbb [& forms] + (when (System/getProperty "babashka.version") + `(do ~@forms))) + (ns babashka.bbin.scripts.common (:require [babashka.bbin.deps :as bbin-deps] [babashka.bbin.dirs :as dirs] [babashka.bbin.specs] - [babashka.bbin.util :as util :refer [sh]] - [babashka.deps :as deps] + [babashka.bbin.util :as util :refer [sh whenbb]] [babashka.fs :as fs] [clojure.edn :as edn] [clojure.main :as main] @@ -1040,8 +1043,9 @@ WARNING: (We won't make any changes without asking you first.) header' (if (#{::no-lib} lib) {:coords {:bbin/url (str "file://" (get-in header [:coords :local/root]))}} header) - _ (when-not (#{::no-lib} lib) - (deps/add-deps {:deps script-deps})) + _ (whenbb (when-not (#{::no-lib} lib) + ((requiring-resolve 'babashka.deps/add-deps) + {:deps script-deps}))) script-root (fs/canonicalize (or (get-in header [:coords :local/root]) (local-lib-path script-deps)) {:nofollow-links true}) @@ -1249,8 +1253,7 @@ WARNING: (We won't make any changes without asking you first.) (:require [babashka.bbin.dirs :as dirs] [babashka.bbin.protocols :as p] [babashka.bbin.scripts.common :as common] - [babashka.bbin.util :as util] - [babashka.deps :as deps] + [babashka.bbin.util :as util :refer [whenbb]] [babashka.fs :as fs] [babashka.http-client :as http] [babashka.json :as json] @@ -1338,7 +1341,8 @@ WARNING: (We won't make any changes without asking you first.) (select-keys cli-opts [:mvn/version])} header {:lib (key (first script-deps)) :coords (val (first script-deps))} - _ (deps/add-deps {:deps script-deps}) + _ (whenbb ((requiring-resolve 'babashka.deps/add-deps) + {:deps script-deps}) ) script-root (fs/canonicalize (or (:local/root cli-opts) (common/local-lib-path script-deps)) {:nofollow-links true}) script-name (or (:as cli-opts) (second (str/split (:script/lib cli-opts) #"/"))) script-config (common/default-script-config cli-opts) diff --git a/deps.edn b/deps.edn index d8ba291..30ad4c7 100644 --- a/deps.edn +++ b/deps.edn @@ -11,4 +11,13 @@ selmer/selmer {:mvn/version "1.12.55"} version-clj/version-clj {:mvn/version "2.0.2"}} :aliases {:neil {:project {:name babashka/bbin - :version "0.2.4"}}}} + :version "0.2.4"}} + :dev {:extra-deps {http-kit/http-kit {:mvn/version "2.8.0"} + io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"} + ring/ring-core {:mvn/version "1.13.0"}} + :extra-paths ["test" "test-resources" "dev"]} + :test {:extra-deps {http-kit/http-kit {:mvn/version "2.8.0"} + io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"} + ring/ring-core {:mvn/version "1.13.0"}} + :extra-paths ["test" "test-resources" "dev"] + :main-opts ["-m" "cognitect.test-runner"]}}} diff --git a/src/babashka/bbin/scripts/common.clj b/src/babashka/bbin/scripts/common.clj index ef8f2f3..eed924b 100644 --- a/src/babashka/bbin/scripts/common.clj +++ b/src/babashka/bbin/scripts/common.clj @@ -2,8 +2,7 @@ (:require [babashka.bbin.deps :as bbin-deps] [babashka.bbin.dirs :as dirs] [babashka.bbin.specs] - [babashka.bbin.util :as util :refer [sh]] - [babashka.deps :as deps] + [babashka.bbin.util :as util :refer [sh whenbb]] [babashka.fs :as fs] [clojure.edn :as edn] [clojure.main :as main] @@ -298,8 +297,9 @@ header' (if (#{::no-lib} lib) {:coords {:bbin/url (str "file://" (get-in header [:coords :local/root]))}} header) - _ (when-not (#{::no-lib} lib) - (deps/add-deps {:deps script-deps})) + _ (whenbb (when-not (#{::no-lib} lib) + ((requiring-resolve 'babashka.deps/add-deps) + {:deps script-deps}))) script-root (fs/canonicalize (or (get-in header [:coords :local/root]) (local-lib-path script-deps)) {:nofollow-links true}) diff --git a/src/babashka/bbin/scripts/maven_jar.clj b/src/babashka/bbin/scripts/maven_jar.clj index 4a58572..2916d68 100644 --- a/src/babashka/bbin/scripts/maven_jar.clj +++ b/src/babashka/bbin/scripts/maven_jar.clj @@ -2,8 +2,7 @@ (:require [babashka.bbin.dirs :as dirs] [babashka.bbin.protocols :as p] [babashka.bbin.scripts.common :as common] - [babashka.bbin.util :as util] - [babashka.deps :as deps] + [babashka.bbin.util :as util :refer [whenbb]] [babashka.fs :as fs] [babashka.http-client :as http] [babashka.json :as json] @@ -91,7 +90,8 @@ (select-keys cli-opts [:mvn/version])} header {:lib (key (first script-deps)) :coords (val (first script-deps))} - _ (deps/add-deps {:deps script-deps}) + _ (whenbb ((requiring-resolve 'babashka.deps/add-deps) + {:deps script-deps}) ) script-root (fs/canonicalize (or (:local/root cli-opts) (common/local-lib-path script-deps)) {:nofollow-links true}) script-name (or (:as cli-opts) (second (str/split (:script/lib cli-opts) #"/"))) script-config (common/default-script-config cli-opts) diff --git a/src/babashka/bbin/util.clj b/src/babashka/bbin/util.clj index b08e6f4..718d51d 100644 --- a/src/babashka/bbin/util.clj +++ b/src/babashka/bbin/util.clj @@ -319,3 +319,7 @@ (defn snake-case [s] (str/replace s "_" "-")) + +(defmacro whenbb [& forms] + (when (System/getProperty "babashka.version") + `(do ~@forms))) diff --git a/test/babashka/bbin/scripts/maven_jar_test.clj b/test/babashka/bbin/scripts/maven_jar_test.clj index 28646e6..edd98f2 100644 --- a/test/babashka/bbin/scripts/maven_jar_test.clj +++ b/test/babashka/bbin/scripts/maven_jar_test.clj @@ -28,7 +28,7 @@ (is (= `{~'http-server ~maven-lib} (tu/run-ls)))))) (def upgraded-lib - (assoc-in maven-lib [:coords :mvn/version] "0.1.12")) + (assoc-in maven-lib [:coords :mvn/version] "0.1.13")) (deftest upgrade-maven-jar-test (testing "upgrade (maven jar)" @@ -42,4 +42,4 @@ (is (fs/exists? (fs/file (dirs/bin-dir nil) (name (:lib upgraded-lib))))) (is (str/starts-with? (tu/run-bin-script (:lib upgraded-lib) "--help") help-text)) - (is (= `{~'http-server ~upgraded-lib} (tu/run-ls)))))) + (is (= {'http-server upgraded-lib} (tu/run-ls))))))