shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
dmrd 2021-04-09T05:04:11.484200Z

Is there a way to filter down tests somehow / only run for a particular file? This issue suggests no: https://github.com/thheller/shadow-cljs/issues/322 Currently simply running them all using a test target:

:test
           {:target    :node-test
            :output-to "out/node-tests.js"
            :ns-regexp "-test$"
            :autorun   true}

thheller 2021-04-09T06:33:18.485100Z

@ritt93 for :autorun true no. otherwise yes. see node out/node-tests.js --help

flowthing 2021-04-09T07:20:08.486800Z

ClojureScript compilation fails for me with shadow-cljs 2.12.2 and ClojureScript 1.10.844. I get a bunch of errors like this:

Multiple files failed to compile.
aborted par-compile, [:shadow.build.classpath/resource "re_frame/interop.cljs"] still waiting for #{reagent.core}
{:aborted [:shadow.build.classpath/resource "re_frame/interop.cljs"], :pending #{reagent.core}}
Oddly, 2.12.1 works.

thheller 2021-04-09T08:01:20.488600Z

@flowthing is this in a :browser build?

thheller 2021-04-09T08:01:38.489100Z

I did change something regarding this in 2.12.2 but I haven't been able to reproduce

ingesol 2021-04-09T08:02:40.490200Z

Hi! I’m latest shadow and tools.deps, trying to pass a config map through CLI. my alias looks like this

{:some-alias  
{:extra-deps  {
 thheller/shadow-cljs  {:mvn/version "2.11.23"}}
:main-opts   ["-m" "shadow.cljs.devtools.cli"
                                         "--config-merge" {:some "thing"}]}}
Running this alias gives me this error:
Error while parsing option "--config-merge {:some": java.lang.RuntimeException: EOF while reading
I did try to change the format of the map to be wrapped in a string, put it inside the string containing --config-merge, and wrapping it with both single and double quotes. Ideas?

flowthing 2021-04-09T08:08:06.490800Z

@thheller :node-test, actually.

thheller 2021-04-09T08:10:51.491Z

oh. then I know.

tvirolai 2021-04-09T10:20:17.491300Z

Hi, I'm being bitten by a strange issue when trying to compile Reagent code to React components using Shadow-CLJS. I don't know whether this has to do with Reagent, build configuration or something else. The problem is that when I'm compiling Reagent to React components, the components fail to render on the React side if they use Material UI components, with the error: Uncaught Error: Minified React error #321; visit <https://reactjs.org/docs/error-decoder.html?invariant=321> for the full message or use the non-minified dev environment for full errors and additional helpful warnings. Could this be caused by the fact that Material UI components use React Hooks, which are disallowed in React class components? While debugging this, I set up a minimal test project to investigate the issue: https://github.com/tvirolai/mui-cljs-test. Here, Component1 renders while Component2 (with a Material UI icon) fails with the error. Any idea how to get around the issue? I asked around in the #clojurescript channel a couple of weeks ago, but couldn't find a workaround...

ingesol 2021-04-09T11:07:30.491600Z

Seems to be caused by the provided config containing spaces. If I just pass an empty map {}, it seems to work.

ingesol 2021-04-09T11:09:19.491800Z

As doing this

["-m" "shadow.cljs.devtools.cli"
                                      "server"
                                      "--config-merge" []]
seems to be valid syntax and gives this message
--config-merge expects an EDN map argument
{:v []}

thheller 2021-04-09T11:13:21.492Z

this is a deps.edn issue. it doesn't properly escape strings and as such the argument doesn't arrive correctly in the shadow-cljs code

ingesol 2021-04-09T11:13:47.492200Z

ah, thanks, was beginning to suspect that

ingesol 2021-04-09T11:14:01.492400Z

is it possible to point to an edn file for config-merge?

thheller 2021-04-09T11:15:16.492600Z

not currently but you can open an issue and I'll add it

ingesol 2021-04-09T11:15:27.492800Z

great

thheller 2021-04-09T11:25:59.493400Z

@tvirolai yes, this is related to hooks. ask in #reagent, this is not a shadow-cljs issue

👍 1
thheller 2021-04-09T11:26:23.493700Z

@flowthing should be fixed in 2.12.3

thheller 2021-04-09T11:30:47.494Z

anyone want to leave a reply here: https://ask.clojure.org/index.php/10403/pros-and-cons-figwheel-vs-shadowcljs

thheller 2021-04-09T11:30:54.494400Z

I'm too biased to answer 😉

flowthing 2021-04-09T11:41:02.495200Z

@thheller Many thanks, will give it a try next week!

raspasov 2021-04-09T12:41:09.495900Z

@thheller I don’t use shadow-cljs currently but I would love you to answer 🙂 Always appreciate your input.

thheller 2021-04-09T12:43:44.497700Z

misread sorry. I feel like I shouldn't answer because I have never used figwheel so I'm not qualified to compare it

thheller 2021-04-09T12:44:06.498200Z

just listing the shadow-cljs features doesn't really answer that question 🙂

raspasov 2021-04-09T12:47:09.001200Z

Fair enough 🙂 I’ve been juggling whether I should try shadow-cljs; not having to deal with JS bundlers (webpack etc) is very compelling; However, for my current project in React Native specifically (and I mentioned that in the thread), you still need to use Metro, even if you use shadow-cljs (I am pretty sure that’s the case); so for that setup specifically, it doesn’t feel like it makes a ton of sense for me right now;

thheller 2021-04-09T12:50:21.002700Z

I always say to never change a running setup, so what you have now is working properly for you and does what you expect it to do keep it

thheller 2021-04-09T12:50:32.003Z

you'll still use metro regardless yes

thheller 2021-04-09T12:51:27.004500Z

I also don't do react-native development so I can't even speak to what figwheel might be doing differntly

thheller 2021-04-09T12:51:40.005Z

I know that the loading mechanism is different but at runtime things are probably quite equal

raspasov 2021-04-09T12:52:04.005400Z

One problem I did run into, but I’m not sure if shadow-cljs can help with this (and I don’t presume you know, because you don’t do much RN), is integrating a library like reanimated-v2

raspasov 2021-04-09T12:53:30.006700Z

They do something unusual, in which they use React hooks that add ‘worklet’ in this style: https://docs.swmansion.com/react-native-reanimated/docs/worklets

aratare 2021-04-09T12:53:56.007700Z

as someone who briefly used figwheel/main and is now using shadow-cljs, I can say that setting up SCLJS takes much much much less time than figwheel/main

😎 1
aratare 2021-04-09T12:54:16.008500Z

I was struggling to get figwheel-main up for an entire day and all it took was 15 mins with SCLJS

raspasov 2021-04-09T12:55:37.009800Z

After that, at compile time (I believe), they look for those worklets and do some fancy stuff with them to make the animation run better.

thheller 2021-04-09T12:55:58.010300Z

hmm yeah no clue sorry

raspasov 2021-04-09T12:56:00.010600Z

They achieve that via some babel plugins; the problem is, that if you have those worklets writte in CLJS

aratare 2021-04-09T12:56:14.011100Z

also one more thing I like about SCLJS is the doc itself. Figwheel/main doc was kind of a mess when I was using it, and it contributed to why it was taking so long to set things up.

raspasov 2021-04-09T12:56:24.011200Z

… the babel plugin can’t understand them;

raspasov 2021-04-09T12:56:41.011400Z

Since they are not written in JSX (I believe)

thheller 2021-04-09T12:56:43.011600Z

well you can always just write them in JS if needed I guess

raspasov 2021-04-09T12:56:50.011800Z

Yes, that’s what I did 🙂

raspasov 2021-04-09T12:56:56.012Z

Just have a local npm package…

raspasov 2021-04-09T12:57:09.012200Z

Which I include… and pass data from CLJS; works well enough.

raspasov 2021-04-09T12:57:31.012400Z

But for the sake of purity, I would like it to work from CLJS! 😄:lightsaber:

raspasov 2021-04-09T12:57:36.012600Z

But otherwise, it works.

thheller 2021-04-09T12:57:49.012800Z

yeah that won't work (with shadow-cljs either)

raspasov 2021-04-09T12:58:38.013500Z

@rextruong yea the shadow-cljs docs are really top notch

👌 1
raspasov 2021-04-09T12:59:06.013600Z

That’s what I thought… thanks!

2021-04-09T13:03:49.014500Z

I'd be interested in seeing an open discussion between the leading lights of the cljs community 😉 on the various approaches to builds, future for cljs etc. there seem to be no end of podcasts these days but apparently never in a debate kind of format

thheller 2021-04-09T13:11:32.014800Z

I try to always document the "why?" when I choose to follow a different path or slightly different setup in shadow-cljs

thheller 2021-04-09T13:12:19.015Z

there are a couple posts in my blog https://code.thheller.com/ and some on clojureverse or just directly in the user guide

2021-04-09T13:14:20.015400Z

I see that.... I really appreciate your efforts and am often sharing links to stuff you've written 👍

p-himik 2021-04-09T13:42:19.016Z

Seems like :target :npm-module is broken in at least 2.12.3:

IllegalArgumentException: No matching field found: stripTypePrefixes for class com.google.javascript.jscomp.CompilerOptions

p-himik 2021-04-09T13:47:56.016100Z

Seems like it's this commit: https://github.com/google/closure-compiler/commit/79ced4fdc09a82d77f61683e33f1e48630d8279d

thheller 2021-04-09T13:49:56.016500Z

stripping was removed yes. what is the full stacktrace?

thheller 2021-04-09T13:50:14.017Z

I mean unless you are setting this in your build config it shouldn't be used anyways?

thheller 2021-04-09T13:51:30.017500Z

ah right ... npm-module calls it

thheller 2021-04-09T13:53:27.018Z

please open an issue or it'll get lost, can't fix it now

p-himik 2021-04-09T14:27:03.018400Z

Done, https://github.com/thheller/shadow-cljs/issues/868

2021-04-09T18:47:05.021Z

Hi! I tried to implement Inertia.js client side with Shadow-CLJS and Reagent. The documentation give this snippet who contains this following dynamic require

import { App } from '@inertiajs/inertia-react'
import React from 'react'
import { render } from 'react-dom'

const el = document.getElementById('app')

render(
  &lt;App
    initialPage={JSON.parse(el.dataset.page)}
    resolveComponent={name =&gt; require(`./Pages/${name}`).default}
  /&gt;,
  el
) 
Is this possible with ClojureScript/Shadow-CLJS in the browser? With goog/require or something like that?

2021-04-09T18:47:27.021200Z

Source: https://inertiajs.com/client-side-setup#initialize-app

2021-04-09T18:54:03.022400Z

For now, I'm stuck with the expected error Uncaught ReferenceError: require is not defined

(ns myreagent.core
  (:require
   ["@inertiajs/inertia-react" :refer [App]]
   [reagent.dom :as d]))


(def el (.getElementById js/document "app"))

(defn home-page []
  [:&gt; App {:initial-page (.parse js/JSON (.. el -dataset -page))
           :resolve-component (fn [name] (.-default (js/require (str "./Pages/" name))))}])

(defn mount-root []
  (d/render [home-page] el))

(defn ^:export init! []
  (mount-root))

thheller 2021-04-09T19:27:16.023400Z

@admin055 dynamic require like that is not supported, but you can probably replace it with either just a normal reference or something using shadow.loader

2021-04-09T19:30:49.024200Z

OK, thx for the confirmation.

2021-04-09T19:33:58.025600Z

I don't about shadow.loader, I'll check, thank you. When you say normal reference, you mean like that?

(defn Home [{:keys [name]}]
  [:h1 (str "Hello " name "!")])

(defn home-page []
  [:&gt; App {:initial-page (.parse js/JSON (.. el -dataset -page))
           :resolve-component (fn [name] (r/reactify-component Home))}])

thheller 2021-04-09T19:35:39.025900Z

yes

thheller 2021-04-09T19:36:05.026300Z

I don't know what intertia.js is so I don't know what it expects, but that would be what I'd guess

2021-04-09T19:37:00.026600Z

OK, in my case this is not suitable because it takes away the principle of Inertia.js.

thheller 2021-04-09T19:37:46.027Z

if this is about code splitting then follow https://code.thheller.com/blog/shadow-cljs/2019/03/03/code-splitting-clojurescript.html

martinklepsch 2021-04-09T19:44:13.027900Z

I’m getting these strange errors in a fresh project recently:

107 |   (let [an (rum/react *active-notes)]
 108 |     [:div
 109 |      [:div [:code (pr-str an)]]
---------------------------------^----------------------------------------------
Use of undeclared Var starter.browser/an
--------------------------------------------------------------------------------
also saw this with another thing where a function argument was regarded as undeclared

martinklepsch 2021-04-09T19:45:53.028200Z

shadow version 2.11.23

2021-04-09T19:51:36.032200Z

@thheller Inertia.js seems interesting project that I'll tried to write an back and adapter for Clojure. From the website: "Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers." The dynamic require is use to load the front component base on backend routing. Inertia read the component from the data-page attribute object.

thheller 2021-04-09T19:53:08.032800Z

but why does it have to be a dynamic require?

thheller 2021-04-09T19:53:38.033500Z

I mean you can use code-splitting but you can also case (case name "foo" ComponentA "bar" ComponentB ...)

thheller 2021-04-09T19:55:34.034Z

@martinklepsch since this is with rum I'm guessing that would be related to https://github.com/tonsky/rum/issues/233

🙌 1
2021-04-09T20:01:49.035300Z

@thheller Yes the case works great but this implies adding the components by hand as the project progresses in this condition + require namespaces, etc.

thheller 2021-04-09T20:02:41.036100Z

well yes but at some point you could write a :target :intertia that automates all of that and emits the code optimal for intertia

thheller 2021-04-09T20:03:13.036900Z

you shouldn't except a generic :browser (or whatever you are using) build to match what intertia wants

thheller 2021-04-09T20:03:42.037400Z

I'm too drained to look into what intertia is so I really don't have a clue what it does or wants

2021-04-09T20:06:47.037900Z

Yeah I understand, your help has already been precious. 😉

2021-04-09T20:06:57.038100Z

Thx Thomas.