shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
nivekuil 2020-10-24T08:37:30.099800Z

how is wasm support nowadays? I think I will try to get https://github.com/antelle/argon2-browser working. I installed it from npm and tried requiring it in cljs, but it looks like something can't even read the wasm magic header: {:line 1, :column 0, :message "Character '\0' (U+0000) is not a valid identifier start char"}

thheller 2020-10-24T08:40:36.100600Z

@kevin842 bundling wasm is not supported. you can still use wasm, just not bundle it

nivekuil 2020-10-24T08:41:08.100700Z

yeah, but I figured I would try to get it working like in https://github.com/thheller/wasm-pack-cljs

nivekuil 2020-10-24T08:41:12.100900Z

or is it still too far away to bother?

thheller 2020-10-24T08:42:04.101400Z

it all depends on the generated JS that comes with the .wasm file

thheller 2020-10-24T08:42:30.101900Z

some works fine out of the box. some will never work.

nivekuil 2020-10-24T08:47:01.102Z

well, reading the generated JS doesn't seem that bad, being only ￱~￱600 lines prettified, but I wish there were better error messages to even see what's going on

thheller 2020-10-24T08:54:09.102400Z

https://unpkg.com/browse/argon2-browser@1.15.2/lib/argon2.js if thats it all the import stuff needs to go

thheller 2020-10-24T08:54:14.102700Z

as well as the require stuff

thheller 2020-10-24T08:54:51.103Z

the rest looks straightforward

thheller 2020-10-24T08:56:14.103300Z

ah nevermind that wasn't the generated file

thheller 2020-10-24T08:57:07.103600Z

hmm yeah the generated file looks much worse

nivekuil 2020-10-24T09:00:46.103800Z

how so? some of the code in there is for node.js, so maybe that's why.. but I am having trouble even figuring out what to look for, is there a resource?

thheller 2020-10-24T09:01:41.104600Z

I didn't write anything beyond the example repo I made

thheller 2020-10-24T09:01:51.104900Z

not aware of anyone else doing stuff with wasm

thheller 2020-10-24T09:02:37.105600Z

what doesn't work is any kind of JS that expects the bundler to provide the .wasm file

thheller 2020-10-24T09:03:04.106Z

if there is a variant that uses fetch or xhr to load the .wasm file then this variant should be used

thheller 2020-10-24T09:03:20.106400Z

and you just copy the .wasm file somewhere and provide the path (assuming thats possible)

thheller 2020-10-24T09:03:48.107100Z

unfortunately the emscripten generated code is quite terrible and contains a lot of useless loading code

thheller 2020-10-24T09:04:09.107500Z

all this dynamic figuring out which runtime it is in needs to be removed

nivekuil 2020-10-24T09:07:22.107600Z

that's unfortunate.. you think the rust wasm toolchain is friendlier than emscripten?

thheller 2020-10-24T09:07:40.107900Z

last time I checked it generated better JS yes

thheller 2020-10-24T09:08:35.108700Z

its been a while since I looked at it though and it was completely different the time I checked before that

thheller 2020-10-24T09:11:17.109200Z

don't think the "standard" for this is any further along too

thheller 2020-10-24T09:11:33.109600Z

so no clue. I only follow casually

nivekuil 2020-10-24T09:22:39.109700Z

this one seems to work out of the box: https://github.com/Daninet/hash-wasm

nivekuil 2020-10-24T09:23:03.109900Z

I wonder what the difference is. anyway thanks for the help :)

wombawomba 2020-10-24T16:23:01.113600Z

So I’m trying to upgrade shadow-cljs from 2.8 to 2.11.5, and I’m having some problems. Specifically, my build compiles without errors, but my ‘core’ ns doesn’t get loaded when I open my app in a browser. Instead, I see the following error in the browser:

react_devtools_backend.js:2450 Failed to load foo/core.cljs SyntaxError: Unexpected identifier
    at eval (<anonymous>)
    at Object.goog.globalEval (base.js:577)
    at Object.shadow$cljs$devtools$client$browser$script_eval [as script_eval] (browser.cljs:23)
    at Object.shadow$cljs$devtools$client$browser$do_js_load [as do_js_load] (browser.cljs:35)
    at eval (browser.cljs:56)
    at eval (env.cljs:232)
    at Object.shadow$cljs$devtools$client$env$do_js_reload_STAR_ [as do_js_reload_STAR_] (env.cljs:204)
    at Function.eval [as cljs$core$IFn$_invoke$arity$4] (env.cljs:240)
    at Object.shadow$cljs$devtools$client$browser$do_js_reload [as do_js_reload] (browser.cljs:48)
    at eval (browser.cljs:92)
Any idea what might be causing this, or how I can fix it?

wombawomba 2020-10-25T13:56:27.124600Z

Alright, good to know.

wombawomba 2020-10-25T13:56:48.124800Z

Any idea why it would break my code?

thheller 2020-10-25T13:58:36.125Z

not a clue

wombawomba 2020-10-25T14:12:03.125200Z

okay 🙂

wombawomba 2020-10-24T16:28:40.113800Z

Okay I figured it out. I had a function marked as ^:export, and it started working as soon as I removed that keyword. Has ^:export been deprecated, or could there be something else going on?

wombawomba 2020-10-24T16:30:46.114100Z

…I assume that ^:export is intended to work, considering that it’s mentioned in the documentation: https://shadow-cljs.github.io/docs/UsersGuide.html#_working_with_optimizations

thheller 2020-10-24T16:44:41.114300Z

:export has not been changed. it works just like before.

afhammad 2020-10-24T19:36:26.116400Z

I can't get shadow-cljs to bundle an npm library with a node-script target. I've installed the lib via npm, its in my packages.json, also added a deps.cljs:

{:npm-deps {"xmlhttprequest" "1.8.0"}}
it's required like this:
["xmlhttprequest" :refer [XMLHttpRequest]]
no complaints on compilation but get
Error: Cannot find module 'xmlhttprequest'
at runtime. What am i missing?

thheller 2020-10-24T20:03:05.117600Z

@afhammad node builds don't bundle their dependencies by default since node can just load them from node_modules directly. so either just include the node_modules whereever you are running it or post process the file with something like https://github.com/vercel/ncc

afhammad 2020-10-24T20:04:11.118Z

got it, thanks

nivekuil 2020-10-24T21:29:46.118100Z

is is possible to target specific node￱_￱modules dependencies to be compiled with :advanced? like:js-provider :closure but for specific modules, not the whole app