Fork me on GitHub
#figwheel-main
<
2018-09-20
>
EmmanuelOga06:09:33

Hey, I'm getting an error on Windows 10 when trying to run the template. Any ideas? I saw some bug referenced before about length of classpath and the limitation of the command line... I don't think it is related (my classpath is "only" around 8K chars)

EmmanuelOga06:09:24

It is confusing because it seems to complain about missing clojure.spec, but when I run lein classpath the spec jar is listed right there

EmmanuelOga06:09:37

something like: C:\Users\emman\.m2\repository\org\clojure\spec.alpha\0.1.143\spec.alpha-0.1.143.jar; (which does exist)

EmmanuelOga06:09:09

found it... lein run -m figwheel.main -- -b dev -r works, so probably a problem with lein trampoline

EmmanuelOga07:09:36

two days later, with teary eyes... I have a figwheel.main running on WIndows 10

EmmanuelOga07:09:24

truly, I started trying to run it with clojure's jar on windows... lots of errors about missing dependencies and stuff. Then I switched to lein.

EmmanuelOga07:09:55

feels like the whole windows platform is a bit neglected in the clojure world

EmmanuelOga07:09:20

(starting by clojurelang itself not providing any easy path to install but lein)

pesterhazy07:09:30

A windows binary for the clojure cli is in the works but not finished

benzap18:09:34

Is it possible to access a background-build's repl from the foreground build repl? Is there a way to switch between the two repls?

benzap18:09:58

Or is it necessary to have two figwheel instances open to manage the client and the server?

benzap18:09:32

ex. I have a browser build, and a node server build, and the node server build is in the background -bb dev-server

benzap18:09:22

i'm trying to mimic a reloaded lifecycle design for both, so I (start) each one individually

benzap18:09:56

alternatively, I could change :main to automatically start and restart on-jsload I suppose

benzap18:09:11

only problem is, the server-side stuff can take several minutes to get to steady-state, so I would like to pick and choose what I restart if i'm only making minor changes to the server

benzap18:09:03

I finished reading the background builds doc, I think I now understand its uses and i'm using it incorrectly

benzap18:09:29

The server and ui builds need to be separate, which makes sense

bhauman18:09:36

@benzap accessing a background-build’s repl from a foreground build is not possible right now

bhauman18:09:55

but if you use the scripting api you can switch between them quite readily

bhauman18:09:25

@benzap is your server a node server?

benzap18:09:47

Yeah, it's entirely clojurescript server+ui

bhauman18:09:03

well that will work for a background build

bhauman18:09:17

and you can use the scripting api to switch between them

benzap18:09:39

interesting, how do I go about doing that?

benzap18:09:15

awesome! i'll take a look

benzap18:09:04

nice, it works really well!

benzap18:09:38

Is there a way to send things to be evaluated to each repl from rebel-readline?

benzap18:09:09

I can see some issues with that idea, since the browser repl requires a window to be open, so it would likely hang the main repl

bhauman18:09:42

you want things to be evaluated in every connected window?

rgm19:09:07

@bhauman so a bit of follow-up on my piggieback/figwheel/vim desert wanderings (cf https://clojurians.slack.com/archives/CALJ3BFLP/p1537311445000100) … what I think is happening is that figwheel is defaulting to putting and serving build products in target/public/cljs-out/dev, but any cljs eval within vim (through :Piggieback) has the impression that it should compile buffer evals into out/, and that’s where it’s going looking for react etc, and not finding it.

rgm19:09:20

so now I’m a bit stuck on the last 10 ft… I guess if I set up a ring handler to serve cljs out of out/ instead of target/public/, then all should be hunky-dory

rgm19:09:40

(probably my inexperience, but adding out/ to the classpath isn’t quite enough… the js would have to be in out/resources to be served by Figwheel’s static file server)

rgm19:09:37

(or I just bail out and add another piece to handle sending out index.html and all the js).

bhauman19:09:49

@rgm thats sounds like your VIM is using the default cljs.repl not the figwheel repl

rgm19:09:25

yeah the weird part is that I’m doing :Piggieback (figwheel.main.api/repl-env "dev") and does seem to connect OK … it just doesn’t seem to have access to figwheel’s build products. So in-editor, I can eval self-contained stuff that only relies on base clojurescript since (I guess?) the base clojurescript compile is providing it ¯\(ツ)

rgm19:09:03

guess I’ll rig up a static file server to use /out and see what happens.

bhauman19:09:05

it sounds like :Piggieback isn’t doing anything

rgm19:09:13

yeah, maybe not

bhauman19:09:20

that sounds like a bad path to take

bhauman19:09:38

i’d look at how you installed vim.fireplace

bhauman19:09:59

when I tried it the first time it was all borked and doing crazy things

bhauman19:09:20

then I installed vim.fireplace only

rgm19:09:31

yeah, maybe so. Don’t wanna waste any more of your time; just hoped you’d find it somewhat intriguing or know the problem within 2 sec.

EmmanuelOga20:09:55

Hey again. I was wondering if these instructions are up to date to run a figwheel.main REPL in cursive: https://github.com/bhauman/lein-figwheel/wiki/Running-figwheel-in-a-Cursive-Clojure-REPL

bhauman20:09:27

You need to use the Scripting API instead of the figwheel api

bhauman20:09:08

you don’t need to use cljsbuild, you just need to make sure that cursive is picking up your dependencies

EmmanuelOga20:09:09

oh, so I can start a repl from cursive and then run (figwheel.main.api/start "dev") inside?

bhauman20:09:42

that’s possible

bhauman20:09:56

but you can also create a script that starts figwheel-main as well

EmmanuelOga20:09:07

I was wondering if it was possible to connect using the "remote repl" feature in cursive

bhauman20:09:24

that is possible but more complicated

bhauman20:09:51

but since you are using lein it should be easier

bhauman20:09:10

you need to start a lein repl

bhauman20:09:15

and then connect to that nREPL port

EmmanuelOga20:09:38

right, but I don't know how to get the port 😛

bhauman20:09:54

its displayed when you start lein repl

bhauman20:09:15

but you have to make sure all your dependencies are available in lein repl

EmmanuelOga20:09:46

ah I think is because I ran lein run -m ...

bhauman20:09:49

a good way to test that is to start figwheel-main from the lein repl prompt using the scripting api

shaun-mahood20:09:14

@emmanueloga if you add a remote REPL and select Use Leiningen REPL port it will connect up to the repl you started from the scripting api, then (figwheel.main.api/start "dev") will get you a cljs repl alongside your clojure repl

bhauman20:09:20

@shaun-mahood I really really need a Cursive Guide 🙂 I’m getting this question all the time

bhauman20:09:01

of course, this is easy for lein

bhauman20:09:14

but to document all the ways is much harder

shaun-mahood20:09:04

Yeah - I'm not sure how well Cursive works without lein these days - I know it's much improved but not sure it's close to parity yet.

shaun-mahood20:09:27

Once I get things working nicely I'll write something up - I'm not sure if there's a nice way to have 2 repls going at the same time in Cursive without a lot of switching back and forth.

cfleming20:09:57

@bhauman @shaun-mahood I’m changing how REPLs work currently for deps support, which should hopefully make some of this easier. My eternal plan to make CLJS REPLs easier and have a proper CLJ/CLJS double REPL should be coming to fruit soon too, hopefully in the next EAP round.

cfleming20:09:01

I refactored a bunch of stuff internally for the EAP that went out today, to allow running any REPL type with any execution method (straight IntelliJ classpath, via lein or via deps).

cfleming20:09:17

That was a surprisingly large change but should be good in the future for more options.

shaun-mahood20:09:25

@cfleming That's awesome 🙂

bhauman20:09:15

sounds good

cfleming20:09:59

Actually, opinions welcome - as a default option, are people likely to want separate processes for the CLJ and CLJS parts? Or are they usually run in the same process?

bhauman20:09:14

same process

cfleming20:09:21

IIRC they used to be usually in the same process… ok, cool.

EmmanuelOga20:09:37

@cfleming I'm super new to clojure and cursive, but fwiw, I was expecting to be able to run the equivalent of "lein run -m figwheel.main" in cursive, somehow. Could not find a way.

bhauman20:09:01

yeah that might be expecting too much 🙂

bhauman20:09:35

its hard to document all the ways it won’t work

cfleming20:09:25

Hmm, interesting - in today’s EAP you can start a REPL with the moral equivalent of lein run -m clojure.main, but not figwheel.main.

cfleming20:09:49

I should allow that to be configured.

bhauman20:09:15

@cfleming how would that be possible?

bhauman20:09:33

are you just sending expressions to the stdin of the process?

bhauman20:09:44

of course you are

cfleming20:09:47

For the clojure.main REPL option, yes.

bhauman20:09:16

yeah that makes sense

bhauman20:09:24

so dang that would work

cfleming20:09:26

I have two REPL types, nREPL and clojure.main. I’m planning to extend the clojure.main one for general streaming REPLs so I’ll support socket REPL too.

bhauman20:09:54

and you aren’t parsing the results so your good for the clojure.main repl

bhauman20:09:03

or the figwheel.main repl

cfleming20:09:06

It’s tricky because there are a lot of different ways to start things now, and it will get exponentially worse for CLJS.

cfleming20:09:34

I’m planning to have an option for prepl-style structured output for the streaming REPLs too, but haven’t tested that yet.

cfleming20:09:39

Basically prepl but without all the tap stuff and not reliant on Clojure 1.10.

cfleming20:09:02

Not sure if/how that would work with figwheel.main, or even CLJS in general yet though.

cfleming20:09:14

I need some UI work for the clojure.main option too which is also pending.

cfleming20:09:13

@bhauman do you have a feeling for what the uptake of figwheel.main has been? Are most people still on old-school figwheel?

EmmanuelOga20:09:09

So, the script API seems to run all right, but then I go to localhost:9500 and nothing happens

EmmanuelOga20:09:12

at least I could connect form cursive, no problems

EmmanuelOga20:09:24

From cursive: (figwheel.main/status) ------- Figwheel Main Status ------- Currently available: dev Currently building: dev => nil

shaun-mahood20:09:29

@emmanueloga You need to add a couple dependencies to your dev profile - should look something like this (as well as whatever you already have)

:dev   {:dependencies   [[cider/piggieback "0.3.9"]]
              :repl-options   {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}]}

