shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
2021-03-10T14:22:59.293700Z

@thheller Is there an API to trigger heads up display so that a warning from a build hook running in flush stage could be visible in a browser?

thheller 2021-03-10T15:44:12.294500Z

@roman01la no API but you can just put a warning into the build-state

2021-03-10T15:45:05.295Z

oh that's nice!

thheller 2021-03-10T15:45:19.295300Z

:shadow.build/build-info is the key of the data that the clients will get

thheller 2021-03-10T15:45:40.295700Z

it has a nested :sources and those have :warnings

πŸ‘ 1
ClΓ©ment Ronzon 2021-03-10T17:11:34.298400Z

Hi gals and guys, I'm having an issue with a NPM dependency I am using: react-color (https://www.npmjs.com/package/react-color) I get a couple of errors and warnings when running karma on the produced code (`:karma-coverage`):

# karma start
10 03 2021 16:57:08.655:INFO [preprocessor.coverage]: coverage not included in reporters dots,progress
10 03 2021 16:57:08.881:WARN [karma]: No captured browser, open <http://localhost:9876/>
10 03 2021 16:57:08.973:INFO [karma-server]: Karma v5.2.3 server started at <http://localhost:9876/>
10 03 2021 16:57:08.973:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
10 03 2021 16:57:08.976:INFO [launcher]: Starting browser ChromeHeadless
10 03 2021 16:57:10.131:INFO [Chrome Headless 88.0.4324.182 (Linux x86_64)]: Connected on socket pvu_uV4i-0kufk6WAAAA with id 85631944
10 03 2021 16:57:10.581:WARN [web-server]: 404: /base/target/cljs-runtime/module$node_modules$icons$material$UnfoldMoreHorizontalIcon.js?80c4489cd485acfeed1e160ad69825303e4ee8e4
10 03 2021 16:57:10.595:WARN [web-server]: 404: /base/target/cljs-runtime/module$node_modules$icons$material$CheckIcon.js?3b1f8ad831751a7b84b35493627cc64278e2c8c7
10 03 2021 16:57:10.765:WARN [web-server]: 404: /base/target/cljs-runtime/module$node_modules$icons$material$UnfoldMoreHorizontalIcon.js?80c4489cd485acfeed1e160ad69825303e4ee8e4
10 03 2021 16:57:10.800:WARN [web-server]: 404: /base/target/cljs-runtime/module$node_modules$icons$material$CheckIcon.js?3b1f8ad831751a7b84b35493627cc64278e2c8c7
Chrome Headless 88.0.4324.182 (Linux x86_64) WARN: 'shadow-cljs - failed to load', 'module$node_modules$react_color$lib$components$chrome$ChromeFields'
Chrome Headless 88.0.4324.182 (Linux x86_64) WARN: 'shadow-cljs - failed to load', 'module$node_modules$react_color$lib$components$chrome$ChromeFields'

Chrome Headless 88.0.4324.182 (Linux x86_64) WARN: 'shadow-cljs - failed to load', 'module$node_modules$react_color$lib$components$chrome$Chrome'
Chrome Headless 88.0.4324.182 (Linux x86_64) WARN: 'shadow-cljs - failed to load', 'module$node_modules$react_color$lib$components$chrome$Chrome'

Chrome Headless 88.0.4324.182 (Linux x86_64) WARN: 'shadow-cljs - failed to load', 'module$node_modules$react_color$lib$index'
Chrome Headless 88.0.4324.182 (Linux x86_64) WARN: 'shadow-cljs - failed to load', 'module$node_modules$react_color$lib$index'

Chrome Headless 88.0.4324.182 (Linux x86_64) ERROR
  Uncaught Module not provided: module$node_modules$$icons$material$UnfoldMoreHorizontalIcon
  at target/cljs-runtime/shadow.js.js:37:9
Chrome Headless 88.0.4324.182 (Linux x86_64) ERROR
  Uncaught Module not provided: module$node_modules$$icons$material$UnfoldMoreHorizontalIcon
  at target/cljs-runtime/shadow.js.js:37:9
