Fork me on GitHub
#clojurescript
<
2018-06-02
>
otwieracz05:06:37

I am playing with shadow-cljs and I am trying to use RandomComponent from npm.

otwieracz05:06:31

I've choosen react-menu-bar. After installing it via npm npm install react-menu-bar

otwieracz05:06:35

I have included it in my ns: (:require ["react-menu-bar" :as menu])) - but now the compilation is raising an error:

otwieracz05:06:50

[:app] Configuring build.
[:app] Compiling ...
[:app] Build failure:
errors in file: /home/otwieracz/dev/clojure/shadow-cljs-test/node_modules/react-menu-bar/src/MenuBar.jsx
{:js-str-offsets [], :js-esm false, :js-imports [], :js-invalid-requires [], :goog-provides [], :js-language "es3", :goog-module nil, :js-warnings [], :resource-name "node_modules/react-menu-bar/src/MenuBar.jsx", :js-requires [], :js-err
s [{:line 34, :column 7, :message "primary expression expected"}], :goog-requires [], :tag :shadow.build.npm/errors}
ExceptionInfo: errors in file: /home/otwieracz/dev/clojure/shadow-cljs-test/node_modules/react-menu-bar/src/MenuBar.jsx
        clojure.core/ex-info (core.clj:4739)
        clojure.core/ex-info (core.clj:4739)
        shadow.build.npm/get-file-info* (npm.clj:527)
        shadow.build.npm/get-file-info* (npm.clj:435)
        shadow.build.npm/get-file-info (npm.clj:563)
        shadow.build.npm/get-file-info (npm.clj:560)
        shadow.build.npm/find-resource (npm.clj:652)
        shadow.build.npm/find-resource (npm.clj:612)

otwieracz05:06:17

What am I doing wrong?

thheller06:06:56

@slawek098 you are doing nothing wrong. it is very bad form for npm packages to contain .jsx code and proper packages do not do that. react-menu-bar has not been updated for years https://github.com/ahutchings/react-menu-bar and has barely any downloads at all https://www.npmjs.com/package/react-menu-bar. so you probably best stay away from it. the package basically assume you are using webpack which is unfortunate.

thheller06:06:13

the quality of some npm deps is quite bad

otwieracz06:06:34

I didn't noticed that

otwieracz07:06:56

What is the valid approach to react-bootstrap with reagent in shadow-cljs? All guides I am seeing suggest using cljsjs/react-bootstrap so it's not applicable for shadow-cljs AFAIK.

jerger_at_dda10:06:16

Hi there ... do somebody know a good cljs lib for templating (like selmer is for clj)? I'm not going to produce html so generation (like enlive) will not work for me ...

whilo11:06:45

selmer looks portable with a decent amount of work

whilo11:06:02

mostly data and java reader related stuff that needs to be ported

whilo11:06:26

@jerger_at_dda i have recently used selmer to render LaTeX, which was pretty cool

jerger_at_dda11:06:30

Porting was my first thought also - but I found some java related stuff like commons-codec in selmer dependencies. So I'm not really sure about portability ...

whilo11:06:37

@jerger_at_dda i think it is only used here

whilo11:06:42

i have similar cross-runtime code for hashing and encoding here https://github.com/replikativ/hasch/

whilo11:06:42

not that you need it, but hex encoding and crypto hashes are readily available in cljs/js

whilo11:06:02

so the apache-commons part should be covered

whilo11:06:09

i guess that converting the date types will be a bit of work

whilo11:06:29

@jerger_at_dda but if you try to port it, i am willing to help if you get stuck

jrbrodie7713:06:07

What's the idiomatic way, with lein and cljs to have a value change between dev and deploy? I have a URL that needs to change (from localhost to live site) on deploy. Can I use :resource-paths for some trickery?

bupkis14:06:07

Look into Google Closure defines

mfikes15:06:39

FWIW, the ClojureScript compiler has support for Google Closure defines: https://clojurescript.org/reference/compiler-options#closure-defines

jrbrodie7722:06:25

Thanks guys! I'll check it out. What I'm doing now, which is slightly cheesy, it to have a namespace defined in two directories. Each build profile points to a different directory, so I can switch out vars depending on profile.

jerger_at_dda14:06:53

@whilo Thanx for your offer. But as discussed with yogthos (see https://github.com/yogthos/Selmer/issues/173) I tend to do some regex magic by my own over trying a full selmer port.

lilactown21:06:36

can anyone explain what I’m doing wrong?

lilactown21:06:05

core.clj:

(ns jsx.core)

(defmacro compile [hiccup]
  '(+ 1 2 3))

lilactown21:06:16

core.cljs:

(ns jsx.core
  (:require-macros jsx.core))

(js/console.log (compile [:div nil "hello"]))

(defn ^:export init []
  (println "init"))

lilactown21:06:30

I’m getting a compile error: Can't take value of macro jsx.core/compile

darwin21:06:19

try (:require-macros [jsx.core :refer [compile]])

👏 4
lilactown21:06:51

o_O OK that worked

lilactown21:06:38

strange error message

lilactown21:06:00

is it possible to use #js in a macro?

darwin21:06:44

not directly, #js is a reader thing, “tagged literal” AFAIK

darwin21:06:37

AFAIK you should be able to construct it in your macro, doing what reader would do (`JSValue` is a clojure thing I believe) but this sounds like too much trouble, I would recommend emitting js-obj and similar function calls for doing what you would like to do via #js

lilactown22:06:44

yeah I ended up just emitting clj->js

lilactown22:06:21

I have another semi-related question though: how do I define my own tagged literals?

lilactown22:06:29

I tried creating a data_readers.clj with {jsx/t jsx.core/compile} and it’s not working

darwin22:06:59

not sure about data_readers, it should be possible somehow, but I would recommend reconsidering clj->js, a lot of work will be done at runtime, which is not necessary

darwin22:06:16

when using js-obj, compiler will emit “static” javascript

darwin22:06:34

try (.toString (fn [] (js-obj "p" 42 "q" 43))) in your favorite cljs repl

lilactown22:06:19

yeah the deeper issue, I realized, is I might be emitting a var or a map

lilactown22:06:41

so I can’t always convert the obj at compile time

lilactown22:06:29

I can probably add an optimization later that if a literal map is passed in to generate js-obj instead

domkm22:06:05

Using npm-deps and graphql, I get Uncaught Error: Undefined nameToPath for graphql when requiring it. Anyone know why or how to fix it?

lilactown22:06:47

I had a hell of a time getting graphql to work with the closure compiler

lilactown22:06:08

I had to upgrade to a newer version than what cljs includes

domkm22:06:32

Hmm, okay, but it worked otherwise?

domkm22:06:25

Cool, thanks

lilactown22:06:01

hrm register-tag-parser! doesn’t seem to work for what I want 😭

domkm23:06:08

@lilactown Updated to [com.google.javascript/closure-compiler-unshaded "v20180506"] but no luck. What version are you using?