Fork me on GitHub
#clojure-europe
<
2022-05-20
>
ordnungswidrig05:05:05

Good 🌅 . morning

dharrigan06:05:35

Good Morning!

RAMart07:05:37

Morning! :rain_cloud: (weather) ☀️ (mood)

otfrom08:05:30

😎 weather 😪 mood

otfrom08:05:41

but thank unions it is Friday

2
nottmey08:05:00

good morning! ☺️

genRaiy08:05:44

Good morning

borkdude08:05:25

Good morning!

practicalli-johnny08:05:58

:rain_cloud::rain_cloud::rain_cloud::rain_cloud::rain_cloud::rain_cloud:

2
genRaiy09:05:55

does anyone know a document that explains how Clojurescript devs should cosume JS libs these days, eg find out what the name of a JS object is that you want to require? I feel like there are docs scattered around but not a simple guide. Am I wrong?

borkdude09:05:41

Is this related to nbb perhaps?

genRaiy09:05:23

not really - it's the same problem wherever one wants to consume JS. As it happens I was using nbb when I came up with the question so your mind-reading is powerful 🙂

borkdude09:05:47

So, nbb approaches JS libs as ES6 which sometimes means it's different than in projects that use CJS modules

borkdude09:05:58

This difference is caused by JS itself, not by CLJS

😬 1
genRaiy09:05:13

for example OKTA - the auth service provider has several JS libraries that are actually written in typescript and how you consume them in CLJS is different eg

borkdude09:05:26

In general you can use an nREPL connection or js/console.log with trial and error to figure it out

genRaiy09:05:44

["@okta/jwt-verifier$default" :as okta-jwt-verifier] <-- you can call "new" on this

genRaiy09:05:12

yes - trial and fucking error ... that's ludicrous, no?

genRaiy09:05:48

["@okta/okta-auth-js" :refer [OktaAuth]] <-- you can call "new" on this

genRaiy09:05:10

that's from the same damn team / provider of the JS libs

genRaiy09:05:52

Maybe just documenting the trial and error approach would be useful?

borkdude09:05:27

Yes. So how I would do it is jump in an nbb REPL:

$ nbb
Welcome to nbb v0.5.103!
user=> (require '["@okta/okta-auth-js" :as auth])
nil
user=> auth/
auth/OktaAuth  auth/crypto    auth/default

borkdude09:05:43

When you then type auth/ followed by TAB (2x), it will come up with auto-completions

borkdude09:05:09

And then you end up with:

(require '["@okta/okta-auth-js" :refer [OktaAuth]])

borkdude09:05:31

But note that this also works:

user=> (require '["@okta/okta-auth-js$default" :refer [OktaAuth]])
nil

borkdude09:05:51

Because some of these libraries duplicate their library object under default again to be compatible with ES6

borkdude09:05:05

This is typically done by TS libraries I think, but not sure why

borkdude09:05:23

So if you could add that approach to the docs, this would be sweet, thanks!

genRaiy10:05:57

ok - will do ... doing a general thing feels like a recipe for 🤕

borkdude10:05:05

you can just transcribe our conversation here, as an example

borkdude10:05:18

and summarize it

orestis11:05:57

And then you update npm, clear node modules and for the same package lock, your consuming CLJS code breaks. True story.

borkdude11:05:07

I haven't had that so far, but I did experience some breakage in APIs...

orestis11:05:41

We were importing date-fns, and referring functions, and suddenly (with no version change of the date-fns package, mind) we had to switch to the $default syntax.

orestis11:05:26

I gave up trying to understand the reasons why, it's not a productive use of my time :)

😢 1
🙀 1
simongray12:05:37

Huh, I had been wondering about this myself. This thread was enlightening… if you can call JS that.

genRaiy09:05:06

forgive me, I'll post on the CLJS channel