Fork me on GitHub
#shadow-cljs
<
2019-04-17
>
orestis04:04:32

Could you share the benchmark code? Would be nice to have around!

thheller08:04:11

my lib isn't public yet though. will publish at some point when its ready.

joelsanchez08:04:39

hello @thheller, I think the documentation regarding nrepl middleware needs to be updated. including the latest shadow-cljs with no nrepl exclusions, you need to use shadow.cljs.devtools.server.nrepl04/... middleware for things to work, and the documentation just mentions the old version https://shadow-cljs.github.io/docs/UsersGuide.html#_embedded_nrepl_server

thheller08:04:00

yeah. I can probably remove the old implementation now. or rather just flip it. nobody should be using .nrepl04 directly

vinurs11:04:19

i create a project from luminus, and then i try to change its cljsbuild to shadow-cljs, and its dependencies by deps.edn, but when i execute shadow-cljs compile app, it show warnning, i don’t know what’s this means

vinurs11:04:58

@thheller i follow your example https://github.com/thheller/lumifoo, but i don’t know how to fix this

hlolli12:04:54

@haiyuan.vinurs you need to fix your source path

hlolli12:04:16

From maybe “src” to”src/cljs”

vinurs12:04:57

in the shadow-cljs.edn, i set this

hlolli12:04:17

Yes :src I think, at my phone so dont remember

hlolli12:04:27

Or :source-paths

hlolli12:04:14

The namespace represent the filepsth starting the the root of the innermost source path

hlolli12:04:04

Oh could you paste the result of “tree ./src” in the shell?

hlolli12:04:53

Wait you have lein true and use deps?

hlolli12:04:08

Change :lein true to :deps true

vinurs12:04:17

because i want to share deps with lein and shadow-cljs

hlolli12:04:23

Or no wiat

hlolli12:04:34

Add :src into your deps.edn file

vinurs12:04:42

:lein true :deps {:aliases [:cljs]}

vinurs12:04:51

this is what i’ve set in shadow-cljs

hlolli12:04:53

And there same as you have in :source-paths

hlolli12:04:11

Deps is in control of the source path if you use it

vinurs12:04:27

:source-paths [“src/cljc” “src/cljs” “env/prod/cljs”]

hlolli12:04:32

Because source path is actually classpath, and deps takes care of tje classpath

hlolli12:04:42

Yes put this in deps.edn

vinurs12:04:56

it has been there

hlolli12:04:40

Not in the file you sent above, or I am terribly blind

hlolli12:04:01

You have :deps and :aliases

vinurs12:04:07

the test i’ve push to the github

hlolli12:04:20

But youre missing source patha

vinurs12:04:35

so , i need to set paths in the deps.edn?

hlolli12:04:17

Yes, if you have deps.edn take care of the deps, shadow wil hand over the responsibility of classpath to depsedn

hlolli12:04:33

Same with leiningen I assume.

hlolli12:04:59

But preferably yu should have lein and shadow point to deps.edn but thats maybe a matter of taste

hlolli12:04:21

As far as i remember its :paths not :source-paths

hlolli12:04:28

In deps.edn

vinurs12:04:40

because some times cljs and clj need the same library, so i want to share deps between clj and cljs, that is lein and shadow-clj, so i use deps.edn

hlolli12:04:18

Yes thats good thinking, but the :lein true you have in shadow-cljs.edn seems redundant to me

hlolli12:04:51

Just use :deps true instead and use in leiningen the deps middleware

vinurs12:04:06

i changed, but it does no effect

hlolli12:04:50

Cant be :) you have now :paths :aliases and :deps in deps.edn?

vinurs12:04:22

set this in deps.edn

vinurs12:04:52

but, i think this should be cljs only, so i set it in the alias :cljs

hlolli12:04:09

Nana its fine that its global

vinurs12:04:23

and in shadow-cljs i use :deps {:aliases [:cljs]}

hlolli12:04:49

Uhh its really unneccecary

vinurs12:04:31

but now it’s global, so in lein, the paths will auto import? does it conflict with clj’s src/clj?

hlolli12:04:52