I read some passed discussions on this channel, about adding :js-options {:ignore-asset-requires true}, others about adding :compiler-options {:output-feature-set :es8} but none solved my issue.

thheller 2021-03-10T17:17:26.299400Z

why do you get 404s? do the files exist on disk?

ClΓ©ment Ronzon 2021-03-10T17:22:57.300400Z

There are those: module$node_modules$$icons$material$UnfoldMoreHorizontalIcon.js module$node_modules$$icons$material$CheckIcon.js ...with that double $ which doesn't match the ones indicated in the 404 warnings.

thheller 2021-03-10T17:24:35.301200Z

the extra $$ are the replacements for the /@ in actual source path (which aren't valid in JS identifiers)

thheller 2021-03-10T17:25:00.301800Z

something in karma must be replacing $$ in $ for some reason?

ClΓ©ment Ronzon 2021-03-10T17:34:58.302500Z

Yeah, that must be it. I'm using a custom :karma-coverage target. With :karma it works just fine.

ClΓ©ment Ronzon 2021-03-10T17:48:28.302800Z

Thank you @thheller

2021-03-10T18:42:58.304700Z

I'm trying to upgrade from shadow-cljs 2.10.6 to 2.11.22, and I see a number of warnings about not being able to infer the type of things. I've gone though and manually hinted most them as ^js , but I'm getting warnings that I don't know how to hint everytime I use a deftype that implements reagent.ratom.IReactiveAtom.

387 | 
388 | (deftype Foo [^:mutable amdoc ^:mutable clj-value ^:mutable snapshot meta validator ^:mutable watches ^:mutable callback]
        -------^------------------------------------------------------------------------
        Cannot infer target type in expression (. (. Foo -prototype) -reagent$ratom$IReactiveAtom$)
        --------------------------------------------------------------------------------
 389 |   IAtom
 390 |   reagent.ratom.IReactiveAtom
 391 | 
 392 |   FooClassification
Any insight as to why this is happening now, and more importantly, how to resolve it?

2021-03-10T18:48:42.305500Z

As to "why now" I understand that at some point some defaults regarding inference changed, but I have no idea how to hint that deftype to make it leave me alone.

2021-03-11T08:37:00.319800Z

Thank you @thheller! I in fact turned the warnings off, but I will see if fixing my reference resolves the error ... thanks again ! πŸ™‚

2021-03-11T08:38:18.320Z

Changing it to / instead of . didn't change anything ...

2021-03-11T08:38:29.320200Z

But I can just leave the warnings disabled, worst-case.

thheller 2021-03-11T08:44:55.320400Z

I think this particular warning will be fixed with the next CLJS release anyways. It originates from deep inside the compiler that shadow-cljs cannot easily modify.

2021-03-11T08:53:28.320600Z

Thank you for your assistance in any case!

2021-03-10T19:20:48.308200Z

is their a clj template for creating a shadow-cljs project targetting the browser? Just to give all the basics to get started, so I can get up and running with hot-reload, dev and test src paths, reloading css, a public folder for the html/css etc ? I'm trying to go through the docs but its so complicated and feels pretty impenetrable without an example to follow along with that I can see works and I can change and mess with.

dpsutton 2021-03-10T20:21:07.309500Z

if i'm using :npm-module and bundling that into a webpack frontend, is it possible to get a cljs repl connected to the webpacked build? Does shadow emit all of the necessary bridge stuff during a watch such that this is a reasonable thing to expect?

thheller 2021-03-10T21:40:56.309600Z

reagent.ratom.IReactiveAtom should be reagent.ratom/IReactiveAtom I think

thheller 2021-03-10T21:41:20.309800Z

you silence externs inference in that file by setting (set! *warn-on-infer* false)

thheller 2021-03-10T21:41:53.310Z

or reverting the old behavior by setting :compiler-options {:infer-extern true}

thheller 2021-03-10T21:43:54.311300Z

@dpsutton yes but you need to manually require the shadow.cljs.devtools.client.browser ns from the JS side of things. so if (process.env.NODE_ENV === "development") { require("wherever/shadow.cljs.devtools.client.browser.js") }

dpsutton 2021-03-10T21:44:45.312400Z

heh, and can't put that behind a flag in a cljs file and sneak it in that way?

thheller 2021-03-10T21:44:50.312600Z

but the REPL has some limits in what it can do since webpack post-processes the code normally but not the code loaded over the REPL

thheller 2021-03-10T21:45:26.313100Z

you can try πŸ˜‰

dpsutton 2021-03-10T21:46:00.313900Z

oh, where should that live? process.env.NODE_ENV? I'm quite the beginner with webpack stuff. presumably that's in the webpack config? i'm surprised to see a require that uses that

thheller 2021-03-10T21:46:31.314200Z

well its a pattern that is commonly setup in webpack

thheller 2021-03-10T21:46:42.314600Z

its that not already configured then that wouldn't work either

thheller 2021-03-10T21:47:35.314900Z

well it might actually be included by default nowadays. not actually sure.

dpsutton 2021-03-10T21:48:50.315200Z

i see. i'll give that a shot. thanks so much @thheller

thheller 2021-03-10T21:50:19.316100Z

FWIW (when (identical? js/process.env.NODE_ENV "development") (js/require "./shadow.cljs.devtools.client.browser.js")) should work

thheller 2021-03-10T21:50:52.316900Z

the trouble is that shadow-cljs doesn't have a clearly defined entry namespace for :npm-module. so it cannot inject that for you before loading that ns

thheller 2021-03-10T22:07:25.317400Z

did you go through https://github.com/thheller/shadow-cljs#quick-start?

thheller 2021-03-10T22:08:36.317900Z

it only handles basic project setup though. if you want more specific templates you need to select one for the libs you want to use

2021-03-10T23:11:38.318100Z

Its the paths and naming thats confusing me. From the quick start you called the project acme-app, but then the namespace is <http://acme.frontend.app|acme.frontend.app> How did we end up with a frontend between acme and app ? The dots become slashes in the expected directory structure? Then in the edn you have

:builds
{:frontend
 ...
What happened to acme and app here? There just seems to be an awful lot of magic happening here based on strings and names that I'm not understanding. I think I just need to create a few examples using the npx create-cljs-project with different names and see what gets created. Thanks!

thheller 2021-03-10T23:20:57.318300Z

the project is called acme-app. that is literally only the directory name the files are in. it has nothing to do with what the project does. The <http://acme.frontend.app|acme.frontend.app> name I picked because naming is hard but I tried to explain why I did

thheller 2021-03-10T23:22:37.318500Z

in many other CLJS examples you'll see a bunch of foo.core namespaces. I personally don't like .core names so I used something else. its just a name, use what makes sense for you.

2021-03-10T23:32:36.318700Z

So I've created a project called learn-reframe in a learn-reframe folder.

.
β”œβ”€β”€ learn-reframe.iml
β”œβ”€β”€ node_modules
β”œβ”€β”€ package.json
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ pom.xml
β”œβ”€β”€ shadow-cljs.edn
└── src
    └─ main
    └─ test
For now I don't care about names so a random prefix will do, exfn So I create
src\main\exfn\app.cljs
With namespace
(ns <http://exfn.app|exfn.app>)
So I my edn should look like this:
{...
 :builds
 {:???
  {:target :browser
   :modules {:main {:init-fn <http://exfn.app/init|exfn.app/init>}}}}}
I'm not sure what my :??? would be :exfn or :app?

2021-03-10T23:33:08.318900Z

Just :app I think?

thheller 2021-03-10T23:33:28.319100Z

also just a name. up to you. :app is fine

thheller 2021-03-10T23:34:31.319300Z

that is the build-id used later in the shadow-cljs watch app etc commands

2021-03-10T23:37:19.319500Z

ok, think i get it now! Thank you for your help. I really appreciate it!

πŸ‘ 1