Fork me on GitHub
#clojurescript
<
2016-08-25
>
danielcompton04:08:59

When ClojureScript is compiling (and recompiling) with :none optimisations, is there a defined ordering to which file will be written out last?

danielcompton04:08:41

I’m trying to use Karma to run tests when my CLJS autobuilds, but it detects the changes in earlier files being written, while later ones haven’t been written, which breaks the JS loading

danielcompton04:08:18

I can add a delay, but that is not ideal

am-a_metail08:08:56

@danielcompton - can you use the notify command? as hideous as that is

danielcompton08:08:57

Ah yeah that will work, forgot about that one. Will give it a try

am-a_metail08:08:33

What I have done in the past is keep tests watching, but use the notify command to touch a file that is being watched

am-a_metail08:08:51

Rather than run the tests directly from the notify command

am-a_metail08:08:20

(if your test runner has the ability to watch and test different files)

rickmoynihan10:08:53

Any idea what this means for clojurescript? https://github.com/google/closure-compiler-js

darwin10:08:28

@rickmoynihan: nothing for clojurescript ATM IMO, maybe future possibility for :advanced compilations with bootstrapped clojurescript

rickmoynihan10:08:28

yeah - was wondering if it would possibly untether it from the jvm dependency

reefersleep11:08:40

@shaunlebron: Thanks for the tip! 🙂

dnolen13:08:38

@rickmoynihan there’s never going to be a plan around that

dnolen13:08:06

but a ton of work has gone into making it possible to solve that problem if they care about it and willing to put in the rest of the work

rickmoynihan14:08:26

dnolen: cool - the JVM dependency certainly isn't a problem for me - was just curious

dnolen14:08:43

@rickmoynihan yes it’s isn’t for most people 🙂 and it’s just a lot of work we don’t have time for. But there’s no reason to get in the way of making it possible - thus bootstrapped.

rickmoynihan14:08:07

dnolen: I'm not really a clojurescripter - so I just follow it casually - I'd got the sense that the bootstrapping work implied this was a goal... but what you're saying makes perfect sense to me

dnolen14:08:26

not a goal

dnolen14:08:34

the goal was just to make it possible

dnolen14:08:41

not to do anything more about it beyond that

nickt14:08:26

hi all. Is it possible to make a plugin for the cljs compiler? Or a plugin into closure compiler? I want to operate on my javascript between the cljs -> js step and the js -> closure-ified js step

kingoftheknoll14:08:40

does anyone here use Httpurr? I’m trying to set withCredentials = true for the XHRio object but I’m not sure how to modify a reified object.

kingoftheknoll14:08:58

might have to change to cljs-ajax if it’s not possible

dialelo14:08:57

@kingoftheknoll hi! you can access the raw xhr object in the -xhr attribute, hope it helps!

kingoftheknoll14:08:34

@dialelo could you elaborate? would that be off the client param that’s passed the the send!?

dialelo14:08:59

@kingoftheknoll let's move to #funcool for not flooding this channel, happy to elaborate there

dnolen16:08:09

@nickt we don’t expose any hooks like that at the moment, no

nickt16:08:47

@dnolen thanks. I had a brief conversation with someone in the #clojurescript IRC channel suggesting I could write a one-off script of my own using the cljs.compiler.api and cljs.build.api

nickt16:08:44

it's not quite the same as writing a plugin but as long as I can go cljs -> js, then my own js -> js, and then js -> closure -> optimized js, I don't mind writing my own script for it

nickt16:08:01

(that is, easily follow each of those steps, presumably by leveraging the api of the cljs compiler)

dnolen16:08:30

@nickt yes you could do something like that, :none doesn’t use Closure Compiler so you could operate on those files

nickt16:08:37

@dnolen and then is it easy to invoke Closure Compiler via the cljs build api on the JS files after I've done my js -> js step?

nickt16:08:54

or, rather I mean, where should I look in the API for that step?

darwin17:08:41

@nickt: alternative idea: I would simply privately fork clojurescript and spend time on writing a simple shell script auto-rebasing my changes on top of official one, then use the fork in my project, I expect adding support for custom js post-processing step is something like an one-line patch so there should not be much headache to roll on top of clojurescript master 🙂

nickt17:08:07

@darwin hm good thought...

darwin17:08:03

git is pretty powerful/intelligent in merging/rebasing, should be a smooth sail

darwin17:08:06

and lein install works in clojurescript repo to build it and install it locally, just replace version in project.clj (if needed)

darwin17:08:46

well, I’m not that much familiar with cljs code base, but I would put it right before Google Closure compiler invocation

nickt17:08:44

@darwin why would I need to replace the version?

