Fork me on GitHub
#shadow-cljs
<
2018-07-25
>
bupkis05:07:08

What is the purpose of the socket REPL that's being also started? Is it currently used, or is it there in preparation for future use? I couldn't find anything in the guide, and I'm curious 🙂

thheller05:07:23

@samuel.wagen you are free to use it. I sometimes use it when I get frustrated by some nrepl stuff.

bupkis06:07:01

@thheller any idea how to get to the CLJS side from it? piggieback is nrepl only

thheller06:07:01

@samuel.wagen shadow-cljs clj-repl uses the socket REPL. then (shadow/browser-repl) switches it to a CLJS browser repl. or (shadow/node-repl) or (shadow/repl :your-build)

bupkis07:07:55

interesting. I tried connecting to the socket repl from unrepl 's unravel

bupkis07:07:40

oh of course. clj-repl does an implicit require. if I do (require '[shadow.cljs.devtools.api :as shadow]) then (shadow/repl :build-id) works and I get the cljs repl

thheller07:07:34

ah right. yeah its the .api namespace

thheller07:07:44

clj-repl starts out in shadow.user

thheller07:07:08

(ns shadow.user
  (:require
    [clojure.repl :refer (source apropos dir pst doc find-doc)]
    [clojure.java.javadoc :refer (javadoc)]
    [clojure.pprint :refer (pp pprint)]
    [shadow.cljs.devtools.api :as shadow :refer (help)]))

bupkis08:07:41

yep, doing (in-ns 'shadow.user) and (shadow/repl :build-id) does the trick with unravel

kwladyka10:07:22

> Cursive does not currently support resolving dependencies via shadow-cljs.edn. You can run shadow-cljs pom to generate a pom.xml and import that using the IntelliJ. How exactly? Curisve still doesn’t recognise detest

thheller11:07:56

@kwladyka you call shadow-cljs pom and then in cursive file -> new -> project from existing sources and select the pom.xml

kwladyka11:07:03

oh in that way. It doesn’t sound like good solution considering dependencies changing, so each time I will have to start new project.

kwladyka11:07:21

but I know there is alternative 🙂

thheller11:07:33

just call shadow-cljs pom again and cursive will automatically update the changed pom.xml

thheller11:07:41

or ask first .. depends on the setting you have there

thheller11:07:48

but you only need to create the project once

thheller11:07:02

check if the file is actually generated properly?

thheller11:07:47

some text editor

thheller11:07:14

ah .. nvm its not pretty printed so its tough to tell if it actually contains something

thheller11:07:28

I guess check if it looks like xml

kwladyka11:07:10

it looks ok

thheller11:07:38

and you did project from existing sources not module from existing sources?

thheller11:07:58

then I don't know. can you post the pom.xml so I can look at it? just tested it on a dummy project and it worked fine.

thheller11:07:08

that imported completely fine for me?

thheller11:07:31

same intellij version

kwladyka11:07:41

I have no idea why

kwladyka11:07:11

or maybe… I have 1 to check

kwladyka11:07:34

haha it is funny, but: > @kwladyka you call shadow-cljs pom and then in cursive file -> new -> project from existing sources and select the pom.xml I was selecting pom.xml file. As I see right way is to choose directory contain pom.xml file, not select file directly.

thheller11:07:05

I selected the pom.xml every time never the directory

kwladyka11:07:08

hmm so maybe it doesn’t work with select directory

thheller11:07:16

where is the source file?

thheller11:07:53

wait what is the problem?

kwladyka11:07:02

BTW do you recommend solution with pom.xml for cursive or another one? 🙂

thheller11:07:18

I do recommend that yes

thheller11:07:44

I use it myself

thheller11:07:53

but what is the actual problem you have?

kwladyka11:07:42

with cmd+down I can jump to the source etc.

kwladyka11:07:56

But with shadow-cljs and Cursive I can’t do both

thheller11:07:26

so your problem is that deftest isn't indented correctly?

thheller11:07:49

or what do you mean by "recognise deftest"?

kwladyka11:07:25

yes, but it is deeper issue. It is not indent correctly, because Cursive doesn’t see this dependency.

thheller11:07:59

didn't you just say that you can navigate to the source?

kwladyka11:07:13

normally I can press cmd+down and it will open source code of deftest. With shadow-cljs I can’t so my assumption Cursive can’t find that dependency

thheller11:07:13

ah you mean you can't

kwladyka11:07:38

sorry if it wasn’t clear

thheller11:07:46

I don't know. It all works completely fine for me

kwladyka11:07:18

But I opened this project by select directory, not pom.xml. It doesn’t work for me as I mentioned before.

kwladyka11:07:50

I have really no idea why.

kwladyka11:07:09

I just tried it with empty folder with only this pom.xml. The same issue.

thheller11:07:05

I don't know what to tell you. I click new -> project -> project from existing sources then select the actual generated pom.xml file. accept a couple times and nothing else

thheller11:07:35

it works fine with the file you just posted and creating the test/boilerplate/example_test.cljs

kwladyka11:07:40

When you select folder instead of a file does it work the same for you or there is a difference?

thheller11:07:01

you can try cloning this repo https://github.com/shadow-cljs/quickstart-browser and trying it there

thheller11:07:41

it doesn't do anything when I select the directory

thheller11:07:51

just closes the dialog

kwladyka11:07:17

hmm when I select directory I have this:

thheller11:07:53

hmm that seems to be missing the maven option?

thheller11:07:39

I thought the maven integration was built-in but maybe its a plugin? or disabled for some reason?

kwladyka11:07:57

hmm doest it mean it is because i don’t have “maeven integration” installed?

thheller11:07:10

I have no idea. maybe?

kwladyka11:07:13

oh so we probable solved it

thheller11:07:51

I didn't install or mess with any other plugin besides cursive

kwladyka11:07:21

now I have different dialogs

thheller11:07:44

no, leave all the defaults

thheller11:07:52

just click next till its done

kwladyka11:07:39

oh yeah it works!

kwladyka11:07:46

you are the boss 🍻

kwladyka11:07:20

it is time for take a break and eat dinner 🙂

thheller11:07:44

so the maven integration was just missing?

kwladyka11:07:56

I didn’t install it

thheller11:07:57

hmm good to know for future reference

kwladyka11:07:29

I went to the plugin list and checked maven integration, restart Intellij and it works

👍 8
wilkerlucio13:07:18

@kwladyka if you can, another good option is to use deps.edn to manage dependencies, Cursive is supporting those already in the latest versions

royalaid16:07:50

@wilkerlucio It is important to point out that there are some caveats and that support is alpha quality AFAIK

thheller16:07:58

FWIW pom.xml is the most stable and well supported option and we really only need to tell cursive about the deps and source paths

lilactown16:07:57

I'm running into an issue using module splitting + shadow-cljs 2.4.24

lilactown16:07:04

(recently updated from 2.3.x)

lilactown16:07:00

when I run in dev mode, everything works as expected. however when I do a release build, I get an error when the bundle runs

lilactown16:07:11

Uncaught TypeError: P.l is not a function
    at main.js:1246

lilactown16:07:41

this is my shadow-cljs.edn config for this build:

:dashboard
          {:target :browser
           ;; :module-loader true
           :modules
           {:main {:entries [cambia.web.experience.dashboard.client.core]}
            :icon-row {:entries [cambia.web.experience.dashboard.components.icon-row.client]
                       :depends-on #{:main}}
            }
           :compiler-options {:infer-externs :auto}
           :output-dir "public/dashboard/assets/app/js"
           :asset-path "assets/app/js/"
           :devtools
           {:after-load cambia.web.experience.dashboard.client.core/start-dev}}

lilactown16:07:07

commenting out the :icon-row module gets rid of the error

thheller16:07:07

@lilactown add :compiler-options {:infer-externs :auto}

lilactown16:07:21

it's present

thheller16:07:30

hehe oh right

thheller16:07:34

no warnings?

lilactown16:07:49

only one in a completely unrelated file:

[:dashboard] Compiling ...
------ WARNING #1 --------------------------------------------------------------
 File: cambia/web/experience/dashboard/components/hsa/client.cljs:3:10

 variable $ is undeclared
--------------------------------------------------------------------------------

nil

lilactown16:07:57

haven't investigated yet

thheller16:07:09

prbably not unrelated

thheller16:07:38

try running with shadow-cljs release dashboard --pseudo-names and do whatever to trigger the error

thheller16:07:02

it'll give you a more readable hint at the error location

thheller16:07:40

it might also be a global variable conflict

thheller16:07:03

if the error goes away with --pseudo-names thats most likely the issue

lilactown16:07:44

...it did 😅

lilactown16:07:58

testing it again without pseudo-names just to be sure

thheller16:07:27

you can try adding :compiler-options {:output-wrapper true} or find out how the global P is defined and what it is

lilactown16:07:31

yep, removing pseudo-names triggers the error

thheller16:07:37

:output-wrapper isn't great when using modules so you should rather find out where that clashing global is coming from

thheller16:07:58

you can then add externs for it so closure doesn't use that variable

thheller16:07:25

just type P in the browser console and see if the object provides any clues

lilactown16:07:28

:output-wrapper did fix it. what are the concerns with modules?

thheller16:07:03

output gets larger. not super important since gzip takes care of most of it

thheller16:07:17

still .. fixing it the other way isn't much harder either

justinlee16:07:03

is there no way to dump a map from munged names to original names?

lilactown16:07:19

not really complaining but I did notice that going from 2.3.x => 2.4.24 that my release bundle got bigger by about 4x (224kb to 804kb)

thheller16:07:20

source maps do that

lilactown16:07:14

> P
ƒ Promise() { [native code] }
:thinking_face: not very illuminating

thheller16:07:15

what? thats not normal

thheller16:07:51

you can compile with shadow-cljs release dashboard --source-maps

thheller16:07:18

wait nevermind that won't tell you where P comes from

thheller16:07:39

do you have the P defined in the page when you remove the script tag for your JS code?

thheller16:07:59

or asked another way: are there any other script tags in the page besides your CLJS code?

lilactown16:07:23

there are, I'll try that out

thheller16:07:30

going from 2.3 to 2.4 should definitely not make your build larger though

thheller16:07:39

and certainly not by that amount

thheller16:07:24

generate a build report and see where all the bytes come from: https://shadow-cljs.github.io/docs/UsersGuide.html#_build_report

lilactown16:07:29

hmm. with sourcemaps on, the error takes me to mount.core

lilactown16:07:40

👍 will do once I figure this out

thheller16:07:17

yeah nevermind that. its a confusing error since closure thinks it created the P variable and points you to the location where it created it

thheller16:07:26

but its var was replaced by something else

thheller16:07:50

some npm deps forcefully create some globals and can cause these issues

thheller16:07:07

I think leaflet always creates window.L

👎 4
thheller16:07:30

:output-wrapper guards you against such things but makes the build larger by 5% or so

thheller16:07:33

but nowhere near 4x

lilactown16:07:44

could be one of the polyfills or analytics scripts that I have to use :face_with_rolling_eyes:

lilactown17:07:05

I'm okay with a 5% increase if I (or my team, who has no idea how to debug this stuff :P) don't need to worry about this

thheller17:07:18

well you know thats its P so the simple fix is to create externs/dashboard.txt with one line global:P and done

thheller17:07:59

but yeah :output-wrapper is generally safer. you can always optimize that away later.

lilactown17:07:44

is the "Optimized" size in the build report the gzipped size or real size?

lilactown17:07:16

I don't see anything super offensive - it looks like clojure.core is the largest offender

lilactown17:07:28

generating a build report from the 2.3.x branch for comparison now

lilactown17:07:52

ah hm, the incantation isn't there

thheller17:07:54

not sure in which version I added the build reports though

thheller17:07:05

how large is cljs.core?

thheller17:07:55

thats about normal and would have been the same in 2.3

thheller17:07:01

but that also gzips down to like 30kb so its no biggy

lilactown17:07:19

hmm. nevermind

lilactown17:07:16

on the 2.3 branch I'm seeing about the same when I run the release build locally - 800kb

thheller17:07:41

where are the other 616kb though?

thheller17:07:03

probably mostly npm deps?

lilactown17:07:57

there's another 100kb from clojure.pprint that I could probably get rid of

lilactown17:07:25

then 90kb for react-dom, 70kb from bluebird and google-closure-library...

lilactown17:07:02

I was comparing it to the bundle I currently have deployed - I wonder why there's such a difference

lilactown17:07:32

it might be gzipped. that would be embarrassing lol

lilactown17:07:57

yep it was gzipped size 😂

lilactown17:07:19

sorry for the false alarm!

kwladyka19:07:58

What is the best way to use cljs REPL with shadow-cljs with cursive? https://github.com/thheller/shadow-cljs/wiki/Cursive#connecting-to-a-shadow-repl ?

thheller19:07:40

set fixed :nrepl {:port <number>}

thheller19:07:52

and connect to that via cursive Clojure REPL -> Remote

thheller19:07:13

then do the watch and nrepl-select described in the guide

🍻 4
richiardiandrea21:07:06

@thheller I wanted to investigate a bit how to add REPL support for :node-test and I see that you are disabling :devtools explicitly?

richiardiandrea21:07:23

is it because of stable namespaces are needed there and we don't have one? (I actually though we always have a main entry point autogenerated)

richiardiandrea21:07:11

I could use the normal :node-script target with a REPL but I don't know if the tests are compiled there