Fork me on GitHub
#shadow-cljs
<
2020-05-11
>
thheller07:05:05

@folcon js files in node_modules no, on the classpath that should already work

folcon12:05:58

It doesn’t appear to? I’ve been trying to do it for a while, the file loads, but to get edits I have to keep rebooting the repl, which is a bit of a pain =)… I’m using the js-options:

:js-options
                   {:resolve {"terrain" {:target :file
                                         :file "resources/public/js/terrain.js"}

thheller14:05:24

why not use https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js instead? no :resolve config required for that

folcon14:05:47

Reading =)…

folcon15:05:29

Well I keep getting failed to convert sources… Not sure if there’s something I need to do to get it working?

folcon15:05:46

I’m not sure that reloading work either? I verbatim copied the imported code across to get things working, but it’s still complaining about missing imports… I thought it might not be watching the folder but:

(shadow/watch :test)
=> :already-watching

thheller15:05:12

well I cannot guess what is happening without more info

folcon15:05:16

I can certainly import the code, but the old code…

thheller15:05:18

whats the actual error?

folcon15:05:32

Well the biggest one is that the javascript code in the path doesn’t appear to reload? I’m not sure if I’m supposed to refresh it in some special way?

thheller15:05:57

I do not have enough information to answer that

thheller15:05:05

I have no clue what you actually have now

thheller15:05:23

:resolve with :target :file is not supposed to reload and never will. mostly because it shouldn't be used in the first place

folcon15:05:48

sorry, I was following your instructions regarding using classpath-js =)…

folcon15:05:54

I’ve removed the :resolve in shadow-cljs config, and now have it under my src and am requiring it with:

["/rm/terrain" :as terrain]
["/rm/language" :as language]

folcon15:05:15

The import works, but making code changes in the js files doesn’t appear to do anything…

thheller15:05:16

first of all please use the full filename

folcon15:05:30

As in the absolute path?

thheller15:05:32

ok reloading depends on how the file is written

thheller15:05:38

as in with extension

folcon15:05:40

Or just using .js

thheller15:05:14

how is the code written? does it use import/export?

folcon15:05:49

Ah sure, I was just copying what’s in the userguide which doesn’t do that =)…

folcon15:05:25

It didn’t originally, I’ve basically just exported every function and am resolving the imports….

thheller15:05:32

yeah it doesn't affect anything ... I'm just likely going to remove the "guess-the-extension" part soon

thheller15:05:49

I need to know how

thheller15:05:59

you are making this harder here ... I'm guessing what you are doing

thheller15:05:12

just give me more info and I can actually help

thheller15:05:22

there are a billion different ways to do things

thheller15:05:27

I cannot guess them all

folcon15:05:06

Ok would a gist help?

thheller15:05:58

a simple example might be enough. basically I do not know what you mean when you say "exported every function" since there are multiple ways of doing that

thheller15:05:15

is is ESM export function foo or is it commonjs exports.foo = function ...

thheller15:05:28

one it hot-reloadable while the other is not

folcon15:05:24

Give me a minute =)… I’m putting something together, I’ve been wanting to figure out a way to get more comfortable with cljs/js interop and I’m still super unfamiliar with this stuff

folcon16:05:28

I’ve just got a minimal case

folcon16:05:38

I can add in the changes I made, but that might be counterproductive… The synopsis is that I just added export before functions that I wanted in language.js, eg:

export function makeRandomLanguage
export function makeWord
and basically all the functions in terrain.js.

folcon16:05:36

Happy to do it if you’d find it helpful, it will just take me a sec to copy/paste…

thheller16:05:26

well without exports you cannot access the functions from CLJS

folcon16:05:53

That’s the changes I made on a different branch

folcon16:05:09

so I can throw it away if there’s a better approach =)…

thheller16:05:11

without that it won't even load normally so you are going to need that regardless

folcon16:05:34

I’m testing it by: Adding a console.log in language.js:

export function makeRandomLanguage() {
    console.log("TEST");
    var lang = makeBasicLanguage();
    lang.noortho = false;
Then calling this in terrain-cljs.core-test:
(.makeWord language (.makeRandomLanguage language) "city")

thheller16:05:40

I'm not actually sure anymore if this is even supposed to work

folcon16:05:56

As in js hot code reload?

thheller16:05:03

haven't worked on direct JS support in a rather long time

thheller16:05:20

importing it should be fine but hot-reload I don't really know

folcon16:05:45

Ok sure, so maybe not something you really want to support any more?

thheller16:05:48

I know it definitely won't work without export though

folcon16:05:27

That’s been added, the branch https://github.com/Folcon/terrain/tree/js-code-reloading has all the changes with the exports…

thheller16:05:38

well reloading JS is always tricky so it will always be more limited than reloading CLJS

folcon16:05:47

I can definitely load the js files, just not reload them =)…

