Fork me on GitHub
#clojurescript
<
2020-10-21
>
kah0ona08:10:47

Hi, anybody else experienced a hanging compilation with :advanced mode, when :target :bundle is used? I canโ€™t for the heck of me figure out why this happens to my project. I have a development/figwheel-main setup that does work with :target :bundle, ie. it will properly use my external libraries, but :advanced compilation seems to hang

kah0ona08:10:54

any pointers in how to debug this?

kah0ona08:10:14

cljs 1.10.773

kah0ona08:10:02

{:main            myns.core
 :output-to       "target/index.js"
 :output-dir      "target"
 :optimizations    :advanced
 :target          :bundle
 :verbose         true
 :bundle-cmd      {:none    ["npx" "webpack" "./target/index.js" "-o" "./target/" "--mode=development"]
                   :default ["npx" "webpack" "./target/index.js" "-o" "./target/"]}
 :closure-defines {cljs.core/*global* "window"}} ;; needed for :advanced compilation

kah0ona08:10:12

thatโ€™s my build.edn

kah0ona08:10:47

but it never gets to the point of bundling, just hangs at: Applying optimizations :advanced to 281 sources

kah0ona08:10:52

or is it just reaaalllly slow?

thheller08:10:09

no clue about the :bundle-cmd side of things but :advanced can take a long time. depends on your code. I've seen anything between a couple sec and a few minutes

thheller08:10:29

whereas a couple minutes is quite extreme and uncommon

thheller08:10:32

so usually a couple secs

victorb08:10:46

@kah0ona if you're on linux, you could try using strace to see if it's hang/waiting for something, or if it's just doing bunch of work. Try strace <your command> and see if you get tons of output (busy working) or if it stops outputting logs after a while (stuck waiting for something)

victorb09:10:08

Using juxt/tick in cljs to do some lightweight formatting (just want to show how long time ago something happened) but tick pulls in js-joda which ends up being 30% of my bundle size. Anyone got any handy library/snippet for cljs for taking a js/Date and turning it "X seconds/minutes/hours ago" that is a bit easier on the size side?

Day Bobby09:10:29

nvm it depends on tick as well

victorb09:10:46

thanks to both for the pointers. Yeah, DateTimeFormat is nice, but don't think it does "durations" that would be needed to get the "X minutes ago", or at least I don't see how I could get that from DateTimeFormat

p-himik09:10:29

dayjs(1536484369695).fromNow();
// => "5 days ago"
Not sure if it has better precision than days.

victorb09:10:29

yeah, js interop is fine, as long as the library is small and nimble, and don't end up to big in the bundle. I'll take a look at dayjs, thanks

p-himik09:10:11

I've glanced at a few articles that talk about replacements for moment - day.js seems to be the most lightweight.

victorb09:10:12

in the end, what ends up taking lots of space is the locales, rather than the libraries themselves

p-himik09:10:24

In any case, https://bundlephobia.com/ is a great service.

๐Ÿ‘ 3
victorb09:10:25

that's nice, thanks again for the pointer :thumbsup:

victorb09:10:16

yeah, tried bundlephobia before but not sure what they use to do the calculations, don't think it's accurate with closure compiler, as it's hard to know before including it and using it how much space it'll actually take

victorb09:10:14

dayjs seems small enough though, looks great

p-himik09:10:22

Indeed. But I think it can be useful when comparing different JS libraries between each other.

๐Ÿ‘ 3
henryw37410:10:34

actually I was thinking of this before https://github.com/tc39/proposal-intl-duration-format ... still a work in progress unfortunately

victorb10:10:34

ah sweet, haven't seen that before. Thanks @U051B9FU1

victorb10:10:51

yeah, unfortunately still a draft but at least the API does look OK ๐Ÿ™‚

thheller10:10:32

I can't believe no one has suggested this but if "X seconds/minutes/hours ago" is all you really need just write that function yourself. its trivial and smaller than any lib you'll find. pretty sure there is also something in the closure library for this.

p-himik10:10:13

Good to know that Closure has such functionality. Regarding writing it yourself - it's not that easy if you need l10n.

thheller10:10:16

well yes that makes everything harder. I think the closure lib variant handles that.

victorb10:10:02

@U05224H0W yeah, was looking for snippets as well! Don't want to spend any time re-writing something that's already been written, the code from relative.js looks good enough so thanks for linking that! :thumbsup:

victorb10:10:45

makes note to self that I should really sit down and at least scan the top-level API for the closure-library, I always tend to forget/miss the built-in functionality

thheller10:10:33

I have a local checkout and typically just "find in files" and pretty often there is something ๐Ÿ˜›

๐Ÿป 3
deadghost15:10:16

I'm running frontend tests on nodejs and since nodejs is missing some browser things, I need to create stubs like (set! (.-document js/global) (clj->js {:getElementsByClassName (fn [_] [])})). I'm wondering if there's already a comprehensive set of stubs in a repo somewhere.

odge18:10:04

I have a customer getting errors where the data format looks weird: The logs says :fxrate #object[h {:value 1.1823}] but I would expect :fxrate 1.1823 where is this format coming from? Any ideas or leads appreciated.

p-himik18:10:31

Hard to say anything specific without my crystal ball. :) But #object[...] can appear when you try to print a JS object that's not a plain object (i.e. for which object? returns false). And the h part may easily come from some minified class name.

odge18:10:43

Thanks, I guess I'll just have to bite the bullet and find out what h was before minifying

p-himik18:10:15

Source maps should help.

odge18:10:13

I can't reproduce the bug, so all I have is my customers error message. I have source maps for the deployed code, but not sure if I can look up whatever h is in them