Fork me on GitHub
#shadow-cljs
<
2022-03-08
>
avi19:03:23

👋 Hi there, I’m an experienced Clojure dev and I’m working on my first CLJS project, which is sort-of a CLI tool that runs on/in Node. Sorry if this is a FAQ or a silly question, but is there a way to use shadow to run a CLJS project with node, recompiling if necessary, as opposed to just (re)compiling the project? My goal is to ensure that people can check out the repo hosting this tool and run it immediately in a single step, and also that if they make changes to the code and then run the tool again, the changes will be picked up. If the answer is just, write a script that first (re)compiles the program and then runs the program, that’s fine. I’m only asking because I’m used to the model provided by Clojure CLI tools (i.e. the clojure script) wherein I can use it to run my project, compiling it on the fly every time I run it; and I find that convenient. Thanks!

lilactown02:03:29

outside of shadow-cljs, you can use a self hosted version of cljs like lumo, although I fear it has fallen into an unmaintained state

lilactown02:03:10

you could check out #nbb, which isn't quite CLJS but might do what you want

lilactown02:03:36

both of these would allow someone to clone your repo and run the script in a single command

lilactown02:03:05

since they will at runtime interpret the code, rather than compiling it to JS

lilactown02:03:26

if you'd rather stick with compiled CLJS, then having a build script that compiles and runs it

thheller05:03:56

I strongly recommend using a compiled script distributed to npm. instead of compiling from source on the end users machine.

thheller05:03:25

otherwise you have to pay the startup cost of the JVM every time which will make the CLI tool unusably slow (if you care about startup time)

thheller05:03:16

checking out the source and compiling it can still be done, just shouldn't be the default

avi16:03:26

Thank you so much!

avi16:03:27

I’m leaning towards a script that looks sort of like shadow-cljs start && shadow-cljs compile <build> && node path/to/compiled/script.js

avi16:03:43

that way if it’s run multiple times it’ll be fast because the server is running in the background

avi16:03:03

I’ve been using a script that does something similar during development and it’s been working well for me

avi16:03:14

I was just wondering if shadow had some built-in command for this.

avi16:03:22

Sounds like it doesn’t, which is totally fine.

avi16:03:32

Just curious though… should it, maybe? Or would that be scope creep?

avi16:03:16

Ah also WRT this: > …using a compiled script distributed to npm. I don’t think I can do this in this case because this is a private, proprietary, internal tool.

thheller18:03:11

doesn't need to be the public npm registry then. could be a github repo und zip file

avi00:03:08

Ah right, sure. I’ll consider that. Thank you!

avi00:03:54

(In this particular case, this tool will probably be used only infrequently, and all its users are developers, so it might be OK if they have to run it using a script in a clone of the repo.)