darwin17:08:31

you don’t, just if you wanted to distinguish it from 0.0-SNAPSHOT 🙂 https://github.com/clojure/clojurescript/blob/master/project.clj#L1

nickt17:08:53

hahaha touché

nickt17:08:51

yea I like this idea... I think there's a really easy hook

dnolen17:08:59

@nickt when using :none you get a bunch of JS files

dnolen17:08:14

all we ever do is feed those to Closure Compiler, you can do whatever you want with those files

dnolen17:08:28

the main challenge is supporting all the extra stuff though

dnolen17:08:41

we do a lot of management of non-Closure JS stuff

dnolen17:08:54

i.e. rando JS libs

nickt17:08:16

yea I have a little project that I'm hacking through and I see that :none yields just normal js files

nickt17:08:28

but it's unclear to me how to feed those back into the cljs compiler for the closure step

dnolen17:08:39

so you can probably accomplish what you want, but replicating everything is probably going to be a non-trivial amount of work for you

dnolen17:08:11

in anycase, like I said this just isn’t really supported and you’re going to be on your own for the most part

dnolen17:08:39

probably would be willing to consider a patch that allows custom passes - but it’s also not a priority

nickt17:08:10

@dnolen thanks, i see. I'm definitely thinking about @darwin's suggestion there... looking through the compiler API it seems like I could probably hook into compile-file or some similar function pretty easily

nickt17:08:33

compile-file becomes (my-step (compile-file ...args)) or something

nickt17:08:49

@darwin yea I suppose I could, but that would probably get skipped for any :none optimization builds

darwin17:08:08

ah, ok, good point

richiardiandrea17:08:34

I remember having seen a data viewer for clojurescript but I haven't saved it...it is a bit like how cljs-devtools shows it (with + for expanding).

richiardiandrea17:08:57

Do you folks have any suggestion?

shaunlebron17:08:22

i vaguely remember noprompt having one

richiardiandrea17:08:58

uhm maybe that was the one...

shaunlebron17:08:38

it was made before cljs.pprint was available, would love to see it use better layouting

richiardiandrea17:08:12

maybe I will go for pprint for now as string...it is for debug purposes anyways, but thanks @shaunlebron

richiardiandrea17:08:10

@darwin I knew you would save my chickens thanks!

nickt18:08:35

@darwin have you tried developing on the cljs compilre?

nickt18:08:47

I got a successful build, but when I try to run my build I get an error

nickt18:08:02

java -cp clojurescript-1.9.226.jar:src clojure.main scripts/build.cljs => Error: could not find or load main class clojure.main

darwin18:08:51

I haven’t done much, just few patches here and there, I was unable to use clojurescript via leiningen checkouts for some reason, so I had to always do lein install on every change (to test my patched version agains my project)

nickt18:08:05

what does lein install do?

darwin18:08:59

it builds and installs the project at hand (into local maven repo)

darwin18:08:31

I’m not a java guy, to me, it is still magic, go read the internets 🙂

nickt18:08:15

got it 😄

nickt18:08:34

there's a script/build and a script/uberjar

darwin18:08:46

btw. I had a small shell file-watching script which did lein install on every file save under clojurescript src tree, that made my dev experience a bit less miserable 🙂

nickt18:08:00

@dnolen yes I was following "Building the Compiler" but it didn't mention anything about the uberjar

dnolen18:08:09

@nickt you don’t need to mess with the uberjar

dnolen18:08:14

that’s just for the Quick Start

nickt18:08:41

@dnolen hm.. the output of build was a jar with which I tried to run java -cp clojurescript-1.9.226.jar:src clojure.main scripts/build.cljs but I got the error I mentioned above

nickt18:08:54

when I run script/uberjar the output is a cljs.jar with which that command succeeds

dnolen18:08:55

@nickt you need something to manage your deps, i.e. Maven

dnolen18:08:03

or something that uses Maven, lein and or boot

dnolen18:08:15

or you can manage them by hand, which I don’t recommend

nickt18:08:26

I see... and uberjar just bundles it all for me?

dnolen18:08:54

yes so that Quick Start users don’t have to think about dependency management when just trying ClojureScript out

dnolen18:08:03

but the uberjar is not the recommended way to do serious development

nickt18:08:08

that makes sense

dnolen18:08:34

to be fair yes I do use it myself to do quick testing quite a bit

nickt18:08:11

I might use it for now just to facilitate my hacking. If my hacks yield reason to get more serious about it then I'll probably revisit

dnolen18:08:03

it’s a pretty slow way to hack on the compiler though

dnolen18:08:18

I just use Cursive, could probably get something decent going with Cider too

