Fork me on GitHub
#shadow-cljs
<
2017-10-26
>
richiardiandrea02:10:50

Nice re-frame example you've built @mhuebert (+ @thheller of course)

mhuebert11:10:17

@richiardiandrea thanks! just pushed an update with some better explanations + a newer version of re-frame-trace https://mhuebert.github.io/shadow-re-frame/

thheller16:10:15

good news. I fixed source maps for :advanced finally

thheller16:10:28

bad news they get huge 🙂

thheller16:10:34

486kb .js 4.3mb .map 🙂

mhuebert17:10:52

i imagine that’s unavoidable?

mhuebert17:10:57

great that its working!

mhuebert17:10:11

are you including the source code inline in the source maps?

thheller17:10:38

seemed to be more reliable that way

thheller17:10:14

funny thing is that a lot of JS deps on npm are already minified

thheller17:10:26

but shadow-cljs can’t know that so it minifies again

thheller17:10:34

and creates a source-map in doing so

thheller17:10:59

so we have a source map from minified -> minified. not all that useful 😉

thheller17:10:49

but yeah .. source maps for “foreign libs” .. yay, that didn’t work before 🙂

mhuebert18:10:50

that’s great!

mhuebert18:10:12

oh, found a simple bug in bootstrap loader: https://dev.maria.cloud/gist/34d3fde5e062fe9ac9027386af588568?eval=true was going to make a PR but got tied up this afternoon

mhuebert18:10:31

i think it just needs to check of a namespace already exists in compiler state before looking in the index

thheller18:10:23

isn’t cljs supposed to do that?

thheller18:10:07

looks like dev.maria.cloud needs to be compiled with source maps 😉

thheller18:10:09

