|
22 | 22 | [cljs.closure :as closure]
|
23 | 23 | [cljs.js-deps :as js-deps])
|
24 | 24 | (:import [java.io File]
|
25 |
| - [java.lang ProcessBuilder Process])) |
| 25 | + [java.lang ProcessBuilder Process] |
| 26 | + (java.util.concurrent TimeUnit))) |
26 | 27 |
|
27 | 28 | ;; =============================================================================
|
28 | 29 | ;; Useful Utilities
|
|
241 | 242 | that the module-deps & JSONStream NPM packages are either locally or
|
242 | 243 | globally installed."
|
243 | 244 | [{: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))) |
253 | 257 | (let [is (.getInputStream proc)]
|
254 | 258 | (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)))) |
261 | 266 | []))))
|
262 | 267 |
|
263 | 268 | (comment
|
|
0 commit comments