Fork me on GitHub
#shadow-cljs
<
2019-10-12
>
papachan15:10:29

@thheller wow thats a great help Thomas ! i was playing with macros a time ago

๐Ÿ‘ 1
papachan15:10:55

BTW do you have an idea why i cannot compile this macro with clojurescript?

(defmacro str->int [s]
  `(js/parseInt s))

thheller15:10:55

@papachan define "cannot compile". When I read "cannot compile" I try this and it compiles just fine

$ clj
Clojure 1.10.1
(defmacro str->int [s]
  `(js/parseInt s))
#'user/str->int

thheller15:10:58

so the macro is technically fine. just something in your use isn't. also why is this a macro and not a regular defn? no point in making this a macro?

papachan15:10:48

hmm ok let me try something again

papachan15:10:52

ah i see now

papachan15:10:56

its a warning

papachan15:10:09

18 |   (js/console.log (str->int "1"))

-------------------------^------------------------------------------------------

Use of undeclared Var server.macros/s

BUILD-WARNING in server/main.cljs at [18:19]
	Use of undeclared Var server.macros/s

thheller15:10:46

so the macro expanded to something using server.macros/s

thheller15:10:46

oh right. I didn't see it at first

thheller15:10:51

your macro is indeed wrong

thheller15:10:23