shaun-mahood20:09:45

https://github.com/nrepl/piggieback#installation is the link to the instructions in case you want more details

bhauman20:09:57

@cfleming its been slow, but I think a lot of folks have it on their todo lists now

bhauman20:09:45

I’d guess the adoption is in the hundreds though??

bhauman20:09:27

its a significant improvement

EmmanuelOga20:09:34

so... adding the dependency shaun said worked

EmmanuelOga20:09:45

I have a running repl and localhost:9500 works

EmmanuelOga20:09:57

but! if I do (js/alert "OK") from the cmd line, it works

EmmanuelOga20:09:03

but if I run the same from cursive it doesn

EmmanuelOga20:09:23

"no such namespace js"

cfleming20:09:40

@bhauman Ok, thanks. I think I’ll probably only support figwheel.main as an integrated solution then, and lein-figwheel users can continue as they are now, which isn’t terrible. Hopefully that will help drive migration too.

shaun-mahood20:09:57

@emmanueloga have you run (cljs-repl "dev") from your cursive repl yet?

EmmanuelOga21:09:11

"unable to resolve symbol cljs-repl"

bhauman21:09:42

@emmanueloga you need to require (require 'figwheel.main.api)

bhauman21:09:49

and run (figwheel.main.api/cljs-repl "dev")

EmmanuelOga21:09:37

only took me 3 days hehe. Sorry guys, I'm just venting a bit since I guess it could be helpful to you tool authors to know what it is like when you are a noob

EmmanuelOga21:09:14

ok, to recap, in order to use figwheel.main in Win10 with cursive I needed to: 1) Install lein (using lein.bat). Put it in a directory somewhere and add it to the %PATH%. 2) lein new figwheel.main 3) Edit the code to fix the paths (the template inserts file paths references like: "edit /myapp\somefile.clj", but then the compiler fails since it tries to insert a escaped char "\s" 4) Add the cider/piggiebak reference and nrepl option 5) run "lein repl", annotate the port 6) add a remote repl in cider and require figwheel main, and run the dev mode 7) profit