thheller16:05:46

I can take a look later

folcon16:05:57

Thanks =)…

thheller16:05:08

code in that branch looks correct and should in theory be hot-reloadable

folcon16:05:02

😕 that’s not a good sign

thheller22:05:16

try 2.9.1, hot-reloading the JS should work fine again assuming they have proper import/export

4
🎉 4
folcon18:05:15

Oh cool! Will give that a go in a bit!

papachan13:05:00

I just included [goog.string :refer [format]] at my require namespaces, in dev it worked fine i can use (format) but it dont find the google lib when i compile a release bundle

papachan14:05:11

anyway i just replace it using (str % " " %) instead of format

thheller14:05:25

@papachan goog.string.format is a separate namespace from goog.string so to use it properly you must require it separately

thheller14:05:45

[goog.string.format]
[goog.string :refer (format)]

👍 4
papachan14:05:50

Ah didnt know that ! thank you @thheller

Logan Powell17:05:38

👋 hi everyone! it's been a while since I've been here. I missed you guys! I am updating a library I wrote in cljs a year or so ago. I updated to the latest version of Clojurescript and for some reason now I can't eval functions with docstrings or macros... does anyone have an idea what's going on?

Logan Powell17:05:01

i'm using the latest shadow-cljs

thheller17:05:13

you'll need to clarify what "I can't eval functions with docstrings or macros" means

☝️ 4
Logan Powell17:05:33

It seems that I can eval functions if I remove the docstrings from them

thheller17:05:44

go back like 100 steps

thheller17:05:50

and start at the beginning

thheller17:05:05

what command did you run?

thheller17:05:30

when you say eval I assume REPL? which one?

Logan Powell17:05:47

I'm using Cursive and I run send (form) to REPL

Logan Powell17:05:35

in general, i'm getting some wierdness... I have been slamming my face against the keyboard for a day

Logan Powell17:05:54

It's been a while, but last time I updated the lib I could send forms to the REPL and they would seem to be read in correctly by printing the function name with a hash in front, like:

#'census.utils.core/update-map

Logan Powell17:05:07

but now the REPL just prints nil

Logan Powell17:05:32

when I include the docstring

Logan Powell17:05:25

I'm like five minutes away from rewritting the thing in js

Logan Powell17:05:51

I can't believe how much of a PITA the tooling is to pick up again (after a year off)

Logan Powell17:05:29

I've tried Cursive, Calva, Chlorine, back to Cursive they all do the same thing

mauricio.szabo17:05:53

I can look at this issue on Chlorine, but I'm not seeing this problem with any target I'm seeing... Did you try to update shadow-cljs? Or even core.async

Logan Powell17:05:39

I don't know what I'm doing wrong

thheller17:05:11

I don't know what you are doing either so I cannot help unless you tell me more

Logan Powell17:05:31

long time, no talk

Logan Powell17:05:03

I really don't know what else to tell you... I mean the same code worked last year

thheller17:05:45

$ shadow-cljs browser-repl
shadow-cljs - config: /mnt/c/Users/thheller/code/shadow-cljs/shadow-cljs.edn
shadow-cljs - connected to server
cljs.user=> (defn foo "docstring" [a] a)
#'cljs.user/foo
cljs.user=> (foo 1)
1

Logan Powell17:05:12

let me try that

thheller17:05:25

works fine for me .. and that is all the details I have gotten from you so far

Logan Powell17:05:14

