figwheel-main

figwheel-main http://figwheel.org
EmmanuelOga 2020-02-05T03:44:46.058Z

this is a bit confusing: https://search.maven.org/search?q=figwheel (returns empty results)

EmmanuelOga 2020-02-05T10:47:11.068Z

hey again, I'm having a hard time wrapping my head around connecting to both a plain clojure nrepl and a figwheel clojurescript repl. I'm using a ring handler as described here: https://figwheel.org/docs/ring-handler.html to write some clojure backend / API. I'm using Cider. I'd like to open a cider repl to the java process, in the same environment that is running the ring middleware, and another to the figwheel clojurescript repl. I finally "succeeded" through this clumsy procedure: 1. Clone https://github.com/dimovich/deps-cider-cljs-reagent 2. Open core.cljs 3. cider-jack-in-cljs, opens a cljs repl, it just works, yay! 4. Ok, now I need the clojure repl. So I found I could do this: :cljs/quit on the cljs repl, now the cljs repl is dead! 5. cider-jack-in-clj, finds the clojure repl started before. Connects! 6. Now I go back to the previous repl and I run: (figwheel.main.api/cljs-repl "dev")The cljs repl is alive again! To be honest I've spent the last whole week trying to open clj+cljs repls from cider... I consider this my break through haha. But I'm sure there must be an easier way! Would appreciate some directions! (I've read the docs a few times but couldn't find specifics of using cider-jack-in-clj&cljs, nor in figwheel-main nor http://cider.mx sites)

EmmanuelOga 2020-02-06T08:20:40.088700Z

ah, good point, will do 🙂

aisamu 2020-02-06T12:18:15.088900Z

> how do you do that with figwheel? Just like you'd do in a regular, non-figwheel project. Figwheel doesn't come with nrepl baked-in:

$ clj -Acider -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.6.0"}}}' -m nrepl.cmdline
...
nREPL server started on port 49712 on host localhost - <nrepl://localhost:49712>
...
[Figwheel] Starting Server at <http://localhost:9500>
[Figwheel] Starting REPL
Then we can connect to the nrepl with a client. (cider is a client, but so is this other command line tool)
$ clojure -Sdeps '{:deps {reply {:mvn/version "0.4.3"}}}' -m reply.main --attach localhost:49712
REPL-y 0.4.3, nREPL 0.6.0
...
user=&gt; (require '[figwheel.main.api :as fig])
nil
user=&gt; (fig/start "dev")
Prompt will show when REPL connects to evaluation environment (i.e. a REPL hosting webpage)
Figwheel Main Controls:
          (figwheel.main/stop-builds id ...)  ;; stops Figwheel autobuilder for ids
          ...
user=&gt; 
(i.e. where we were with `-A:figwheel` or `clojure -m figwheel.main -b dev -r`, but using nrepl)
Note that it'll also complain of other missing pieces (e.g. piggieback middleware for CLJS support). Either you add them to the project, to your user profile, or use the jack-in-* commands (which add those for you)

EmmanuelOga 2020-02-06T18:52:41.089100Z

thx! took me a while but I figured out cider jack in was running the repl cmd line

EmmanuelOga 2020-02-06T18:52:47.089300Z

clojure -A:cider -Sdeps '{:deps {nrepl {:mvn/version ""0.6.0""} cider/piggieback {:mvn/version ""0.4.2""} cider/cider-nrepl {:mvn/version ""0.23.0""}}}' -m nrepl.cmdline --middleware '[""cider.nrepl/cider-middleware"", ""cider.piggieback/wrap-cljs-repl""]'

👍 1
EmmanuelOga 2020-02-05T10:50:00.068500Z

Another attempt: I figured I could start an nREPL server with known port for the java REPL and then call figwheel's API to start the "dev" build in the background. I thought it would create an additional nREPL server for the CLJS side, so I could print the repl-env and get a different port to cider-jack-in-cljs with. I WAS WRONG 😛

pyrmont 2020-02-05T12:50:18.072200Z

I'm not saying this isn't possible (it sounds like you got it to work in a fashion) but I'm struggling to really imagine it being very ergonomic. I don't quite get how the editor would know what REPL to send code to for evaluation, for example.

aisamu 2020-02-05T13:08:11.073Z

There might be something going on with your setup. Locally, just cider-jack-in-clj&amp;cljs works out of the box on the repo you've provided! (Gives me one clj and one cljs repl, and evaluating code works everywhere) I'd double check that the CIDER versions are up to date (on your user's profile and also on your emacs). It is ergonomic when it works - emacs knows which REPL to use by the file extension. You can also arbitrarily associate a buffer with a specific repl via sessman commands. (But I must confess that I'd never seen that command work before 😂. I usually start the repls from the command line and just connect with Cider)

👍 1
2020-02-05T17:39:38.073900Z

Hi, I am having trouble getting a ClojureScript REPL up and running with Figwheel Main.

2020-02-05T17:39:50.074400Z

Here is a log of my interaction with the system.

2020-02-05T17:40:03.074700Z

$ lein repl
2020-02-05 17:31:01.428:INFO::main: Logging initialized @4623ms to org.eclipse.jetty.util.log.StdErrLog
"To start a cljs repl call `(figwheel/cljs-repl \"app\")`"
"where `app` is the build you want to attach to."
nREPL server started on port 3888 on host 0.0.0.0 - <nrepl://0.0.0.0:3888>
REPL-y 0.4.3, nREPL 0.6.0
Clojure 1.10.1
OpenJDK 64-Bit Server VM 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=&gt; (use 'figwheel-sidecar.repl-api)
(use 'figwheel-sidecar.repl-api
nil
user=&gt; (start-figwheel!)
(start-figwheel!
Figwheel: Starting server at <http://0.0.0.0:3449>
Figwheel: Watching build - admin
Compiling build :admin to "resources/public/js/admin.js" from ["src/cljs" "src/cljc" "test/cljs"]...
WARNING: cljs.core/&lt;=, all arguments must be numbers, got [#{nil js/Number} number] instead at line 1193 resources/public/js/admin/clojure/test/check/generators.cljc
WARNING: cljs.core/&lt;=, all arguments must be numbers, got [#{nil js/Number} number] instead at line 1193 resources/public/js/admin/clojure/test/check/generators.cljc
WARNING: Cannot resolve property getElementById for inferred type js/HTMLDocument in expression (. js/document getElementById "app") at line 14 src/cljs/com/openmarkets/exchange/ui/shopping/core.cljs
Successfully compiled build :admin to "resources/public/js/admin.js" in 36.858 seconds.
nil
user=&gt; (figwheel-sidecar.repl-api/print-config)
(figwheel-sidecar.repl-api/print-config
{:id "admin",
 :source-paths ["src/cljs" "src/cljc" "test/cljs"],
 :figwheel {:build-id "admin"},
 :watch-paths ["src/cljs" "src/cljc" "test/cljs"],
 :compile-paths ["src/cljs" "src/cljc" "test/cljs"],
 :build-options
 {:infer-externs true,
  :output-dir "resources/public/js/admin",
  :optimizations :none,
  :output-to "resources/public/js/admin.js",
  :source-map-timestamp true,
  :asset-path "<http://exchange-cljs.test/cljs-out/admin>",
  :devcards true,
  :external-config {:re-frisk {:enabled true}},
  :main com.openmarkets.exchange.ui.admin.core}}
{:id "shared",
 :source-paths ["src/cljs" "src/cljc" "test/cljc"],
 :figwheel {:build-id "shared"},
 :watch-paths ["src/cljs" "src/cljc" "test/cljc"],
 :compile-paths ["src/cljs" "src/cljc" "test/cljc"],
 :build-options
 {:main com.openmarkets.exchange.ui.shared.panel-channels.views,
  :asset-path "<http://exchange-cljs.test/cljs-out/shared/>",
  :output-to "resources/public/js/shared.js",
  :output-dir "resources/public/js/shared",
  :external-config {:re-frisk {:enabled true}},
  :infer-externs true,
  :source-map-timestamp true,
  :optimizations :none}}
{:id "shopping",
 :source-paths ["src/cljs" "src/cljc" "test/cljc"],
 :figwheel {:build-id "shopping"},
 :watch-paths ["src/cljs" "src/cljc" "test/cljc"],
 :compile-paths ["src/cljs" "src/cljc" "test/cljc"],
 :build-options
 {:main com.openmarkets.exchange.ui.shopping.core,
  :asset-path "<http://exchange-cljs.test/cljs-out/shopping/>",
  :output-to "resources/public/js/shopping.js",
  :output-dir "resources/public/js/shopping",
  :devcards true,
  :infer-externs true,
  :source-map-timestamp true,
  :optimizations :none}}
nil
user=&gt; (cljs-repl)
(cljs-repl
Launching ClojureScript REPL for build: admin
Figwheel Controls:
          (stop-autobuild)                ;; stops Figwheel autobuilder
          (start-autobuild id ...)        ;; starts autobuilder focused on optional ids
          (switch-to-build id ...)        ;; switches autobuilder to different build
          (reset-autobuild)               ;; stops, cleans, and starts autobuilder
          (reload-config)                 ;; reloads build config and resets autobuild
          (build-once id ...)             ;; builds source one time
          (clean-builds id ..)            ;; deletes compiled cljs target files
          (print-config id ...)           ;; prints out build configurations
          (fig-status)                    ;; displays current state of system
          (figwheel.client/set-autoload false)    ;; will turn autoloading off
          (figwheel.client/set-repl-pprint false) ;; will turn pretty printing off
  Switch REPL build focus:
          :cljs/quit                      ;; allows you to switch REPL to another build
    Docs: (doc function-name-here)
    Exit: :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Prompt will show when Figwheel connects to your application

2020-02-05T17:40:14.074900Z

It just sits there at that point

2020-02-05T17:40:38.075400Z

My further actions: > <Browse to http://0.0.0.0:3449/> > <Notice error: ClojureScript could not load :main, did you forget to specify :asset-path?>

2020-02-05T17:42:20.075900Z

:asset-path is there in the configs, but maybe in the wrong place?

practicalli-john 2020-02-05T17:58:16.076800Z

At the top of that output it says to run (figwheel/cljs-repl \"app\") in the repl, where app I assume is admin in your case. Did you try that?

2020-02-05T18:15:53.077200Z

It leads to the same result

2020-02-05T18:15:59.077500Z

Sitting there waiting for Figwheel to connect

2020-02-05T18:26:49.078400Z

I've started it a different way now, inside of CIDER -- so that I can get all the dependencies

2020-02-05T18:26:56.078800Z

I don't see the same error in the browser

2020-02-05T18:27:09.079200Z

In fact, I see this: > [http://goog.net.WebSocket] WebSocket opened on <ws://exchange-cljs.test:9500/figwheel-connect?fwprocess=73e2bb&fwbuild=admin&fwsid=c9b0b578-b41a-4b36-bf6d-8e47d1fbd6d2&fwsname=Shelia>

2020-02-05T18:27:23.079600Z

So that suggests to me that the application is indeed connecting to Figwheel

2020-02-05T18:27:46.080Z

But still on the REPL I have the same "Prompt will show when Figwheel connects to your application" message

2020-02-05T18:29:19.080400Z

Maybe the issue is that Figwheel has already started elsewhere, so my REPL version is superfluous

2020-02-05T18:29:50.080900Z

Is there a way to connect from user&gt; to an existing Figwheel, rather than run (start-figwheel!)?

2020-02-05T18:33:11.081200Z

Aha, I have at least extracted information about it:

2020-02-05T18:33:31.081500Z

user&gt; (figwheel/repl-env "admin")
{:output-dir "target/public/cljs-out/admin",
 :bound-printer #&lt;Atom@68b97064: nil&gt;,
 :ring-server-options {:host "0.0.0.0", :port 9500},
 :broadcast false,
 :out-print-fn nil,
 :server
 #&lt;Atom@4256e519: 
   #object[org.eclipse.jetty.server.Server 0x623ea2af "Server@623ea2af{STARTED}[9.4.12.v20180830]"]&gt;,
 :open-url-fn #function[figwheel.main.api/repl-env/fn--8708],
 :port 9500,
 :output-to "target/public/cljs-out/admin-main.js",
 :focus-session-name #&lt;Atom@437e775a: nil&gt;,
 :prevent-server-tear-down true,
 :err-print-fn nil,
 :node-proc #&lt;Atom@dc17c43: nil&gt;,
 :ring-stack-options
 #:figwheel.server.ring{:dev
                        #:figwheel.server.ring{:system-app-handler
                                               #function[figwheel.main/add-default-system-app-handler/fn--8485/fn--8486]}},
 :print-to-output-streams true,
 :printing-listener
 #&lt;Atom@65caaa34: #function[clojure.core/bound-fn*/fn--5749]&gt;,
 :open-url "<http://exchange.test/app>",
 :connection-filter
 #function[figwheel.main/config-repl-connect/fn--8222]}

2020-02-05T18:34:24.081700Z

OK, woah, I am in

2020-02-05T18:35:09.081900Z

I'm not sure what changed

🎉 2
EmmanuelOga 2020-02-05T19:49:55.082200Z

right! When it works, it is beautiful: https://docs.cider.mx/cider/usage/managing_connections.html

EmmanuelOga 2020-02-05T19:50:00.082400Z

and it mostly works!

EmmanuelOga 2020-02-05T19:50:16.082600Z

but it's been kinda hard to get it to work in the first place

EmmanuelOga 2020-02-05T19:52:47.082800Z

@aisamu you mentioned you start the repl from the command line, how do you do that with figwheel? 1. When I start with a command like clojure -m figwheel.main -b dev -r the output shows a running HTTP server and that's that, it doesn't show the nREPL port. 2. Is the figwheel's nREPL able to handle both clj and cljs connections? 3. Should I just attempt to connect to clj and then to cljs in cider one after the other with the same port? (assuming I can find out which port is that)