darwin18:08:54

@nickt: btw. what are you trying to build? for more serious JS transformation, another consideration could be writing a custom Google Closure compiler pass (if experienced in Java)

nickt18:08:15

mmm I haven't been in IDE land in a long time haha

nickt18:08:45

@darwin i'm exploring some stylesheet optimizations

nickt18:08:27

and it's relation to react/om

darwin18:08:53

inlining external stylesheets?

darwin18:08:55

you could write a simple file-watching tool converting css -> edn, and then use macros/functions in clojure(script) to do the heavy-lifting work

darwin18:08:11

macros are kinda "compiler plugin” 🙂

shaunlebron18:08:28

@dnolen: is the uberjar faster for building somehow?

nickt18:08:13

@darwin yea that's pretty close hahah

darwin18:08:11

I used garden library in one of my earlier Om projects, and it is awesome once you have "CSS as data" you can do anything to it and use macros as compile-time preprocessor/optimizer/compiler.

dnolen18:08:40

@shaunlebron what do you mean ?

nickt18:08:59

@darwin yea I was looking at garden, I'm not sure it covered what I was trying to do

shaunlebron18:08:41

@dnolen: I vaguely remember the quick start method having a faster startup, maybe that’s because it’s skirting lein and doesn’t have anything to do with the uberjar. i thought maybe the uberjar had precompiled some things as well

dnolen18:08:54

@shaunlebron oh right, avoiding lein is always gonna be faster

nickt18:08:27

why? What makes lein slow?

shaunlebron18:08:17

I thought the uberjar might’ve contained a precompiled compiler core as well

shaunlebron18:08:51

I suppose that would mean an analysis cache

shaunlebron18:08:12

@nickt: i think lein spins up at least two jvm instances

dnolen18:08:34

@shaunlebron yes that helps too, but we ship an AOTed artifact as well that anyone can take advantage of

shaunlebron18:08:40

@nickt: i can’t remember why, something about running one in the context of your project

shaunlebron18:08:08

ah, aot was the keyword I was looking for

dnolen18:08:29

@nickt lein never prioritized speed, and it’s too far along to change any of the fundamental decisions

dnolen18:08:28

which isn’t to say you shouldn’t use it, it’s a fine tool - it’s just why I don’t use it

richiardiandrea18:08:39

Pertinent to this, there was a discussion about repl speed here: https://github.com/clojure-emacs/cider/issues/1717

kingoftheknoll20:08:36

How can I rebind a dynamic var in another namespace? This var is used by the function I’m calling but is not referenced from the call location. Was going to try something like this.

(defn post!
  [{:keys [url body headers]}]
  (with-bindings {#'xhr/*xhr-impl* MyXhrIO}
    (p/then (http/send! client {:method :post
                                :url url
                                :body (js/JSON.stringify (clj->js body))
                                :headers (spy headers)})
            process-response)))
but with-bindings doesn’t seem to exist in cljs.

dnolen20:08:21

@kingoftheknoll there are multiple things going on here

dnolen20:08:37

A) it seems to me binding works fine

dnolen20:08:47

B) binding around an async call isn’t going to work

kingoftheknoll20:08:11

I’m only wanting to bind to replace the XhrIo constructor so I can set withCredentials to true. So nothing should be async at the time.

darwin20:08:49

what kind of promise library do you use? p/then might be async

kingoftheknoll20:08:12

httpurr. But I’m not even getting to the binding part. Figwheel says with-bindings doesn’t exist and binding gives me errors.

fellshard20:08:33

Could be one of those commands leverages an internal thread pool for execution, yeah. E.g. using an agent?

dnolen20:08:19

@kingoftheknoll “gives me errors” is not useful information

dnolen20:08:26

show us what you tried with binding

darwin20:08:31

binding is a thing, for sure 🙂

dnolen20:08:16

@fellshard we’re compiling to JavaScript so single threaded

dnolen20:08:54

@kingoftheknoll OK, so Vars in ClojureScript aren’t really a thing you shouldn’t write stuff like that

dnolen20:08:03

also there’s just no need to bother

dnolen20:08:13

xhr/*xhr-impl* should work fine

shaunlebron20:08:56

I believe the only use case for #’ in cljs is to retrieve metadata for a var at runtime

dnolen20:08:52

even then a bit questionable to do in normal code since it dumps line, column, file etc.

kingoftheknoll20:08:44

@dnolen wow thanks for the clarification! So I should be about to just do something like (aset xhr/*xhr-impl* MyXhrIO)

shaunlebron20:08:08

@kingoftheknoll you may try set! instead of aset there

shaunlebron20:08:37

but binding is probably preferred