Fork me on GitHub
#shadow-cljs
<
2018-08-08
>
cjmurphy03:08:01

I've done npm install d3 and setup to resolve to "d3/build/d3.js", as recommended in the book, but get the error: "ExceptionInfo: could not find module-entry: d3/build/d3.js".

cjmurphy03:08:08

Wanting to be able to require d3, like so: (:require ["d3" :as d3]).

thheller06:08:45

@cjmurphy ideally don't require the d3 meta package. instead require only the parts you actually need. d3 was split up into many smaller packages for this reason. see https://www.npmjs.com/search?q=d3-

thheller06:08:19

eg. (:require ["d3-color" ...])

thheller06:08:59

it pretty much maps 1:1. so if you used d3.color before thats just imported via d3-color now

cjmurphy06:08:40

What I did works but other things will be harder.

thheller06:08:54

well if you don't care about download size too much you can use d3 directly too. its really just an optimization to only require the smaller packages

cjmurphy06:08:07

I want to call the function: (.interpolateWarm), but there is no context, so how do I call it?

cjmurphy06:08:23

It takes a number and rets a colour.

cjmurphy06:08:12

(.interpolateWarm js/d3 30) would work I think.

thheller06:08:32

using js/d3 is incorrect in shadow-cljs

thheller06:08:04

(:require ["d3" :as d3]) means that you pull d3 into the local scope. js/d3 is the global scope, just use d3 instead

thheller06:08:11

(.interpolateWarm d3 30)

thheller06:08:17

or better yet

thheller06:08:31

(d3/interpolateWarm 30)

cjmurphy06:08:57

Oh, will try, thanks...

thheller06:08:22

or even better (:require ["d3-interpolate" :refer (interpolateWarm)]) and then (interpolateWarm 30)

thheller06:08:51

althought I can't find the interpolateWarm fn?

cjmurphy06:08:13

It is not d3

thheller06:08:54

do you have the JS example you are trying to convert/use?

cjmurphy06:08:23

Trying to do the whole article.

thheller06:08:48

and btw (:require ["d3" :as d3]) should work just fine today. they were in a weird state packaging-wise for a while but all of that was sorted out.

thheller06:08:03

you just have to remember to use d3 directly and never js/d3

cjmurphy06:08:24

Right yes, and not have the dot even when doing interop.

thheller06:08:50

. is fine if you want

thheller06:08:05

(d3/thing) is the same as (.thing d3) just looks nicer

thheller06:08:28

import {interpolateWarm} from 'd3-scale-chromatic'; is (:require ["d3-scale-chromatic" :refer (interpolateWarm)]) and then just (interpolateWorm ...)

cjmurphy06:08:37

["d3-scale-chromatic" :refer (interpolateWarm)]

cjmurphy06:08:00

Yes above what been using. Been referring to the book.

thheller06:08:53

I'll remove the confusing d3 example from the book. its not relevant anymore.

cjmurphy06:08:55

So (:require ["d3" :as d3]) should work, and I do need it right? But not working for me at the moment.

thheller07:08:10

no you do not need it but yes it works.

thheller07:08:26

whats not working?

cjmurphy07:08:36

ExceptionInfo: could not find module-entry: d3/build/d3.js

thheller07:08:41

no config whatsoever, so if you took the :resolve config example you need to remove that

cjmurphy07:08:09

Yes I removed the wrong bit of config ....

thheller07:08:45

so you have nothing d3 related configured in your config?

cjmurphy07:08:54

Corect now.

thheller07:08:55

and it still doesn't work?

cjmurphy07:08:27

"ui.cljs:70 Uncaught ReferenceError: d3 is not defined"

thheller07:08:38

probably because you are using js/d3 again?

cjmurphy07:08:35

Fantastic, works now.

thheller17:08:14

I'm experimenting with a couple of options for quickly create shadow-cljs projects. pretty much all templates that currently exist use lein and I want non-lein options. One option I'm properly abandoning is npx create-cljs-project. I was just messing with a couple ideas for UI but it doesn't actually create anything yet. it already bugs me that its way too slow though

thheller17:08:23

$ npx create-cljs-project foo
npx: installed 35 in 18.384s
? Name of your project? test
? Which target? Browser
? Would you like some demo content? re-frame - A Reagent Framework For Writing SPAs, in ClojureScript.
#js {:project-name "test", :target :browser, :template :re-frame}

thheller17:08:43

18.3s just to run the damn thing is pretty much a non-starter for me

flyboarder17:08:12

@thheller is there an example repo for new projects?

flyboarder17:08:40

There is boot-new which works great for boot project templates

thheller17:08:49

also a non-starter

thheller17:08:09

basic ground rules: this is for JS devs. neither boot nor lein are available. not going to make them install that first.

