Fork me on GitHub
#shadow-cljs
<
2021-12-10
>
Lukas Domagala01:12:12

@metasoarous me and @djblue have been fighting with the same usecase for portal. his https://github.com/djblue/portal/pull/87, using sci, seems to work pretty well in my initial tests.

metasoarous06:12:51

@domagala.lukas Yes; Thanks for the suggestion. SCI is at the very least my backup plan.

metasoarous06:12:05

Just trying to get a sense of what's possible right now.

metasoarous06:12:02

The simplicity of SCI for this is very appealing, but there are potentially good reasons to want to use traditional cljs.

metasoarous06:12:06

I was thinking about this though, and we're really just talking about the live-view here (Oz can both: a) compile md/clj/etc to static html files, b) send a live-view of these files to a browser pane as you edit, for a kind of static live code reloading). Since presumably the live-view will mostly be accessed from the same machine that is serving it, there may not be as much of a need for advanced compilation. So maybe it's fine to leave the live-view app target just whitespace optimized, so that we can more easily extend the base app?

mkvlr06:12:13

@metasoarous one nice thing about sci is that it can extend an advanced compiled build. We're doing this in nextjournal and Clerk and it gets you both: best performance for the paths that are compiled with the ability to extend it and call into those compiled functions later.

🤯 1
metasoarous06:12:42

What!? How does it do that?

metasoarous06:12:36

Once again, @borkdude is blowing my mind over here.

thheller06:12:56

thats not entirely accurate I would say. you still cannot extend SCI from a secondary build. you can only extend SCI from the build that includes SCI itself?

thheller06:12:25

please note that when code size is not a concern at all going with :simple might be a viable option (or even :none)

thheller06:12:00

there is no built-in way to make this work for now but there probably could be

mkvlr06:12:03

yes @thheller that's correct but you can put sci into a module and lazy load it only when you need it, then the bundle size effect should be negligible if you don't load it?

mkvlr06:12:59

@metasoarous this works because sci is just a Clojure script program that can be advanced compiled with the rest of your code

✔️ 1
metasoarous07:12:34

I continue to realize things in relation to sci that astound me, yet which in retrospect are entirely obvious

thheller06:12:27

yeah of course. Just commenting with regards to the initial questions wanting snippets of code interacting with live-view after a separate compile

thheller06:12:47

this is still somewhat of a holy grail I've been thinking about quite a lot but there is just no possible way to do this with :advanced

thheller06:12:34

but I usually very much care about build size so :simple is usually out of the question. for oz/portal/clerk that might not be of such a high concern

thheller06:12:48

so there should be better possible ways for doing this 😛

👍 1
metasoarous07:12:12

That makes; Thank you both!

metasoarous07:12:34

I continue to realize things in relation to sci that astound me, yet which in retrospect are entirely obvious

Lukas Domagala11:12:58

yeah being able to use cljs just like clj files would be great for library users and would make sharing a lot easier. sadly even a :none compilation makes it difficult. and even if you manage to get that running you still have to handle npm packages somehow, which would mean merging profiles which seems very brittle

roklenarcic16:12:34

What could be the reason for npx shadow-cljs release :main producing a file that has 4096 lines instead of 1? The dev build is 13M, but release build is 2M so some optimization was done, but I expected all whitespace to be gone and the build being 1 liner.

thheller16:12:44

why does that matter?

folcon16:12:27

How do you debug a build where the calling, npx shadow-cljs release appscript --debug fails but npx shadow-cljs compile appscript succeeds? More details in thread 😃... Any ideas on what to try next would be appreciated!

folcon16:12:39

How do you debug a build where the calling:

npx shadow-cljs release appscript --debug
fails with:
[:appscript] Compiling ...
IllegalStateException:
        com.google.common.base.Preconditions.checkState (Preconditions.java:492)
        com.google.javascript.jscomp.OptimizeParameters.addVariableToFunction (OptimizeParameters.java:1025)
        com.google.javascript.jscomp.OptimizeParameters.optimizeFunctionDefinition (OptimizeParameters.java:933)
        com.google.javascript.jscomp.OptimizeParameters.tryEliminateConstantArgs (OptimizeParameters.java:644)
        com.google.javascript.jscomp.OptimizeParameters.process (OptimizeParameters.java:128)
        com.google.javascript.jscomp.OptimizeCalls.process (OptimizeCalls.java:125)
        com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process (PhaseOptimizer.java:317)
        com.google.javascript.jscomp.PhaseOptimizer$Loop.process (PhaseOptimizer.java:462)
        com.google.javascript.jscomp.PhaseOptimizer.process (PhaseOptimizer.java:232)
        com.google.javascript.jscomp.Compiler.performTranspilationAndOptimizations (Compiler.java:2592)
        com.google.javascript.jscomp.Compiler.lambda$stage2Passes$8 (Compiler.java:966)
        com.google.javascript.jscomp.CompilerExecutor.runInCompilerThread (CompilerExecutor.java:127)
        com.google.javascript.jscomp.Compiler.runInCompilerThread (Compiler.java:1014)
        com.google.javascript.jscomp.Compiler.stage2Passes (Compiler.java:963)
        com.google.javascript.jscomp.Compiler.compileModules (Compiler.java:905)
        jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
        jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
        jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
        java.lang.reflect.Method.invoke (Method.java:568)
        clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:167)
        clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:102)
        shadow.build.closure/compile-js-modules (closure.clj:1102)
        shadow.build.closure/compile-js-modules (closure.clj:1088)
        shadow.build.closure/optimize/fn--11127 (closure.clj:1297)
        shadow.build.closure/optimize (closure.clj:1283)
        shadow.build.closure/optimize (closure.clj:1274)
        shadow.build.api/optimize (api.clj:273)
        shadow.build.api/optimize (api.clj:267)
        shadow.build/optimize (build.clj:476)
        shadow.build/optimize (build.clj:468)
        shadow.cljs.devtools.api/release* (api.clj:339)
        shadow.cljs.devtools.api/release* (api.clj:324)
        shadow.cljs.devtools.cli-actual/do-build-command (cli_actual.clj:28)
        shadow.cljs.devtools.cli-actual/do-build-command (cli_actual.clj:25)
        shadow.cljs.devtools.cli-actual/do-build-commands (cli_actual.clj:49)
        shadow.cljs.devtools.cli-actual/do-build-commands (cli_actual.clj:38)
        shadow.cljs.devtools.cli-actual/main/body-fn--15307--auto----15979 (cli_actual.clj:166)
        shadow.cljs.devtools.cli-actual/main (cli_actual.clj:165)
        shadow.cljs.devtools.cli-actual/main (cli_actual.clj:132)
        clojure.core/apply (core.clj:671)
        clojure.core/apply (core.clj:662)
        shadow.cljs.devtools.cli-actual/-main (cli_actual.clj:219)
        shadow.cljs.devtools.cli-actual/-main (cli_actual.clj:217)
        clojure.lang.Var.applyTo (Var.java:705)
        clojure.core/apply (core.clj:667)
        clojure.core/apply (core.clj:662)
        shadow.cljs.devtools.cli/-main (cli.clj:75)
        shadow.cljs.devtools.cli/-main (cli.clj:67)
        clojure.lang.Var.applyTo (Var.java:705)
        clojure.core/apply (core.clj:667)
        clojure.main/main-opt (main.clj:514)
        clojure.main/main-opt (main.clj:510)
        clojure.main/main (main.clj:664)
        clojure.main/main (main.clj:616)
        clojure.lang.Var.applyTo (Var.java:705)
        clojure.main.main (main.java:40)
But npx shadow-cljs compile appscript just succeeds?:
[:appscript] Compiling ...
[:appscript] Build completed. (43 files, 42 compiled, 0 warnings, 11.39s)
shadow-cljs.edn config:
;; shadow-cljs configuration
{:source-paths
 ["src"]

 :dependencies
 [[applied-science/js-interop "0.3.1"]]

 :builds
 {:appscript {;:main example.core
              :target :node-library
              :output-to "shadow-Code.js"
              ;:optimizations :advanced
              :output-dir "target"
              ;:pretty-print false
              :externs ["resources/gas.ext.js"]
              :exports-var example.core/main}}}

folcon16:12:32

I've tried running npx shadow-cljs check appscript, but I'm just getting some warnings, no errors. I'm running shadow-cljs version 2.16.8.

thheller17:12:51

well release runs actual optimizations but compile does not

thheller17:12:01

so it seems to run into some kind of bug inside the closure compiler

thheller17:12:38

kinda tough to narrow it down I guess

folcon17:12:53

Hmm, that's frustrating. So basically build a empty project and see if release works, slowly paste code back in until I can pin down the issue?

thheller17:12:05

hmm yeah. I've never seen this error before so no guesses as to what may be happening

thheller17:12:17

maybe try searching googe/closure-compiler github issues

folcon17:12:31

Hmm, I might have found it

folcon17:12:39

Can you do multiple export?

folcon17:12:13

IE: (defn ^:export start []) and (defn ^:export main [])

thheller17:12:33

^export has no effect at all for :node-library

folcon17:12:06

Ok, well it seems to

folcon17:12:23

If I have two functions with export it's failing with the error

folcon17:12:28

If I have one it doesn't

thheller17:12:30

:exports {:start foo.bar/start :main foo.bar/main}

folcon17:12:37

Just figured that out by commenting it out

thheller17:12:15

hmm ok. using ^:export in :node-library or :node-script builds is pointless anyways so don't use it at all 😛

folcon17:12:27

Hmm, can I do the same with :exports-var?

thheller17:12:44

did you read the docs?

thheller17:12:50

I mean it even has an example

folcon17:12:18

I mean I'm still figuring out how to use shadow-cljs to write appscripts 😃... So this stuff is weird.

folcon17:12:37

Interesting, so it doesn't work for :exports-var

thheller17:12:01

what doesn't work?

folcon17:12:22

:exports-var {:main example.core/main, :start example.core/start},
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   :build-id ...}

should satisfy

  unquoted-qualified-symbol?

thheller17:12:50

its :exports then

thheller17:12:04

:exports-var is for a single var pointing to a JS object

thheller17:12:26

its all in the docs

folcon17:12:18

Yep, makes sense

folcon17:12:27

Just checking it works

folcon17:12:07

Nope, now just back at illegal state exception

folcon17:12:47

Hmm, it's weirdly happy with one export, but not two

thheller17:12:40

what are you exporting? regular defn I assume?

thheller17:12:53

yeah dunno. can't say much without seeing the code/config

folcon17:12:36

That's fair

folcon17:12:57

I'll dig into this some more and see if I can pin down a minimal case 😃

folcon17:12:03

Thanks for the help!