Skip to content

Commit c435427

Browse files
author
dnolen
committed
add some error handling
1 parent be15b57 commit c435427

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/main/clojure/cljs/build/api.clj

+21-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
[cljs.closure :as closure]
2323
[cljs.js-deps :as js-deps])
2424
(:import [java.io File]
25-
[java.lang ProcessBuilder Process]))
25+
[java.lang ProcessBuilder Process]
26+
(java.util.concurrent TimeUnit)))
2627

2728
;; =============================================================================
2829
;; Useful Utilities
@@ -241,23 +242,27 @@
241242
that the module-deps & JSONStream NPM packages are either locally or
242243
globally installed."
243244
[{:keys [file]}]
244-
(let [code (string/replace
245-
(slurp (io/resource "cljs/module_deps.js"))
246-
"JS_FILE" file)
247-
proc (-> (ProcessBuilder.
248-
(into-array
249-
["node" "--eval" (str code)]))
250-
.start)
251-
err (.waitFor proc)]
252-
(if (zero? err)
245+
(let [code (string/replace
246+
(slurp (io/resource "cljs/module_deps.js"))
247+
"JS_FILE" file)
248+
proc (-> (ProcessBuilder.
249+
(into-array
250+
["node" "--eval" (str code)]))
251+
.start)
252+
timeout? (.waitFor proc 10 TimeUnit/SECONDS)]
253+
(when timeout?
254+
(println "Node.js process timed out"))
255+
(if (and (not (.isAlive proc))
256+
(zero? (.exitValue proc)))
253257
(let [is (.getInputStream proc)]
254258
(into []
255-
(map (fn [{:strs [file]}] file
256-
{:file file :module-type :commonjs}))
257-
(butlast (json/read-str (slurp is)))))
258-
(let [es (.getErrorStream proc)]
259-
(binding [*out* *err*]
260-
(println (slurp es)))
259+
(map (fn [{:strs [file]}] file
260+
{:file file :module-type :commonjs}))
261+
(butlast (json/read-str (slurp is)))))
262+
(do
263+
(when-not (.isAlive proc)
264+
(let [es (.getErrorStream proc)]
265+
(println (slurp es))))
261266
[]))))
262267

263268
(comment

0 commit comments

Comments
 (0)