From a323d6acb1606bf67e70d55a663584ba2a4bd63e Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 7 Mar 2023 14:58:32 -0500 Subject: [PATCH 1/4] Support :init option in repl api --- src/nbb/impl/repl.cljs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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))))))))) From c24818a47e5c6a775dd5643242c7f96051e4bc6f Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 7 Mar 2023 15:02:41 -0500 Subject: [PATCH 2/4] Updated changelog + bumped package.json --- CHANGELOG.md | 4 ++++ package.json | 62 ++++++++++++++++++++++++++-------------------------- 2 files changed, 35 insertions(+), 31 deletions(-) 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..efb2ad16 100644 --- a/package.json +++ b/package.json @@ -1,33 +1,33 @@ { - "name": "nbb", - "version": "1.2.169", - "type": "module", - "main": "index.mjs", - "bin": { - "nbb": "cli.js", - "nbbun": "nbbun.js" - }, - "description": "Babashka-like tool for Node.js.", - "dependencies": { - "import-meta-resolve": "^2.1.0" - }, - "devDependencies": { - "ink": "^3.0.9", - "moment": "^2.29.4", - "nbb": ".", - "react": "^17.0.2", - "react-dom": "^17.0.2", - "shadow-cljs": "^2.15.2", - "source-map-support": "^0.5.19" - }, - "repository": { - "type": "git", - "url": "https://github.com/babashka/nbb" - }, - "license": "EPL-1.0", - "files": [ - "README.md", - "img", - "lib" - ] + "name": "nbb", + "version": "1.2.170", + "type": "module", + "main": "index.mjs", + "bin": { + "nbb": "cli.js", + "nbbun": "nbbun.js" + }, + "description": "Babashka-like tool for Node.js.", + "dependencies": { + "import-meta-resolve": "^2.1.0" + }, + "devDependencies": { + "ink": "^3.0.9", + "moment": "^2.29.4", + "nbb": ".", + "react": "^17.0.2", + "react-dom": "^17.0.2", + "shadow-cljs": "^2.15.2", + "source-map-support": "^0.5.19" + }, + "repository": { + "type": "git", + "url": "https://github.com/babashka/nbb" + }, + "license": "EPL-1.0", + "files": [ + "README.md", + "img", + "lib" + ] } From 2f8d1cde3a3178a018fb0ba428f4a04b37b51d30 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 7 Mar 2023 15:05:13 -0500 Subject: [PATCH 3/4] Revert package.json formatting --- package.json | 62 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index efb2ad16..8a352688 100644 --- a/package.json +++ b/package.json @@ -1,33 +1,33 @@ { - "name": "nbb", - "version": "1.2.170", - "type": "module", - "main": "index.mjs", - "bin": { - "nbb": "cli.js", - "nbbun": "nbbun.js" - }, - "description": "Babashka-like tool for Node.js.", - "dependencies": { - "import-meta-resolve": "^2.1.0" - }, - "devDependencies": { - "ink": "^3.0.9", - "moment": "^2.29.4", - "nbb": ".", - "react": "^17.0.2", - "react-dom": "^17.0.2", - "shadow-cljs": "^2.15.2", - "source-map-support": "^0.5.19" - }, - "repository": { - "type": "git", - "url": "https://github.com/babashka/nbb" - }, - "license": "EPL-1.0", - "files": [ - "README.md", - "img", - "lib" - ] + "name": "nbb", + "version": "1.2.170", + "type": "module", + "main": "index.mjs", + "bin": { + "nbb": "cli.js", + "nbbun": "nbbun.js" + }, + "description": "Babashka-like tool for Node.js.", + "dependencies": { + "import-meta-resolve": "^2.1.0" + }, + "devDependencies": { + "ink": "^3.0.9", + "moment": "^2.29.4", + "nbb": ".", + "react": "^17.0.2", + "react-dom": "^17.0.2", + "shadow-cljs": "^2.15.2", + "source-map-support": "^0.5.19" + }, + "repository": { + "type": "git", + "url": "https://github.com/babashka/nbb" + }, + "license": "EPL-1.0", + "files": [ + "README.md", + "img", + "lib" + ] } From 648b9b5179e88c2b49514c964d50dbf1f46a23ea Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 7 Mar 2023 15:18:47 -0500 Subject: [PATCH 4/4] Created test script for repl init --- test-scripts/repl-init-test/init-test.cljs | 4 ++++ test-scripts/repl-init-test/package.json | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 test-scripts/repl-init-test/init-test.cljs create mode 100644 test-scripts/repl-init-test/package.json 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:../.." + } +}