Fork me on GitHub
#shadow-cljs
<
2022-09-08
>
Lidor Cohen08:09:26

is there an :autorun equivalent for :node-script? I want that in development, executing shadow-cljs watch :some-build will automatically execute the resulting node script for the REPL runtime

thheller08:09:03

there is not but can trivially achieve that with other tools, eg. https://www.npmjs.com/package/chokidar-cli

Lidor Cohen08:09:33

not sure this tool is what I was looking for, I'm using vscode calva to execute and connect the shadow-cljs. So I need some kind of hook to execute the output at the end of the first build. I think I can use https://shadow-cljs.github.io/docs/UsersGuide.html#build-hooks, the question was mostly to make sure I'm not missing some built-in functionality like :autorun...

thheller08:09:22

there is no functionality for this. there are simply too many ways you might want to run a :node-script

thheller08:09:38

the intent is you opening a second terminal and running it yourself

thheller08:09:55

you may after all also want access to stdin/stderr in the app

Lidor Cohen08:09:52

yeah I totally understand the underling design, that's what I do today. Just trying to smooth things up for our team. I'll just hack my way through it 🙂

thheller08:09:19

but very likely that you do not want :node-script for the REPL at all

thheller08:09:26

just use shadow-cljs node-repl instead. that just gives you the REPL without any build config or so

Lidor Cohen08:09:52

I don't want just the REPL, I work on a project and want the project's runtime. I might misunderstand how the REPL work, but iiuc in order to work in my files, ns, functions and data I need to build, run and then connect to the script's\lib runtime, correct?

thheller08:09:09

:node-script builds your entire project and produces a "executable" which you can then run via node

thheller08:09:26

node-repl just gives you a REPL, in which you can (require 'your.code) and run it, with no executable or other "output" apart from the REPL

Lidor Cohen08:09:50

So executing the output code is not necessary at all for dev? Mostly I just want node\browser repl and start hacking? I'm guessing a real browser is required only for experimenting with real application...

thheller08:09:12

well that all depends on what you are building

thheller08:09:33

for example with :node-script you might be doing something that takes command line arguments, executes and exits

thheller08:09:47

having a REPL here would keep the process alive and would actually hinder the development

thheller08:09:00

so you'd maybe have the :node-script in addition to the node-repl

thheller08:09:22

for browsers you might want to have actual HTML you generate yourself

thheller08:09:31

or embed in other ways in the HTML

thheller08:09:51

browser-repl only gives you a very basic HTML, that for example you can't include CSS into

thheller08:09:19

yes, you can just use browser/node-repl to start hacking. whether or not that makes sense depends on what you are building

thheller08:09:38

REPLs also don't automatically hot-reload and only builds do that

Lidor Cohen08:09:34

Yes, I just noticed that and started looking for a solution, I love the hot-reload 🙂

witek15:09:09

Hallo. I am trying to use the npm package https://www.npmjs.com/package/leader-line. It just defines the constructor LeaderLine. The source for leader-line.min.js looks like this: var LeaderLine=function(){...}(); But how do I use it in my ClojureScript code? (:require ["leader-line" :as leader-line]) gives me a JavaScript object, but it is no function and it has no .-LeaderLine property.

thheller17:09:56

@witek can't say. what does the object look like?

witek17:09:01

JavaScript Console shows:

{}
[[Prototype]]: Object
constructor: Æ’ Object()
hasOwnProperty: Æ’ hasOwnProperty()
isPrototypeOf: Æ’ isPrototypeOf()
propertyIsEnumerable: Æ’ propertyIsEnumerable()
toLocaleString: Æ’ toLocaleString()
toString: Æ’ toString()
valueOf: Æ’ valueOf()
__defineGetter__: Æ’ __defineGetter__()
__defineSetter__: Æ’ __defineSetter__()
__lookupGetter__: Æ’ __lookupGetter__()
__lookupSetter__: Æ’ __lookupSetter__()
__proto__: (...)
get __proto__: Æ’ __proto__()
set __proto__: Æ’ __proto__()
When I include the library via <script src="..."> I can call (js/LeaderLine e1 e2). But js/LeaderLine does not exist when I just (:require ["leader-line"])

thheller17:09:48

so it has a constructor

thheller17:09:02

so probably just (:require ["leader-line" :as leader-line]) and (leader-line.), ie. constructing a new instance?

witek18:09:13

This fails with Uncaught TypeError: module$node_modules$leader_line$leader_line_min is not a constructor

thheller18:09:49

maybe its only intended to be used via a script tag

thheller18:09:59

doesn't appear to be a proper npm package otherwise