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. ☺️
@jntn what do you mean by "add new builds dynamically"?
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 😅
you can just go through the API functions directly
(shadow.cljs.devtools.api/release* {:build-id :app :target :node-script :main 'foo.bar/main :output-to "somewhere/script.js"} {})
thats like calling shadow-cljs release app
but instead of loading the build config from shadow-cljs.edn you just pass it in directly
the map is what you'd usually have in shadow-cljs.edn
:builds
but also requires the :build-id
to be present
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
Thanks a lot! That seems like a great way to do it.
coupled with https://shadow-cljs.github.io/docs/UsersGuide.html#clj-run you can do pretty much anything you want
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
I did some experiments some time ago as well as others
I just can't remember any of it 😛
@jntn this sounds like a great article if you have any interest in writing
@dpsutton If I get something working, why not! 🙂
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
So I am looking for new possibilities
(reposting from #clojurescript as i just found this channel for shadow-cljs specifically)
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`
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…
does --debug
preserve line numbers by chance? 😬
@alexstokes need more info. how are you installing the JS library?
I guess pretty-print def would not preserve line numbers
pseudo-names also seems to change the line numbers quite a bit 😞
just npm install @chainsafe/discv5
and what’s the full error?
following this: https://shadow-cljs.github.io/docs/UsersGuide.html#js-deps
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]
this looks relevant: https://github.com/google/closure-compiler/issues/3167
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
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
the lib you posted relies on https://github.com/no2chem/bigint-buffer
which does seem to use the proposed native BigInt
@alexstokes yeah the closure compiler cannot transpile bigints away, so the only option is turning off ALL transpilation
:compiler-options {:output-feature-set :es-next}
I believe it the setting. let me check.
or :compiler-options {:language-out :no-transpile}
@lilactown what do you mean by "preserve line numbers"? --debug
adds source maps so you can get the original line from that?
I had an issue in production that I’m trying to reverse engineer the line numbers/symbols
the sourcemaps aren’t showing up in the stack trace unfortunately
in a --debug
build?
no, in the production build. I haven’t figured out how to reproduce the error either
release
builds don't have source maps by default? did you enable them?
yeah they’re enabled
--debug
is source map + pseudo names
hmm then everything should be source mapped? unless your error is somewhere deep in react-dom
or so.
that uses the minified react-dom.production.min.js
which doens't have source maps
it starts in React but bubbles up to cljs.core
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
it could be that we’re catching them and console.log
ing them?
> catching them
whos them?
ah the exceptions
depends on how you log them
if you (js/console.log ex)
chrome source maps them. if you (js/console.log (.-stack ex))
it does not I believe
@thheller neither of those :compiler-options
changed anything, but thanks for your help
is this lib meant to run in the browser?
it is running here
perhaps there is an issue w/ typescript?
i tried this as well and getting the same error still
:compiler-options {:language-in :es-next
:output-feature-set :es-next}
:language-out
not in
in already defaults to :es-next
and changes nothing
docs say :output-feature-set
replaces :language-out
yes don't use both
thats why I suggested them separately ... try :compiler-options {:language-out :no-transpile}
ONLY, without :output-feature-set
:output-feature-set
is the newer option but I don't think it has a "do nothing" option
i tried both separately, will double check again
can’t get past the error w/ any of the above options
I believe the release that came out a few days ago had some changes in that area
dunno how the support looks though. may still not work.
v20200830
maybe try that
if all else fails use webpack ala https://code.thheller.com/blog/shadow-cljs/2020/05/08/how-about-webpack-now.html#option-2-js-provider-external 😉
v20200830
is referring to a shadow-cljs release?
no the closure compiler [com.google.javascript/closure-compiler-unshaded "v20200830"]
currently is at [com.google.javascript/closure-compiler-unshaded "v20200719"]
(if you are on 2.11.x
)
ah thanks, i’ll try some of these options
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?
I don't know. what did you modify?
like (assoc build-state :output-dir whatever)
won't do anything
(update-in build-state [:shadow.build/config :closure-defines] merge {some/other "config"})
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
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
so closure defines would be in (update-in build-state [:compiler-options :closure-defines] merge {})
Ah, that is likely my error…
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
There isn’t any pre-configure stage, is there?
no
Okie dokie, I’ll modify those values in their final locations. :thumbsup: