Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't drop :exclusions when running neil dep add or neil dep upgrade #190

Merged
merged 12 commits into from
Sep 26, 2023
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ See the [New Clojure project quickstart](https://blog.michielborkent.nl/new-cloj
- fix tests by referring to latest hiccup ([@teodorlu](https://github.com/teodorlu))
- [#180](https://github.com/babashka/neil/issues/180): `neil dep upgrade`: allow upgrading from an unstable version to the latest unstable version ([@teodorlu](https://github.com/teodorlu))
- [#180](https://github.com/babashka/neil/issues/180): `neil dep upgrade`: with `--unstable`, opt-into unstable library updates ([@teodorlu](https://github.com/teodorlu))
- [#183](https://github.com/babashka/neil/issues/183): Don't drop `:exclusions` when running `neil dep add` or `neil dep upgrade` ([@borkdude] and [@teodorlu])

[@borkdude]: https://github.com/borkdude
[@teodorlu]: https://github.com/teodorlu

## 0.1.60 (2023-03-22)

Expand Down
24 changes: 15 additions & 9 deletions neil
Original file line number Diff line number Diff line change
Expand Up @@ -1254,24 +1254,30 @@ chmod +x bin/kaocha
(not (contains? existing-aliases alias)))
[:aliases alias]
path)
;; force newline in
;; [:deps as] if no alias
;; [:aliases alias] if alias DNE
;; [:aliases alias :deps as] if :deps present
;; [:aliases alias :extra-deps as] if alias exists
edn-nodes (-> edn-nodes (r/assoc-in nl-path nil) str r/parse-string)
edn-nodes (if (r/get-in edn-nodes nl-path)
;; if this dep already exists, don't touch it.
;; We risk loosing :exclusions and other properties.
edn-nodes
;; otherwise, force newlines!
;; force newline in
;;
;; [:deps as] if no alias
;; [:aliases alias] if alias DNE
;; [:aliases alias :deps as] if :deps present
;; [:aliases alias :extra-deps as] if alias exists
(-> edn-nodes (r/assoc-in nl-path nil) str r/parse-string))
nodes (cond
missing? edn-nodes
mvn?
(r/assoc-in edn-nodes path
{:mvn/version version})
(r/assoc-in edn-nodes (conj path :mvn/version) version)
git-sha?
;; multiple steps to force newlines
(-> edn-nodes
(r/assoc-in (conj path :git/url) git-url)
str
r/parse-string
(r/assoc-in (conj path :git/sha) version))
(r/assoc-in (conj path :git/sha) version)
(r/update-in path r/dissoc :sha))

git-tag?
;; multiple steps to force newlines
Expand Down
24 changes: 15 additions & 9 deletions src/babashka/neil.clj
Original file line number Diff line number Diff line change
Expand Up @@ -396,24 +396,30 @@ chmod +x bin/kaocha
(not (contains? existing-aliases alias)))
[:aliases alias]
path)
;; force newline in
;; [:deps as] if no alias
;; [:aliases alias] if alias DNE
;; [:aliases alias :deps as] if :deps present
;; [:aliases alias :extra-deps as] if alias exists
edn-nodes (-> edn-nodes (r/assoc-in nl-path nil) str r/parse-string)
edn-nodes (if (r/get-in edn-nodes nl-path)
;; if this dep already exists, don't touch it.
;; We risk loosing :exclusions and other properties.
edn-nodes
;; otherwise, force newlines!
;; force newline in
;;
;; [:deps as] if no alias
;; [:aliases alias] if alias DNE
;; [:aliases alias :deps as] if :deps present
;; [:aliases alias :extra-deps as] if alias exists
(-> edn-nodes (r/assoc-in nl-path nil) str r/parse-string))
nodes (cond
missing? edn-nodes
mvn?
(r/assoc-in edn-nodes path
{:mvn/version version})
(r/assoc-in edn-nodes (conj path :mvn/version) version)
git-sha?
;; multiple steps to force newlines
(-> edn-nodes
(r/assoc-in (conj path :git/url) git-url)
str
r/parse-string
(r/assoc-in (conj path :git/sha) version))
(r/assoc-in (conj path :git/sha) version)
(r/update-in path r/dissoc :sha))

git-tag?
;; multiple steps to force newlines
Expand Down
17 changes: 15 additions & 2 deletions test/babashka/neil/dep_upgrade_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
(:require
[babashka.neil :as neil]
[babashka.neil.test-util :as test-util]
[clojure.test :as t :refer [deftest is testing are]]
[clojure.edn :as edn]
[clojure.set :as set]))
[clojure.set :as set]
[clojure.test :as t :refer [are deftest is testing]]))

(def test-file-path (str (test-util/test-file "deps.edn")))

Expand Down Expand Up @@ -232,3 +232,16 @@
stable "1.0.4"
stable "1.0.5"
unstable "2.0.0-RC1")))

(deftest upgrade-with-exclusions
(testing "Neil keeps :exclusions data when upgrading deps"
(spit test-file-path "
{:deps {
clojure2d/clojure2d {:mvn/version \"1.4.4\"
:exclusions [org.apache.xmlgraphics/batik-transcoder]}
}}")
(test-util/neil "dep dep upgrade" :deps-file test-file-path)
(let [clojure2d-exclusions (fn [] (:exclusions (get-dep-version 'clojure2d/clojure2d)))]
(is (clojure2d-exclusions) "Exclusions are present before upgrading")
(test-util/neil "dep upgrade" :deps-file test-file-path)
(is (clojure2d-exclusions) "Exclusions are present after upgrading"))))