shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
jntn 2020-09-03T12:54:31.034700Z

Hey! Anyone knows if it possible to hook into and change the configuration before any builds starts? I know of the :build-hooks but they are just for a particular build. I want to be able to add new builds dynamically. ☺️

thheller 2020-09-03T13:04:41.035100Z

@jntn what do you mean by "add new builds dynamically"?

jntn 2020-09-03T13:10:47.040500Z

Well, I want to create node-script builds for at lot of files without having to add them all to the shadow-cljs.edn. I am looking into using Vercel (formerly zeit now) to deploy a clojurescript project. And Vercel has a folder (/api) where every file becomes a lambda function. I basically want to be able to put a *.cljs file into a folder and magically shadow-cljs produces a js file in, say /api. I could of course add them all to the shadow-cljs manually, but there could potentially be very many. Sorry of this does not make any sense 😅

thheller 2020-09-03T13:11:49.040800Z

you can just go through the API functions directly

thheller 2020-09-03T13:12:16.041400Z

(shadow.cljs.devtools.api/release* {:build-id :app :target :node-script :main 'foo.bar/main :output-to "somewhere/script.js"} {})

thheller 2020-09-03T13:13:00.042200Z

thats like calling shadow-cljs release app but instead of loading the build config from shadow-cljs.edn you just pass it in directly

thheller 2020-09-03T13:13:42.042800Z

the map is what you'd usually have in shadow-cljs.edn :builds but also requires the :build-id to be present

thheller 2020-09-03T13:14:19.043100Z

sounds a bit crazy to me to build one file per handler though but I can't remember if it let you load other files as well

jntn 2020-09-03T13:15:07.044100Z

Thanks a lot! That seems like a great way to do it.

thheller 2020-09-03T13:15:11.044300Z

coupled with https://shadow-cljs.github.io/docs/UsersGuide.html#clj-run you can do pretty much anything you want

jntn 2020-09-03T13:16:29.046Z

It could indeed be a bad idea, I am just experimenting 😋 I really like Vercel and shadow-cljs and really want them to work together

thheller 2020-09-03T13:18:37.046400Z

I did some experiments some time ago as well as others

thheller 2020-09-03T13:18:45.046700Z

I just can't remember any of it 😛

dpsutton 2020-09-03T13:20:12.047500Z

@jntn this sounds like a great article if you have any interest in writing

jntn 2020-09-03T13:24:28.048Z

@dpsutton If I get something working, why not! 🙂

1
jntn 2020-09-03T13:25:31.049400Z

I have actually created a custom builder for Now that works well, but it is a bit outdated and uses old deprecated apis. https://github.com/jntn/now-shadow-cljs

jntn 2020-09-03T13:25:55.049900Z

So I am looking for new possibilities

alexstokes 2020-09-03T15:50:37.051Z

(reposting from #clojurescript as i just found this channel for shadow-cljs specifically)

alexstokes 2020-09-03T15:50:38.051200Z

hi all, I’m trying to use a js lib w/ shadow-cljs and getting an error from the closure compiler about an unsupported feature `bigint`  — my dependency uses `bn.js`

alexstokes 2020-09-03T15:50:47.051400Z

does anyone know how to fix this or where I can read more? i’m wondering if there is a flag i can set somewhere or if it truly is just unsupported in cljs right now…

lilactown 2020-09-03T15:54:50.051800Z

does --debug preserve line numbers by chance? 😬

lilactown 2020-09-03T15:55:58.052400Z

@alexstokes need more info. how are you installing the JS library?

lilactown 2020-09-03T15:57:03.052700Z

I guess pretty-print def would not preserve line numbers

lilactown 2020-09-03T16:07:53.053100Z

pseudo-names also seems to change the line numbers quite a bit 😞

alexstokes 2020-09-03T16:17:15.053500Z

just npm install @chainsafe/discv5

lilactown 2020-09-03T16:18:28.053800Z

and what’s the full error?

alexstokes 2020-09-03T16:18:46.054Z

following this: https://shadow-cljs.github.io/docs/UsersGuide.html#js-deps

alexstokes 2020-09-03T16:19:21.054300Z

cljs.user=> (require '["@chainsafe/discv5" :as discv5])
[2020-09-03 08:18:14.954 - WARNING] :shadow.cljs.devtools.server.worker.impl/cljs-compile-ex - {:input {:code "(require '[\"@chainsafe/discv5\" :as discv5])", :ns cljs.user, :repl true}}
ExceptionInfo Failed to process REPL command {:eof? false, :ns cljs.user, :form (require (quote ["@chainsafe/discv5" :as discv5])), :source "(require '[\"@chainsafe/discv5\" :as discv5])", :tag :shadow.cljs.repl/process-ex}
        shadow.cljs.repl/process-read-result (repl.clj:520)
        shadow.cljs.repl/process-read-result (repl.clj:494)
        shadow.cljs.repl/process-input (repl.clj:674)
        shadow.cljs.repl/process-input (repl.clj:658)
        shadow.cljs.devtools.server.worker.impl/fn--15149 (impl.clj:755)
        shadow.cljs.devtools.server.worker.impl/fn--15149 (impl.clj:745)
        clojure.lang.MultiFn.invoke (MultiFn.java:234)
        shadow.cljs.devtools.server.util/server-thread/fn--14812/fn--14813/fn--14821 (util.clj:285)
        shadow.cljs.devtools.server.util/server-thread/fn--14812/fn--14813 (util.clj:284)
        shadow.cljs.devtools.server.util/server-thread/fn--14812 (util.clj:257)
        java.lang.Thread.run (Thread.java:834)
Caused by:
ExceptionInfo closure errors {:tag :shadow.build.closure/errors, :errors [{:resource-name nil, :source-name nil, :line -1, :column -1, :msg "Attempted to run pass \"markUntranspilableFeaturesAsRemoved\" on input with features it does not support. Running pass anyway.\nUnsupported features: [bigint]"}]}
        shadow.build.closure/throw-errors! (closure.clj:1164)
        shadow.build.closure/throw-errors! (closure.clj:1158)
        shadow.build.closure/convert-sources-simple* (closure.clj:1902)
        shadow.build.closure/convert-sources-simple* (closure.clj:1759)
        shadow.build.closure/convert-sources-simple (closure.clj:2057)
        shadow.build.closure/convert-sources-simple (closure.clj:2009)
        shadow.build.compiler/maybe-closure-convert (compiler.clj:1172)
        shadow.build.compiler/maybe-closure-convert (compiler.clj:1165)
        shadow.build.compiler/compile-all (compiler.clj:1417)
        shadow.build.compiler/compile-all (compiler.clj:1284)
        shadow.build.api/compile-sources (api.clj:259)
        shadow.build.api/compile-sources (api.clj:251)
------ REPL Error while processing ---------------------------------------------
(require '["@chainsafe/discv5" :as discv5])
Closure compilation failed with 1 errors
--- null:-1
Attempted to run pass "markUntranspilableFeaturesAsRemoved" on input with features it does not support. Running pass anyway.
Unsupported features: [bigint]

lilactown 2020-09-03T16:25:06.054500Z

this looks relevant: https://github.com/google/closure-compiler/issues/3167

lilactown 2020-09-03T16:26:01.055600Z

you can try setting your language-in / language-out to ECMASCRIPT_2019. I’m not sure if that will resolve the compiler error or not

alexstokes 2020-09-03T16:33:14.056200Z

yeah as far as i know that lib is not using the native type so i’m not sure why the closure compiler will fail

lilactown 2020-09-03T16:34:27.056400Z

the lib you posted relies on https://github.com/no2chem/bigint-buffer

lilactown 2020-09-03T16:34:55.056900Z

which does seem to use the proposed native BigInt

thheller 2020-09-03T16:43:56.057700Z

@alexstokes yeah the closure compiler cannot transpile bigints away, so the only option is turning off ALL transpilation

thheller 2020-09-03T16:44:12.058100Z

:compiler-options {:output-feature-set :es-next} I believe it the setting. let me check.

thheller 2020-09-03T16:44:55.058500Z

or :compiler-options {:language-out :no-transpile}

thheller 2020-09-03T16:57:03.059100Z

@lilactown what do you mean by "preserve line numbers"? --debug adds source maps so you can get the original line from that?

lilactown 2020-09-03T16:58:33.059800Z

I had an issue in production that I’m trying to reverse engineer the line numbers/symbols

lilactown 2020-09-03T16:59:14.060500Z

the sourcemaps aren’t showing up in the stack trace unfortunately

thheller 2020-09-03T16:59:26.060700Z

in a --debug build?

lilactown 2020-09-03T16:59:45.061100Z

no, in the production build. I haven’t figured out how to reproduce the error either

thheller 2020-09-03T17:00:02.061500Z

release builds don't have source maps by default? did you enable them?

lilactown 2020-09-03T17:00:10.061800Z

yeah they’re enabled

thheller 2020-09-03T17:00:15.062Z

--debug is source map + pseudo names

thheller 2020-09-03T17:00:47.062500Z

hmm then everything should be source mapped? unless your error is somewhere deep in react-dom or so.

thheller 2020-09-03T17:01:03.062900Z

that uses the minified react-dom.production.min.js which doens't have source maps

lilactown 2020-09-03T17:02:53.063600Z

it starts in React but bubbles up to cljs.core

lilactown 2020-09-03T17:03:27.064200Z

I think we figured it out (it was really bizarre) but in general I would like to have the source maps show in up in exceptions

lilactown 2020-09-03T17:03:42.064600Z

it could be that we’re catching them and console.loging them?

thheller 2020-09-03T17:10:46.064800Z

> catching them

thheller 2020-09-03T17:10:49.065Z

whos them?

thheller 2020-09-03T17:11:08.065200Z

ah the exceptions

thheller 2020-09-03T17:11:19.065500Z

depends on how you log them

thheller 2020-09-03T17:11:42.066100Z

if you (js/console.log ex) chrome source maps them. if you (js/console.log (.-stack ex)) it does not I believe

alexstokes 2020-09-03T17:12:48.066600Z

@thheller neither of those :compiler-options changed anything, but thanks for your help

thheller 2020-09-03T17:17:33.066900Z

is this lib meant to run in the browser?

alexstokes 2020-09-03T17:18:06.067100Z

it is running here

alexstokes 2020-09-03T17:18:07.067300Z

https://enr-viewer.com/

alexstokes 2020-09-03T17:18:15.067600Z

perhaps there is an issue w/ typescript?

alexstokes 2020-09-03T17:18:32.067900Z

i tried this as well and getting the same error still

alexstokes 2020-09-03T17:18:34.068200Z

:compiler-options {:language-in :es-next
                    :output-feature-set :es-next}

thheller 2020-09-03T17:18:45.068400Z

:language-out not in

thheller 2020-09-03T17:19:06.069100Z

in already defaults to :es-next and changes nothing

alexstokes 2020-09-03T17:19:08.069200Z

docs say :output-feature-set replaces :language-out

thheller 2020-09-03T17:19:16.069400Z

yes don't use both

thheller 2020-09-03T17:19:50.069800Z

thats why I suggested them separately ... try :compiler-options {:language-out :no-transpile}

thheller 2020-09-03T17:20:07.070200Z

ONLY, without :output-feature-set

thheller 2020-09-03T17:20:25.070700Z

:output-feature-set is the newer option but I don't think it has a "do nothing" option

alexstokes 2020-09-03T17:20:37.071100Z

i tried both separately, will double check again

alexstokes 2020-09-03T17:22:44.071400Z

can’t get past the error w/ any of the above options

thheller 2020-09-03T17:24:16.071800Z

I believe the release that came out a few days ago had some changes in that area

thheller 2020-09-03T17:24:25.072200Z

dunno how the support looks though. may still not work.

thheller 2020-09-03T17:24:51.072600Z

v20200830 maybe try that

alexstokes 2020-09-03T17:29:37.073600Z

v20200830 is referring to a shadow-cljs release?

thheller 2020-09-03T17:31:49.073900Z

no the closure compiler [com.google.javascript/closure-compiler-unshaded "v20200830"]

thheller 2020-09-03T17:32:16.074300Z

currently is at [com.google.javascript/closure-compiler-unshaded "v20200719"] (if you are on 2.11.x)

alexstokes 2020-09-03T18:35:46.074700Z

ah thanks, i’ll try some of these options

Pete Parker 2020-09-03T20:44:39.078400Z

I’m under the impression that returning a modified build-state in a build hook will affect the build, but it does not appear to. I have tried updating both :output-dir and :closure-defines in the :configure stage and the build appears to use their original values. (When I log the build config in subsequent stages it is updated, but the build does not reflect the update.) Am I misunderstanding how to modify build-state via hooks?

thheller 2020-09-03T20:45:59.078600Z

I don't know. what did you modify?

thheller 2020-09-03T20:46:25.078900Z

like (assoc build-state :output-dir whatever) won't do anything

Pete Parker 2020-09-03T20:47:56.080Z

(update-in build-state [:shadow.build/config :closure-defines] merge {some/other "config"})

thheller 2020-09-03T20:48:03.080300Z

for example if you want to override the :output-dir of a :browser build you need to override this value https://github.com/thheller/shadow-cljs/blob/9178e39a84108b1c0b9b26368b161a9501f4b39f/src/main/shadow/build/targets/browser.clj#L317

thheller 2020-09-03T20:48:46.081100Z

build-hooks run after the specific :target implementation and the :target implementation will already have taken everything out of :shadow.build/config and not look at it again

thheller 2020-09-03T20:49:19.082Z

so closure defines would be in (update-in build-state [:compiler-options :closure-defines] merge {})

Pete Parker 2020-09-03T20:50:01.082500Z

Ah, that is likely my error…

thheller 2020-09-03T20:51:37.083600Z

yeah you can look at the config and get stuff for your hook from it if needed but the target usually won't use it anymore after the :configure stage

Pete Parker 2020-09-03T20:52:43.084Z

There isn’t any pre-configure stage, is there?

thheller 2020-09-03T20:53:48.084900Z

no

Pete Parker 2020-09-03T20:54:22.085500Z

Okie dokie, I’ll modify those values in their final locations. :thumbsup: