Fork me on GitHub
#shadow-cljs
<
2020-09-03
>
jntn12:09:31

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. ☺️

thheller13:09:41

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

jntn13:09:47

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 😅

thheller13:09:49

you can just go through the API functions directly

thheller13:09:16

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

thheller13:09:00

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

thheller13:09:42

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

thheller13:09:19

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

jntn13:09:07

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

thheller13:09:11

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

jntn13:09:29

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

thheller13:09:37

I did some experiments some time ago as well as others

thheller13:09:45

I just can't remember any of it 😛

dpsutton13:09:12

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

jntn13:09:28

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

parens 3
jntn13:09:31

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

jntn13:09:55

So I am looking for new possibilities

alexstokes15:09:37

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

alexstokes15:09:38

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`

alexstokes15:09:47

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…

lilactown15:09:50

does --debug preserve line numbers by chance? 😬

lilactown15:09:58

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

lilactown15:09:03

I guess pretty-print def would not preserve line numbers

lilactown16:09:53

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

alexstokes16:09:15

just npm install @chainsafe/discv5

lilactown16:09:28

and what’s the full error?

alexstokes16:09:21

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]

lilactown16:09:01

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

alexstokes16:09:14

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

lilactown16:09:55

which does seem to use the proposed native BigInt

thheller16:09:56

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

thheller16:09:12

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

thheller16:09:55

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

thheller16:09:03

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

lilactown16:09:33

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

lilactown16:09:14

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

thheller16:09:26

in a --debug build?

lilactown16:09:45

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

thheller17:09:02

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

lilactown17:09:10

yeah they’re enabled

thheller17:09:15

--debug is source map + pseudo names

thheller17:09:47

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

thheller17:09:03

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

lilactown17:09:53

it starts in React but bubbles up to cljs.core

lilactown17:09:27

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

lilactown17:09:42

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

thheller17:09:46

> catching them

thheller17:09:08

ah the exceptions

thheller17:09:19

depends on how you log them

thheller17:09:42

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

alexstokes17:09:48

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

thheller17:09:33

is this lib meant to run in the browser?

alexstokes17:09:06

it is running here

alexstokes17:09:15

perhaps there is an issue w/ typescript?

alexstokes17:09:32

i tried this as well and getting the same error still

alexstokes17:09:34

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

thheller17:09:45

:language-out not in

thheller17:09:06

in already defaults to :es-next and changes nothing

alexstokes17:09:08

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

thheller17:09:16

yes don't use both

thheller17:09:50

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

thheller17:09:07

ONLY, without :output-feature-set

thheller17:09:25

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

alexstokes17:09:37

i tried both separately, will double check again

alexstokes17:09:44

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

thheller17:09:16

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

thheller17:09:25

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

thheller17:09:51

v20200830 maybe try that

alexstokes17:09:37

v20200830 is referring to a shadow-cljs release?

thheller17:09:49

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

thheller17:09:16

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

alexstokes18:09:46

ah thanks, i’ll try some of these options

Pete Parker20:09:39

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?

thheller20:09:59

I don't know. what did you modify?

thheller20:09:25

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

Pete Parker20:09:56

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

thheller20:09:03

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

thheller20:09:46

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

thheller20:09:19

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

Pete Parker20:09:01

Ah, that is likely my error…

thheller20:09:37

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 Parker20:09:43

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

Pete Parker20:09:22

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