diff --git a/CHANGELOG.md b/CHANGELOG.md index 15b3bbd0..935c1b9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.170 + +- [#315](https://github.com/babashka/nbb/issues/315): support `:init` option in repl api + ## 1.2.169 (2023-02-25) - [#312](https://github.com/babashka/nbb/issues/312): same as [#311](https://github.com/babashka/nbb/issues/311) but with `$default` diff --git a/package.json b/package.json index de74bbbd..8a352688 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nbb", - "version": "1.2.169", + "version": "1.2.170", "type": "module", "main": "index.mjs", "bin": { diff --git a/src/nbb/impl/repl.cljs b/src/nbb/impl/repl.cljs index 1033b7a0..6086f2d8 100644 --- a/src/nbb/impl/repl.cljs +++ b/src/nbb/impl/repl.cljs @@ -187,7 +187,7 @@ (defn repl ([] (repl nil)) - ([_opts] + ([opts] (when tty (.setRawMode js/process.stdin true)) (let [eval-require (fn [ns-form] @@ -200,6 +200,7 @@ (-> (eval-require ns1) (.then (fn [] (eval-require ns2))) + (.then (:init opts identity)) (.then (fn [] (js/Promise. (fn [resolve] (input-loop nil resolve))))))))) diff --git a/test-scripts/repl-init-test/init-test.cljs b/test-scripts/repl-init-test/init-test.cljs new file mode 100644 index 00000000..a925f767 --- /dev/null +++ b/test-scripts/repl-init-test/init-test.cljs @@ -0,0 +1,4 @@ +(require '[nbb.repl :as repl]) + +(repl/repl + {:init #(apply require '[[promesa.core :as p]])}) diff --git a/test-scripts/repl-init-test/package.json b/test-scripts/repl-init-test/package.json new file mode 100644 index 00000000..8a4e4c0d --- /dev/null +++ b/test-scripts/repl-init-test/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "nbb": "file:../.." + } +}