Fork me on GitHub
#shadow-cljs
<
2019-12-01
>
Pavel Klavík23:12:49

Hi, there seems to be a problem when using both Web Workers and Module hash names. I have the following shadow-cljs.edn:

{:target            :browser
                         :output-dir        "resources/public/js/compiled"
                         :asset-path        "/js/compiled"
                         :module-hash-names true
                         :modules           {:shared {:entries []}
                                             :main   {:init-fn    orgpad.client.core/init
                                                      :depends-on #{:shared}}
                                             :layout {:entries    [orgpad.client.layout.webworker.core]
                                                      :depends-on #{:shared}
                                                      :web-worker true}}
                         :compiler-options  {:infer-externs :auto}
                         :devtools          {:after-load  orgpad.client.core/mount-root
                                             :before-load orgpad.client.core/stop-web-workers
                                             :watch-dir   "resources/public"}}

Pavel Klavík23:12:23

When I run the release version, I get the following error: Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://reorgpad.herokuapp.com/js/compiled/shared.js' failed to load. at https://reorgpad.herokuapp.com/js/compiled/layout.2C8E9F9F47AB1338B6ABF2B8D798D22B.js:1:1

Pavel Klavík23:12:09

Where the actual name is shared.0A18608384A13578DC44FDC090CF8CC5.js

thheller23:12:58

yes :module-hash-names doesn't work when using workers

thheller23:12:04

that is known and can't really be fixed 😛

thheller23:12:26

adding the hash of something to a file changes its hash

thheller23:12:52

adding it also messes up the source map

thheller23:12:25

so kinda no idea how to do this cleanly

thheller23:12:42

I've been thinking about adding something like shadow-cljs release app --config-merge '{:module-fingerprint "foo"}'

thheller23:12:59

so that would produce shared.foo.js and layout.foo.js

thheller23:12:13

so in theory you could provide a version number or git sha or whatever

thheller23:12:17

not really using a hash

thheller23:12:14

@pavel.klavik did you report the source maps not working or was that someone else? in any case I reproduced that myself and :devtools {:loader-mode :script} seems to fix that

Pavel Klavík23:12:04

Couldn't the hash problem be solved by first compiling shared.js, this would produce the hash, then add it into layout.js and then computing hash for it?

thheller23:12:53

its all compiled in one go by the closure compiler

thheller23:12:33

I guess it could prepend the importScripts after the compilation though

Pavel Klavík23:12:25

The source maps are fixed by what you suggested, thx.

thheller23:12:39

dunno the whole hash-names thing isn't solved very cleanly currently

thheller23:12:29

but the web-worker case should be fixable I think. please open an issue so I don't forget

Pavel Klavík23:12:59

the stuff with module-fingerprint does not work yet?

thheller23:12:47

no its just an idea

thheller23:12:24

but I like it more than all the hashing stuff

thheller23:12:42

since you don't really get reusable files anyways between compiles

thheller23:12:34

seems better to use something a human can actually recognize (eg. version number or even using the git sha to lookup commits)

Pavel Klavík23:12:15

makes sense, both solutions would be fine, at least as an alternative

Pavel Klavík23:12:01

of course, I can imagine that I will make commits only changing the server (which I have in the same repository) and it will change the client js name, but it does not seem like a big problem

thheller23:12:07

well then you shouldn't trigger a CLJS build in the first place probably 😛

thheller23:12:24

you'll very likely get different hashes currently already

Pavel Klavík23:12:41

ya, currently it is not a big problem if the filename changes more often, but it is a big problem if someone uses old client version due to caches