shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
dazld 2021-02-09T12:12:48.089700Z

hey there - I'm trying to understand what's happening with *print-fn* such that if I print something from a function in the browser, I'll see that output in my repl. I can see that *print-fn* appears to be bound to the same thing (?) in both the client and the repl, but the behaviour diverges.

dazld 2021-02-09T12:13:30.089800Z

repl-print-fn it seems.. although I guess that's just the var

dazld 2021-02-09T12:13:45.090Z

I couldn't see anything in the docs about repl output too

dazld 2021-02-09T12:14:35.090200Z

if I (prn :foo) from a connected repl, I see the output in the repl and the browser console, but if I do the same thing from a function (eg reagent component), then i only see it in the console.

thheller 2021-02-09T13:26:25.091Z

shadow-cljs does not capture arbitrary prints outside the nREPL evaluation. pretty sure no CLJS REPL does

1👍
2021-02-09T13:36:24.092500Z

Hello 👋 Is it expected that release build won't write into location specified in {:release {:output-to "..."}}?

thheller 2021-02-09T13:38:13.092700Z

actually this is more or less a problem with nrepl and the nrepl clients

thheller 2021-02-09T13:38:27.092900Z

if you use the plain shadow-cljs cljs-repl app then those prints should be captured

thheller 2021-02-09T13:38:53.093100Z

it is just an artifact of most nrepl clients not accepting output that is not tied to a specific evaluation

thheller 2021-02-09T13:39:09.093300Z

shadow-cljs does capture the prints, it just has nowhere to send them in case of nrepl

thheller 2021-02-09T13:39:27.093700Z

depends. which :target are you talking about? :output-to for example is not an option for :browser

2021-02-09T13:39:40.094Z

:target :browser

thheller 2021-02-09T13:39:48.094300Z

that should be :output-dir then

2021-02-09T13:50:35.094700Z

ah, so there's no way to specify output-dir per module?

thheller 2021-02-09T13:51:23.095200Z

no, it is by design that all :modules should live in the same directory. otherwise complicates things with loader and source maps and so on

2021-02-09T13:53:26.096100Z

got it :thumbsup: what about compiler namespaces, are they written into :output-dir as well when running release?

thheller 2021-02-09T13:54:32.096400Z

no, in case you mean the cljs-runtime dir you otherwise get with watch or compile output

2021-02-09T13:56:44.096900Z

perfect! thanks 🙏

2021-02-09T14:06:15.098200Z

btw, are there any docs on how shadow bundles NPM deps? is it using own bundler? does it split npm deps together with cljs splits?

thheller 2021-02-09T14:07:19.098400Z

yes, yes, yes

thheller 2021-02-09T14:08:27.099500Z

https://code.thheller.com/blog/shadow-cljs/2018/06/15/why-not-webpack.html has some background info on how things work

thheller 2021-02-09T14:09:53.100Z

some other posts also talk about it

2021-02-09T14:12:06.101300Z

thanks! I have some more questions if you don't mind: what about DCE? does it exist, is it on par or better than webpack? what happens with NPM deps when compiling with advanced optimizations?

thheller 2021-02-09T14:13:28.102400Z

for npm dependencies it does not exist no, they only go through :simple

thheller 2021-02-09T14:15:39.103600Z

I might add it at some point but currently everything is pretty webpack specific so even other JS bundlers struggle with it

2021-02-09T14:20:12.104900Z

I see. So how's JS deps are included into cljs splits then? Does shadow splits NPM deps into modules based on requrie's from cljs code and then prepends JS splits to CLJS ones?

thheller 2021-02-09T14:20:36.105100Z

basically yes

thheller 2021-02-09T14:20:52.105400Z

but its file based not module based, so even if they are in the same package they might end up in different modules depends on how you use them

2021-02-09T14:25:53.106700Z

cool! thanks :thumbsup:

johnjelinek 2021-02-09T15:12:40.107500Z

does anyone know of a reference architecture/starter kit for clojurescript that has typescript interop? Would this be interesting to anyone?

dazld 2021-02-09T16:05:07.107700Z

thanks @thheller

dazld 2021-02-09T16:05:17.107900Z

and yep, i'm using an nrepl

dazld 2021-02-09T16:07:39.108100Z

some kind of plumbing for a connected build would be pretty neat, getting prints back from the client

2021-02-09T20:28:03.108700Z

I got to code splitting and hitting an issue now: goog is not defined

2021-02-09T20:28:49.109500Z

the setup is simple: there's module A and module B that depends on A, when A is loading the exception is thrown

2021-02-09T20:29:55.110Z

should mention it happens in release build with advanced optimizations

2021-02-09T20:30:34.110600Z

the line where it fails is goog=goog||{} which I guess comes from goog's base.js

thheller 2021-02-09T20:33:13.111Z

hmm? advanced shouldn't contain this?

2021-02-09T20:35:11.111600Z

hmm, good point, might be something coming from a library, let me see, thanks

2021-02-09T20:40:15.112200Z

here's code block around that line compiled with :pseudo-names true

$APP.$JSCompiler_stubMap$$ = [];
    goog = goog || {};
    $goog$global$$ = this || self;
    $goog$NONCE_PATTERN_$$ = /^[\w+/_-]+[=]{0,2}$/;
    $goog$cspNonce_$$ = null;
    $goog$UID_PROPERTY_$$ = "closure_uid_" + (1E9 * Math.random() >>> 0);
    $goog$uidCounter_$$ = 0;
    $APP.$goog$now$$ = Date.now || function() {
        return +new Date
    }
    ;
    $goog$evalWorksForGlobals_$$ = null;
    $APP.$goog$inherits$$($goog$debug$Error$$, Error);

2021-02-09T20:40:49.112800Z

is that something that shouldn't be there after advanced?

thheller 2021-02-09T20:42:22.113100Z

not a clue where this is from. it shouldn't be there.

thheller 2021-02-09T20:43:35.113900Z

which versions do you use? make sure it all matches properly. using mismatched closure compiler, CLJS or shadow-cljs versions causes all sorts of weird issues

2021-02-09T20:44:46.114200Z

shadow 2.10.21 cljs 1.10.773

thheller 2021-02-09T20:46:11.115500Z

in a regular build it should be something like var da=da||{} or pseudo-named var $goog$$ = $goog$$ || {}

2021-02-09T20:46:33.116300Z

huh, actually I'm building using shadow from NPM of one version and requiring shadow's loader, which is coming from shadow of another version declared in deps.edn, should fix that as well

thheller 2021-02-09T20:47:21.117100Z

yeah those should be somewhat close but only the deps.edn version is really relevant

thheller 2021-02-09T20:47:45.117600Z

npm stuff only affects the shadow-cljs command line tools, nothing from the compilation

1👍