Fork me on GitHub
#shadow-cljs
<
2019-08-01
>
colinkahn01:08:07

If I had a macro like (defjson my-json "/some/path/to.json") and that macro slurped in the json file at the path is there a way to tell shadow-cljs that when I change the file at "some/path/to.json" it should recompile the cljs file I've used the macro in?

tianshu05:08:54

I think you can't. why not write edn in a clojure file, that can be auto reload I think.

thheller07:08:52

@colinkahn see https://clojureverse.org/t/using-none-code-resources-in-cljs-builds/3745. if you use that helper function it'll recompile. otherwise it won't

danielneal11:08:00

Hey, I’ve just asked a question on the new http://ask.clojure.org about source maps for react native in shadow-cljs - if anyone has any ideas or leads please chime in! https://ask.clojure.org/index.php/8294/there-approaches-source-maps-working-with-react-native-shadow

thheller10:08:51

could you help me by setting up a very basic figwheel/react-native project that has an actual source mapped error? I can't seem to figure out how to get that working

thheller10:08:08

the redbox from react-native never shows anything mapped?

thheller10:08:32

I mean it doesn't even map its own built-in stuff?

thheller10:08:08

or am I just expecting to much? (js/console.log "foo") is mapped correctly

thheller10:08:12

just errors are not

danielneal10:08:04

ah sure, so the red box never shows anything - it’s only ever in chrome

danielneal10:08:22

let me see if I can set up a project

danielneal10:08:33

I’m using expo is that ok?

thheller10:08:55

currently trying without expo

thheller10:08:04

dunno if expo adds anything special

thheller10:08:20

but should be ok with expo. if I get it to work there I can probably get it to work without

danielneal11:08:13

I’m trimming back one of our working projects; we diverged a fair bit from the template over time, might take a little bit of time. It’s quite informative to do so I’m glad to be doing it 🙂

thheller11:08:35

(def styles
  ^js (-> {:container
           {:flex 1
            :backgroundColor "#fff"
            :alignItems "center"
            :justifyContent "center"}
           :title
           {:fontWeight "bold"
            :fontSize 24
            :color "blue"}}
          (clj->js)
          (rn/StyleSheet.create)))

(defn bad-press [e]
  (js/console.log "pressed the bad button")
  (throw (ex-info "button pressed" {})))

(defn root []
  (react/createElement rn/View #js {:style (.-container styles)}
    (react/createElement rn/Text #js {:style (.-title styles)} "Hello!")
    (react/createElement rn/Button #js {:onPress (fn [e] (bad-press e))
                                        :title "error"})))

thheller11:08:41

thats what was testing with

thheller11:08:53

the js/console.log is properly mapped in chrome

thheller11:08:00

but the throw is not

danielneal11:08:21

I’ll put this up on git in a mo - it’s a bit rough around the edges apologies

danielneal11:08:38

just to double check - have you got “pause on caught exceptions” on

danielneal11:08:30

might just be that

thheller11:08:43

I didn't check the "pause on caught exceptions"

thheller11:08:48

only eht pause on exception

thheller11:08:10

ok that works as expected then

danielneal11:08:21

ah brilliant ok

thheller11:08:22

but can you confirm that the chrome console still shows to stacktrace

thheller11:08:39

and the redbox stacktrace from RN doesn't show the mapped sources either?

danielneal11:08:07

I’ve never seen the redbox show mapped sources

danielneal11:08:35

chrome seems to be ok - it’s just that particular example is called from react native code so there’s no other user/ code-mapped stack frames

thheller11:08:59

ok .. then I got it working I guess 😛

thheller11:08:12

somehow expected the redbox to show mapped sources

danielneal11:08:22

oo have you got it working with shadow-cljs?

thheller11:08:34

depends on how we define working but yes

danielneal11:08:02

^ this is definitely working enough for me -

danielneal11:08:31

it takes it from being almost impossible to debug an error in a large project to being possible

danielneal11:08:05

what did you have to do to get it to work with shadow?

thheller11:08:32

adjust how the code is loaded

danielneal12:08:35

🙂 brilliant - am pumped about this 😄

colinkahn19:08:30

@thheller thanks for link. I think I have a special case though because I’m using the :npm-module target and while (r/inline "/my/path") inlines the resource it doesn’t recompile the file i’m using it in when the resource changes during the watch. This does work for the :browser target though.

colinkahn19:08:14

A bit more info, i’m using the output from :npm-module within storybook, but I’ve confirmed that it’s shadow not rebuilding the files by looking at the generated source in my out dir

thheller19:08:51

look at the compiler log instead

thheller19:08:12

it should be starting a new compile? it certainly isn't limited to the :browser target?

colinkahn19:08:56

I see it compiling my :stories build, saying it has compiled 1 file. Can I run w/ a debug flag to see which file it’s compiling?

thheller19:08:16

shadow-cljs watch app --verbose yes

colinkahn19:08:27

@thheller

[:stories] Compiling ...
-> build target: :npm-module stage: :resolve
-> Resolving Module: :main
<- Resolving Module: :main (31 ms)
<- build target: :npm-module stage: :resolve (34 ms)
-> build target: :npm-module stage: :compile-prepare
<- build target: :npm-module stage: :compile-prepare (0 ms)
-> Compile CLJS: project/ui/stories/button_stories.cljs
<- Compile CLJS: project/ui/stories/button_stories.cljs (20 ms)
-> Cache write: project/ui/stories/button_stories.cljs
<- Cache write: project/ui/stories/button_stories.cljs (19 ms)
-> build target: :npm-module stage: :compile-finish
<- build target: :npm-module stage: :compile-finish (0 ms)
-> build target: :npm-module stage: :flush
-> NPM module flush: /Users/colinkahn/code/project-web/out/stories
<- NPM module flush: /Users/colinkahn/code/project-web/out/stories (34 ms)
<- build target: :npm-module stage: :flush (35 ms)
[:stories] Build completed. (412 files, 1 compiled, 0 warnings, 0.23s)

colinkahn19:08:27

which looks right, but if I go to the built file it’s unchanged

thheller19:08:11

and you are checking /Users/colinkahn/code/project-web/out/stories?

colinkahn19:08:44

yes, specifically out/stories/project.ui.stories.button_stories.js

thheller19:08:28

dunno. can't test right now. will check when I get a chance. would help if you create a reproducible example

colinkahn19:08:20

Ok cool, yeah i can throw something up on github

isak23:08:33

Is it possible to have an :after-load for a module instead of for a build? (Tried the obvious thing and it had no effect)