EmmanuelOga21:09:50

I don't think I've seen all the pieces of this "flow" together anywhere

EmmanuelOga21:09:05

I know there's a lot of docs but sometimes the forest hides the trees...

EmmanuelOga21:09:37

also, a bit of an inconvenience: if I restart the repl, the port changes, so I need to edit the cursive configuration

bhauman21:09:03

@emmanueloga please show me where to change the template and I will

cfleming21:09:27

@emmanueloga When you configure your remote REPL, use the “Use Leiningen REPL port” option and Cursive will pick up the port from where lein writes it out.

👍 4
EmmanuelOga21:09:27

sorry I'm switching between computers 😛

EmmanuelOga21:09:18

apparently nested-dirs returns a windows path, e.g. "hola\mundo" instead of "hola\\mundo" or "hola/mundo"

bhauman21:09:24

but that is just text that won’t prevent things from running

bhauman21:09:08

perhaps its being used in a place that will cause an error?

EmmanuelOga21:09:40

right, so if you introduce an error when figwheel was already running it will show that error HUD right,

EmmanuelOga21:09:59

but if you try to run figwheel with an error from the start, it will just fail to start

EmmanuelOga21:09:19

and in my machine that happened because the compiler choke on an invalid scape character

bhauman21:09:39

oh you are saying that this will fail to compile as javascript on windows

shaun-mahood21:09:59

Is there a way to set an :advanced build from figwheel config or using lein run?

bhauman21:09:39

-O advanced

bhauman21:09:46

for figwheel-main

bhauman21:09:08

-m figwheel.main -O advanced -bo dev

shaun-mahood21:09:30

Looks good, thanks! Should there still be a folder named after the build in the output folder after the build has completed?

bhauman21:09:42

it will build in the same spot as the dev build

shaun-mahood21:09:19

Sorry, bad question - in that folder, for my "prod" build, I have a "prod-main.js" file and a "prod" folder. Just wondering if that's the normal behaviour (I have this recollection that it cleaned out that "prod" folder but my memory might be lying to me again)

bhauman21:09:11

yes that’s normal

bhauman21:09:30

the output directory default goes there

bhauman21:09:48

but yes something to think about

shaun-mahood22:09:16

Ok thanks - think I've pretty much got things working like I want now, amazing how much of an improvement figwheel-main is over lein-figwheel. Pretty amazing work!

tmarble22:09:43

@cfleming your REPL work sounds great! I'm working on a client project right now to replace lein-cljsbuild with figwheel-main... and I've got all the basic bits going (static tests, creating an uberjar). I can launch a figwheel-main CLJS REPL from CIDER and add a "sibling" REPL to do CLJ. Right at the moment I'm trying to see how to emulate this in Cursive. On the CLJS side I can start a REPL in a terminal window with the approach ["trampoline" "run" "-m" "figwheel.main" "-b" "dev" "-r"], but that's not smartly connected to Cursive 😞 I've been thinking about starting a competely separate rebel readline REPL for CLJ and have Cursive connect that port, but @bhauman suggests it would be good to connect to the same REPL process??? Not sure how to do that

cfleming22:09:31

@tmarble Hi Tom! Yes, that sounds a bit tricky. For the next build I’ll make the clojure.main REPL config more flexible so you can do the run -m figwheel.main <args> from within Cursive - currently that’s hard-coded to run clojure.main.

