shadow-cljs

migalmoreno 2025-04-03T15:46:42.926459Z

Hi, forgive me if this isn't strictly related to shadow-cljs, I'm not sure what channel to ask this in. I'm writing a JS script that interacts with https://github.com/LuanRT/BgUtils to generate YouTube po-tokens. I want to feed an already existing CLJ backend with these tokens so the requests it makes to YouTube are not blocked, but I'd like keep my backend self contained and not have to run an extra Node server to serve these tokens. My first attempt involved using GraalJS straight from CLJ to evaluate the JS script, but I soon ran into problems because the JS fetch API is not supported in the GraalJS runtime (which the bgutils library uses to make requests), and I also wasn't able to import jsdom (or linkedom/happy-dom) which the library needs to simulate a web-browser for the potoken generation to succeed. All-in-all, I was pretty disillusioned with GraalJS capabilities in running JS that requires Node/browser APIs. I also wanted to rewrite this JS script in CLJS to plug it into a shadow-cljs REPL, so my next idea was to write a standalone script targeting shadow's node-script. Run this script from the CLJ backend and pipe its output to the application, perhaps with babashka. The problem with this approach is that I would have to assume that node is installed in the system for the script to be run from CLJ, and I would have to use the resulting JS output generated by shadow-cljs, which I'm not sure could bring problems on deployment. Otherwise, would using nbb mitigate this? Does this make sense at all, or should I look for other ways to run Node.js in Java such as https://github.com/caoccao/Javet?

thheller 2025-04-03T15:57:23.055159Z

I'd start a node process and have that connect to the CLJ backend via tcp or http websocket or so

thheller 2025-04-03T15:57:34.924359Z

building on top of stdout sucks

thheller 2025-04-03T15:57:56.211589Z

forget about alternative runtimes if you intend to use npm packages that weren't designed for those runtimes

thheller 2025-04-03T15:58:25.776379Z

or ask some LLM to rewrite the npm library in java or CLJ 😛

thheller 2025-04-03T15:59:06.143039Z

doesn't look like its a whole lot of code to begin with

migalmoreno 2025-04-03T16:00:55.681309Z

Uggh I guess I'll have to go that way, I just didn't want to have to spawn an extra server just for this. Problem is the library need some sort of browser environment to make the requests in, so YouTube thinks it's a normal request, so it cannot be rewritten in JVM since there are not browser simulation libraries available (jsdom et all)

thheller 2025-04-03T16:02:26.813679Z

🤷‍♂️