|
99 | 99 | (defn setup
|
100 | 100 | ([repl-env] (setup repl-env nil))
|
101 | 101 | ([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") |
116 | 118 | ;; represent paths as vectors so we can emit JS arrays, this is to
|
117 | 119 | ;; 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)) |
122 | 124 | rewrite-path (conj root-path "goog")]
|
123 | 125 | (reset! (:proc repl-env) proc)
|
124 | 126 | (loop [r nil]
|
|
206 | 208 | (close-socket @socket)))
|
207 | 209 |
|
208 | 210 | (defn repl-env* [options]
|
209 |
| - (let [{:keys [host port]} |
| 211 | + (let [{:keys [host port debug-port]} |
210 | 212 | (merge
|
211 | 213 | {:host "localhost"
|
212 | 214 | :port (+ 49000 (rand-int 10000))}
|
213 | 215 | options)]
|
214 |
| - (NodeEnv. host port (atom nil) (atom nil)))) |
| 216 | + (assoc (NodeEnv. host port (atom nil) (atom nil)) |
| 217 | + :debug-port debug-port))) |
215 | 218 |
|
216 | 219 | (defn repl-env
|
217 | 220 | "Construct a Node.js evalution environment. Can supply :host and :port."
|
|
0 commit comments