shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
2020-10-07T09:54:42.306500Z

Hi! Is there any documentation / articles about usage of :js-options {:babel-preset-config { ... }}? I'm trying to enable polyfills for IE11.

thheller 2020-10-07T10:03:48.307400Z

this only affects npm packages that are actually transpiled by babel. which is only a very small percentage. so much so that this option is mostly useless.

thheller 2020-10-07T10:04:41.308100Z

what kind of polyfills is it not detecting already? this is usually controlled by setting :compiler-options {:output-feature-set :es5} (which is the default)

thheller 2020-10-07T10:04:45.308300Z

you can try :es3

2020-10-07T10:33:54.312Z

Oh, I see. Looks like I should be using :compiler-options, instead of :babel-preset-config, because my project probably don't have such npm packages. Thanks for your answer, I'll try it.

thheller 2020-10-07T10:39:13.312500Z

also note that watch/compile builds may not work in IE11 regardless of polyfill status

thheller 2020-10-07T10:39:21.312700Z

best to test that with release only

2020-10-07T11:31:52.313Z

Got it, thanks!

jcf 2020-10-07T16:52:43.316600Z

Hello, everyone! I'm having a go at spinning up a Lambda function with Clojurescript via Shadow CLJS, and I'm running into a strange error that returns three results via Google. 🙂

$ yarn run shadow-cljs compile lambda --verbose
shadow-cljs - config: /home/jcf/code/example/shadow-cljs.edn
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
[:lambda] Compiling ...
-> build target: :node-library stage: :configure
<- build target: :node-library stage: :configure (3 ms)
-> Resolving Module: :main
With both release and compile I get this error after the output above:
The required namespace "example.lambda" is not available, it was required by "shadow/umd_helper.cljs".
I've found a GitHub issue related to generating single files, with a recommendation to use ncc to package everything into a single file, which I can do as soon as I have something compiling. My build looks like this:
{:builds
 {:lambda
  {:deps             {:aliases [:lambda]}
   :output-to        "amplify/backend/function/example/src/index.js"
   :target           :node-library
   :exports          {:handler example.lambda/handler}
   :devtools         {:enabled false}
   :compiler-options {:infer-externs :auto
                      :source-map    true}}}}
