Fork me on GitHub
#clojurescript
<
2018-06-08
>
Garrett Hopper04:06:34

Am I doing something wrong? clj -m cljs.main -co "{:foreign-libs [{:global-exports '{global.test global}}]}" -re node -r Exception in thread "main" java.lang.RuntimeException: Map literal must contain an even number of forms :global-exports is supposed to be a quoted map of namespaces to global exports, right?

bhauman04:06:16

@ghopper that single quote is screwing up the shell arg

bhauman04:06:30

you can safely get rid of it

Garrett Hopper04:06:25

...I was about to say that it does the same thing with a file. Then I tried the file without the quote. Thanks, @bhauman!

Hukka07:06:52

Bah. I should've solved the online requirement of cljsbuild earlier. Now I'm stuck working in a train with mobile connection that works... sometimes. If the problem is in the lein side (as I thought) and hairy to untangle, what are the alternatives for building cljs files?

dnolen09:06:26

Just gave figwheel-main a spin, good stuff 🙂

8
valtteri09:06:50

Noob question. Trying to build with lein-cljsbuild and all my deps seem to end up in app.js but not my own sources. What am I doing wrong?

{:id           "not-min"
     :source-paths ["src/cljs" "src/cljc"]
     :compiler     {:main            lipas.ui.core
                    :output-to       "resources/public/js/compiled/app.js"
                    :optimizations   :whitespace
                    :closure-defines {goog.DEBUG false}
                    :pretty-print    false}}

valtteri09:06:40

I’ve been developing this with figwheel so far and it works nicely. However I’m now trying to create a js-file that I can upload to server

valtteri09:06:30

lein clean && lein cljsbuild once not-min

valtteri09:06:48

It’s also very like that I’ve understood something wrong. I’m now assuming that all JS would be emitted to single file (app.js)

valtteri09:06:19

Now app.js contains thousands of rows from my deps but nothing from my own sources (checked with grep). However all my code + deps was compiled under target/cljsbuild-compiler-1/… into separate files. Why is my stuff missing from app.js?

valtteri09:06:43

I’m supposed to demo this in 10min 😄 It would’ve been cool to have it on internet so people could try with their own devices. But maybe I’ll stick with figwheel & screenshare this time.

dnolen11:06:11

@valtteri seems strange, did you try :simple?

valtteri11:06:22

Heh, updated to latest clojurescript and got better error message from the compiler. I had a file with bad name local-storage.cljs instead of local_storage.cljs. I guess that’s why it failed earlier.. though the last line in output was always “Successfully compiled ….” 😅

dnolen11:06:14

that result string is from cljsbuild, it’s odd that you didn’t get an exception during build though

valtteri11:06:14

Odd indeed

root@52717b0e031c:/usr/src/app# lein cljsbuild once not-min
Compiling ClojureScript...
root@52717b0e031c:/usr/src/app#

valtteri11:06:50

This was with 1.9.908 EDIT: looking at the output it doesn’t say ‘success’ even though I earlier claimed so. Now thinking about it.. It’s possible that my STDERR was going to /dev/null or something since I was playing with a bash session in Docker.

valtteri11:06:53

And with 1.10.238

Compiling ClojureScript...
Compiling "resources/public/js/compiled/app-min.js" from ["src/cljs" "src/cljc"]...
Jun 08, 2018 2:18:47 PM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: /Users/vaotjuha/lipas/lipas/webapp/target/cljsbuild-compiler-1/lipas/ui/core.js:5: ERROR - required "lipas.ui.local_storage" namespace never provided
goog.require('lipas.ui.local_storage');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

valtteri11:06:16

But now advanced optimizations work which is sweeeet! 👍

valtteri11:06:21

Ahhh. Here’s another weird attempt when run on host (MacOS)

lein clean && lein cljsbuild once not-min
Compiling ClojureScript...
Compiling "resources/public/js/compiled/app.js" from ["src/cljs" "src/cljc"]...
Jun 08, 2018 12:41:26 PM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: /Users/vaotjuha/lipas/lipas/webapp/target/cljsbuild-compiler-1/cljs/core.js:3579: ERROR - Parse error. primary expression expected
case ##Inf:
      ^

Jun 08, 2018 12:41:26 PM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 1 error(s), 0 warning(s)
ERROR: JSC_PARSE_ERROR. Parse error. primary expression expected at /Users/vaotjuha/lipas/lipas/webapp/target/cljsbuild-compiler-1/cljs/core.js line 3579 : 6
Successfully compiled "resources/public/js/compiled/app.js" in 18.084 seconds.

