Fork me on GitHub
#clojurescript
<
2022-11-20
>
qqq09:11:03

I've looked at https://lwhorton.github.io/2018/10/20/clojurescript-interop-with-javascript.html . One thing I don't understand is this: How do I get shadow-cljs to emit a es module or a iife (is this the default?) where it exports some cljs functions which I can then call from js land? Most of the docs I find online seem to make the assumption of "js has libraries; cljs drives main loop"; I want a situation where "cljs builds to a js library I can import; and js drives the main loop, calling into the exported cljs functions"

thheller09:11:21

probably in combination with https://shadow-cljs.github.io/docs/UsersGuide.html#_third_party_tool_integration if you intend to integrate into another build tool

borkdude11:11:39

What's the issue here with goog.dom NodeType?

cljs.user=> (require '[goog.dom])
nil
cljs.user=> goog.dom/NodeType
WARNING: Use of undeclared Var goog.dom/NodeType at line 1 <cljs repl>
#js {:ELEMENT 1, :ATTRIBUTE 2, :TEXT 3, :CDATA_SECTION 4, :ENTITY_REFERENCE 5, :ENTITY 6, :PROCESSING_INSTRUCTION 7, :COMMENT 8, :DOCUMENT 9, :DOCUMENT_TYPE 10, :DOCUMENT_FRAGMENT 11, :NOTATION 12}

borkdude11:11:56

This is in a Node.js REPL and I understand it's not a browser

p-himik16:11:29

Seems like you should import it instead of requiring it:

cljs.user=> (import 'goog.dom.NodeType)
nil
cljs.user=> NodeType
#js {:ELEMENT 1, :ATTRIBUTE 2, :TEXT 3, :CDATA_SECTION 4, :ENTITY_REFERENCE 5, :ENTITY 6, :PROCESSING_INSTRUCTION 7, :COMMENT 8, :DOCUMENT 9, :DOCUMENT_TYPE 10, :DOCUMENT_FRAGMENT 11, :NOTATION 12}
From https://clojurescript.org/reference/google-closure-library#import-a-class.

p-himik16:11:29

The (import '(goog.dom NodeType)) syntax (which I myself prefer more) seems to work as well, even though the link above uses it for enums.

valerauko12:11:20

anyone know of a js or cljs library for quickly generating flake ids in the browser?

skylize13:11:20

You can use test.check generators (or spec uses that under the hood) to generate data. For example, if by "ids" you mean UUIDs, there is a generator that already does that.

(require '[clojure.test.check.generators :as gen])

(gen/sample gen/uuid)

(#uuid "ba5f8d50-bb93-4b0f-9520-445d7481cc94"
 #uuid c7a0fc19-fbf9-40d7-8ee2-1e80e589f14e"
 #uuid "aeadc7c6-6872-4d96-9a9b-db898913860c"
 #uuid "292f6f3a-7e92-4f29-8379-d0056c769284"
 #uuid "87ff55ab-7964-4515-8606-34d15396a0bc"
 #uuid "873059ce-55a3-43dd-832f-9a4c2fb762ec"
 #uuid "a5aa04f0-62a9-4c5a-8144-42252f655fda"
 #uuid "6aff1af1-deeb-44fe-a877-0f90f1f40bc2"
 #uuid "ae0b0062-3087-434b-b111-521927a03470"
 #uuid "1ee61c50-1f6d-47fe-8e4e-48c218654f16")

valerauko13:11:56

no i'm specifically looking for "flake id" generation

skylize13:11:35

Lol. Sorry, I thought it was a typo for "fake id". Looks like you can turn to npm for that https://www.npmjs.com/package/flakeid

skylize13:11:55

This looks to be clj-only, but you could use it on the server-side. https://github.com/maxcountryman/flake/blob/master/src/flake/core.clj

valerauko13:11:57

yeah i already have a flake generator on the server from mulog. i was looking for something in the browser

Eric Scott14:11:23

How concerned should we be about this entry in NVD: https://nvd.nist.gov/vuln/detail/CVE-2022-41719 ? It's rated as a 'high' risk.

thheller14:11:37

do you accept msgpack data from untrusted sources? if not, not at all

vemv14:11:58

probably it's a false positive as that appears to be a Go dependency? even if it was a Java one, they only affect cljs compilation, not your production code

Eric Scott15:11:52

I just working on a library that has clojurescript as a dependency, so I guess this won't be an issue until someone uses it to face the public. Thanks.

thheller17:11:20

clojurescript doesn't use msgpack at all, its just a dependency due to transit-java supporting it. so you are fine.

thheller17:11:42

you can just exclude it, if you are feeling paranoid 😉

qqq22:11:42

in a deps.cljs, there is a section that says:

{:npm-deps [ ... ] }
Is it possible to specify a path where instead of giving it a "npm-name, npm-version", we specify a path on the local filesystem ?

qqq23:11:22

For :foreign-libs , i.e. https://clojurescript.org/reference/packaging-foreign-deps why do we need the :externs file ? Wouldn't the goog closure read in the *.js files, then rename everything consistently ?

dnolen17:11:49

:foreign-libs means Closure will not see it