diff --git a/sci b/sci index f29089b6..aaf5821f 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit f29089b68e2e7d41e9491be0c1d7c48e1b9691e7 +Subproject commit aaf5821f8c084d6301c96da88f05c570bffcc84d diff --git a/src/babashka/impl/deps.clj b/src/babashka/impl/deps.clj index 65c40860..735ec477 100644 --- a/src/babashka/impl/deps.clj +++ b/src/babashka/impl/deps.clj @@ -44,8 +44,8 @@ paths))) #_(merge-default-deps '{:deps {medley/medley nil} - :aliases {:foo {medley/medley nil}}} - '{medley/medley {:mvn/version "1.3.0"}}) + :aliases {:foo {medley/medley nil}}} + '{medley/medley {:mvn/version "1.3.0"}}) ;;;; end merge edn files @@ -66,31 +66,35 @@ paths) paths)] (cp/add-classpath (str/join cp/path-sep paths)))) - (when-let [deps-map (not-empty (dissoc deps-map - ;; paths are added manually above - ;; extra-paths are added as :paths in tasks - :paths - :tasks :raw :min-bb-version))] - (binding [*print-namespace-maps* false] - (let [deps-map (assoc-in deps-map [:aliases :org.babashka/defaults] - {:replace-paths [] ;; babashka sets paths manually - :classpath-overrides (cond-> - '{org.clojure/clojure "" - org.clojure/spec.alpha ""} - ;; only remove core specs when they are not mentioned in deps map - (not (str/includes? (str deps-map) "org.clojure/core.specs.alpha")) - (assoc 'org.clojure/core.specs.alpha ""))}) - args (list "-Srepro" ;; do not include deps.edn from user config - "-Spath" "-Sdeps" (str deps-map) - "-Sdeps-file" "") ;; we reset deps file so the local deps.edn isn't used - args (if force (cons "-Sforce" args) args) - args (concat args [(str "-A:" (str/join ":" (cons ":org.babashka/defaults" aliases)))]) - cp (with-out-str (binding [deps/*env* env - deps/*extra-env* extra-env] - (apply deps/-main args))) - cp (str/trim cp) - cp (str/replace cp (re-pattern (str cp/path-sep "+$")) "")] - (cp/add-classpath cp)))))) + (let [need-deps? (or (:deps deps-map) + (and (:aliases deps-map) + aliases))] + (when need-deps? + (let [deps-map (dissoc deps-map + ;; paths are added manually above + ;; extra-paths are added as :paths in tasks + :paths :tasks :raw :file :deps-root + :min-bb-version)] + (binding [*print-namespace-maps* false] + (let [deps-map (assoc-in deps-map [:aliases :org.babashka/defaults] + {:replace-paths [] ;; babashka sets paths manually + :classpath-overrides (cond-> + '{org.clojure/clojure "" + org.clojure/spec.alpha ""} + ;; only remove core specs when they are not mentioned in deps map + (not (str/includes? (str deps-map) "org.clojure/core.specs.alpha")) + (assoc 'org.clojure/core.specs.alpha ""))}) + args (list "-Srepro" ;; do not include deps.edn from user config + "-Spath" "-Sdeps" (str deps-map) + "-Sdeps-file" "") ;; we reset deps file so the local deps.edn isn't used + args (if force (cons "-Sforce" args) args) + args (concat args [(str "-A:" (str/join ":" (cons ":org.babashka/defaults" aliases)))]) + cp (with-out-str (binding [deps/*env* env + deps/*extra-env* extra-env] + (apply deps/-main args))) + cp (str/trim cp) + cp (str/replace cp (re-pattern (str cp/path-sep "+$")) "")] + (cp/add-classpath cp)))))))) (def deps-namespace {'add-deps (sci/copy-var add-deps dns) diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index e585ece4..05942116 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -5,6 +5,7 @@ [babashka.impl.common :as common] [babashka.main :as main] [babashka.test-utils :as test-utils] + [borkdude.deps] [clojure.edn :as edn] [clojure.string :as str] [clojure.test :as test :refer [deftest is testing]])) @@ -362,3 +363,11 @@ (is (= 1 (count entries))) (is (= (fs/parent config) (fs/parent entry))) (is (str/ends-with? entry "src")))))) + +(deftest without-deps-test + (when-not test-utils/native? + (with-redefs [borkdude.deps/-main (fn [& _] + (throw (ex-info "This ain't allowed!" {})))] + (testing "bb.edn without :deps should not require deps.clj" + (test-utils/with-config '{:tasks {a 1}} + (bb "-e" "(+ 1 2 3)"))))))