This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-17
Channels
- # aleph (2)
- # announcements (20)
- # aws (43)
- # aws-lambda (5)
- # babashka (9)
- # beginners (231)
- # calva (4)
- # cider (12)
- # cljdoc (8)
- # cljsrn (3)
- # clojure (47)
- # clojure-europe (5)
- # clojure-nl (4)
- # clojure-spec (41)
- # clojure-uk (47)
- # clojuredesign-podcast (3)
- # clojurescript (20)
- # cryogen (3)
- # cursive (4)
- # data-science (2)
- # datomic (15)
- # emacs (4)
- # fulcro (21)
- # jackdaw (6)
- # jobs (1)
- # joker (13)
- # juxt (8)
- # kaocha (10)
- # malli (7)
- # off-topic (29)
- # pathom (11)
- # re-frame (19)
- # reagent (3)
- # reitit (26)
- # remote-jobs (8)
- # schema (2)
- # shadow-cljs (112)
- # spacemacs (1)
- # tools-deps (49)
- # vim (2)
- # xtdb (7)
Hello. I am attempting to write a macro in cljs using shadow-cljs. https://gist.github.com/samedhi/f8c6aa8eb5ca435ffac808da27e85978 .
I have sidestepped most of the issues with referring to clojurescript ns by using their full names rather than using :as
and a symbols to the respective ns.
However, I am just not sure how to refer to a a NPM package "firebase-admin" from within my cljs macro.
Two questions:
1. Is there a better way of referring to cljs ns from my macro? Some seem to work and some don't, quick summary on why that is?
2. How do I refer to node packages from a clojure macro? In my case I am attempting to use ["firebase-admin" :as admin]
, but that does not work within my clj macro namespace.
End goal is to have a testing helper that lets me write expressions like the following.
(deftest-function create-example-with-macro-test
sut/create-example-cloudfx
[doc1 "messages/message-1" {"foo" "bar"}
doc2 "messages/message-2" {"foo" "baz"}]
(t/is (not= (.get doc1 "foo") (.get doc1 "foo")))
(t/is (not= "bar" (.get doc1 "foo")))
(t/is (not= "baz" (.get doc2 "foo")))
;; And presumably also testing some side effect of the sut/create-example-cloudfx running
)
@samedhi you can't reference JS namespaces directly in macros without using resolve-var
. the common thing I recommend is doing something like (ns foo.bar (:require ["thing" :as x]))
(def thing-you-need-in-macro x/foo)
also follow https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html
I'd advise moving most of it out into a helper function and only use the macro to generate the boilerplate needed
@thheller just by chance do you remember how you added support for :default keyword into your ns analyze phase? as documented here: https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages
I tried to look into shadow-cljs sources, but I don’t see any explicit mention how it is handled
when I try to pass shadow-cljs ns-form with :default
into vanilla cljs analyze it gives me “Only :as, :refer and :rename options supported in :require / :require-macros…”
@darwin I replaced the ns
parser with one that I wrote. https://github.com/thheller/shadow-cljs/blob/5ee9efcb7cae4ec558227bd04aa9d083c8aefc7c/src/main/shadow/build/compiler.clj#L169
the feature was kinda rejected though: https://clojure.atlassian.net/browse/CLJS-2376
ok, thanks, are you aware of anything else like :default which would cause error in ana/analyze in normal cljs?
if it is just :default, I can easily preprocess ns-forms before feeding them into cljs analyze
I'm messing about with yarn link
to test some third party library feature that's not pushed to npm yet. Am I right to conclude shadow-cljs doesn't deal with links?
made a symbolic link to the directory node_modules
but still getting
Search in:
/Users/baruchberger/work/gsv/node_modules
You probably need to run:
npm install
See:
so does /Users/baruchberger/work/gsv/node_modules/deck.gl/package.json
exist or not?
I think http://deck.gl was one of those packages the closure compiler doesn't like? its from uber right?
If I want to develop a library in shadow-cljs that uses an NPM package, is there simply no way to distribute this as a jar that can be used in a non-shadow-cljs project?
> Please note that currently only `shadow-cljs` has a clean automatic interop story with `npm`. That may represent a problem for users of your libraries using other tools. You may want to consider providing a CLJSJS fallback and/or publishing extra documentation for `webpack` related workflows.
So what does this mean in practice? Either I create a CLJSJS package in which case the business value of shadow-cljs diminishes or I distribute some kind of setup instructions with the library?
Yes, it's from uber, huge repo. https://github.com/uber/deck.gl/blob/master/package.json they seem to work with lerna
for sub modules.
@simongray there is a trick, you can add a deps.cljs
in your source root, and there you can declare NPM deps, example: https://github.com/wilkerlucio/pathom-viz/blob/master/src/core/deps.cljs
them, if you use the CLJS library with Shadow, it will automatically install those deps
oh, sorry, just noticed you asked for non-shadow, in that case will be hard considering that no other cljs build tools have proper support for NPM directly
Exactly. Hm, I think will investigate making a CLJSJS package instead then and probably just stick with figwheel.
@simongray yeah you pretty much have to create a matching cljsjs package. if you configure things correctly shadow-cljs will use npm directly and the others will fall back to cljsjs
or you can skip the cljsjs and provide manual instructions for people using webpack+cljs
aynone seen this error? “Requested module does not have an export <name>” it gets printed afte “Closure compilation failed with 2 errors”
I’m trying to convert react-three-fiber examples into cljs with shadow-cljs, and wanted to require their shader js files as is by following https://shadow-cljs.github.io/docs/UsersGuide.html#_requiring_js (using absolute path)
I put this file[1] on classpath and then require it as ["/resources/shaders/Backface" :as BackfaceMaterial]
, shadow-cljs then complains
`
[1] https://github.com/react-spring/react-three-fiber/blob/master/examples/src/resources/shaders/Backface.js
ShaderMaterial is defined here: https://github.com/mrdoob/three.js/blob/dev/src/materials/ShaderMaterial.d.ts#L34
since it doesn't understand the way shadow-cljs processes JS it seems three as a commonjs dependency
but .. given that you can't provide type hints in JS for inference it'll likely have problems with :advanced
btw. in the meanwhile I tried to attach Intellij Java debugger to the shadow-cljs process, I was able set breakpoints and break on them but no debug inspections were possible, it always displayed “Debug information is inconsistent”
then I followed your “Hacking” docs and was able to replace some shadow-cljs sources with my copy, so I was able to work around it
I wonder if it is not related to the way how you prioritize “The shadow-cljs compiler ensures that things on your source paths are compiled first”
btw. this is my first real shadow-cljs project and I’m impressed with the whole experience. Kudos!
I still seem to be unable to make it work. Cannot access Three.something
, because it generates Three.default.something
instead of Three.something
in js
this is result from plain require: https://gist.github.com/darwin/d0f1f7853f742aa9544034a9585fee4d
thanks a lot, I wouln’t be able to solve this - I’m unfamiliar with all these details of JS modules
I almost wanted to hack it by storing three
object in some global js var in cljs code and access it in the js file
yep, now the generated code looks the same (just decorated to prevent clashes) not sure about advanced mode tough
but it is dirty to go explicitely via globals, so I’m happy that at least one form of import worked 🙂
I decided to give the AdoptOpenJDK 13 a try and it seems to work for the most part. But there are some bizarre errors that pop up intermittently during compilation. It seems that it always involves clojure.lang.KeywordLookupSite$1
.
Example 1:
------ WARNING #1 - :invalid-arithmetic ----------------------------------------
File: /home/p-himik/dev/git/ensemble/src/hgs/strayhorn/named_expressions/views.cljs:26:5
--------------------------------------------------------------------------------
23 | (cst/split model ",")
24 | [])))
25 | roman-on-change #(on-change (cst/join "," %))]
26 | (fn [_ & {:keys [error]}]
-----------^--------------------------------------------------------------------
cljs.core/unsafe-bit-and, all arguments must be numbers, got [#object[clojure.lang.KeywordLookupSite$1 0xae194d44 "clojure.lang.KeywordLookupSite$1@ae194d44"] number] instead
--------------------------------------------------------------------------------
27 | [rc/v-box
28 | :gap "10px"
29 | :children [[rc/horizontal-bar-tabs
30 | :tab-style tabs-style
--------------------------------------------------------------------------------
Example 2:
------ ERROR -------------------------------------------------------------------
File: jar:file:/home/p-himik/.m2/repository/com/cognitect/transit-cljs/0.8.256/transit-cljs-0.8.256.jar!/cognitect/transit.cljs:295:6
--------------------------------------------------------------------------------
292 | ([tag-fn rep-fn str-rep-fn]
293 | (write-handler tag-fn rep-fn str-rep-fn nil))
294 | ([tag-fn rep-fn str-rep-fn verbose-handler-fn]
295 | (reify
------------^-------------------------------------------------------------------
Syntax error macroexpanding cljs.core/deftype.
ClassCastException: clojure.lang.KeywordLookupSite$1 incompatible with clojure.lang.IFn
clojure.spec.alpha/spec-impl/reify--2059 (alpha.clj:923)
Example 3:
------ ERROR -------------------------------------------------------------------
File: /home/p-himik/dev/git/ensemble/src/hgs/ella/score_details/sequences/views.cljs:297:3
--------------------------------------------------------------------------------
294 | :children (mapv (fn [w] [rc/label :label w]) issues)]])
295 |
296 | (defn question-panel [_game-id changeset-id q args]
297 | (let [{:keys [events subs]} args
---------^----------------------------------------------------------------------
Syntax error macroexpanding cljs.core/nil?.
ClassCastException: clojure.lang.KeywordLookupSite$1 incompatible with clojure.lang.IFn
Couldn't find anything on the warning about unsafe-bit-and
.
But the warning about ClassCastException
is also mentioned here: https://github.com/thheller/shadow-cljs/issues/443 As well as OpenJ9 (aka AdoptOpenJDK I believe).
I do embed shadow-cljs, but I definitely don't interact with the REPL in any way when these issues occur.
re: "...as OpenJ9 (aka AdoptOpenJDK..." - iiuc, adoptopenjdk does have openj9 builds, but adoptopenjdk != openj9 adoptopenjdk also provides openjdk builds or may be i misunderstand?
Yes, in my experience unless it's a simple project, is close to impossible to run shadow-cljs on OpenJ9. These errors happen sometimes, specially when I'm using macros or core.async
never tried openj9. do other clojure apps work? don't know why shadow-cljs would break. its just normal clojure.
Yes, everything works fine. I remember that in the past I opened another bug on shadow because of OpenJ9 (something about detecting if a file was stale, if I'm not mistaken)
To be honest, I did not try other CLJS implementations like Figwheel, so it can be a ClojureScript compiler issue too...
I'm curious if anyone would know of this to be a problem.
(defmacro slurp [file]
(clojure.core/slurp (io/file (io/resource file))))
(ns ezmonic.e-data
(:require [cljs.reader :as reader])
(:require-macros [ezmonic.util :refer [slurp]]))
(defonce data
(reader/read-string (slurp "number-to-word-tree.edn")))
I'm using that to read a I would not expect it to have to parse the EDN when going to/from the background though. I would only expect that on startup, no?
also consider reading https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html