9696 (.printStackTrace e *err*))))
9797 (recur buf)))))
9898
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+
99111(defn setup
100112 ([repl-env] (setup repl-env nil ))
101113 ([repl-env opts]
106118 (string/replace (slurp (io/resource " cljs/repl/node_repl.js" ))
107119 " var PORT = 5001;"
108120 (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))
114122 _ (do (.start (Thread. (bound-fn [] (pipe proc (.getInputStream proc) *out*))))
115123 (.start (Thread. (bound-fn [] (pipe proc (.getErrorStream proc) *err*)))))
116124 env (ana/empty-env )
189197 (js/CLOSURE_IMPORT_SCRIPT
190198 (aget (.. js/goog -dependencies_ -nameToPath) name))))))))))
191199
192- (defrecord NodeEnv [host port socket proc]
200+ (defrecord NodeEnv [host port path socket proc]
193201 repl /IReplEnvOptions
194202 (-repl-options [this]
195203 {:output-dir " .cljs_node_repl"
209217 (close-socket @socket)))
210218
211219(defn repl-env* [options]
212- (let [{:keys [host port debug-port]}
220+ (let [{:keys [host port path debug-port]}
213221 (merge
214222 {:host " localhost"
215223 :port (+ 49000 (rand-int 10000 ))}
216224 options)]
217- (assoc (NodeEnv. host port (atom nil ) (atom nil ))
225+ (assoc (NodeEnv. host port path (atom nil ) (atom nil ))
218226 :debug-port debug-port)))
219227
220228(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)."
222231 [& {:as options}]
223232 (repl-env* options))
224233
225234(defn -main []
226- (repl/repl (repl-env )))
235+ (repl/repl (repl-env )))
0 commit comments