Fork me on GitHub
#shadow-cljs
<
2020-03-31
>
awb9902:03:43

I have a question of sub-npm dependencies that are written to deps.cljs

awb9902:03:54

If I require multiple projects that have deps.cljs

awb9902:03:09

I guess the only way for shadow-cljs to find out about them, is to access the resources.

awb9902:03:13

Now my question is,

awb9902:03:31

if multiple libraries are included, that all add the deps.cljs with the same location,

awb9902:03:38

then this resources will override each other.

awb9902:03:04

So basically, the deps.cljs files would need to be placed into UNIQUE locations

awb9902:03:08

for each library.

awb9902:03:16

Could this be the case?

coby05:03:37

I'm trying to serve a web worker but I'm running into Content Security Policy issues when the browser tries to init the worker. It appears the Content-Security-Policy header is not being sent. Am I using :push-state/headers wrong?

{:source-paths ["src"]

 :dependencies [[binaryage/devtools "0.9.7"]
                [reagent "0.8.0-alpha2"]]

 ;; serve the public directory over http at port 8700
 :dev-http {8700 {:root "public"
                  :push-state/headers {"Content-Security-Policy" "default 'self'"}}}

 :builds
 {:app {:target :browser
        :output-dir "public/js/compiled"
        :asset-path "/js/compiled"

        :modules
        {:common {:entries []}
         :main {:entries [pwa.core]
                :depends-on #{:common}}
         :service-worker {:web-worker true
                          :depends-on #{:common}
                          :init-fn pwa.service-worker/init}}}}}

thheller08:03:41

@ctamayo the server doesn't set any CSP by default so you are likely setting it in your HTML?

coby16:03:01

@thheller no, it's just the default generated index.html from lein new shadow-cljs pwa +reagent

thheller16:03:35

no clue what that generates

coby16:03:20

TL;DR, no http-equiv to be found

coby16:03:26

Back to basics for now, does my :push-state/headers look right?

thheller08:03:03

@hoertlehner each library can have its own deps.cljs in the .jar it ships. they won't conflict.

awb9908:03:13

@thheller many thanks for the clarification!

awb9908:03:55

in case of web servers that serve from embedded resources, they ar eonly able to serve one version.

awb9908:03:05

so I thought that this might be similar for shadow-cljs

awb9908:03:16

seems you look deep inside the jars to find that out.

thheller08:03:37

well generally it is true that names on the classpath must be unique

thheller08:03:04

but instead of asking for one thing by name you can also ask for all the things using that name

thheller08:03:15

classloader .getResource vs .getResources

thheller08:03:09

so there can always be multiple versions, there are just simple rules to determine which one is the "winner" when looking up a single one by name

thheller08:03:38

sometimes it is useful to get all (eg. deps.cljs)

awb9908:03:35

perfect!!

Ben Hammond11:03:41

I'm trying to use the auth0 SinglePageApp client library like this

"dependencies": {
    "@auth0/auth0-spa-js": "^1.6.5",
and then from within cljs
(:require ["@auth0/auth0-spa-js" :as auth0]
...
(auth0/createAuth0Client auth0-config)
but I just see a

Ben Hammond12:03:46

main.js:2226 failed to load uix.control_auth.js TypeError: module$node_modules$$auth0$auth0_spa_js$dist$auth0_spa_js_production.createAuth0Client is not a function
    at eval (control_auth.cljs:23)
    at eval (alpha.cljc:162)
    at eval (alpha.cljc:140)
and when I look in the repl I see that the namespace is a function
(require '["@auth0/auth0-spa-js" :as nsauth])
=> nil
(type nsauth)
=> #object[Function]
the resources/public/js/cljs-runtime/module$node_modules$$auth0$auth0_spa_js$dist$auth0_spa_js_production.js.map looks like
"names":[...,
"createAuth0Client",
...]
the original function is declared as
export default async function createAuth0Client(options: Auth0ClientOptions) {
so it IS default, (which I can call), but why cannot I call the real function? is it the ES8-only async causing linking problems?

Ben Hammond12:03:45

I set my :compiler-options to

:compiler-options
        {:infer-externs :auto
         :closure-warnings {:global-this :off}
         :closure-defines {"goog.DEBUG" true#}
         :output-feature-set :es8}
but it doesn't seem to have helped...

thheller12:03:32

@ben.hammond nothing to do with your config

thheller12:03:39

createAuth0Client is not a function

thheller12:03:58

(type nsauth)
=> #object[Function]

thheller12:03:09

so its likely that you just call (nsauth config)

Ben Hammond12:03:41

I'd like to understand why the actual named function call doesn't work though if I can

thheller13:03:17

there is no such thing as a named function

thheller13:03:38

see the export default the only name that has is default

thheller13:03:06

but that depends on how the package is actually bundled

👍 4
Ben Hammond13:03:06

ah okay; that is the gap in my understanding

thheller13:03:47

well not really. generally default exports don't have a name. it is just the default

thheller13:03:20

so import Foo from "@auth0/auth0-spa-js" is just as valid as import createAuth0Client from "@auth0/auth0-spa-js"

thheller13:03:38

the importer defines the name, not the lib

thheller13:03:52

but .. yeah it is subject to how things are bundled

thheller13:03:57

:default exports are weird

Saikyun16:03:36

currently teaching two people cljs using shadow-cljs, so far so good 🙂 thanks for making it such an enjoyable experience

💯 32
papachan17:03:47

Is there a template to publish shadow-cljs project to github page?

hindol17:03:34

I did a few recently, e.g. https://github.com/hindol/genesis Let shadow write files to docs/ instead of the default public/ and in Github's repo settings, enable pages from docs folder.

👍 4
hindol17:03:29

Everytime you want to update the site, remember to 1) first clean existing built files, 2) npx shadow-cljs release app (assuming app is your build target) and 3) git push!

hindol17:03:09

The caveat is, you have to check-in the shadow built files.

hindol20:03:19

No problem. Let me know if you face any issues.

Chris McCormick00:04:13

something i have found useful is to configure two separate targets, one for dev and one for prod, and have the prod target build to a different place from the dev target. This way you don't have to do the cleaning step.

👍 4
hindol05:04:23

That's a great tip! @UUSQUGUF3 Is it possible to share the same index.html between two builds? By copying as part of the build step, perhaps?

thheller08:04:28

that is not how shadow-cljs is meant to be used!

thheller08:04:42

DO NOT USE DIFFERENT BUILDS FOR DEV/PROD!

thheller08:04:17

if you just want a different output dir for release then do :release {:output-dir "foo"} in your build config

💯 4
facepalm 4
thheller08:04:27

no point in making totally different builds!

Chris McCormick09:04:49

oh awesome, thanks for that :release :output-dir option 👍

Chris McCormick09:04:30

my apologies for the fake news

Chris McCormick09:04:13

@UJRDALZA5 in terms of build I use a Makefile to do the final build which invokes the production build and also copies files from public to build.

hindol09:04:46

Can you please link to the repo if it's in the public domain?

Chris McCormick11:04:20

👍 will see if i can find a public one

Chris McCormick11:04:50

though here i am using the technique which @thheller said not to use, with the two different targets. so i should update that.

hindol11:04:21

Thanks for the link! Really helpful.

hindol12:04:25

The deps.edn approach also looks interesting.