Fork me on GitHub
#beginners
<
2017-07-21
>
Oleh K.12:07:59

Hi guys! How can I rewrite this function with spawn instead of exec? I tried but got ENOENT errors

(defui build-configuration [this]
  [:button {:type "button"
            :style {:margin-left 15}}
   "Build"]
  :click #(do
            (when (:builder @state)
              (kill-process (:builder @state)))
            (let [builder (.exec child-process (str "cd " (:path @this)
                                                    (if (= (:build @this) "dev")
                                                      (str (if (= (:platform @this) "android")
                                                             " && adb reverse tcp:8081 tcp:8081 && adb reverse tcp:3449 tcp:3449"
                                                             "")
                                                           " && re-natal use-" (:platform @this) "-device " (:device @this)
                                                           " && re-natal use-figwheel && lein figwheel " (:platform @this))
                                                      " && lein prod-build")))]
              (-> (.-stdout builder)
                  (.on "data" (fn[data]
                                (println data))))
              (-> (.-stderr builder)
                  (.on "data" (fn[data]
                                (println data))))
              (swap! state assoc :builder builder))))

gonewest81816:07:32

One difference between exec and spawn is whether the process executes in a shell by default. In node it seems, exec defaults to running the command via bash, but spawn defaults to no shell. That could be a problem; for example your command runs multiple programs in series via &&, which is a shell construct.

ajpierce21:07:50

Hi friends, I'm having trouble getting React to play nicely in figwheel with the latest version of clojurescript I'm trying to use the new functionality described in https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules Here's what I've done so far: + Checked out the latest version of Clojureuscript + Run script/build + BUILD SUCCESS for 1.9.820 + lein new figwheel example + Edit project.clj with the following: - Update org.clojure/clojurescript "1.9.820" - Update lein-figwheel "0.5.11" (also sidecar to match) - Update lein-cljsbuild "1.1.6" - Update the cljsbuild compiler options to include :npm-deps {:react "15.6.1" :react-dom "15.6.1"} + Change the default core.cljs to match the simple example in the news post above + Start a REPL (so VIM can connect to it) + lein figwheel in another shell The page renders the default Figwheel template and gives me no CLJS errors, but React spits out a ton in the web console: Uncaught ReferenceError: process is not defined Is there some step that I've missed in order to get NPM deps to magically compile?

spinningtopsofdoom21:07:47

That sounds like figwheel or cljsbuild is not using the latest version of ClojureScript (`1.9.820`) . Try using excluding the ClojureScript dependecies.

spinningtopsofdoom21:07:58

Like so [figwheel "0.5.11" :exclusions [org.clojure/clojurescript]]

ajpierce21:07:08

I've got the following now: [lein-figwheel "0.5.11" :exclusions [org.clojure/clojurescript]] [lein-cljsbuild "1.1.6" :exclusions [org.clojure/clojure org.clojure/clojurescript]] seems to compile, but I get the same error

ajpierce21:07:25

Even after running (clean-builds)

ajpierce21:07:07

(Really appreciate your help btw; thanks!)

spinningtopsofdoom21:07:06

Oh wait you're running this in the browser right?

ajpierce21:07:51

Yes sir, trying to view it through the default figwheel URL: http://localhost:3449/

ajpierce21:07:07

i have :optimizations :none though; could that have something to do with it?

spinningtopsofdoom21:07:09

You have to run the example in node since the react.dom/server is server side rendering

ajpierce21:07:29

what if i change it to react-dom instead?

spinningtopsofdoom21:07:50

That would might work. I'd try compiling the example exactly how it's shown in the blog post first

ajpierce21:07:26

Looks like I get errors in node because Figwheel is injecting some stuff under the assumption that the document variable exists. Thanks for the help!

spinningtopsofdoom21:07:43

You're welcome, I'd file an issue in the figwheel project and setup a sample repo showing the behavoir

ajpierce21:07:13

That's a great idea, thanks!

ajpierce22:07:33

FYI: I got it working with node by specifying :target :nodejs in the cljsbuild options (and then running it with node)

ajpierce22:07:45

Still need to figure out the whole web target business!