when I do (contains? @cljs.js/*loaded* 'maria.user$macros) I get false

thheller18:10:23

maria.user exists though

thheller18:10:56

not sure why bootstrap would call the load fn when its already loaded?

thheller18:10:20

I can add a check for it but I thought cljs was doing that

thheller18:10:26

hmm wait I can’t add a check if its not in cljs.js/*loaded*

mhuebert19:10:42

does cljs.js/*loaded* get updated when namespaces are created, repl-style?

mhuebert19:10:07

one could check the compiler state, :cljs.analyzer/namespaces

mhuebert19:10:24

re: source maps, i’ll try that soon!

mhuebert20:10:35

in lumo:

cljs.user=> (ns )
nil
=> (contains? @cljs.js/*loaded* ')
false
=> (contains? (set (keys (:cljs.analyzer/namespaces @cljs.env/*compiler*))) ')
true
=> (require ')
No such namespace: , could not locate the_thing/me.cljs, the_thing/me.cljc, or Closure namespace ""

mhuebert20:10:39

have i gone mad. i totally thought this should work: (planck now)

cljs.user=> (ns a.core)
nil
a.core=> (ns b.core (:require [a.core]))
No such namespace: a.core, could not locate a/core.cljs, a/core.cljc, or Closure namespace "a.core"

mhuebert20:10:08

lumo again:

cljs.user=> (ns a.core)
nil
a.core=> (def x 10)
#'a.core/x
a.core=> (ns b.core)
nil
b.core=> a.core/x
10
b.core=> (require '[a.core :as a])
No such namespace: a.core, could not locate a/core.cljs, a/core.cljc, or Closure namespace "a.core"

mhuebert20:10:12

how is everything broken

thheller20:10:27

do you have an example namespace that is available but not yet loaded?

thheller20:10:20

(part of the bootstrap build I mean)

thheller20:10:59

shadow-cljs node-repl
shadow-cljs - config: /Users/zilence/code/shadow-cljs/shadow-cljs.edn version: 2.0.42
shadow-cljs - connected to server
shadow-cljs - starting node-repl
[:node-repl] Configuring build.
[:node-repl] Compiling ...
[:node-repl] Build completed. (39 files, 19 compiled, 0 warnings, 11.63s)
[3:1]~cljs.user=> JS runtime connected.
[3:1]~cljs.user=> (ns a.core)
[3:1]~a.core=> (ns b.core (:require [a.core]))
[3:1]~b.core=>

thheller20:10:33

I guess my REPL works 😉

thheller21:10:29

do you still have the checkout setup or should I release a new version?

thheller21:10:52

not quite easy for me to test since I don’t have that editor setup

mhuebert21:10:46

still have it set up

mhuebert21:10:20

works for me

thheller21:10:09

do you have a namespace that is not yet loaded but available in the boostrap index?

thheller21:10:58

this change probably just broke (require 'thing :reload)

thheller21:10:57

(ns reagent.core)
   (def x 1)
   (ns b.core (:require [reagent.core :as a]))
   (js/console.log "x" a/x)
   (require 'reagent.core :reload)

thheller21:10:01

tested it in my setup

thheller21:10:06

and yes it broke :reload

thheller21:10:05

that should load reagent.core from disk but does nothing (since there is analyzer data)

thheller21:10:56

but the reload flag is not passed to the callback, so its impossible to tell 😞

mhuebert21:10:56

i thought :reload was passed to :load-fn

thheller21:10:08

doesn’t appear so no, logged the data thats passed in and its just

thheller21:10:29

I guess its safer to always load then?

thheller21:10:33

meh .. that should really be fixed on the CLJS side of things

mhuebert21:10:17

so now :reload will modify *loaded* but not inform :load-fn

thheller21:10:05

it does modifiy *loaded*?

mhuebert21:10:32

in cljs.js:

(defn require
  ([name cb]
    (require name nil cb))
  ([name opts cb]
    (require nil name opts cb))
  ([bound-vars name opts cb]
   (require bound-vars name nil opts cb))
  ([bound-vars name reload opts cb]
   (let [bound-vars (merge
                      {:*compiler*     (env/default-compiler-env)
                       :*data-readers* tags/*cljs-data-readers*
                       :*load-macros*  (:load-macros opts true)
                       :*analyze-deps* (:analyze-deps opts true)
                       :*load-fn*      (or (:load opts) *load-fn*)
                       :*eval-fn*      (or (:eval opts) *eval-fn*)}
                      bound-vars)
         aname (cond-> name (:macros-ns opts) ana/macro-ns-name)]
     (when (= :reload reload)
       (swap! *loaded* disj aname))
     (when (= :reload-all reload)
       (reset! *loaded* #{}))
...

mhuebert21:10:56

i haven’t followed up the chain of how require is invoked

thheller21:10:13

ah ok didn’t see that

mhuebert21:10:22

was assuming that this reload option is coming from the repl command

mhuebert21:10:26

hmm, so… an error should be thrown if the ns is not in compiler-state nor the index; but if it is in the index, always load it, even if it exists in compiler state?

mhuebert21:10:27

that would make sense to me

mhuebert21:10:57

no not really.

thheller21:10:02

ok .. AFAICT the fix would be in cljs.js/ns-side-effects

thheller21:10:30

that SHOULD set cljs.js/*loaded* but doesn’t

mhuebert21:10:44

makes sense

thheller21:10:42

quick fix is doing your or

mhuebert21:10:49

if we aggressively reloaded, then we could wipe out changes to an ns that had been made locally. i don’t think a user ever expects a simple (require ’the.thing) to modify it if it exists.

mhuebert21:10:54

yeah. i don’t use :reload much.

mhuebert21:10:05

we don’t even have a namespaces module in maria yet 🙂

mhuebert21:10:13

but for later this could be important.

thheller21:10:28

pushed the fix

thheller21:10:08

but should probably be fixed upstream

thheller22:10:34

only problem is that (require 'my.thing :reload) now doesn’t throw an error and pretends to load something 😉

thheller22:10:48

since its not in the index

thheller22:10:52

but I guess thats ok

thheller22:10:02

off to bed, gn8