Fork me on GitHub
#shadow-cljs
<
2020-06-22
>
mauricio.szabo01:06:10

Hi, is this a problem with Shadow or with ClojureScript? When I try to compile a file with:

(when something
  (nil 10))
It should point to the second line, right? But it is pointing to the first one...

mauricio.szabo01:06:35

This is an example of the error that gets displayed:

------ ERROR -------------------------------------------------------------------
 File: /home/mauricio/.atom/packages/chlorine/repl-tooling/src/repl_tooling/repl_client/shadow_ws.cljs:195:1
--------------------------------------------------------------------------------
 192 | 
 193 | 
 194 | 
 195 | (when-not true
-------^------------------------------------------------------------------------
Error in phase :compilation
Can't call nil at line 196 repl_tooling/repl_client/shadow_ws.cljs
--------------------------------------------------------------------------------
 196 |   (nil 10))
 197 | 
 198 | ; (lol/bar 10)
 199 | ; (-> msg :build-status :report println)
--------------------------------------------------------------------------------

mauricio.szabo01:06:02

This points to the right line, for example:

(when something
  ::wrong-ns/keyword)

mauricio.szabo01:06:09

(Well, I also found lots of interesting behaviors with compilation errors, so maybe it's not really a problem after all 😄. After all, compilation errors are quite rare anyway 😄)

pwalsh05:06:08

Excuse the cross-posting but I just added this to #clojurescript but I am currently using Shadow and part of my problem may be able to be solved in Shadow. Any help appreciated https://clojurians.slack.com/archives/C03S1L9DN/p1592802205168100

p-himik05:06:31

My tl;dr for the above: Is there a way to output function my_function(...) {...} for CLJS functions marked with ^:export (or somehow marked in any other way)? Specifically this kind of construct is needed. var my_function = ... and _function = ... will not work.

👍 3
Casey07:06:55

Is there a trick to getting core async go blocks to execute to work when using the :node-test target?

thheller08:06:50

@pwalsh you can specify a name for :export

(defn foobar
  {:export "someName"}
  []
  (js/console.log "called me!"))

pwalsh11:06:19

thanks @U05224H0W - unfortunately it does not work. It looks like it does expose someName in the global scope, but, it still compiles foobar to function c() {} (i.e; the function definition, which apps script needs, is not the original name of the function).

thheller11:06:58

so you are saying that var onOpen = function() { ... }; would be invalid in apps-script?

thheller12:06:02

https://developers.google.com/apps-script/guides/v8-runtime#improved_function_detection I guess thats the issue then. looks like it tries to analyze the code instead of just calling it?

pwalsh17:06:23

> so you are saying that `var onOpen = function() { ... };` would be invalid in apps-script? Yes, exactly

pwalsh17:06:05

btw I solved this not even with externs. I just compile my clojurescript, and also push a javascript file to app script which exposes the public interface for app script and calls the functions from the compiled clojurescript.

pwalsh17:06:46

(for anyone who every does this in future, use https://github.com/google/clasp so you can work with your code using a normal workflow and push to apps script like "deploying" your code - it is very useful)

thheller17:06:22

you could use (js* "function onOpen() { your.ns.actual_on_open() };") but don't tell anyone I said that

😍 3
thheller08:06:53

so judging from the apps script example just (defn on-open {:export "onOpen"} [] ...)?

thheller08:06:39

don't know much about the context this is running in so this may not work though

thheller09:06:37

@ramblurr there is nothing special regarding :node-test and async go blocks. they work exactly as they do in all other targets

smogstate10:06:33

hi i want to split our project. i read about modules, but as i understand its still same project.

smogstate10:06:47

same code base

thheller10:06:49

:modules has nothing to do with how you organize your project. it only splits the output into several files but still requires compiling everything together.

smogstate10:06:03

so module can be arbitrary js?

thheller10:06:55

"modules" unfortunately is a bad name with very different meaning in many different contexts

thheller10:06:08

so this will be much quicker if you explain what you want to do

smogstate10:06:50

i wnat to split my project in multiple projects each has own CI/CD

smogstate10:06:44

then assemble them in SPA with dynamicly loaded modules

thheller10:06:00

ok. one has nothing to do with the other.

thheller10:06:35

:modules is about the produced output. so thats what you do to get "dynamically loaded modules" from

thheller10:06:56

the input however does not matter for this. so whether this is coming from multiple libraries or not doesn't matter

smogstate10:06:24

i read this article 🙂

smogstate10:06:09

i checked source on github you got those lazy loaded components in same project

thheller10:06:40

yes but it literally doesn't matter where those components come from

thheller10:06:55

could be from a library somewhere

thheller10:06:32

if you are asking how to use multiple independent projects and their produced .js files together on one page then that is not supported

rickmoynihan10:06:58

I’ve just tried putting {:deps-aliases [:cider]} in my .shadow-cljs/config.edn file and I now get the error nREPL middleware: shadow.cljs.devtools.cli has no namespace error Command failed with exit code 2. when running shadow-cljs watch myapp, any idea how to resolve this?

rickmoynihan11:06:45

weird copying the alias into :dependencies style works

smogstate10:06:17

so if i have react components compiled into js i cant use them in one page

thheller10:06:18

what I think you want is moving some code into a library that you use as a dependency in your main project

smogstate10:06:22

so basicaly i got view components which are used in core project which provides routing between those components

thheller10:06:04

yes, put the components into libraries of their own

thheller10:06:12

but your main project still compiles everything together

smogstate10:06:07

as a node.js libs?

thheller10:06:26

sorry. I don't have time for this right now.

smogstate10:06:54

and tnanks for shadow-cljs

Casey12:06:19

Are there any docs/guides for connecting emacs/cider to a :node-test target? I can't figure out how to connect to the right repl. It's erroring with no js runtime available.

thheller12:06:19

node-test isn't supposed to have a REPL

thheller12:06:01

just use shadow-cljs node-repl if you want a generic node repl

Casey12:06:47

When I follow the instructions from the guide (https://shadow-cljs.github.io/docs/UsersGuide.html#_launch_the_clojurescript_repl) after the repl connects, I've given a cljs.user> prompt, but typing anything in it prints No available JS runtime. I selected my app using the :node-script target

Casey12:06:38

The shadowjs web ui (http://localhost:9630/runtimes) only shows a single clj runtime, no cljs runtimes

Casey12:06:59

Hm ok strange. Rather than choosing my app build target, I just chose node-repl and then I get a functioning cljs.user> repl.

rschmukler21:06:27

Hey all! Is there any way to resolve a javascript require via a symbol at compile time? I've got a library that's an NPM dependency and I'm writing a macro that generates code for it. How can I consume that macro in a different namespace? ie. unlike "normal" shadow requires, I can't use the fully qualified namespace since that'd be a string. Furthermore, the macro is meant to be used inside a function body, so something like (do (require "foo" :as foo) (defn something [] (foo/bar))) won't work

rschmukler21:06:52

Never mind, looks like js/module$node_modules$str

lilactown22:06:45

@rschmukler are you trying to dynamically require a module?

lilactown22:06:15

FWIW require is only available at dev time; it won’t work when you do a release build even if it’s static AFAIK

rschmukler22:06:32

It's at compile time. I managed to get it working by looking at what resolve resolves the symbol to when you do (:require ["library" :as foo]) - turns out it's a string concat of node_modules + other stuff

rschmukler22:06:37

Thanks though 🙂