Fork me on GitHub
#shadow-cljs
<
2022-02-02
>
Gokul Syam14:02:16

Hi @thheller, can you tell me where I’m supposed to be setting closure-defines option at?

Gokul Syam14:02:16

Here it’s not wrapped inside compiler-options, is that not necessary?

thheller14:02:34

see sentence below this thread

thheller14:02:31

can be directly in the build config or :compiler-options {:closure-defines ...}. both work

Gokul Syam14:02:02

I followed this - https://github.com/thheller/shadow-cljs/issues/217, and my config looks similar to it

Gokul Syam14:02:21

But CLOSURE_DEFINES is still coming up as undefined

thheller14:02:06

CLOSURE_DEFINES should be of no concern to you. if you are trying to use it you are doing something incorrectly.

thheller14:02:13

what is your :target build?

thheller14:02:15

and you have a namespace with a goog-define?

Gokul Syam14:02:35

oh, I don’t

Gokul Syam15:02:07

But if I’m setting something from the Closure library, I don’t need to explicitly define that right?

Gokul Syam15:02:09

:closure-defines {goog.json.USE_NATIVE_JSON true}

thheller15:02:49

yeah thats fine

thheller15:02:15

looks fine to me

Gokul Syam15:02:40

Weird, I’ve added it inside builds and even in every individual profile, still no luck

thheller15:02:57

should be in {:builds {:build-id {:target :browser :closure-defines {goog.json.USE_NATIVE_JSON true}}} in shadow-cljs.edn

Gokul Syam15:02:00

Yep, just checked, I’m able to find it there

Gokul Syam15:02:51

Just to confirm, I’m checking for CLOSURE_DEFINES in the browser, if it’s undefined then that means it was not configured properly right?

thheller15:02:21

again CLOSURE_DEFINES is of no concern. it is an implementation detail. forget it exists.

thheller15:02:36

please instead describe what you are actually doing

thheller15:02:46

you have a :target :browser build

thheller15:02:54

you are loading in a HTML page somewhere?

thheller15:02:02

you have a REPL into that page for the build?

thheller15:02:38

it is running in an actual browser. directly without any other build tools post processing it in any way? meaning you are loading the output actually produced by shadow-cljs, not something else.

Gokul Syam15:02:14

The way that it’s configured is using lein with shadow-cljs

Gokul Syam15:02:36

I’m actually very new to Clojure and especially the tooling so my apologies if that’s not what you were asking for

Gokul Syam15:02:06

I’m building an uberjar with lein uberjar-app

Gokul Syam15:02:18

:uberjar-app {:prep-tasks [["shadow" "release" "app"]
                                "compile"]}

Gokul Syam15:02:11

“app” is the build-id

thheller15:02:12

ok that does a release of the app build

thheller15:02:52

exactly. I assume that is a standard :advanced build. this will be optimized and no traces of the CLOSURE_DEFINES will be left. so you definitely cannot look that up there

thheller15:02:19

(assuming you actually set it for the release build and not just dev)

thheller15:02:46

but point is looking it up manually via CLOSURE_DEFINES in release builds is not possible

thheller15:02:00

you can do in watch or compile but not release

Gokul Syam15:02:06

I was able to see it in dev so I figured the same would be possible in release as well

Gokul Syam15:02:28

okay got it, but yea I’m setting it in release as well

thheller15:02:56

the closure compiler will inline the value you set and then optimized

thheller15:02:09

so looking up the result is kinda difficult 😛

thheller15:02:14

why do you think it isn't working?

Gokul Syam15:02:40

the whole purpose is to prevent closure compiler from using eval methods

Gokul Syam15:02:56

cause I have a content-security-policy configured to block all eval methods

Gokul Syam15:02:47

I found out online that this is the flag that actually prevents it from using eval

thheller15:02:54

it should already use JSON.parse if thats available? so it won't use eval if that is available?

Gokul Syam15:02:48

Hmm doesnt seem to be the case, CSP is still flagging methods for using eval in the compiled script

thheller15:02:19

you can compile shadow release app --debug. that'll give you source maps and use pseudo names

thheller15:02:28

that should make it much easier to find out where exactly eval is used

Gokul Syam15:02:43

oh awesome, i’ll try that

Gokul Syam15:02:00

been banging my head at this for hours, thank you for some direction

thheller15:02:01

(it should also allow verifying the closure define actually did something

thheller15:02:06

pseudo names renames stuff

thheller15:02:15

so goog.json should be $goog$json

thheller15:02:19

just look for that in the source code