Fork me on GitHub

👋 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!


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


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


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


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


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


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


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)


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


Thank you so much!


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


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


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


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


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


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


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.


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


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


(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.)