tmarble22:09:56

... when done that way Cursive would know how to do things like "eval a form (or buffer)" and update the REPL?

cfleming22:09:17

That’s right.

cfleming22:09:36

And you’d run it from within the IDE without having to drop to the terminal.

tmarble22:09:10

Way back when I did the https://github.com/tmarble/tenzing3 technical study I ended up starting separate processes for the CLJ and CLJS REPL's and then had Cursive connect to each on different ports... I'm wondering if there's a way to "share one backend" (i.e. connect to the the figwheel.main REPL) but not automatically pivot in to CLJS (in order to create a CLJ REPL)?

cfleming22:09:37

My long term pipe dream is to have a single REPL run config that will start both CLJ and CLJS simultaneously and have them in tabs.

tmarble22:09:51

yes, that's what I'm talkin' about!

tmarble22:09:19

... where editing a *.cljc file will update BOTH!

cfleming22:09:34

Right - I actually think CIDER does that right now.

cfleming22:09:51

Currently CIDER does dual REPLs better than Cursive, and we can’t have that 🙂

tmarble22:09:06

hahaha... can't we all just get along 🙂

cfleming22:09:39

Hehe, yes, actually I was just with @bozhidar in ClojuTRE, it’s all friendly 🙂

tmarble22:09:19

sorry to have missed it! will you be at the Conj?

cfleming22:09:04

That’s just too much travel.

tmarble22:09:23

i totally get that

cfleming22:09:40

Anyway, we’re somewhat hijacking #figwheel-main, this should all really be over in #cursive

shaun-mahood22:09:26

@tmarble Reading above, are you trying to have your figwheel server start up but remain in Clojure?

tmarble22:09:43

no... I really want to do what I can with CIDER.. that is keep all the CLJS REPL goodness ... AND, separately, have a CLJ REPL (Ideally connected to the same backend)

shaun-mahood22:09:37

You can do that in Cursive as long as you are happy switching between 2 REPL windows when you need to - I've got it set up and it seems to work pretty well

shaun-mahood22:09:45

I'm running figwheel in my main repl (using :mode :serve), then connecting to it with a remote repl. I then run (cljs/repl) in the remote repl and can send forms to either one as needed

tmarble22:09:43

nice! do you have an example with the various *.cljs.edn files (possibly project.clj) ?

shaun-mahood22:09:10

figwheel-main.edn

{:watch-dirs      ["src/cljs"]
 :css-dirs        ["resources/public/css"]
 :target-dir      "resources"
 :open-url        ""
 }
(the open-url would likely be the "http://localhost:9500" or whatever your ring server is)

shaun-mahood22:09:25

prod.cljs.edn

^{:mode      :build-once
  :output-to "astrodon.js"}
{:main astrodon.core}

shaun-mahood22:09:02

dev.cljs.edn

^{:mode            :serve
  :open-url        ""}
{:main astrodon.core}

shaun-mahood23:09:36

user.clj

(ns user
    (:require
      [integrant.core :as ig]
      [integrant.repl :refer [clear go halt prep init reset reset-all]]
      [figwheel.main.api :as figwheel]
      [astrodon.system :as system]))

(integrant.repl/set-prep! (constantly system/dev-config))

(defn cljs-repl
      ([] (figwheel/cljs-repl "dev"))
      ([build] (figwheel/cljs-repl build)))

shaun-mahood23:09:20

Starting and stopping the figwheel dev process

(defmethod ig/init-key :figwheel/dev [_ opts]
  {:build    "dev"
   :running? true
   :main     (figwheel/start "dev")})

(defmethod ig/halt-key! :figwheel/dev [_ {:keys [running?] :as opts}]
  (when running? (figwheel/stop-all)))

shaun-mahood23:09:34

If you aren't using integrant, all you really need to do is start up a repl, make sure the figwheel namespaces are included, and and run (figwheel.main.api/start "dev") to get it going

shaun-mahood23:09:40

To add the second repl, add a Remote REPL and select Use leiningen repl port - it should connect to the running figwheel process