No because you can only have 1 compiler reading at any given time. Cant have clj and cljs running as 1 compiler

vinurs12:04:05

but in project.clj, i have this setting: :source-paths [“src/clj” “src/cljc”]

vinurs12:04:46

oh, i see, the clojure compiler doesn’t read cljs file

hlolli12:04:48

Ok. You dont want deps edn to take care of the deps for leiningen then?

vinurs12:04:35

actually, i do want, but i don’t know how to set seperately for clj and cljs, so i set in project.clj before

hlolli12:04:28

Look at the leiningen deps middleware/plugin. Then you dont neeed to set classpaths in leiningen, 1 source of truth for both shadow and lein, that would be clean

vinurs12:04:09

[lein-tools-deps “0.4.5”]

vinurs12:04:12

i use this

hlolli12:04:47

Ah yeh i see now you have it setup right. If you give me 10 mins I can run your app

hlolli12:04:07

But need then to add the resource path to deps edn too

hlolli12:04:27

Thats lein side tough, your problem is with cljs source path

vinurs12:04:58

yes, i want to move all deps to deps.edn

vinurs12:04:36

some deps are cljs only, is there anyway i can seperate it from global?

vinurs12:04:04

i read the doc, and found aliases

hlolli13:04:52

sorry long 10 minutes, testing now

hlolli13:04:25

@haiyuan.vinurs its taking some time, are you using leiningen to generate the index.html?

hlolli13:04:10

Caused by: java.lang.RuntimeException: could not find a non empty configuration file to load. looked in the classpath (as a "resource") and on a file system via "conf" system property

polymeris13:04:11

Hello How do I handle local clojurescript dependencies with shadow-cljs? I.e. I have foo/shadow-cljs.edn and a bar/shadow-cljs.edn, and want bar to depend on foo. If this was leiningen, I'd go into foo and do lein install, then that would copy the artifact to my local maven cache, and I would depend on it from bar normally. Is there a shadow-cljs equivalent?

thheller14:04:42

library dev is currently not covered by shadow-cljs. so either lein or deps.edn works. if your foo doesn't add any deps you can just do :source-paths ["src/main" "../foo/src/main"] in shadow-cljs.edn of bar

thheller14:04:04

lein install in foo and just using the dep in bar also works fine

thheller14:04:28

if I ever get around to it I'll add a shadow-cljs install equivalent 😛

polymeris14:04:44

Yeah, I think I'll have lein handle that for now. Thanks!

polymeris14:04:25

Then again, if foo has npm dependencies, and I do lein install the resulting jar won't include those deps or any reference to them :(

thheller14:04:15

you can add a deps.cljs with {:npm-deps {"the-lib" "version"}} to foo

polymeris14:04:20

Ohhh.. but then I'd have to keep that in sync with foo's package.json?

polymeris15:04:37

Thanks for all the help!

vinurs13:04:44

i mv the resource dir to deps.edn

hlolli13:04:49

I remove the jvm opts and sass, dont have sass

hlolli13:04:55

(I dont..)

hlolli13:04:36

@polymeris I'd use leiningen for this usecase to create a jar

polymeris13:04:07

Thanks. I was trying to avoid having 2 tools, but maybe it makes sense

hlolli13:04:37

yes I think this is one of the case where shadow-cljs wont solve, to package clojure sourcefiles.

hlolli13:04:17

you can have a fairly minimal leiningen file that only has the source files set up and lein jar will produce the jar you need to iinstall into your maven path

polymeris13:04:50

I just wanted to have everything handled by npm to make things easier for people coming from that ecosystem

polymeris13:04:58

Maybe if npm could install lein :thinking_face:

hlolli14:04:40

Theres a lein runner in npm. But you should ofc only upload compiled js respurces to npm

hlolli13:04:56