(defmacro str->int [s]
  `(js/parseInt ~s))

thheller15:10:50

otherwise the macro expands to (js/parseInt server.macros/s) since it is just expanding the regular s symbol

thheller15:10:08

buy you want to use the actual value that was passed to the macro instead

thheller15:10:54

thats why ~s (look up unquote)

papachan22:10:17

oh yeah you are right, its working pretty well now ! ๐Ÿ™‚

papachan22:10:38

thank for your link reference, i will read it ๐Ÿ™‚

thheller15:10:31

but seriously. this shouldn't be a macro in the first place ๐Ÿ˜‰

erwinrooijakkers18:10:55

I try to run shadow with an npm package

erwinrooijakkers18:10:08

But when I add it and import it in the require

erwinrooijakkers18:10:24

package.json:

{
  "name": "zenroom-example",
  "version": "0.0.1",
  "private": true,
  "devDependencies": {
    "shadow-cljs": "2.8.64"
  },
  "dependencies": {
    "core-js": "^3.2.1",
    "core-util-is": "^1.0.2",
    "create-react-class": "15.6.3",
    "react": "16.8.6",
    "react-dom": "16.8.6",
    "regenerator-runtime": "^0.13.3",
    "zenroom": "0.9.5"
  }
}

erwinrooijakkers18:10:28

I get the message:

erwinrooijakkers18:10:34

The required JS dependency "core-util-is" is not available, it was required by "node_modules/readable-stream/lib/_stream_readable.js". Note: this only happens when I change a file and shadow-cljs pushes changes to the browser.

erwinrooijakkers18:10:22

When doing npm i core-util-is or npm i --save core-util-is the error remains

erwinrooijakkers18:10:30

Only way to avoid it is by removing the [zenroom] import in the view

erwinrooijakkers18:10:40

(ns zenroom-example.views
  (:require
   [re-frame.core :as re-frame]
   [zenroom]
   [zenroom-example.subs :as subs]))

erwinrooijakkers18:10:47

Any solution for this?

erwinrooijakkers18:10:49

From the documentation this should be the way to do an npm import

erwinrooijakkers19:10:03

Via lein dev I see this: The required JS dependency "readable-stream/writable.js" is not available, it was required by "node_modules/stream-browserify/index.js".

erwinrooijakkers19:10:12

You probably need to run:
  npm install readable-stream/writable.js

erwinrooijakkers19:10:20

npm install readable-stream/writable.js
npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t 
npm ERR!
npm ERR! ERROR: Repository not found.

erwinrooijakkers19:10:51

Code in readable-stream/writeable.js

module.exports = Stream;

var EE = require('events').EventEmitter;
var inherits = require('inherits');

inherits(Stream, EE);
Stream.Readable = require('readable-stream/readable.js');

erwinrooijakkers19:10:07

Try removing node_modules and package.json apparently

erwinrooijakkers19:10:37

The required JS dependency "readable-stream/writable.js" is not available, it was required by "node_modules/stream-browserify/index.js".

thheller19:10:00

@erwinrooijakkers I don't know what zenroom is but it looks like it just isn't supposed to run in the browser?

thheller19:10:41

it also seems dead with 12 weekly downloads? https://www.npmjs.com/package/zenroom

thheller19:10:59

and there is a deprecated message on the repo https://github.com/DECODEproject/zenroomjs (and it is archived)

thheller19:10:18

and it appeared the package used wasm, which shadow-cljs currently doesn't support

erwinrooijakkers19:10:20

Aha thanks! ๐Ÿ™‚

erwinrooijakkers19:10:26

It does work in the browser there are examples on https://dev.zenroom.org/demo/

erwinrooijakkers19:10:52

Itโ€™s not dead, itโ€™s just born. The npm package is indeed refering to deprecated repo

erwinrooijakkers19:10:05

It does use wasm yes

erwinrooijakkers19:10:44

I do see an error exception: abort("abort(\"both async and sync fetching of the wasm failed\"). Build with -s ASSERTIONS=1 for more info."). Build with -s ASSERTIONS=1 for more info. when running

erwinrooijakkers19:10:01

Anyway I get an object thatโ€™s accessible now in the browser, Iโ€™ll try to use that

erwinrooijakkers19:10:10

Thanks for the feedback! I appreciate it

erwinrooijakkers19:10:49

Hmm errors like failed to load shadow.module.app.append.js TypeError: "module$node_modules$zenroom$index.script is not a function". So this approach is not the right one. I wonder how to run it in a browser at all ๐Ÿ™‚

erwinrooijakkers19:10:21

Ah this helped:

(:require [zenroom :default zenroom])

erwinrooijakkers19:10:07

Now (js/Object.getOwnPropertyNames zenroom) lists all its properties scriptkeysconfdataprintsuccessverbosityzenroom_execzencode_execerrorinitreset__debug

erwinrooijakkers19:10:56

So something is working

erwinrooijakkers19:10:20

But the wasm error uncaught exception: abort("abort(\"both async and sync fetching of the wasm failed\"). Build with -s ASSERTIONS=1 for more info."). Build with -s ASSERTIONS=1 for more info. might be due to limitations of shadow-cljs?

thheller20:10:25

@erwinrooijakkers wasm is not supported, so you are not going to get this running with shadow-cljs

erwinrooijakkers16:10:00

I see. I also see the shadow-cljs issue related to wasm: https://github.com/thheller/shadow-cljs/issues/397. What makes it difficult to use wasm from shadow-cljs? I mean the npm package uses it, not shadow-cljs itself?

thheller16:10:09

shadow-cljs bundles the npm package. it doesn't know how to bundle .wasm. if you load wasm manually it all works completely fine, there just is no "standard" for packaging .wasm yet and I haven't had the time to implement it the way webpack did

erwinrooijakkers16:10:26

Ah okay so I can include the wasm file

erwinrooijakkers16:10:57

And for including an npm package in a plain javascript project it does work?

thheller16:10:31

I don't know how to explain this

erwinrooijakkers16:10:19

I look up information on how wasm is bundled in npm

thheller16:10:23

.wasm is just a file. it is normally loaded at runtime via some JS calls

thheller16:10:46

it basically does a HTTP to load it, just like loading a .css file or so

thheller16:10:26

but the file somehow needs to get out of node_modules/whatever/foo.wasm to your public/wasm/foo.wasm or so

thheller16:10:36

so that you can load /wasm/foo.wasm

erwinrooijakkers16:10:45

And that is not a standard location?

thheller16:10:01

how that happens isn't defined in any standard and there are no conventions for it

thheller16:10:20

and webpack instead just inlines the complete file b64 encoded

thheller16:10:28

so it doesn't need to do an extra request

thheller16:10:43

that is the part shadow-cljs doesn't support currently

thheller16:10:11

but your npm library likely expects it to work like that or something

thheller16:10:14

I don't know

thheller16:10:24

haven't looked at the source

thheller16:10:48

it likely either does a require("./foo.wasm") or import("./foo.wasm")

erwinrooijakkers16:10:59

Thanks this clears things up!

thheller16:10:03

and shadow-cljs only supports loading actual .js files