diff --git a/CHANGELOG.md b/CHANGELOG.md index 889a5eb..ffe279f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) ;;=> #` + ## 1.3.205 (2025-12-19) - [#395](https://github.com/babashka/nbb/issues/395): fix `vim-fireplace` infinite loop on nREPL session close. diff --git a/deps.edn b/deps.edn index 7aacfb9..96ba00c 100644 --- a/deps.edn +++ b/deps.edn @@ -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"} @@ -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"} diff --git a/package.json b/package.json index 28711f6..f066a57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nbb", - "version": "1.3.205", + "version": "1.4.205", "type": "module", "main": "index.mjs", "bin": { diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 8daba21..6d89cf7 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -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 diff --git a/src/nbb/impl/nrepl_server.cljs b/src/nbb/impl/nrepl_server.cljs index c24d98f..621b5e7 100644 --- a/src/nbb/impl/nrepl_server.cljs +++ b/src/nbb/impl/nrepl_server.cljs @@ -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 "#") + "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)) @@ -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))))] diff --git a/src/nbb/impl/repl.cljs b/src/nbb/impl/repl.cljs index cdf91f1..b9a96dd 100644 --- a/src/nbb/impl/repl.cljs +++ b/src/nbb/impl/repl.cljs @@ -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 "#")) + wrapper)) + (do (prn v) + wrapper)))))} _ (.createContext vm ctx)] (.runInContext vm "f()" ctx #js {:displayErrors true @@ -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 "#\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)) diff --git a/test/nbb/test_test.cljs b/test/nbb/test_test.cljs index 9781123..d70be7f 100644 --- a/test/nbb/test_test.cljs +++ b/test/nbb/test_test.cljs @@ -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 "")] @@ -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 "")] @@ -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 "")] @@ -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 "