@haiyuan.vinurs Caused by: java.lang.RuntimeException: could not start [#'admin.config/env] this is beyond the scope of shadow-cljs, I'll just create a index.html, confirm if the paths are correct, then you can ask for lein question on different channel

vinurs13:04:01

the code i pushed to the github works well in my pc

vinurs13:04:41

now, the problem is that, when i in emacs cider-jack-in, then it start a nrepl, and then in terminal, i type: shadow-cljs watch app, then in chrome i visit http://127.0.0.1:3000/, but it shows

vinurs13:04:03

it seems that the compiled app.js doesn’t affect

vinurs13:04:37

but the js has been there

vinurs13:04:50

there is app.js in my home.html

hlolli13:04:02

ignore the html, but shadow-cljs is working fine

hlolli13:04:57

ok make sure you don't have any figwheel or anything connected to clojurescript operating in your leiningen file

hlolli13:04:34

just tell your dev ring handler to load the shadow-cljs artifacts and that's it

vinurs13:04:31

:resource-paths [“resources”] the resource-paths in project can not be removed

hlolli13:04:29

resource path is another example of a classpath, just add it into :paths in deps.edn

vinurs13:04:45

i’ve added, but it seems doesn’t affect

hlolli13:04:53

and I'd refactor your project.clj file, I think the source of this mess is there, for example all the dependencies you have under your profiles, you don't need it with deps.edn, and figwhell cand shadow are solving the same problem in development so you don't want any cljsbuild or leiningen running

hlolli13:04:17

you can ofc have deps.edn aliasaes

hlolli13:04:15

what resource doesn't work for you?

vinurs13:04:48

wait a minute

vinurs13:04:53

i’ve tried again, works ok now

vinurs13:04:20

there is another problem, that is the compiled app.js init doesn’t executed

vinurs13:04:02

:modules {:app {:entries [admin.core]}} :devtools {:after-load admin.core/mount-components}}}}

vinurs13:04:10

this is setting in my shadow-cljs

vinurs13:04:27

it seems that mount-components doesn’t execute

hlolli13:04:03

