Fork me on GitHub
#shadow-cljs
<
2018-07-16
>
denis_krivosheev06:07:12

@thheller Hi. Do you have an example of how to call cljs from js with shadow-cljs? I created namespace and tried

import {foo} from 'goog:demo.foo';
it doesn’t work. I tried this example from documentation either:
import cljs, { keyword } from "goog:demo.foo";

cljs.array_map(keyword("foo"), "hello world");
In both cases javascript loader says: Module not found: Can’t resolve ‘goog:demo.foo’ in ‘/Users/den/git/test/mhello-cljs/src’

thheller08:07:50

@denis_krivosheev this only works if the JS is compiled by shadow-cljs. I have some code for testing in the shadow-cljs repo. it looks like this https://github.com/thheller/shadow-cljs/blob/master/src/dev/demo/es6.js#L1

thheller09:07:11

@tomi.hukkalainen_slac you still seem to be fighting with :foreign-libs. I'm curious if you tried shadow-cljs and if you chose not to use it why?

Hukka09:07:10

I checked the docs to see how I could replace the current build with shadow without reworking too much, but got a bit stuck at the server side, again. I'm currently letting figwheel start the ring server for backend in dev mode. That works by simply telling figwheel where the ring handler is. At first I figured that shadow doesn't do that at all, only static files. Then I did get a pointer that there is a fallback handler config when client requests urls that aren't available as static, but that was... pretty sparsely documented. Just says that it's a function from req to response, without saying anything what the request or the response are

Hukka09:07:40

Surely I could have looked into source to figure it out, but once again I tried a different way to include libs that are not in cljsjs

Hukka09:07:26

I can't escape the feeling that moving to shadow would require significant refactoring of the way the backend and frontend are built and work together

thheller10:07:24

what do you use to serve the backend in production?

thheller10:07:49

thanks for the feedback though. I'll smooth over that part of the docs. shadow-cljs focus is on CLJS and I always run my own webserver when I need server side stuff.

thheller10:07:54

@tomi.hukkalainen_slac FWIW the backend and the frontend work together exactly the same way. figwheel doesn't do anything to the backend and you can start the backend server by any other means. the only thing CLJS requires from the backend is that the generated JS files are served properly.

thheller10:07:19

you can use run-server with whatever you have specified as :ring-handler in figwheel

thheller10:07:25

don't even have to shadow-cljs about it whatsoever

Hukka13:07:31

We use compojure-api

Hukka13:07:23

I think an example showing the whole stack would go a long way, though of course what the stack is varies. I think that the compojure-api + reagent/re-frame is pretty usual

Yehonathan Sharvit11:07:07

A question related to the :browser target

Yehonathan Sharvit11:07:28

Here is my shadow-cljs.edn file:

{:target :browser
           :output-dir "resources/public/js/browser"
           :devtools  {:http-port 8025
                       :http-root "resources/public/js/browser"}
           :modules {:main {:entries [audyx.app.init]}}}
 

Yehonathan Sharvit11:07:33

I created an index.html in resources/public/js/browser with the following content:

<script src="main.js"></script>

Yehonathan Sharvit11:07:13

but when I load localhost:8025/index.html

Yehonathan Sharvit11:07:47

I get many console errors for all the js dependencies

Yehonathan Sharvit11:07:06

For instance:

 Not found

Yehonathan Sharvit11:07:28

What is wrong with my configuration?

thheller12:07:34

@viebel :asset-path "/" in your config, it defaults to "/js"

thheller12:07:35

any reason why you don't use resources/public as :http-root though? typically you should avoid putting anything other than generated output into :output-dir

Yehonathan Sharvit12:07:13

and then the :asset-path should be "js/browser". Right?

thheller12:07:22

/js/browser yes

thheller12:07:34

always try to use absolute paths. much easier to work with later.

Yehonathan Sharvit12:07:00

This is what I meant. I made a typo

Yehonathan Sharvit12:07:18

Now I am launching a REPL with shadow-cljs cljs-repl browser

Yehonathan Sharvit12:07:13

@thheller The code doesn't seem to reload on code change. I mean: I see in the browser a notification that the compilation started but the code changes don't take effect and the :before-load function is not triggered. In my case, I have a couple of build warnings, so I set :ignore-warnings true but it didn't help

thheller12:07:34

do you have the :after-load hook properly set?

thheller12:07:06

in figwheel that would be :on-jsload I think

thheller12:07:02

either like this in the code via metadata or :devtools {:after-load your.app/start} in the config

Yehonathan Sharvit12:07:02

but it didn't help

Yehonathan Sharvit12:07:24

