This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-20
Channels
- # announcements (16)
- # babashka (104)
- # beginners (77)
- # bristol-clojurians (1)
- # calva (3)
- # chlorine-clover (50)
- # cider (19)
- # clojure (73)
- # clojure-australia (1)
- # clojure-europe (37)
- # clojure-france (3)
- # clojure-nl (3)
- # clojure-norway (13)
- # clojure-spec (21)
- # clojure-uk (79)
- # clojurescript (225)
- # conjure (102)
- # cursive (11)
- # datascript (1)
- # datomic (1)
- # defnpodcast (1)
- # events (3)
- # figwheel-main (2)
- # fulcro (49)
- # ghostwheel (10)
- # helix (1)
- # kaocha (17)
- # leiningen (10)
- # meander (1)
- # off-topic (26)
- # other-lisps (3)
- # pathom (5)
- # re-frame (40)
- # reagent (6)
- # reitit (33)
- # shadow-cljs (107)
- # testing (3)
- # tools-deps (68)
- # xtdb (16)
- # yada (3)
I have a question regarding to clojure.spec, how is it integrated with shadow-cljs? can It have a different run command? like npm test
? how do you setup the files with it? is there an example ?
The question’s a bit confusing, that’s not really how spec works - but it exists for cljs in the same way as it does for clojure.
I’ve been working with it over the last few days - just require cljs.spec.alpha
and you’re good to go
This is a good general reference - https://clojure.org/guides/spec
yeah, absolutely
it’s just a library to allow declarative specification of data structures - it’s used a lot in testing, but also for validation of incoming data (in my case)
check out the guide I linked above
@U012XM1CH39 clojure.spec.alpha
is a code library for adding assertions to your code. it gets included in your bundle by default
Hello.
Just a question regarding cider and shadow-cljs.
Is there a way to automatically start my app and directly tell cider-connect-sibling-cljs
to use my unique :app
alias ? I have my dir-locals.el
on this project with the basic settings:
((nil . ((cider-default-cljs-repl . shadow)
(cider-shadow-cljs-default-options . "app"))))
it might be a good question for #cider . I’m not sure, and I know that thheller doesn’t use Emacs or CIDER
@U4YGF4NGM yeah i supposed it too. but maybe some dev using shadow-cljs have a tip for me.
I’ve worked around this for now, but just to throw it out there - it looks like shadow (or cljs in general?) doesn’t support -
characters in namespaces when referencing namespaced keywords (i.e. when using spec)
typically my-ns
becomes my_ns.cljs
, but otherwise is referenced everywhere as e.g. (my-ns/my-fn …)
but when namespacing keys, :my-ns/mykey
doesn’t work, it has to be :my_ns/mykey
oh sorry - huge omission on my part - this is only an issue when running the node-test
target - it works fine in the REPL
@andrew.heywood can you explain what “doesn’t work” means?
I should have threaded this too, sry - it’s easy enough to work around, but if it’s a legit issue I can submit an actual report with proper repro etc. Just thought I’d see if it was an obvious known issue
haha sorry, of course
basically ‘spec not found’:
I’m trying to upload shots here but something’s crapping out sry
/.shadow-cljs/builds/test/dev/out/cljs-runtime/cljs/spec/alpha.cljs:71
(throw (js/Error. (str "Unable to resolve spec: " k))))
yeah, I’m trying to simplify it down because it’s all slightly sensitive in it’s current form
ok this is confusing me. when I recreate it with a trivial example it works fine, but it works because now I can reference the ns properly:
:lambda.my-spec/myspec
previously, that failed, and I could only reference my spec as :
I switched between the repl and the test runner, and had a server running the whole time, and probably renamed the namespace… maybe some wires got crossed and I hit an edge case
I don’t think so?
going back to the original code that I just fixed, and if it re-breaks, I’ll dm it to you
no I wasn’t
nope, it’s all working fine now, back in the state that was previously broken. It definitely was broken, but I’m very sure that after renaming the ns, the REPL was only accepting :my_ns/keyword
whereas the test runner expected :my-ns/keyword
. I was simultaneously running:
shadow-cljs watch :test
shadow-cljs watch :repl
node dist/node/repl.js
idk. I’m glad it’s not a real issue though 😄
ah so you renamed the namespace. that’s valuable info. not sure what to do with it tho 😛
yeah, I can’t remember why/when exactly, it was this morning, I’ve been on the REPL all day. But I remember messing with stuff this morning because I thought it was very weird that I had to reference my namespaced keyword with an underscore instead of a dash
and I’ve been generating from specs all day using an underscore for a ns that has a dash in it. and when I went over to the tests, nothing worked.
I’ve figured it out (I think)! When referencing a kw, you have to require the ns separately. So it was all red-herrings - what’s actually fixed the problem is requiring the spec’s namepsace in the consuming namespace
i.e.
(s/gen :lambda.leads-spec/lead)
will only work if you also require
[lambda.leads-spec :as ls]
Hello. Should the build-option :print-fn :none
with :target :browser
result in my not seeing println
messages in the browser console? I’ve tried setting this locally is dev mode and there doesn’t seem to be any effect. Somewhat ironically, I was only checking it disabled printing in dev mode so that I can be sure that I’ve got the correct setting to use in my release build. I’m now wondering if it is overridden in dev when the shadow-cljs websocket is in use. Anyway, I’d like to disable printing in prod / release builds… so does anybody know if this option should still work, because it’s not mentioned in the current documentation, but I can see it in the source code?
@scottlowe I’m not sure, but you can test this pretty quickly by doing a release build
if you’ve already got a dev watcher running, in another terminal run:
shadow-cljs release <build>
and do a hard refresh of the page you’re developing inHeh. I should have done that initially, but we have a complicated setup (don’t ask!). Was being lazy. Have built in release mode now and it doesn’t seem to work.
Perhaps this is why: https://github.com/thheller/shadow-cljs/blob/fda0dc02d8199d5475a3ab42a3d2fd247c237235/src/main/shadow/build.clj#L306-L308
yeah print-fn can't be disabled because otherwise you always get an exception for anything that prints
is it possible to use :module-hash-name
with a :node-script
target ? I couldn’t get it to work but was just wondering if this is possible
no. what would be the point? do you want to guess the name of the script you want to execute?
lol no - it’s more of a versioning thing but I realised it’s a bit of a dumb idea I am using the commit hash instead
ah so you renamed the namespace. that’s valuable info. not sure what to do with it tho 😛
Is there anything special I need to do to get clojure.spec.gen.alpha
up and running in a CLJS project with shadow?
I’ve followed https://clojure.org/guides/spec#_generators and added org.clojure/test.check
to our dependencies, but when I invoke (gen/generate (s/gen int?))
in the repl I get something like a deref error. (`[clojure.spec.gen.alpha :as gen]` & [cljs.spec.alpha :as s]
)
top of my head, having just been through this, you need to require clojure.test.check.generators
i.e. require it in that ns, even though you’re not referencing it directly
!!! Thanks @andrew.heywood you just saved my day (actually my evening 😄 )
took me a while to find that one. I’ve definitely sunk a couple of wasted hours into cljs/shadow/spec integration this week
well worth it overall though!
Yes, I added specs to a hughe part of my lib but what gives if it breakes my tests because of my hand build test data 😄 I’m so excited about this right now. Thanks again @andrew.heywood The future is bright 😎
@thheller I’m seeing some strange behaviour with shadow-cljs :dev-http server redirection. I’m using reitit-frontend so I can switch hashtag routing on or off. Looking at localhost:8280/lung and localhost:8280/lung/centre - these URLs both work with internal reitit navigation, but on address bar navigation /lung works but not /lung/centre. Hashtag versions work from the address bar as expected. I’m concluding that the dev servers can only redirect single-level addresses when typed in back to index.html. So /lung gets redirected to /index.html, but /lung/centre doesn’t. It seems strange, because if there were no redirection happening at all, I would expect the /lung address to fail too. The /lung/centre address gives a 404 in the browser.
@grumplet the :dev-http
servers NEVER redirect. that functionality does not exist. unless of course you use a custom handler that does that. the built-ins don't
I’ve figured it out (I think)! When referencing a kw, you have to require the ns separately. So it was all red-herrings - what’s actually fixed the problem is requiring the spec’s namepsace in the consuming namespace
That’s truly strange then. The docs do say they fall back to index.html when a resource is not found.
I just started using shadow-cljs, and trying to get it set up with cursive. I also just started blogging, and wrote a https://ghufran.posthaven.com/setting-up-a-reagent-clojurescript-project-with-shadow-cljs-and-cursive trying to detail the steps - the documentation was super helpful, so thanks to everyone who contributed to that! Take a look at the post if you get a chance - if you're new to shadow-cljs like me, let me know if anything is unclear, or could be improved, if you're an experienced user, let me know if I'm just doing it wrong... 🙂
hi @ghufran, I followed this guide and it helps me a lot, you can see if you find something useful
I actually came here to ask - everything seems to be compiling fine, and will show up correctly when I refresh, but the 'hot reloading' doesn't seem to be working - I thought it came 'automatically' with shadow-cljs watch :build_name ? I tried using a different browser and incognito mode in case I had a chrome extension that was interfering, but still not working so far. Any pointers on things I should check?
@ghufran for Cursive I recommend running shadow-cljs pom
and importing the pom.xml
as a project https://shadow-cljs.github.io/docs/UsersGuide.html#_cursive
if you want hot-reload you need to configure a function to call that does the actual re-rendering. see :dev/after-load
https://shadow-cljs.github.io/docs/UsersGuide.html#_hot_code_reload
https://code.thheller.com/blog/shadow-cljs/2019/08/25/hot-reload-in-clojurescript.html
I saw that, but wasn't sure if that was because cursive didn't handle deps then, or because there was some other advantage
> Go to and select node_modules > shadow-cljs-jar > bin > shadow-cljs.jar, then click "open"
you also might want to read https://github.com/thheller/shadow-cljs#quick-start
Wow, totally missed that! - the current "beginner guide" link goes to a blog post, might be best to just make that link to this instead!
I have a simple test like this, which raises an exception when the test is run: foo_test.foo is not a function
I have a simple test like this, which raises an exception when the test is run: foo_test.foo is not a function
The broader context is that I’m trying to use https://github.com/alexanderjamesking/spy to mock some functions.
Hi all, I'm a long time Clojure dev, but first time venturing into Clojurescript. I am struggling to get a skeleton deps.edn + shadow-cljs project up and running. I hate to dump a bunch of file contents to the channel, but I honestly can't even figure out a thread to pull on.
Here is my deps.edn
{:src ["paths"]
:deps {org.clojure/clojurescript {:mvn/version "1.10.758"}
reagent {:mvn/version "1.0.0-alpha2"}}
:aliases {:shadow-cljs
{:extra-deps {thheller/shadow-cljs {:mvn/version "2.8.8"}}
:main-opts ["-m" "shadow.cljs.devtools.cli"]}}}
and my shadow-cljs.edn
{:deps true
:dev-http {8080 "target/"}
:builds {:app {:target :browser
:output-dir "target/"
:asset-path "."
:modules {:main {:entries app.core}}
:devtools {:after-load app.core/main}}}}
when I call clj -A:shadow-cljs compile app
I get the following exception.
Execution error (IllegalArgumentException) at shadow.build.js-support/eval11018$loading (js_support.clj:1).
No matching field found: getRegisteredGroups for class com.google.javascript.jscomp.DiagnosticGroups
If anybody can spot what I am doing wrong, I would greatly appreciate it.@erp12 you are using mismatched versions, see https://shadow-cljs.github.io/docs/UsersGuide.html#failed-to-load
Thanks @thheller! So if I am reading this correctly, if looks like: shadow-cljs 2.9.8 is compatible with clojurescript 1.10.758. Changing that allows me to load.
Although the build starts, I get a build failure no output for id: [:shadow.build.classpath/resource "goog/base.js"]
Is that still a deps and/or versioning problem?
well your :entries
should be [app.core]
. dunno why the spec allows a lone symbol there.
Ah forgot to mention that I noticed that and fixed it after getting the versions correct.
I had to go offline for a bit and when I came back i couldn't reproduce the error. I'm up and running now. Thanks a million for your help!
you might want to read https://code.thheller.com/blog/shadow-cljs/2017/11/18/the-many-ways-to-use-shadow-cljs.html
maybe try adding these exclusions to the clojurescript dep, but full trace would help.
:exclusions
[com.google.javascript/closure-compiler-unshaded
org.clojure/google-closure-library
org.clojure/google-closure-library-third-party]