(r/render [#'page] (.getElementById js/document "app"))

vinurs13:04:47

this is mount-components

hlolli13:04:47

ah it's fine, though denoting page as a variable is unusual

hlolli13:04:58

I see @haiyuan.vinurs you have :devtools in the wrong map

hlolli13:04:19

{:app {:devtools not {:app {} :devtools {}}

hlolli13:04:20

sorry Im blind, it is like that, I'm leaving anyway, maybe @thheller can see why it fails 😄

hlolli13:04:04

alternative is to just execute the function in that file (mount-components) at the bottom

vinurs13:04:23

ok, i try it first

thheller14:04:21

well you've been busy 😛

thheller14:04:40

@haiyuan.vinurs did you figure it out or still need help?

vinurs14:04:57

yes, need help

vinurs14:04:22

all code has been pushed

thheller14:04:36

alright: first issue is the source-paths

vinurs14:04:47

when i visit the homepage, it seems doesn’t execute the mount-components function

thheller14:04:53

you can either use shadow-cljs.edn to manage them, or deps.edn or project.clj

thheller14:04:20

if you set either :deps or :lein in shadow-cljs.edn the :source-paths and :dependencies there will have no effect at all

thheller14:04:12

and what do you actually want to use? the repo has everything so I'm not sure what you actually want

thheller14:04:20

deps.edn or project.clj?

thheller14:04:04

alright then you probably want to remove :source-paths from project.clj as well

thheller14:04:24

I'm not sure how lein-tools-deps works though but you are currently setting :source-paths in 3 places which is just confusing

thheller14:04:40

there should be only one place where all of this is configured

vinurs14:04:53

so all set in the deps.edn?

thheller14:04:01

yes probably the best

vinurs14:04:19

this is project.clj, lein may use different source paths in different env, how can i do this?

thheller14:04:50

I don't know. check lein-tools-deps docs.

vinurs14:04:09

ok, i do this later, there is another problem

thheller14:04:25

:dev
        {:compiler-options {:closure-warnings {:global-this :off}
                            :source-map true
                            :optimizations :none
                            :pretty-print true}}
        :release
        {:compiler-options {:optimizations :advanced
                            :pretty-print false
                            :closure-warnings
                            {:externs-validation :off
                             :non-standard-jsdoc :off}}}

thheller14:04:27

this makes no sense

thheller14:04:57

you can leave it in but you are just setting the already used defaults again

vinurs14:04:17

ok, i removed it

thheller14:04:44

:compiler-options {:closure-warnings
                   {:global-this :off
                    :externs-validation :off
                    :non-standard-jsdoc :off}}

vinurs14:04:43

i need to add this?

thheller14:04:56

no clue. I assume you had it in there for a reason?

thheller14:04:48

is probably what you want

vinurs14:04:54

is there any error with this?

thheller14:04:09

{:deps {:aliases [:cljs]}
 :builds
 {:app {:target :browser
        :output-dir "resources/public/js"
        :asset-path "/js"
        :compiler-options {:closure-warnings
                           {:global-this :off
                            :externs-validation :off
                            :non-standard-jsdoc :off}}
        :modules {:app {:entries [admin.core]}}
        :devtools {:after-load admin.core/mount-components}}}}

thheller14:04:42

AFAICT that should be the config you need

thheller14:04:19

what is the problem?

vinurs14:04:10

i changed the shadow-cljs.edn

vinurs14:04:20

it also doesn’t effect the app.js

thheller14:04:34

what does that mean?

thheller14:04:50

resources/public/js/app.js is the file shadow-cljs will create

thheller14:04:07

you should be loading it at /js/app.js

vinurs14:04:20

yes, app.js has been created,

thheller14:04:57

I can't find where the HTML is created that loads the file

thheller14:04:02

but what is the issue?

vinurs14:04:40

the content is just the html content, but in html i wrote {% script “/js/app.js” %}, and when i visit this page, i want the html execute the mount-components function, it a render

vinurs14:04:43

admin/resources/html

thheller14:04:09

ah. you expect :devtools {:after-load admin.core/mount-components} to call mount-components?

thheller14:04:26

that is not what that does. that tells the devtools to call that function after it has loaded code

thheller14:04:35

it has nothing to do with your normal app flow

thheller14:04:57

so you want :modules {:app {:init-fn admin.core/mount-components}}

thheller14:04:12

that will make it run the function on initial load

thheller14:04:56

you actually want the init! fn

thheller14:04:07

so :modules {:app {:init-fn admin.core/init!}}

thheller14:04:53

{:deps {:aliases [:cljs]}
 :builds
 {:app {:target :browser
        :output-dir "resources/public/js"
        :asset-path "/js"
        :compiler-options {:closure-warnings
                           {:global-this :off
                            :externs-validation :off
                            :non-standard-jsdoc :off}}
        :modules {:app {:init-fn admin.core/init!}}}}}


;; admin.core js

(defn ^:dev/after-load mount-components []
  (rf/clear-subscription-cache!)
  (r/render [#'page] (.getElementById js/document "app")))

thheller14:04:58

that is what I'd do probably

thheller14:04:27

^:dev/after-load tells the devtools to call that function after loading code. I think its cleaner there than in the build config

thheller14:04:36

works the same though

thheller14:04:00

the luminus template has to be the most complicated template ever 😛

thheller14:04:23

there has to be an easier way to do this

vinurs14:04:03

yes, the author said would change to shadow-cljs next month

vinurs14:04:57

if i change the mount-components to this, then i need to set :modules {:app {:init-fn admin.core/init!}} this?

thheller14:04:49

yes it is meant that way by looking at the code

thheller14:04:04

mount-components only re-renders code

thheller14:04:17

init! actually does all the app initialization stuff

lilactown14:04:27

what options can I pass to shadow/release to get e.g. readable names?

vinurs14:04:35

thanks very much @thheller

lilactown15:04:34

seems like (shadow/release :thing {:debug true}) works 😄

thheller15:04:20

@lilactown --pseudo-names would be :pseudo-names true

thheller15:04:33

:debug is pseudo-names + source-maps

lilactown15:04:47

random question: is there a way to get chrome to tell me what JS corresponds to a line in a source map file?

lilactown15:04:57

ah. I might just disable or elide source-maps

thheller15:04:07

thats why those are separate options 😉

lilactown15:04:33

well it’s being helpful in that I know what part of my CLJS code is slow. but I want to see the JS now 😛

lilactown15:04:37

any tricks you know of?

lilactown15:04:19

seems like if it can go JS line -> source map, i should be able to go the other way!

thheller15:04:26

JS code after optimizations or before? 😛

lilactown15:04:56

after optimizations I guess

thheller15:04:29

I just use pseudo names for that. the names are close enough so you can figure out where it came from in the CLJS code

thheller15:04:49

can't jump directly from CLJS loc -> JS loc since the code may be changed in ways that make that impossible 😛

thheller15:04:51

@lilactown there might be tools similar to this buried in the closure compiler stuff that allow going that way? https://clojureverse.org/t/server-side-decoding-of-javascript-sourcemaps/1591/3?u=thheller

vinurs16:04:30

when i do lein uberjar, it output these

vinurs16:04:40

is it need to set somthing?

thheller16:04:47

no. safe to ignore those ...

thheller16:04:20

{:type :shadow.build.closure/invalid-closure-warning, :key :non-standard-jsdoc, :level :off, :shadow.build.log/level :warn} this means you can remove :non-standard-jsdoc from the build config

thheller16:04:23

since it doesn't seem to exist

vinurs16:04:50

ok, it seems that it doesn’t need to move deps from project.clj to deps.edn, shadow-cljs can read deps from project.clj well

thheller16:04:19

yeah just project.clj is fine. thought you wanted to use deps.edn

thheller16:04:39

shadow-cljs doesn't read deps from project.clj in any way however. it just uses lein to launch itself.

thheller16:04:48

so whatever is configured there applies

vinurs16:04:52

😆,i don’t know that shadow-cljs can read the deps from project.clj before

vinurs16:04:57

just now i tried it and works ok

thheller16:04:25

if you have :lein true in your config shadow-cljs watch app literally runs lein run -m shadow.cljs.devtools.cli watch app

thheller16:04:04

project.clj is never parsed in any way

vinurs16:04:06

or i just run shadow-cljs watch app the same effect?

vinurs16:04:23

shadow-cljs watch app

thheller16:04:46

yes thats what I mean. you run shadow-cljs watch app and that internally just calls lein run -m shadow.cljs.devtools.cli watch app for you

thheller16:04:01

you don't ever need to call lein yourself. its just what is done internally.

vinurs16:04:28

i see, thanks

kenny20:04:37

I was looking at https://github.com/thheller/netlify-cljs and wondering if the same setup would work for a project using deps.edn instead of Lein.

thheller21:04:28

@kenny the project doesn't actually use lein. netlify just enables maven caching if it finds the project.clj

thheller21:04:44

no clue if it does the same for deps.edn?

kenny21:04:57

I tried it and got:

Executable 'clojure' not found on system path.

thheller21:04:00

doesn't look like it supports deps.edn yet

thheller21:04:15

lein isn't used to do anything other than caching deps

kenny21:04:48

Gotcha. I was able to get it to work with the following:

curl -O 
chmod +x linux-install-1.10.0.442.sh

install_dir=/opt/buildhome/clojure
mkdir -p ${install_dir}
./linux-install-1.10.0.442.sh --prefix ${install_dir}

echo "Installing Clojure to ${install_dir}/bin"
export PATH="${install_dir}/bin":$PATH

thheller21:04:07

that still won't cache the maven deps though

kenny21:04:29

Right but at least it'll build. Unfortunate about caching though.

thheller21:04:26

shadow-cljs unfortunately has too many deps so builds got way too slow for my taste without cache 😛

kenny21:04:15

Yeah... Right now I am using manual deploys to Netlify on CircleCI but I'd really like to take advantage of the deploy and branch previews.

thheller21:04:11

maybe they'd be open to adding support for deps.edn and maybe shadow-cljs.edn even

thheller21:04:26

since I'm not actually using the platform I didn't bother asking

dpsutton22:04:14

Netlify builds my shadow project just fine

kenny16:04:00

Are you using deps.edn with private repo Git deps ?

dpsutton16:04:36

ah no. sorry i missed that part. simple public repo on lein i think