:browser
          {:target :browser
           :output-dir "resources/public/js/browser"
           :asset-path "/js/browser/"
           :ignore-warnings true
           :devtools  {:http-port 8025
                       :http-root "resources/public/"
                       :before-load audyx.app.init/before-load
                       :after-load audyx.app.init/start}
           :modules {:main {:entries [audyx.app.init]}}}

thheller12:07:00

what does the browser console show?

Yehonathan Sharvit12:07:16

shadow-cljs: WebSocket connected!
browser.cljs:27 shadow-cljs: REPL init successful
browser.cljs:121 BUILD-WARNING in audyx/audio/ambiences/calibration.cljs at [77:3]
	Wrong number of args (1) passed to audyx.audio.ambiences.calibration/create-noise-node
shadow$cljs$devtools$client$browser$handle_build_complete @ browser.cljs:121
shadow$cljs$devtools$client$browser$handle_message @ browser.cljs:258
shadow$cljs$devtools$client$env$process_ws_msg @ env.cljs:148
(anonymous) @ browser.cljs:318
browser.cljs:121 BUILD-WARNING in audyx/audio/ambiences/transducer_calibration.cljs at [32:3]
	Wrong number of args (3) passed to cljs.core/replace
shadow$cljs$devtools$client$browser$handle_build_complete @ browser.cljs:121
shadow$cljs$devtools$client$browser$handle_message @ browser.cljs:258
shadow$cljs$devtools$client$env$process_ws_msg @ env.cljs:148
(anonymous) @ browser.cljs:318
browser.cljs:121 BUILD-WARNING in audyx/audio/input.cljs at [35:13]
	Use of undeclared Var audyx.audio.input/-Infinity
shadow$cljs$devtools$client$browser$handle_build_complete @ browser.cljs:121
shadow$cljs$devtools$client$browser$handle_message @ browser.cljs:258
shadow$cljs$devtools$client$env$process_ws_msg @ env.cljs:148
(anonymous) @ browser.cljs:318
browser.cljs:121 BUILD-WARNING in audyx/test/records/loop/volume.cljs at [29:1]
	Bad method signature in protocol implementation, ILoop initial-index does not declare arity 3
shadow$cljs$devtools$client$browser$handle_build_complete @ browser.cljs:121
shadow$cljs$devtools$client$browser$handle_message @ browser.cljs:258
shadow$cljs$devtools$client$env$process_ws_msg @ env.cljs:148
(anonymous) @ browser.cljs:318
browser.cljs:121 BUILD-WARNING in audyx/test/records/loop/single.cljs at [10:1]
	->Single already refers to: audyx.test.records.loop.single/->Single being replaced by: audyx.test.records.loop.single/->Single
shadow$cljs$devtools$client$browser$handle_build_complete @ browser.cljs:121
shadow$cljs$devtools$client$browser$handle_message @ browser.cljs:258
shadow$cljs$devtools$client$env$process_ws_msg @ env.cljs:148
(anonymous) @ browser.cljs:318
browser.cljs:121 BUILD-WARNING in audyx/graphs/vocalsnr_graph.cljs at [13:1]
	Bad method signature in protocol implementation, Graph graph-definition does not declare arity 3
shadow$cljs$devtools$client$browser$handle_build_complete @ browser.cljs:121
shadow$cljs$devtools$client$browser$handle_message @ browser.cljs:258
shadow$cljs$devtools$client$env$process_ws_msg @ env.cljs:148
(anonymous) @ browser.cljs:318

Yehonathan Sharvit12:07:43

I see the shadow-cljs icon rotating

thheller12:07:07

thats it? nothing after those warnings?

thheller12:07:08

ah the ignore-warnings is misplaced

thheller12:07:13

should be in :devtools

Yehonathan Sharvit12:07:40

Now I have exactly the same as figwheel. right?

thheller12:07:59

no idea. I have never use figwheel. 😛

Yehonathan Sharvit12:07:18

Is there a way to have code completion in the shadow-cljs REPL?

thheller12:07:44

connect your editor then yes. otherwise currently no

Yehonathan Sharvit12:07:12

Will try to connect emacs

Yehonathan Sharvit12:07:00

what editor will you recomend on windows?

thheller12:07:15

I use Cursive only (and would recommend)

Yehonathan Sharvit12:07:18

I have recently switched from Macos to Windows 10

Yehonathan Sharvit12:07:59

I am having troubles installing leiningen on Windows

Yehonathan Sharvit12:07:58

Trying to install shadow-cljs now

Yehonathan Sharvit13:07:08

Meanwhile I was able to enjoy a shadow repl inside emacs (cider)

Yehonathan Sharvit13:07:19