lilactown17:08:08

how long does create-react-app take?

thheller17:08:51

just launching it about 6sec or so

lilactown17:08:53

~/Code  npx create-react-app foo
npx: installed 67 in 4.526s
huh

thheller17:08:31

yeah I could optimize like they do

thheller17:08:43

but still bugs me that it takes so long

lilactown17:08:23

oh btw, we moved our CI runner to it’s own EC2 and starting + compiling takes <1 min now 😉

lilactown17:08:37

turns out running on something other than a toaster helps

thheller18:08:29

hehe I bet. did you notice a difference in start up with AOT? or were you on deps/lein anyways?

lilactown18:08:03

we’re using lein, but I’m working on migrating us off of that so we can take advantage of that as well

thheller18:08:37

you can do it in lein but I do not recommend it if you have any CLJ server side code

flyboarder17:08:14

@thheller you could use mustache templates and build a command into shadow-cljs

thheller17:08:03

@flyboarder

(ns shadow.cljs.create.cli
  (:require
    [goog.object :as gobj]
    ["inquirer" :as inq]
    ["mustache" :as mst]
    ["fs" :as fs]))

thheller17:08:23

that was the plan ... but install time matters to me and if the baseline is 18sec I'm doing something else.

thheller17:08:47

npm install shadow-cljs already takes way too long

thheller17:08:15

I'm stronly considering implementing https://github.com/thheller/shadow-cljs/issues/290 so npm doesn't take forever installing all the shitty deps

thheller17:08:57

http://npm.broofa.com/?q=shadow-cljs this is already pretty ridiculous ... just because of babel

thheller17:08:35

every time I start a new test shadow-cljs project I already forgot what I wanted to do by the time it finished installing

thheller17:08:21

npm is so horribly slow in WSL its absolutely no fun to work with

lilactown18:08:56

yeah that is a bummer. I remember reading about some weird WSL disk issues, I wonder if it’s related

thheller18:08:47

don't really have any issues ... its just slow. there is an open ticket about it but doesn't seem to be a priority

thheller18:08:02

its really only npm thats slow however since it deals with soooooo many files

thheller18:08:06

on a single thread ...

thheller18:08:15

gotta hate node sometimes

bbss19:08:04

Is there a trick to make shadow-cljs not load whole libraries? e.g. I refer from @material-ui/icons like so:

["@material-ui/icons" :refer [PlayArrow Pause Stop]]
it slows down incremental compilation significantly, 3-4 seconds on my machine. And now something worse is happening: my browser stops loading with a failed to load resource: net::ERR_INSUFFICIENT_RESOURCES. It seems to load a ton of node_modules.

thheller19:08:57

yes. only require what you need. (:require ["@material-ui/icons/PlayArrow" :default PlayArrow])

bbss19:08:28

Got it, thanks.

thheller19:08:36

this "@material-ui/icons" requires every single icon and there are a lot of them

bbss19:08:04

Okay, I hoped :refer would be smart. But I understand that might be hard (impossible) to implement.

bbss19:08:20

Or well I hoped the JS world would have figured out a nice way actually.

thheller19:08:06

yeah can't do it with :refer gotta do it manually

bbss19:08:29

So be it. Thanks.

thheller19:08:12

961 files are included by @material-ui/icons

bbss19:08:19

Yeah, it's ridiculous.

thheller19:08:23

gotta love the crap the JS world comes up with

wilkerlucio20:08:17

@bbss I have used http://react-icons.github.io/react-icons/ and it seems to play nice, specially if you only include the icons you need (they have each separated in its own file)

bbss20:08:07

Cool, I'll give it a look. The approach of requiring as default works too, but it's a bit cumbersome.

lilactown21:08:48

does shadow-cljs have a command to just “download all dependencies”?

thheller21:08:37

not currently. but I'm currently reworking how all of that is handled.

thheller21:08:41

open a ticket if you need it

🎫 4
lilactown22:08:20

just updated to 2.4.33 and seeing this error:

Exception in thread "main" java.lang.NoSuchMethodError: com.cognitect.transit.TransitFactory.writer(Lcom/cognitect/transit/TransitFactory$Format;Ljava/io/OutputStream;Ljava/util/Map;Lcom/cognitect/transit/WriteHandler;Ljava/util/function/Function;)Lcom/cognitect/transit/Writer;
	

lilactown22:08:18

hrm. it might be due to a dependency…

lilactown22:08:22

adding this to my dependencies [nubank/workspaces "1.0.0-preview6"] triggers the error

lilactown22:08:40

downgrading to nubank/workspaces 1.0.0-preview5 works just fine

lilactown22:08:34

has nothing to do with shadow-cljs. raised an issue with workspaces