I've triple checked the namespace and path to my namespace and it's very correct (I've copied and pasted the name back and forth to be doubly sure).

jcf 2020-10-07T16:53:13.316700Z

In my deps.edn I have an alias that sets :paths ["src"]…

jcf 2020-10-07T16:53:37.316900Z

If anyone has a working example of generating a :node-library that I can package up with ncc I'd be extremely grateful.

jcf 2020-10-07T16:53:54.317100Z

Definitely scratching my head on this one. :thinking_face:

jcf 2020-10-07T17:01:39.317800Z

https://github.com/vercel/ncc

jcf 2020-10-07T17:02:21.318100Z

Relevant links above, with two archived Slack convos coming right up…

jcf 2020-10-07T17:16:41.320Z

I think tomorrow I might create a little repo to see if I can reproduce outside of my codebase. If so, I can open a decent issue on GitHub.

2020-10-07T18:00:18.320200Z

Hello, for my information, why do you build a "node-library" and not a "node-script" or "esm" (https://clojureverse.org/t/generating-es-modules-browser-deno/6116)? Moreover, shadow-cljs will generate one js file: why do you need ncc for?

jcf 2020-10-07T19:14:37.321Z

@mandimby.raveloarinja see this GitHub issue and its conclusion: https://github.com/thheller/shadow-cljs/issues/290#issuecomment-539087352

đź‘Ť 1
thheller 2020-10-07T20:12:03.322600Z

@jcf the file is supposed to be /home/jcf/code/example/src/example/lambda.cljs. make sure it actually exists. the :deps inside :builds is incorrect. it is supposed to be at the top level

thheller 2020-10-08T07:45:45.340Z

it doesn't matter if you have rum on the classpath or not for other code

thheller 2020-10-08T07:45:55.340200Z

if it isn't explicitely required in any of your code it won't be used

thheller 2020-10-08T07:46:06.340400Z

so the lambda isn't affected at all whether its on the classpath or not

đź‘Ť 1
thheller 2020-10-07T20:12:38.323100Z

can't see your :paths though

thheller 2020-10-07T20:12:58.323500Z

assuming :paths ["src"] in deps.edn is set correctly

âś… 1
2020-10-07T20:34:20.323700Z

indeed I just did a small test. The target "node-lib" needs the node_modules to be bundled with the js; The target "esm" bundles everything in one js natively. However, the version of node on lambda is node 12 that does not support esm without the flag "--experimental-modules" (http://2ality.com/2019/04/nodejs-esm-impl.html#using-es-modules-on-nodejs)

đź‘Ť 1
jcf 2020-10-07T21:42:05.326400Z

I wasn’t sure if :deps could be nested. I want to use different dependencies for different builds, and went for :aliases…

jcf 2020-10-07T21:44:13.328Z

I think I’ve done all of the above, but will double check after a good night’s rest. Thanks, thheller. 🙇

thheller 2020-10-07T21:46:11.328100Z

this is not supported and also usually quite useless. see https://code.thheller.com/blog/shadow-cljs/2018/02/08/problem-solved-source-paths.html

jcf 2020-10-07T21:54:22.332Z

Is that post related to isolating dependencies declared using tools.deps’ :deps or is it to do with source paths (e.g. src/cljs)? I was trying to include a different set of third-party dependencies (my Lambda doesn’t need Rum) and have all my Clojure-like source collocated.

jcf 2020-10-07T21:58:46.335300Z

I’ll have a proper read in the morning to make sure I’m understanding it. Thanks, thheller! You’re work as always is appreciated. 🙇

kennytilton 2020-10-07T23:59:48.337800Z

Is there an issue with shadow and macros, perhaps in the context of .cljc? I define…

(defmacro deftags [& tags]
  `(do ~@(for [tag tags]
           `(deftag ~tag))))
…in one NS, require it in another,
(ns mxweb.tag
  (:require
    [mxweb.gen :as gen]))

(gen/deftags a abbr acronym ...etc..)
…then a check reports
------ WARNING #1 - :undeclared-var --------------------------------------------
 Resource: mxweb/tag.cljc:5:2
 Use of undeclared Var mxweb.gen/deftags
A conventional CLJS build using the lein meis scripts works OK. Thx!

Karol WĂłjcik 2020-10-08T07:03:19.339Z

Did you include require-macros :refer [deftags] in cljc file?

thheller 2020-10-08T07:44:38.339700Z

@hiskennyness https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html most likely your are missing the :require-macros in the mxweb.gen ns for itself

kennytilton 2020-10-08T08:54:36.341300Z

@karol.wojcik I started with :require-macros in the using mxweb.tag NS and was seeing the same error. Thx to @thheller’s blog post I see the linkage is a bit hairier than I realized and will give it another go. btw, I had everything in .cljcs, and will start by moving macros into a .clj just to reduce the unknowns.

Karol WĂłjcik 2020-10-08T10:26:46.341800Z

You should have put it in mxweb.gen

kennytilton 2020-10-08T15:07:38.345Z

Yeah, that was the shocker I picked up from @thheller’s blog. I did all this years ago using the mies scripts. That worked OK, but I am curious about Shadow. One puzzle is that I do not have the macros in a .clj, which I do remember as a requirement! I guess the .cljc gives me the .clj compile for the macros? Anyway, I plan to KISS and move the macros into a .clj, then set things up as you have described. Thx!

thheller 2020-10-08T15:20:00.345200Z

.cljc as far as CLJS macros are concerned are just two files in one. one for CLJ one for CLJS. the macro rules are exactly the same but IMHO it is much easier to follow those rules with two actual files instead of one

kennytilton 2020-10-08T15:41:15.345600Z

Yeah, I am splitting them up now. This will be a challenge for any tooling, tho: deftag generates a macro. 🙂 Results shortly…

kennytilton 2020-10-08T16:52:13.349Z

Works like a charm. Thx @karol.wojcik and @thheller!

🎉 2