valtteri11:06:58

This was with 1.9.908.. and definitely the weirdest 🙂

mfikes12:06:55

But, in the above, it is as if ClojureScript is being put in your JavaScript file? Odd.

valtteri12:06:24

I’m not absolutely sure what was going on there because I didn’t know what I was doing. 🙂 But I think that the problem was indeed that there was a file with bad name and the latest clojurescript compiler was able to provide useful error which lead me to right direction. The confusion game from lein-cljsbuild telling that build was success even though it failed and error-message was really cryptic from 1.9xxx compiler.

valtteri12:06:19

HMmm isn’t tools.reader shipped with clojurescript? So there shouldn’t be version mismatch unless something pulled me another version somehow?

valtteri12:06:23

Hmm or is it actually shipped with clojure.. Anyways my clojure version is “1.9.0”

valtteri12:06:42

I probably need to figure out how this whole compliation process and related tooling actually works. 🙂

mfikes12:06:52

@valtteri Yeah, usually things work correctly with the tools.reader version that ClojureScript depends upon, and you really only run into trouble if something else in your build tooling causes an older version to be put on the classpath. But, the above sounds like ##Inf made it into JavaScript, and then Google Closure Compiler failed when it saw it.

valtteri12:06:49

Ok, thanks for the explanation.

valtteri12:06:00

I just lately realized that js-libs are nowadays HUGE and :advanced is really necessary. I added a ui-lib to my project and BOOM 2Mb of js. 🙀

mfikes12:06:05

(Actually, as you said, it is not "made it into JavaScript", but just a filenameing confusion)

👍 4
mfikes12:06:41

The JavaScript for cljs.core is about 1.2 Mb, but typically after :advanced you end up in the less than 100 Kb range.

roti12:06:42

I upgraded figwheel, and the code reloading is not working anymore (the compilation happens, but the new code is not loaded). has anyone experienced this?

pesterhazy12:06:51

@roti, try lein clean, remove target/ manually, shift-reload, different browser, roughly in that order

Hukka13:06:39

Hmh. How can I mark callback parameters in externs, or otherwise keep the names intact? So I want to pass a callback to external JS lib. That callback will get an object, which has a method I need to call (leaflet marker clusters and the function to create an icon for the cluster)

mhuebert15:06:16

You could try putting a ^js type hint in front of the arg, if you have the :infer-externs compiler option enabled. Eg (fn [^js the-arg] ...)

Hukka16:06:16

Hm, true. I can do that and see what the generated extern looks like

Hukka16:06:28

Although based on the example I would need to supply the path to the object.

Hukka16:06:05

Ok, so what the inferred externs did was what I had hacked up: set up the methods on Object...

Hukka17:06:48

Whoa, If I manage to figure out the right object in the global namespace and extern that, closure compiler knows that the callback is going to get that object and keep the methods as is

Hukka17:06:07

So if I put a ^js type hint for a parameter, does that actually mean "This is of type Object" and not just "this is some kind of JS object", and therefore it forces the compiler to treat it as such, even though it's capable of inferring the exact type?

Hukka17:06:51

Hmm, no. If I misspell the object, the methods under it are still inferred. I suppose the compiler will just keep all method names under any object in externs, just in case

Hukka10:06:39

I'm starting to think that I will just stop thinking about how to make better externs (seems like the project which I inherited is in fact equivalent of having all methods defined on Object) I will just drop them completely and move to cljs-oops

mhuebert11:06:03

For several months I have been using ^js hints whenever I encounter an issue with externs, and find that it "just works" and is a nice/lightweight approach. If you have warnings enabled, it will still show warnings for these cases (unless you use shadow-cljs, which directly supports ^js). cljs-oops works too. I just personally prefer to avoid extra libs.

Hukka13:06:51

Since the object is not in global scope, I can't do it the usual way

Hukka13:06:37

I tried getting the function with goog.object/get and call it then, but then it's called with null this

ajs13:06:07

Is it possible in cljs or even just in JS to get a pem certificate delivered in code only (via ajax, etc) and automatically use that for further REST requests to a server?

ajs13:06:23

I can't find any information suggesting certificates can be installed automatically or used in a browser without explicit user intervention

manutter5113:06:36

@ajs wouldn’t it be a security hole if code were able to install certs without user knowledge and/or approval?

ajs13:06:59

i would think so, but i'm working with another team that seems to think this might be possible, even though they haven't done it before

Hukka15:06:28

Heh, even accessing goog.object gets munged

dehli15:06:56

