Fork me on GitHub
#calva
<
2021-01-30
>
grumplet00:01:13

I’d like to automate cljs/figwheel-main/webpack a little better using deps. 1. Using a fig alias I can jack-in with Figwheel Main and compile. 2. With another alias I can then start a figwheel main repl that is connected to the editor. Between (1) and (2) I want to run webpack at least once. It looks like I can get access at this point by adding a :post-build-hooks vector in figwheel-main.edn. I feel it should be possible to supply a clojure function there which shells out to call webpack.

grumplet00:01:36

:post-build-hooks wants a namespaced function to call. However I can’t get this to resolve correctly - e.g. if I give it [user/foo] it can’t resolve namespace user. It would be simple if I understood how the classpath was defined when the :post-build-hooks functions are resolved. This might be a figwheel-main issue, but it may also be a Calva defined classpath. Does anybody have an idea how to put functions on the classpath at that point?

grumplet00:01:18

OK - answering my own question - I guess the classpath there is the one built by Calva Jack-in which is echoed in the terminal.

grumplet00:01:18

Now is there a way to add source paths to that?

pez08:01:51

Calva does not build any classpaths. That will be done by Leiningen or the clojure CLI tool, depending on which one you use. If you define a profile (lein) or an alias (clj) then you can select these at Calva Jack-in and the command line will be built such that it invokes the profile/alias. I tried to explain the Jack-in feature a bit here: https://calva.io/jack-in-guide/

grumplet10:01:53

Sorry - I was thinking out loud there. Yes I agree, but Calva does build the CLI command line and passes it dependencies to go on the classpath using clojure -Sdeps. Maybe this output will clarify the problem I’m trying to solve - I can’t see how to get ‘user’ on the classpath. I have :post-build-hooks [user/foo]in figwheel-main.edn. user/foo is a placeholder for a function that will run webpack. I see this:

> Executing task: clojure -Sdeps '{:deps {nrepl {:mvn/version "0.8.2"} cider/cider-nrepl {:mvn/version "0.23.0"} clj-kondo {:mvn/version "2020.04.05"} cider/piggieback {:mvn/version "0.4.2"}}}' -A:fig:dev <
...

WARNING: Use of :main-opts with -A is deprecated. Use -M instead.
2021-01-30 00:21:41.178:INFO::main: Logging initialized @3750ms to org.eclipse.jetty.util.log.StdErrLog
[Figwheel] Validating figwheel-main.edn
[Figwheel] figwheel-main.edn is valid \(ツ)/
[Figwheel:WARNING] Compile Exception: Could not locate user__init.class, user.clj or user.cljc on classpath.  
post-build-hook-fn: There was an exception while requiring the namespace 'user while trying to load the var 'user/foo

grumplet10:01:18

There’s probably a simpler way to tackle this 🙂

pez11:01:50

I’m not sure I am following. But I get this to work. 1. Create a directory env as a sibling to src 2. Put a file user.clj there with (ns user) and (defn foo [arg] (println "Hello world, args: " arg)) 3. Add "env" to :extra-paths of the alias I am using 4. Add user/foo to :post-build-hooks

pez11:01:46

I also see that you are using the alias :fig which I think often contains :main-opts . If so that will not chime with jack-in, unless those opts start the nrepl server. Try without selecting that alias. (Even if this should be unrelated to the problem with finding user/foo.)

grumplet10:02:37

[email protected], Stupidly I’d tried that earlier but with source-paths rather than extra-paths. With extra-paths It no longer barfs about the user namespace, but I’m not seeing the println anywhere. And fair point - my fig alias is now misnamed as its :main-opts moved elsewhere.

pez11:02:09

You’re welcome. I’m glad I got to try that out and learn a bit about these settings. As for the printout. Don’t recall where I found them. Maybe in the Jack-in terminal? Maybe in the (wrongly named) Output channel Calva Connection Log

grumplet10:02:20

Don’t spend time on this - but I tried all those. No errors, but nothing in any log as far as I can see.

pez10:02:35

Haha, try to stop me. 😃 But not right now, working for food time.

grumplet18:02:02

Just picked up on this again when I saw that missing Hello World suddenly appear at startup. So the println is working now and outputting to the REPL buffer after the build as it should. 🙂

grumplet18:02:53

When I get some time I’ll see if I can get it to do something sensible with the npx webpack call.

calva 1
pez09:01:01

Wow, @eric.uitbeijerse It is a pleasure to try to contribute to Clojure success, because the community is so welcoming, helpful, and interested in helping each other succeed. It makes me happy to hear that we Calva peeps are following the example. Thanks for sharing that!

alekszelark18:01:42

Just reported two printing related issues. It would be nice to get them fixed. 🙏

Hagenek20:01:16

Quick question for Vs code and Calva users. How do you stop evaluating when your functions enters an infinite loop?

clyfe20:01:29

What OS you on?

Hagenek20:01:58

https://app.slack.com/team/USMLDU9BR  [9:07 PM] Tried Ctrl-Alt-C Ctrl-Alt-D, but that does not seem to do the trick. (Should stop evaluations). (edited)

clyfe20:01:32

How about: Ctrl+Shift+P -> Calva: Interrupt Running Evaluations ?

clyfe20:01:25

(I'm on Ubuntu/Gnome & Ctrl+Alt+D is show desktop)

Hagenek20:01:37

It might be that there is a sluggishness in the system, that it actually interrupts it but text keeps coming into the REPL

Hagenek20:01:48

I will stop it and wait and see if it stops coming text in the REPL after a while

pez20:01:46

Yes, sluggishness. If you are printing from that loop that will not stop until the print queue use empty.

pez20:01:03

There's a command for that. Iirc somethng like Interrupt running evaluation

clyfe20:01:01

I need a good story for customization; can't do well w/o my nitty gritty keyboard behaviors. a) I'm thinking: Calva to expose pretty much all it can (mirrored doc map, paredit fns, etc) in it's public API. That's the way to allow people to customize to their workflows. We can tag: "API subject to change" and things can break from time to time. That RH "never break API" is not the mother lode of good things, there are cases like here. b) Maintain a series of patches applied on releases from time to time. c) A setting flag "Calva: Natural mode" (killSpace, backspaceNoFormat) but the rabbit hole may be deep here.

clyfe20:01:53

Probably a) with a well thought API is a good plan.

pez09:01:02
replied to a thread:

Wonderful. And super extra great that you both contributed to Calva’s shiny Review section at the marketplace. ❤️ As for who to thank: A lot of people! @bozhidar and his CIDER team comes to mind, of course, since Calvados is distilled from Cider. And now lately we are sourcing the power of #lsp and, by that proxy, also #clj-kondo which brings in all the many hours of hacking and supporting put in by @borkdude, @ericdallo and @snoe to serve the Calva users.

❤️ 2
clojure-lsp 2
calva 3
clj-kondo 1
cider 2
hyper-clap 1