shaun-mahood23:09:22

Then you should be able to call (cljs-repl) from whichever repl you want to use for your cljs work.

shaun-mahood23:09:56

Let me know if you need more specifics or run into any problems, hope it helps!

tmarble13:09:26

The existance of figwheel.main.edn is significant for cursive?

tmarble14:09:02

Oh, I see this is a common config file per https://figwheel.org/tutorial#figwheel-mainedn but should probably be figwheel-main.edn

shaun-mahood15:09:57

Good catch, it was a typo in the slack message above 🙂 In case it ever comes up, I was able to get everything working as well using the scripting api without edn config files as long as I added :validate-config false to the code (I switched so that I could use figwheel to build my uberjar the way you posted earlier)

tmarble15:09:10

ok, I've really struggled to get the REPL configured correctly with Cursive (I guess I'm not doing it correctly?)

tmarble15:09:27

.. when I configured the Cursive REPL to run the lein task to start the CLJS REPL (via figwheel.main -b dev -r) it complained about the terminal and recommended against using rebel readline

shaun-mahood15:09:30

I'm using the normal Run nREPL with Leinengen setting with nothing else, then starting figwheel using the scripting API - I'll try using it in a similar way you are trying too and see what happens

tmarble15:09:53

local or remote?

tmarble15:09:55

ok finishing up an e-mail then I'll try it

tmarble15:09:49

ok, so no prelaunch tasks.. how do I start figwheel "using the scripting API"?

shaun-mahood15:09:36

From the repl,

(require 'figwheel.main.api)
(figwheel.main.api/start "dev")
If your dev config is running without specifying :mode :serve, it should start up figwheel and the cljs-repl

shaun-mahood15:09:41

Once you add :mode :serve to the config, it will start figwheel but not the cljs-repl - you can then run

(figwheel.main.api/cljs-repl "dev")
to get it started, and :cljs/quit should get you back out. I've tested going in and out of the cljs-repl repeatedly and my figwheel build kept going without any issues

tmarble16:09:37

i'm trying it again now... do you have a special (EAP) version of cursive?

tmarble16:09:03

I'm just hitting the "Play" icon for te REPL

shaun-mahood16:09:31

I'm on Cursive 1.7.0-eap2-2017.2

tmarble16:09:03

ok, I'm on 1..0-2018.2 -- how do I get your version?

tmarble16:09:37

my version starts a generic nREPL

shaun-mahood16:09:49

Yeah, so does mine - I think that should be fine. Once it's started, what happens when you try to require and start the figwheel server from the repl?

tmarble16:09:56

When I run (figwheel.main.api/cljs-repl "dev") it says ExceptionInfo Build dev isn't registered. Did you start it?

shaun-mahood16:09:03

You have to run (figwheel.main.api/start "dev") to start it first

tmarble16:09:15

yay! that works!

tmarble16:09:53

now... since I set :mode :serve ... how do I start a second, CLJ REPL?

shaun-mahood16:09:56

Run -> Edit Configurations -> Add a Remote REPL In the radio button options, select "Use Leiningen REPL Port"

shaun-mahood16:09:54

When you start that Remote REPL, it should connect to your existing repl as a clojure repl - you should be able to start your cljs-repl from there as well if you want.

tmarble16:09:26

ok, that's working! awesome! thank you!

shaun-mahood16:09:41

I haven't tried it, but in theory you should be able to open more than 1 remote repl and have different repls attached to different figwheel builds (one for dev, one for test, etc.)

shaun-mahood16:09:52

Glad it worked!

shaun-mahood22:09:39

I'll try and throw the specific parts into a thread here

gas23:09:23

using fig script api I get error

(fig/start {:id "dev" :config {:mode  :serve :watch-dirs ["src"] :open-url "/dev.html"}})
AssertionError Assert failed: Figwheel Start: build argument required
(build-option-arg? build)  figwheel.main/start* (main.cljc:1906)
Looks like its expecting another main-build to join?