The instructions on the shadow doc are very clear

Yehonathan Sharvit13:07:47

the only thing that was not 100% straightforward was that I had to configure [cider/cider-nrepl "0.17.0"] according to my cider version: 0.18.0-SNAPSHOT Maybe you can add a comment about that here: https://shadow-cljs.github.io/docs/UsersGuide.html#_dependencies_2

Yehonathan Sharvit13:07:53

also, M-x cider-create-sibling-cljs-repl is now: M-x cider-connect-sibling-cljs

thheller13:07:00

if you use the built-in shadow-cljs support in cider you don't have to specify it at all I think

thheller13:07:09

but I do not use emacs and know nothing about it

dpsutton13:07:33

if you start shadow-cljs from emacs through CIDER it will insert the dependencies for you (I think)

Yehonathan Sharvit13:07:37

@thheller now trying to configure Cursive

Yehonathan Sharvit14:07:04

What context module should I provide in the Clojure remote REPL settings?

thheller14:07:49

do you have more than one?

Yehonathan Sharvit14:07:14

No idea. I don't know what is a context module?

thheller14:07:46

how did you create the cursive project?

Yehonathan Sharvit14:07:33

I opened my project root folder

thheller14:07:55

you should probably generate a pom.xml via shadow-cljs pom

thheller14:07:24

and then file -> new -> from existing sources and then select the pom.xml

thheller14:07:35

leave everything as is and accept acouple times

thheller14:07:42

that should setup all the deps properly

thheller14:07:34

whenever you change dependencies just call shadow-cljs pom again and let cursive update it

thheller14:07:01

you can also use project.clj with lein of course. cursive has a bit better integration with that.

thheller14:07:13

but I had no issues with using pom.xml

Yehonathan Sharvit14:07:43

What REPL should I create? A remote Clojure REPL?

Yehonathan Sharvit14:07:54

I don't see an option for a Cljs REPL

thheller14:07:33

yes remote clojure repl

thheller14:07:54

once connecte call (shadow.cljs.devtools.api/repl :browser) to switch it to CLJS

Yehonathan Sharvit14:07:19

Is there a way to call this code automatically?

thheller14:07:56

dont think so

thheller14:07:42

you can create a REPL command and assign that to a keybinding

Yehonathan Sharvit15:07:54

Now I have a very weird issue in Cursive

Yehonathan Sharvit15:07:07

I don't get a prompt in the REPL window

Yehonathan Sharvit15:07:19

I can send commands to the REPL but I cannot type any command

thheller15:07:41

are you typing in the correct window? the input thing has its own space below

thheller15:07:15

sorry gotta go. Cursive has pretty extensive docs and should contain everything you need.

thheller15:07:22

I'll be back later

Yehonathan Sharvit15:07:50

and for shadow-cljs

Yehonathan Sharvit15:07:55

It really rocks!!!

Jon16:07:50

I want to quote this.

Jon16:07:11

screenshot~

Yehonathan Sharvit16:07:40

I am having a warning at the beginning of the execution of compilation:

shadow-cljs - running: lein run -m shadow.cljs.devtools.cli --npm watch browser
Compiling ClojureScript...
Compiling ["public/clojurescript/dev/2ffae5ec-aa76-40ed-aadc-d3878fce327a.js"] from ["src/cljs/audyx" "resources"]...
module.js:549
    throw err;
    ^

Error: Cannot find module '@cljs-oss/module-deps'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at [eval]:3:13
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at Object.runInThisContext (vm.js:139:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:652:30)
    at evalScript (bootstrap_node.js:463:27)

Yehonathan Sharvit16:07:30

After that the compilation completes successfully. But I'd prefer fixing this warning

thheller16:07:46

that is something from standard CLJS

thheller16:07:51

that is not a shadow-cljs compilation, possibly lein-cljsbuild or so?

thheller16:07:14

definitely not a shadow-cljs message though

Yehonathan Sharvit22:07:09

some package.json contains a browser key (e.g https://github.com/aws/aws-sdk-js/blob/master/package.json) According to https://docs.npmjs.com/files/package.json#browser :

If your module is meant to be used client-side the browser field should be used instead of the main field. This is helpful to hint users that it might rely on primitives that aren't available in Node.js modules. (e.g. window)

Yehonathan Sharvit22:07:05

Does shadow-cljs behave like this when browser key is present on a npm module imported?

Yehonathan Sharvit22:07:37

Currently, I am not able to require aws-sdk in my shadow-cljs project

Yehonathan Sharvit22:07:27

It seems like shadow-cljs ignores the browser key

Yehonathan Sharvit22:07:57

on :target :browser builds