From 573db8ea79ab1e347440fbb33ebbe112f9de9765 Mon Sep 17 00:00:00 2001 From: Odd A Date: Mon, 20 Jun 2022 12:48:31 +0200 Subject: [PATCH] Exposing babashka.nrepl.server-functions (#1297) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Odd Andreas Sørsæther Co-authored-by: Odd Andreas Sørsæther --- CHANGELOG.md | 5 +++++ src/babashka/impl/nrepl_server.clj | 16 ++++++++++++++++ src/babashka/main.clj | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 src/babashka/impl/nrepl_server.clj diff --git a/CHANGELOG.md b/CHANGELOG.md index b8ac8280..5a2d6143 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ For a list of breaking changes, check [here](#breaking-changes). A preview of the next release can be installed from [babashka-dev-builds](https://github.com/babashka/babashka-dev-builds). +## Unreleased + +- Expose `babashka.nrepl.server/start-server!`- and `stop-server!`-functions to support programmatically starting + an nrepl-server. `start-server!` is redefined to not require a sci-context as its first argument. + ## 0.8.156 (2022-06-08) - macOS aarch64 support. Upgrading via brew or the installer script should diff --git a/src/babashka/impl/nrepl_server.clj b/src/babashka/impl/nrepl_server.clj new file mode 100644 index 00000000..f20e239b --- /dev/null +++ b/src/babashka/impl/nrepl_server.clj @@ -0,0 +1,16 @@ +(ns babashka.impl.nrepl-server + {:no-doc true} + (:require [babashka.impl.common :as common] + [babashka.nrepl.server :refer [start-server! stop-server!]] + [sci.core :refer [create-ns new-var copy-var]])) + +(def nrepl-server-namespace + (let [ns-sci (create-ns 'babashka.nrepl.server)] + {'start-server! (new-var 'start-server! + (fn + ([] + (start-server! @common/ctx)) + ([opts] + (start-server! @common/ctx opts))) + {:ns ns-sci}) + 'stop-server! (copy-var stop-server! ns-sci)})) \ No newline at end of file diff --git a/src/babashka/main.clj b/src/babashka/main.clj index c68d7369..0aacc00b 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -32,6 +32,7 @@ [babashka.impl.error-handler :refer [error-handler]] [babashka.impl.features :as features] [babashka.impl.fs :refer [fs-namespace]] + [babashka.impl.nrepl-server :refer [nrepl-server-namespace]] [babashka.impl.pods :as pods] [babashka.impl.pprint :refer [pprint-namespace]] [babashka.impl.print-deps :as print-deps] @@ -354,6 +355,7 @@ Use bb run --help to show this help output. 'clojure.tools.cli tools-cli-namespace 'clojure.java.shell shell-namespace 'babashka.core bbcore/core-namespace + 'babashka.nrepl.server nrepl-server-namespace 'babashka.wait wait-namespace 'babashka.signal signal-ns 'clojure.java.io io-namespace