96
96
(.printStackTrace e *err*))))
97
97
(recur buf)))))
98
98
99
+ (defn- build-process
100
+ [opts repl-env input-src]
101
+ (let [xs (cond-> [(get opts :node-command " node" )]
102
+ (:debug-port repl-env) (conj (str " --debug=" (:debug-port repl-env))))
103
+ proc (-> (ProcessBuilder. (into-array xs)) (.redirectInput input-src))]
104
+ (when-let [path-fs (:path repl-env)]
105
+ (.put (.environment proc)
106
+ " NODE_PATH"
107
+ (string/join File/pathSeparator
108
+ (map #(.getAbsolutePath (io/as-file %)) path-fs))))
109
+ proc))
110
+
99
111
(defn setup
100
112
([repl-env] (setup repl-env nil ))
101
113
([repl-env opts]
106
118
(string/replace (slurp (io/resource " cljs/repl/node_repl.js" ))
107
119
" var PORT = 5001;"
108
120
(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)
121
+ proc (.start (build-process opts repl-env of))
114
122
_ (do (.start (Thread. (bound-fn [] (pipe proc (.getInputStream proc) *out*))))
115
123
(.start (Thread. (bound-fn [] (pipe proc (.getErrorStream proc) *err*)))))
116
124
env (ana/empty-env )
189
197
(js/CLOSURE_IMPORT_SCRIPT
190
198
(aget (.. js/goog -dependencies_ -nameToPath) name))))))))))
191
199
192
- (defrecord NodeEnv [host port socket proc]
200
+ (defrecord NodeEnv [host port path socket proc]
193
201
repl /IReplEnvOptions
194
202
(-repl-options [this]
195
203
{:output-dir " .cljs_node_repl"
209
217
(close-socket @socket)))
210
218
211
219
(defn repl-env* [options]
212
- (let [{:keys [host port debug-port]}
220
+ (let [{:keys [host port path debug-port]}
213
221
(merge
214
222
{:host " localhost"
215
223
:port (+ 49000 (rand-int 10000 ))}
216
224
options)]
217
- (assoc (NodeEnv. host port (atom nil ) (atom nil ))
225
+ (assoc (NodeEnv. host port path (atom nil ) (atom nil ))
218
226
:debug-port debug-port)))
219
227
220
228
(defn repl-env
221
- " Construct a Node.js evalution environment. Can supply :host and :port."
229
+ " Construct a Node.js evalution environment. Can supply :host, :port
230
+ and :path (a vector used as the NODE_PATH)."
222
231
[& {:as options}]
223
232
(repl-env* options))
224
233
225
234
(defn -main []
226
- (repl/repl (repl-env )))
235
+ (repl/repl (repl-env )))
0 commit comments