Fork me on GitHub
#shadow-cljs
<
2023-03-30
>
Aron Gabor12:03:04

hi, can build hooks be node scripts?

thheller13:03:27

no. they execute the JVM

hidethepain 2
thheller14:03:49

what would you even do in a node script that makes sense? likely just trying to abuse build hooks for something they werent meant to do? 😛

Aron Gabor14:03:13

how did you know

Aron Gabor14:03:38

Ok, how can I debug lifecycle hooks? I don't know what's happening, if anything happens at all

thheller14:03:43

check the browser console. shadow-cljs tells you what it is calling and when

Aron Gabor14:03:59

I was looking there too. I don't see anything, so I will assume nothing runs. I just need to figure out why.

thheller14:03:00

if you want to provide more details I can maybe make suggestions

❤️ 2
Aron08:03:00

hard to say details when I am not sure what I am doing. I wanted to have a backend node service, but I am unable to setup the lifecycle hooks to that too.

thheller08:03:41

what do lifecycle hooks have to do with a backend node service?

Aron08:03:04

this is what I mean, that I don't know what I am doing:)

thheller08:03:10

just describe what you are trying to do, not how you are attempting to do it

Aron08:03:44

:target :node-script with hooks, so that when I build it, I can start the built script

thheller08:03:11

get rid of any shadow-cljs terminology

thheller08:03:38

using hooks here just confuses me

Aron08:03:04

sorry, this is more difficult than I expected:D i want to write a backend server and have the normal devtools available while writing it

thheller08:03:08

you mean when you start the build you want to start the node script?

Aron08:03:27

after the build

thheller08:03:38

this is not supported, and also not desirable

thheller08:03:48

the intent is that you have shadow-cljs built the :node-script

Aron08:03:53

that's all right, at least I asked after trying it for a day anyway

thheller08:03:08

you then, in a separate terminal, run node the/output.js

thheller08:03:27

this gives you a clear place where the output goes

Aron08:03:33

yeah, I don't know what to write the script in that starts pm2 or similar thing

Aron08:03:32

pm2 then can monitor output.js and restart the node process

thheller08:03:04

well, with hot-reload you shouldn't need to restart in the first place

thheller08:03:21

if you actually need to restart you can ctrl+c the process and restart it

thheller08:03:45

I mean you can, and you know the tools to use for it

Aron08:03:03

i don't think i would have hot reload in any of these cases

thheller08:03:08

you just won't find anything in shadow-cljs to do this for you

Aron08:03:06

yeah, thanks, I just misunderstood the docs, thought it would work because the :target wasn't specified in the example and I wrongly assumed it's more general than what actually is. But I don't need shadow-cljs to do this auto-restart, just would be nice to not have to manually ctrl+c and restart 200 times a day

Aron08:03:22

anyway, thanks again for the help, I will figure something out

thheller08:03:16

I agree that restarting 200 times a day is not great. hot-reload/REPL give you the option to drastically reduce that. I usually start my clojure REPL once a week or so, same could be true for a node script in theory. All depends on your workflow.

Aron08:03:20

I don't have a flow of work. It's sporadic hiccups. 😅

borkdude15:03:24

Is there a way to disable the websocket stuff in watch mode? I'm using target esm on node but when I want to invoke a test script , I'm getting:

file:///Users/borkdude/dev/trip/out/cljs-runtime/shadow.cljs.devtools.client.websocket.js:21
return shadow.cljs.devtools.client.websocket.start.cljs$core$IFn$_invoke$arity$2(WebSocket,runtime);
I know esm is for browsers but it works perfectly fine for node.js too including the build report, except this bit

thheller15:03:53

:runtime :node in the build config

borkdude15:03:33

sweet, thanks!

thheller15:03:51

or :devtools {:enabled false} to disable it entirely

❤️ 2
borkdude15:03:01

@U05224H0W I think I have an issue with vanilla CLJS advanced vs shadow-cljs advanced in the area of keywords, but I haven't gotten to the root of this. But I suspect it may be related to the keyword optimizations in shadow. Is there a way to disable that in advanced, to debug this issue?

borkdude15:03:11

In vanilla CLJS I don't have this problem, to be clear

thheller15:03:01

what is the problem?

thheller15:03:08

no, you cannot disable it

thheller15:03:23

only thing you can set is :compiler-options {:shadow-keywords true} which optimizes it even more

thheller15:03:02

but I never tried that with :esm, so no clue if that even works

borkdude15:03:58

let me try a repro

borkdude15:03:11

hmm, no that wasn't it. I thought that keywords optimized at build time weren't correctly matched against keywords created at runtime, but it works. the issue I'm having is with clojure.spec.alpha which dynamically processes some input at runtime, which works with vanilla but not with shadow... I'll debug further

borkdude15:03:02

ah, it was my bad facepalm vanilla CLJS has something like (set! *main-fn* ...) and then the arguments are the command line arguments and I relied on that, but when porting to target esm that no longer works (as expected, probably)

borkdude15:03:12

luckily it works now with manual process.argv processing 😅