is it possible to use javascript’s async/await in cljs? I’m wanting to use it when writing an abstraction on top of amazon lambda

dehli15:06:21

I’ve set my target to ecmascript2017, but i’m not sure how I can define a function as async (and it shows async/`await` here: https://cljs.github.io/api/compiler-options/language-in)

justinlee16:06:40

@dehli no, but you can use promises fairly conveniently with clojurescript. if I have something complicated, I use the alet macro from the promesa library which works quite well. that library also has a macro that emulates async/await, but I’ve found it to be a little fragile (and honestly you can do anything with alet)

dpsutton16:06:53

big discussion thread on some of the challenges here: https://groups.google.com/forum/#!topic/clojurescript/scUMhU-ctEM

👍 4
dehli17:06:32

Thanks you guys! I’m currently using promises and just wanted to double check 🙂

Hukka17:06:07

So if I put a ^js type hint for a parameter, does that actually mean "This is of type Object" and not just "this is some kind of JS object", and therefore it forces the compiler to treat it as such, even though it's capable of inferring the exact type?

johnj17:06:27

@lee.justin.m talking out of ignorance here, why not just use core.async for his async/await needs?

dehli18:06:03

Also I am using core.async, however I needed promises (or async/await) for interop with amazon lambda. Basically just have to convert a core.async channel into something that lambda recognizes

johnj17:06:56

nvm, you links explains some of it

justinlee17:06:59

@lockdown- for me personally, my reasons are (1) i do not like the exception handling semantics of core.async, (2) it produces tons of code that is hard to understand and debug, (3) it creates huge stack traces, (4) its way more complex than I need

johnj18:06:46

@lee.justin.m ok, I'm starting to like JS 2018+ 😉 - is not that bad, and there is always lodash/fp

johnj18:06:35

I think the difference in performance of doing immutability in JS(browser) but without the 'persistent' part is very low

dnolen18:06:07

FWIW I do not like princess, personally I don’t know why you would want to bother with async/await when you have core.async

8
dnolen18:06:41

If you use it at the edge and for coordination it really not hard to use nor do you encounter serious debugging issues

dnolen18:06:57

That’s promesa not princess :)

dnolen18:06:36

I’ve used it for a year on a client project along with nomadic macros

dnolen18:06:54

It’s not good IMO, certainly no easier to understand or debug than core.async

dnolen18:06:21

Erg sorry on phone, monadic macros

dpsutton18:06:24

ran into issues using #?@ reader conditional in (:require ... section of ns form. Is this a known limitation/bug?

dnolen18:06:52

No issue has been reported before

john18:06:10

Working with ServiceWorkers, they expect you to use async/await in some places

👍 4
dpsutton18:06:23

seems to only happen when cljsjs/big is involved....

dpsutton18:06:27

that's super strange

favila18:06:10

Yeah it has nothing to do with splicing but I can't make sense of it

favila19:06:05

(ns com.foo (:require [cognitect.transit :as t] [cljsjs.big])) is as small as I can get it

favila19:06:47

(require 'com.foo)
TypeError: Cannot load script from .cljs_nashorn_repl/goog/undefined
	 (NO_SOURCE_FILE <eval>:1:0)
	 (NO_SOURCE_FILE <eval>:1:0)
	 (NO_SOURCE_FILE <eval>:19:0)
	 <program> (.cljs_nashorn_repl/com/foo.cljc:5:0)
	 (NO_SOURCE_FILE <eval>:1:0)
	 (NO_SOURCE_FILE <eval>:1:0)
	 (NO_SOURCE_FILE <eval>:19:0)
	 (NO_SOURCE_FILE <eval>:1:0)

favila19:06:22

actually I can get it down to just big

justinlee19:06:25

@john to be clear nothing requires async/await as a language feature. You can always use promises

john19:06:12

Yeah, but for a particular sort of control flow, when trying to hit the ServiceWorker's cache and blocking on the response, when trying to implement that in cljs... just seemed impossible. My understanding is that a cljs macro that does the same thing the polyfill does over generators, could accomplish something similar?

john19:06:07

I ended up just tossing a js* in there, as I was mostly just exploring anyway.

justinlee19:06:41

Ah gotcha yea I understand what you’re saying.

john19:06:09

Yeah, cause I think async/await (at least the polyfilled version) is rewriting the code flow, similar to core.async.

Hukka10:06:39

I'm starting to think that I will just stop thinking about how to make better externs (seems like the project which I inherited is in fact equivalent of having all methods defined on Object) I will just drop them completely and move to cljs-oops