Skip to content

Commit 139da19

Browse files
author
dnolen
committed
CLJS-1396: Allow starting Node.js with debug port set
1 parent e5b7234 commit 139da19

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

script/repl.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(require '[cljs.repl :as repl])
22
(require '[cljs.repl.node :as node])
3-
(repl/repl (node/repl-env))
3+
(repl/repl (node/repl-env :debug-port 5002))

src/main/clojure/cljs/repl/node.clj

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,28 @@
9999
(defn setup
100100
([repl-env] (setup repl-env nil))
101101
([repl-env opts]
102-
(let [output-dir (io/file (util/output-directory opts))
103-
_ (.mkdirs output-dir)
104-
of (io/file output-dir "node_repl.js")
105-
_ (spit of
106-
(string/replace (slurp (io/resource "cljs/repl/node_repl.js"))
107-
"var PORT = 5001;"
108-
(str "var PORT = " (:port repl-env) ";")))
109-
proc (-> (ProcessBuilder. (into-array [(get opts :node-command "node")]))
110-
(.redirectInput of)
111-
.start)
112-
_ (do (.start (Thread. (bound-fn [] (pipe proc (.getInputStream proc) *out*))))
113-
(.start (Thread. (bound-fn [] (pipe proc (.getErrorStream proc) *err*)))))
114-
env (ana/empty-env)
115-
core (io/resource "cljs/core.cljs")
102+
(let [output-dir (io/file (util/output-directory opts))
103+
_ (.mkdirs output-dir)
104+
of (io/file output-dir "node_repl.js")
105+
_ (spit of
106+
(string/replace (slurp (io/resource "cljs/repl/node_repl.js"))
107+
"var PORT = 5001;"
108+
(str "var PORT = " (:port repl-env) ";")))
109+
xs (cond-> [(get opts :node-command "node")]
110+
(:debug-port repl-env) (conj (str "--debug=" (:debug-port repl-env))))
111+
proc (-> (ProcessBuilder. (into-array xs))
112+
(.redirectInput of)
113+
.start)
114+
_ (do (.start (Thread. (bound-fn [] (pipe proc (.getInputStream proc) *out*))))
115+
(.start (Thread. (bound-fn [] (pipe proc (.getErrorStream proc) *err*)))))
116+
env (ana/empty-env)
117+
core (io/resource "cljs/core.cljs")
116118
;; represent paths as vectors so we can emit JS arrays, this is to
117119
;; paper over Windows issues with minimum hassle - David
118-
path (.getPath (.getCanonicalFile output-dir))
119-
[fc & cs] (rest (util/path-seq path)) ;; remove leading empty string
120-
root (.substring path 0 (+ (.indexOf path fc) (count fc)))
121-
root-path (vec (cons root cs))
120+
path (.getPath (.getCanonicalFile output-dir))
121+
[fc & cs] (rest (util/path-seq path)) ;; remove leading empty string
122+
root (.substring path 0 (+ (.indexOf path fc) (count fc)))
123+
root-path (vec (cons root cs))
122124
rewrite-path (conj root-path "goog")]
123125
(reset! (:proc repl-env) proc)
124126
(loop [r nil]
@@ -206,12 +208,13 @@
206208
(close-socket @socket)))
207209

208210
(defn repl-env* [options]
209-
(let [{:keys [host port]}
211+
(let [{:keys [host port debug-port]}
210212
(merge
211213
{:host "localhost"
212214
:port (+ 49000 (rand-int 10000))}
213215
options)]
214-
(NodeEnv. host port (atom nil) (atom nil))))
216+
(assoc (NodeEnv. host port (atom nil) (atom nil))
217+
:debug-port debug-port)))
215218

216219
(defn repl-env
217220
"Construct a Node.js evalution environment. Can supply :host and :port."

0 commit comments

Comments
 (0)