Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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.4.206 (2026-02-07)

- Support async/await. See [docs](https://github.com/babashka/sci/blob/master/doc/async-await.md) for syntax.
- Print promise result value in REPL/nREPL: `(js/Promise.resolve 1) ;;=> #<Promise 1>`

## 1.3.205 (2025-12-19)

- [#395](https://github.com/babashka/nbb/issues/395): fix `vim-fireplace` infinite loop on nREPL session close.
Expand Down
6 changes: 3 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{:paths ["src"]
:aliases {:test {:extra-paths ["test"]}}
:deps {thheller/shadow-cljs {:mvn/version "3.3.4"}
:deps {thheller/shadow-cljs {:mvn/version "3.3.5"}
#_#_org.clojure/clojurescript {:mvn/version "1.11.51"}
;; reagent/reagent {:mvn/version "1.0.0"}
cljsjs/react {:mvn/version "18.2.0-1"}
Expand All @@ -14,8 +14,8 @@
cljs-bean/cljs-bean {:mvn/version "1.9.0"}
org.babashka/sci
#_{:local/root "../babashka/sci"}
#_{:mvn/version "0.9.44"}
{:git/url "https://github.com/babashka/sci"
{:mvn/version "0.12.51"}
#_{:git/url "https://github.com/babashka/sci"
:git/sha "33995afb71d58dae270f1a8035e21196ea2157f0"}
org.clojure/tools.cli {:mvn/version "1.0.214"}
com.cognitect/transit-cljs {:mvn/version "0.8.280"}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nbb",
"version": "1.3.205",
"version": "1.4.205",
"type": "module",
"main": "index.mjs",
"bin": {
Expand Down
1 change: 1 addition & 0 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:target :esm
:runtime :node
:output-dir "lib"
:devtools {:enabled false}
:modules
{:nbb_core {:init-fn nbb.core/init}
:nbb_goog_string {:init-fn nbb.impl.gstring/init
Expand Down
18 changes: 11 additions & 7 deletions src/nbb/impl/nrepl_server.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@
(sci/alter-var-root sci/*3 (constantly @sci/*2))
(sci/alter-var-root sci/*2 (constantly @sci/*1))
(sci/alter-var-root sci/*1 (constantly v))
(let [v (format-value (:nrepl.middleware.print/print request)
(:nrepl.middleware.print/options request)
v)]
(send-fn request {"value" v
"ns" (str sci-ns)}))))
(if (instance? js/Promise v)
(.then v (fn [resolved]
(send-fn request {"value" (str "#<Promise " (pr-str resolved) ">")
"ns" (str sci-ns)})))
(let [v (format-value (:nrepl.middleware.print/print request)
(:nrepl.middleware.print/options request)
v)]
(send-fn request {"value" v
"ns" (str sci-ns)})))))

(defn handle-error [send-fn request e]
(sci/alter-var-root sci/*e (constantly e))
Expand All @@ -126,8 +130,8 @@
(.then v
(fn [v]
;; (prn :v v)
(send-value request send-fn v)
(loop-fn v))))))
(-> (js/Promise.resolve (send-value request send-fn v))
(.then #(loop-fn v))))))))
(catch :default e
(handle-error send-fn request e)
(loop-fn nil))))]
Expand Down
19 changes: 13 additions & 6 deletions src/nbb/impl/repl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@
(let [ctx #js {:f (if socket (fn [] wrapper)
(fn []
(let [v (first wrapper)]
(prn v)
wrapper)))}
(if (instance? js/Promise v)
(.then v (fn [resolved]
(println (str "#<Promise " (pr-str resolved) ">"))
wrapper))
(do (prn v)
wrapper)))))}
_ (.createContext vm ctx)]
(.runInContext vm "f()" ctx
#js {:displayErrors true
Expand Down Expand Up @@ -121,10 +125,13 @@
(sci/alter-var-root sci/*3 (constantly @sci/*2))
(sci/alter-var-root sci/*2 (constantly @sci/*1))
(sci/alter-var-root sci/*1 (constantly val))
(when socket
(.write socket (prn-str val))
#_(prn val))
(continue rl socket))))
(if (and socket (instance? js/Promise val))
(.then val (fn [resolved]
(.write socket (str "#<Promise " (pr-str resolved) ">\n"))
(continue rl socket)))
(do (when socket
(.write socket (prn-str val)))
(continue rl socket))))))
(.catch (fn [err]
(prn (str err))
(sci/alter-var-root sci/*e (constantly err))
Expand Down
12 changes: 8 additions & 4 deletions test/nbb/test_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
(defmethod t/report [:cljs.test/default :end-run-tests] [m])
(t/deftest foo (t/is (= 1 2))) (t/run-tests 'foo0)"))
(.then (fn [_]
(is (str/includes? @output "expected: (= 1 2) actual: (not (= 1 2))")))))))
(is (str/includes? @output "expected: (= 1 2)"))
(is (str/includes? @output "actual: (not (= 1 2))")))))))

(deftest-async cljs-test-test
(let [output (atom "")]
Expand All @@ -29,7 +30,8 @@
(t/deftest foo (t/is (= 1 2)))
(cljs.test/deftest bar (t/is (= 1 2))) (t/run-tests 'foo01)"))
(.then (fn [_]
(is (str/includes? @output "expected: (= 1 2) actual: (not (= 1 2))")))))))
(is (str/includes? @output "expected: (= 1 2)"))
(is (str/includes? @output "actual: (not (= 1 2))")))))))

(deftest-async refer-macros-test
(let [output (atom "")]
Expand All @@ -41,7 +43,8 @@
(defmethod t/report [:cljs.test/default :end-run-tests] [m])
(deftest foo (is (= 1 2))) (t/run-tests 'foo02)"))
(.then (fn [_]
(is (str/includes? @output "expected: (= 1 2) actual: (not (= 1 2))")))))))
(is (str/includes? @output "expected: (= 1 2)"))
(is (str/includes? @output "actual: (not (= 1 2))")))))))

(deftest-async are-test
(let [output (atom "")]
Expand All @@ -54,7 +57,8 @@
(defmethod t/report [:cljs.test/default :end-run-tests] [m])
(t/deftest foo (t/are [x] (= x 2) 1 2 3)) (t/run-tests 'foo-are)")
(.then (fn [_]
(is (str/includes? @output "expected: (= 3 2) actual: (not (= 3 2))"))))
(is (str/includes? @output "expected: (= 3 2)"))
(is (str/includes? @output "actual: (not (= 3 2))"))))
(.then (fn [_]
(reset! output "")
(nbb/load-string "
Expand Down