Fork me on GitHub
#shadow-cljs
<
2019-04-13
>
talgiat01:04:52

Hi there, I’m looking for a way to use shadow-cljs to recompile sass files, I’ve looked into the build hooks but not sure if that can be done. Figwheel has similar capabilities via writing a custom script, and I thought you can do it using a hook, but seems like watching the sass source folder in watch mode doesn’t invoke the compile-prepare stage with the sass files that were changed. I know you can run some other watcher, but I believe one of the goals of shadow-cljs is to reduce the number of build tools and processes running, so it’ll be nice to find a way to do that.

thheller08:04:24

@talgiat there is a very basic "plugin" feature that I started working one quite a while ago. I isn't documented since I'm still not sure I want to go with that route so I wouldn't make any guarantees that it stays the way it is but you could definitely build all kinds of things with that

thheller08:04:13

:plugins just takes a vector of symbols

thheller08:04:02

so that points to demo.dummy-plugin/plugin which is just a map

thheller08:04:18

:start should be a function. :stop should be a function that will be called with whatever :start returned when the server shuts down

thheller08:04:41

so for example you could start a sass process in :start, return the process handle and kill it in :stop

thheller08:04:29

I haven't explored this further but in theory this is enough

thheller08:04:55

:build-hooks are indeed not a good fit for something like sass since sass compilation is independent of CLJS

orestis11:04:57

@talgiat I’ve done this by wrapping kickstarting the shadow CLJS build processes from my own code. I could share something come Monday.

talgiat14:04:16

thanks @thheller is there an option to watch some folder with shadow (same way that the build works), so I can watch the sass folder and run sassc command on file chagnes? I saw watch under worker.clj but not sure if that’s something too internal to use. @orestis a code sample would be great

orestis14:04:33

@talgiat I basically just use the hawk library (shadow already depends on it) to run sass-clj

thheller14:04:51

@talgiat there is something yeah. shadow.cljs.devtools.server.fs-watch

thheller14:04:53

(fs-watch/start
  {}
  [(io/file "some" "dir")]
  ["scss"]
  (fn [updates]
    (prn [:scss-updates updates])
    ))

talgiat14:04:56

ok, yeah was just looking at that

thheller14:04:08

first {} is config, which you don't really need

thheller14:04:28

second [...] is an array or java file instances (eg. via )

thheller14:04:43

["scss"] is the file extensions to watch

talgiat14:04:44

great, so I can start that in the plugin

thheller14:04:07

yes. but make sure to (fs-watch/stop what-start-returned) also

talgiat14:04:20

yeah, for sure

talgiat14:04:38

it’s like figwheel with component start and stop lifecycle

thheller14:04:04

yeah kind of

mauricio.szabo19:04:17

How do I get a CLJS repl using node-test target? When I try to connect to a REPL, I'm getting "No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code."

thheller19:04:49

that is not supported. tests are supposed to run once and exit (since we need the exit code)

thheller19:04:25

you can however just shadow-cljs node-repl (require 'your.ns) (your.ns/the-test)

thheller19:04:30

that will run a test

thheller19:04:05

or use the cljs.test methods to run them (eg. (cljs.test/run-tests) for all

mauricio.szabo19:04:46

Oh, I think the documentation must be outdated: it say "The node process exit code will not be returned when using :autorun", so I though I could use it to run a REPL

thheller19:04:19

no that is accurate. you just misunderstand what :autorun does

thheller19:04:17

:autorun executes the tests the a watch build completes. the node process running the tests will still exit. the shadow-cljs process however continues.

thheller19:04:29

so there is no "exit code" in that sense

thheller19:04:50

nothing you could use in a meaningful sense

mauricio.szabo19:04:28

What's the preferred way to develop code targeting Node.JS? Right now I'm using two targets, one to autorun tests and one to compile the project. Is there another way you recommend?

thheller19:04:32

docs could probably explain that in more detail but the work the node process does remains the same

thheller19:04:09

that is up to you. I tend to do it the same way I do CLJ development ... using the REPL

thheller19:04:44

:node-script targets I usually run with :devtools {:enabled false} since I want them to exit when they "complete"

thheller19:04:58

otherwise the websocket for the devtools keeps everything running

mauricio.szabo20:04:06

Yes, I do use the same way, but in Clojure mode I require a test namespace even when none of my "main" namespace doesn't require it. On CLJS, this is not really possible, so that's why I'm using another target

thheller20:04:39

I don't understand what you mean

mauricio.szabo20:04:14

For example, when I use :node-script I need a :mainfunction - my tests namespaces are not included on the :main namespace

mauricio.szabo20:04:36

So when I save a test file, it doesn't get compiled...

thheller20:04:37

yes but what does that have to do with anything?

mauricio.szabo20:04:57

and in Clojure mode I can force a "require" and run it by the REPL

thheller20:04:08

well you could use :devtools {:preloads [your.test-ns]}

thheller20:04:25

you can do that repl require in CLJS too?

mauricio.szabo20:04:08

I think I missed the documentation part about :preloads. Great to know! I'll check it. Thanks 🙂

thheller20:04:49

well it isn't exactly meant for tests but you can abuse it for that

mauricio.szabo20:04:12

I'll check out and post if it works for me. Thanks again 🙂

lilactown20:04:46

@mauricio.szabo what stops you from running (require 'your.test-ns) at the REPL?

lilactown20:04:04

FWIW I keep the devtools on because most of my :node-scripts are servers

mauricio.szabo20:04:50

In my experience this tends to confuse reloads. Maybe newer versions have fixed this issue though... I'll probably need to revisit my workflow :)

lilactown20:04:20

you will probably have to (require 'your.test-ns :reload) again if you make changes