λ shadow-cljs node-repl
shadow-cljs - config: C:\Users\logan\Projects\census\census-geojson\shadow-cljs.edn  cli version: 2.8.59  node: v10.16.2
shadow-cljs - connected to server
census.utils.core=> (defn foo "docstring" [a] a)
nil
census.utils.core=> (foo 1)
TypeError: Cannot read property 'call' of undefined
    at cljsEval (<eval>:1:31)
    at global.SHADOW_NODE_EVAL ([stdin]:90:10)
    at Object.shadow$cljs$devtools$client$node$node_eval [as node_eval] (C:\Users\logan\Projects\census\census-geojson\.shadow-cljs\builds\node-repl\dev\out\cljs-runtime\shadow\cljs\devtools\client\node.cljs:24:1)
    at C:\Users\logan\Projects\census\census-geojson\.shadow-cljs\builds\node-repl\dev\out\cljs-runtime\shadow\cljs\devtools\client\node.cljs:49:13
    at Object.ret [as repl_call] (C:\Users\logan\Projects\census\census-geojson\.shadow-cljs\builds\node-repl\dev\out\cljs-runtime\shadow\cljs\devtools\client\env.cljs:104:11)
    at Object.shadow$cljs$devtools$client$node$repl_invoke [as repl_invoke] (C:\Users\logan\Projects\census\census-geojson\.shadow-cljs\builds\node-repl\dev\out\cljs-runtime\shadow\cljs\devtools\client\node.cljs:47:1)
    at shadow$cljs$devtools$client$node$process_message (C:\Users\logan\Projects\census\census-geojson\.shadow-cljs\builds\node-repl\dev\out\cljs-runtime\shadow\cljs\devtools\client\node.cljs:118:5)
    at C:\Users\logan\Projects\census\census-geojson\.shadow-cljs\builds\node-repl\dev\out\cljs-runtime\shadow\cljs\devtools\client\env.cljs:183:9
    at Object.shadow$cljs$devtools$client$env$process_next_BANG_ [as process_next_BANG_] (C:\Users\logan\Projects\census\census-geojson\.shadow-cljs\builds\node-repl\dev\out\cljs-runtime\shadow\cljs\devtools\client\env.cljs:171:7)
    at Object.shadow$cljs$devtools$client$env$process_ws_msg [as process_ws_msg] (C:\Users\logan\Projects\census\census-geojson\.shadow-cljs\builds\node-repl\dev\out\cljs-runtime\shadow\cljs\devtools\client\env.cljs:184:7)
census.utils.core=>

Logan Powell17:05:14

and without docstring...

> (defn foo [a] a)
#'census.utils.core/foo
> (foo 1)
1
census.utils.core=>

thheller17:05:17

that is odd. works fine for me with node-repl too.

thheller17:05:27

do you use project.clj or deps.edn? or just plain shadow-cljs.edn?

Logan Powell17:05:52

project.clj, but I kinda rely on the pom.xml file with cursive

Logan Powell17:05:58

just plain shadow-cljs.edn

thheller17:05:17

what is it ... project.clj or shadow-cljs.edn?

thheller17:05:26

do you have :lein true or something in shadow-cljs.edn?

Logan Powell17:05:26

shadow-cljs.edn

Logan Powell17:05:38

no to :lein true

Logan Powell17:05:59

here's my setup:

{:source-paths ["src"]
 :dependencies [[org.clojure/core.async "1.0.567"]
                [cljs-ajax "0.8.0"]
                [funcool/cuerdas "2.2.0"]
                [clojusc/defun "0.4.0"]
                [frankiesardo/linked "1.3.0"]
                ;[jamesmacaulay/cljs-promises "0.1.0"] ; FIXME: When batching cartography files: uncomment and `shadow-cljs pom`
                ;[cider/cider-nrepl "0.21.0"]
                [net.cgrand/xforms "0.19.2"]]
 :nrepl        {:port 3333}
 :builds       {:lib    {:target           :node-library
                         :output-dir       "public/census"
                         :output-to        "public/census/census.js"
                         :compiler-options {:optimizations :advanced}
                         :exports-var      census.core/census}
                :geo    {:target           :node-library
                         :output-dir       "public/geo"
                         :output-to        "public/geo/batch_convert.js"
                         :compiler-options {:optimizations :simple}
                         :exports-var      configs.geojson.core/batch_convert}}}

thheller17:05:09

hmm only guess I have is that the core.async version does not match

thheller17:05:29

try [org.clojure/core.async "1.1.587"] but also upgrade shadow-cljs to 2.9.0

thheller17:05:43

dunno why it would error out like that though

thheller17:05:21

better yet just remove the core.async dependency completely. shadow-cljs depends on core.async so it will always be available

thheller17:05:29

and that way you get the version it expects

Logan Powell18:05:41

Fuck yes dude!

Logan Powell18:05:01

btw, I did have to npm i -D ws

Logan Powell18:05:13

was getting an error that that was missing

thheller18:05:38

you should have shadow-cljs installed in the project itself, that will take care of that also

Logan Powell18:05:01

OMG you have no idea how angry I was getting 😄

thheller18:05:50

I'm curious to know what exactly happened since core.async issues usually fail in different ways 😛

Logan Powell18:05:05

you and me both

Logan Powell18:05:27

your intuition was right though

Logan Powell18:05:18

man, I feel so much better... did you ever set up a way for us to donate to the project?