Fork me on GitHub
#shadow-cljs
<
2020-05-21
>
ghufran06:05:29

I am trying to get source maps working, but having trouble This is my shadow-cljs.edn file:

;; shadow-cljs configuration
{:source-paths ["src"]
 :dev-http {8081 "public"}
 :nrepl {:port 55555}
 :dependencies			[[reagent "1.0.0-alpha2"]]
 :builds {:app { :target		    :browser
                :output-dir	  "public/scripts/"
                :modules	    {:core
                                  {:init-fn com.ghufran.core/run }}
                :compiler-options {:source-map                          true
                                   :source-map-detail-level             :all
                                   :source-map-include-sources-content  true
                                   }}}}
and this is the error I’m getting in the browser console (chrome) on first loading the page:
DevTools failed to load SourceMap: Could not parse content for : Unexpected token < in JSON at position 0
and this is the error in the firefox console:
Source map error: Error: request failed with status 404
Resource URL: 
Source Map URL: com.ghufran.core.js.map
I’m actually getting around 30 such errors, one for each file in /cljs-runtime/ whose source map the browser can’t find It looks like the browser is expecting the source map to be in /js/cljs-runtime/ when it should be /scripts/cljs-runtime/ based on the shadow-cljs.edn file, if I’ve understood that correctly. I’ve confirmed that com.ghufran.core.js.map is in fact in /scripts/cljs-runtime/ Any idea what might be going on? Is there some other config I need to tweak?

thheller08:05:08

@ghufran you don't need to set any of the :compiler-options, you are just relying on the default :asset-path "/js" which is incorrect in your case.

thheller08:05:37

{:source-paths ["src"]
 :dev-http {8081 "public"}
 :nrepl {:port 55555}
 :dependencies [[reagent "1.0.0-alpha2"]]
 :builds {:app {:target :browser
                :output-dir "public/scripts"
                :asset-path "/scripts"
                :modules {:core {:init-fn com.ghufran.core/run}}
                }}}

ghufran15:05:30

Perfect, thanks!

flyboarder15:05:12

@thheller is there a shortcut in shadow-cljs to automatically require some namespaces in all or some files when compiling?

flyboarder15:05:06

my use case: I would like to have my framework namespaces always available without a require block in every file that has to duplicate the same block of code, currently I have some front end stuff and our ui library has ~30 namespaces

flyboarder15:05:33

{:require {#{app.ui} [[hoplon.core :as h]]}} something like that in shadow-cljs.edn would be great as a build option

lilactown15:05:52

that would be pretty surprising and wouldn’t transfer to any other build tool 😕 dislike

lilactown15:05:08

I’m struggling to use shadow inspect

lilactown15:05:34

I’ve included the preload in my build:

:devtools {:preloads [day8.re-frame-10x.preload
                                      shadow.remote.runtime.cljs.browser
                                      devtools.preload]}

lilactown15:05:52

I’ve opened my app in one tab and the ui at localhost:9630 in the other

lilactown15:05:51

in my editor, I’ve a CLJS REPL open:

shadow.user> (shadow/watch :app)
[:app] Configuring build.
[:app] Compiling ...
[:app] Build completed. (1202 files, 4 compiled, 7 warnings, 13.32s)
shadow.user> (shadow/repl :app)
To quit, type: :cljs/quit
[:selected :app]
cljs.user> (tap> 123)
true
however, I see no output in the inspect tab of the shadow UI

isak17:05:30

Strange, works for me. Do you see anything if you use the cljs.user prompt at the bottom to do the tap> ?

lilactown17:05:51

I don’t see a cljs.user prompt either

isak17:05:31

Oh, do you see a runtime connected near the top?

lilactown17:05:40

it’s simply blank underneath the dashboard/builds/runtimes/inspect header tabs

isak17:05:56

for example, I see this:

isak17:05:29

Hm, do you have browser window that is loading your clojurescript code?

lilactown17:05:55

I have a jacked-in CIDER session that I can evaluate CLJS code in the browser

isak18:05:01

Hm, not sure then

lilactown18:05:35

under “Runtimes” I don’t see anything under “Available ClojureScript Runtimes”

thheller18:05:06

@U4YGF4NGM check the networks websockets tab. there should be a dedicated websocket for the remote stuff

thheller18:05:02

if all else fails just try shadow-cljs browser-repl and then (require 'shadow.remote.runtime.cljs.browser)

lilactown16:05:03

there are no errors in either tab’s console

isak17:05:01

@flyboarder yea I've thought about that too, I think something like that is a good idea for the ns macro. Best place would be in ClojureScript, but that will never happen, unfortunately

isak17:05:42

In your case, maybe a decent workaround would be to re-export things from another namespace? Wouldn't work for :refers, though

flyboarder17:05:16

@isak what do you mean by re-exporting?

flyboarder17:05:33

can I def a ns as a symbol? and then refer that symbol?

lilactown17:05:31

@flyboarder you can have one namespace that require’s all 30 of your other namespaces, then re-exports them

isak17:05:47

For example, re-frame does this so you don't need to import so many namespaces: https://github.com/day8/re-frame/blob/master/src/re_frame/core.cljc#L576-L597

isak17:05:56

Just re-frame.core for most things

flyboarder17:05:50

ah yes I do this already, but I need to be able to resolve namespaced keywords ::card/card

isak17:05:50

So you can point to a function, but I guess you need to copy the docstring and any other meta

flyboarder17:05:19

where ::card is one of my ui libs

isak17:05:47

Ah right, guess it wont work

flyboarder17:05:51

thats why I think an auto included list of requires would be a good fit here

(ns 
  (:require-shadow :exclude [some.unwanted.ns]))
  (:require [[the.usual :as whatever]])

isak17:05:35

yea they have a mechanism for this in Elixir, very useful

flyboarder17:05:26

hm, I wonder if I can hack the ns macro and extend it with this

lilactown17:05:09

you’ll run into lots of problems with anything that uses static analysis

lilactown17:05:27

e.g. Cursive, clj-kondo, cljfmt/cljstyle

flyboarder17:05:14

oh for sure, but I also wouldnt expect this to work outside of shadow

dvingo23:05:32

hey yall. I have a macro that spits out some cljs code and I'd like to configure the output of the macro based on a var that, ideally, the user can pass in. Anyone have any ideas how to go about that? I guess in the worst case I could deal with the config at runtime in cljs instead

darwin23:05:44

so letting user specify it as a macro argument is not convenient? you want something to configure this once externally?

dvingo00:05:22

yea, it's for a library - a wrapper around emotion css-in-js. it would be a global config to determine if the library assigns the component name as part of the className for the generated component. you'd specify :full to get ns/symbol :short for symbol or nil to not apply it. I have it using metadata for each individual call so you can override at the single level, but I'm thinking you could have a release build disable all className assignment, but you'd keep it for dev to see your components in the elements tab in devtools

darwin10:05:36

you can have a macro which emits nothing and as a side effect sets some globals in clojure context, subsequent macro expansions can use this value - it is doable, but side-effecting macros are not a good practice

dvingo12:05:25

ah thank you! yea, I'm thinking the better user api is to set the config via closure-define and to execute the configuration logic at runtime instead of tryint to do it at macroexpansion time.