Fix #1544: :local/root in script-adjacent bb.edn should resolve relative to script

This commit is contained in:
Michiel Borkent 2023-04-23 12:27:31 +02:00
parent 39e4ea71e9
commit d2fece3f80
6 changed files with 30 additions and 17 deletions

View file

@ -11,6 +11,10 @@ A preview of the next release can be installed from
Berlin. Save the date and/or submit your babashka/clojure-related 20 minute talk Berlin. Save the date and/or submit your babashka/clojure-related 20 minute talk
in the CfP! in the CfP!
## Unreleased
- [#1544](https://github.com/babashka/babashka/issues/1544): `:local/root` in script-adjacent bb.edn should resolve relative to script
## 1.3.178 (2023-04-18) ## 1.3.178 (2023-04-18)
- Fix regression with [#1541](https://github.com/babashka/babashka/issues/1541) - Fix regression with [#1541](https://github.com/babashka/babashka/issues/1541)

View file

@ -1128,7 +1128,7 @@ Use bb run --help to show this help output.
config (:config global-opts) config (:config global-opts)
merge-deps (:merge-deps global-opts) merge-deps (:merge-deps global-opts)
abs-path #(-> % io/file .getAbsolutePath) abs-path #(-> % io/file .getAbsolutePath)
bb-edn-file (cond config (cond
config (when (fs/exists? config) (abs-path config)) config (when (fs/exists? config) (abs-path config))
jar (some-> [jar] cp/new-loader (cp/resource "META-INF/bb.edn") .toString) jar (some-> [jar] cp/new-loader (cp/resource "META-INF/bb.edn") .toString)
:else (if (and file (fs/exists? file)) :else (if (and file (fs/exists? file))
@ -1142,16 +1142,16 @@ Use bb run --help to show this help output.
;; default to local bb.edn ;; default to local bb.edn
(when (fs/exists? "bb.edn") (when (fs/exists? "bb.edn")
(abs-path "bb.edn")))) (abs-path "bb.edn"))))
bb-edn (when (or bb-edn-file merge-deps) bb-edn (when (or config merge-deps)
(when bb-edn-file (System/setProperty "babashka.config" bb-edn-file)) (when config (System/setProperty "babashka.config" config))
(let [raw-string (when bb-edn-file (slurp bb-edn-file)) (let [raw-string (when config (slurp config))
edn (when bb-edn-file (read-bb-edn raw-string)) edn (when config (read-bb-edn raw-string))
edn (if merge-deps edn (if merge-deps
(deps/merge-deps [edn (read-bb-edn merge-deps)]) (deps/merge-deps [edn (read-bb-edn merge-deps)])
edn) edn)
edn (assoc edn edn (assoc edn
:raw raw-string :raw raw-string
:file bb-edn-file) :file config)
edn (if-let [deps-root (or (:deps-root global-opts) edn (if-let [deps-root (or (:deps-root global-opts)
(some-> config fs/parent))] (some-> config fs/parent))]
(assoc edn :deps-root deps-root) (assoc edn :deps-root deps-root)

View file

@ -1 +1,2 @@
{:deps {medley/medley {:mvn/version "1.3.0"}}} {:deps {medley/medley {:mvn/version "1.3.0"}
my-local/dep {:local/root "../local-dep"}}}

View file

@ -1,5 +1,9 @@
#!/usr/bin/env bb #!/usr/bin/env bb
(require '[local-dep])
(assert (= :foo local-dep/local-dep-var))
(ns medley (ns medley
(:require [medley.core :as medley])) (:require [medley.core :as medley]))

View file

@ -0,0 +1 @@
{:paths ["src"]}

View file

@ -0,0 +1,3 @@
(ns local-dep)
(def local-dep-var :foo)