Skip to content

Commit

Permalink
Fix babashka#318: fix :local/root deps in nbb.edn when not invoke…
Browse files Browse the repository at this point in the history
…d from current directory
  • Loading branch information
borkdude committed Apr 9, 2023
1 parent 2c19bc8 commit 5d390da
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ For a list of breaking changes, check [here](#breaking-changes).

[Nbb](https://github.com/babashka/nbb): Scripting in Clojure on Node.js using [SCI](https://github.com/babashka/sci)

## 1.2.173

- [#318](https://github.com/babashka/nbb/issues/318): fix `:local/root` deps in `nbb.edn` when not invoked from current directory

## 1.2.172

- [#95](https://github.com/babashka/nbb/issues/95): add `invoked-file`
Expand Down
4 changes: 4 additions & 0 deletions script/nbb_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@
(is (str/includes? o "TEST1"))
(is (str/includes? o "BAR"))))

(deftest local-root-test
(let [o (nbb* "test-scripts/local-root-test/run.cljs")]
(is (str/includes? o "{:a 1}"))))

(defn parse-opts [opts]
(let [[cmds opts] (split-with #(not (str/starts-with? % ":")) opts)]
(into {:cmds cmds}
Expand Down
13 changes: 8 additions & 5 deletions src/nbb/impl/deps.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(defn download-and-extract-deps!
"Given a map of dependencies and a path, downloads all dependencies to
'*nbb-path*/_deps/*hash-of-deps-map*/nbb-deps' and returns that full path."
[deps nbb-path]
[deps nbb-path config-dir]
(let [deps-hash (hash-deps deps)
deps-path (path/resolve nbb-path deps-hash)
deps-edn-path (path/resolve deps-path "deps.edn")
Expand All @@ -32,7 +32,10 @@
(fs/mkdirSync deps-path #js {:recursive true})
(fs/writeFileSync deps-edn-path (str {:deps deps}))
(*print-err-fn* "Downloading dependencies...")
(cproc/execSync (str bb " --config " deps-edn-path " uberjar " jar-path))
(cproc/execSync (str bb
" --config " deps-edn-path
" --deps-root " config-dir
" uberjar " jar-path))
(*print-err-fn* "Extracting dependencies...")
(fs/writeFileSync extract-script
(str "(fs/unzip "
Expand All @@ -50,6 +53,6 @@
(let [config-dir (get @opts :config-dir)
cache-path (path/resolve config-dir ".nbb" ".cache")]
(when-let [deps (get-in @opts [:config :deps])]
(-> deps
(download-and-extract-deps! cache-path)
(cp/add-classpath)))))
(->
(download-and-extract-deps! deps cache-path config-dir)
(cp/add-classpath)))))
1 change: 1 addition & 0 deletions test-scripts/local-root-test/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:paths ["src-nbb"]}
1 change: 1 addition & 0 deletions test-scripts/local-root-test/nbb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:deps {local-root/test {:local/root "."}}}
4 changes: 4 additions & 0 deletions test-scripts/local-root-test/run.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(require '[foo])

(foo/exec-fn {:a 1})

6 changes: 6 additions & 0 deletions test-scripts/local-root-test/src-nbb/foo.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns foo)

(defn exec-fn [m]
(prn m))


0 comments on commit 5d390da

Please sign in to comment.