vouch-opensource / krell

Simple ClojureScript React Native Tooling
Eclipse Public License 1.0
675 stars 37 forks source link

REPL not considering namespace aliases #84

Closed olivergeorge closed 4 years ago

olivergeorge commented 4 years ago

This only seems to happen if compiling before REPL. Tested on 00b46eaf and 07b3a80c.

Steps to repeat based on Reagent tutorial.

  1. Compile (e.g. clj -m krell.main -co build.edn -c)
  2. Run REPL (e.g. clj -m krell.main -co build.edn -r)
  3. In REPL: (in-ns 'awesome-project.core)
  4. In REPL: (r/atom {})

Expect: Function resolves based on namespace alias and calls correctly.

Actual: REPL throws WARNING: No such namespace: r

olivergeorge@Condense-iMac krell-repros % cat src/awesome_project/core.cljs 
(ns awesome-project.core
  (:require [reagent.core :as r]
            [reagent.react-native :as rn]))

(defn hello []
  [rn/view {:style {:flex 1 :align-items "center" :justify-content "center"}}
   [rn/text {:style {:font-size 50}} "Hello Krell!"]])

(defn ^:export -main [& args]
  (r/as-element [hello]))

olivergeorge@Condense-iMac krell-repros % clj -m krell.main -co build.edn -c
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

olivergeorge@Condense-iMac krell-repros % clj -m krell.main -co build.edn -r
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Waiting for device connection on port 5001
ClojureScript 0.0.862373453
cljs.user=> (in-ns 'awesome-project.core)
nil
awesome-project.core=> (r/atom {})
WARNING: No such namespace: r, could not locate r.cljs, r.cljc, or JavaScript source providing "r" at line 1 <cljs repl>
WARNING: Use of undeclared Var r/atom at line 1 <cljs repl>
swannodette commented 4 years ago

This can probably addressed by making sure that :analysis-path is set. I'm pretty sure it isn't currently.

olivergeorge commented 4 years ago

Perhaps referring to this? https://github.com/vouch-opensource/krell/blob/cbeccc6e73d03e0510d1a96f716a2f579c79c2a4/src/krell/main.clj#L6

Just tried setting the :analyze-path repl option but no change.

olivergeorge@Condense-iMac krell-repros % cat repl-options.edn 
{:analyze-path ["src"]}

olivergeorge@Condense-iMac krell-repros % clj -m krell.main -ro repl-options.edn -co build.edn -r
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Waiting for device connection on port 5001
ClojureScript 0.0.862373453
cljs.user=> (in-ns 'awesome-project.core)
nil
awesome-project.core=> (r/atom nil)
WARNING: No such namespace: r, could not locate r.cljs, r.cljc, or JavaScript source providing "r" at line 1 <cljs repl>
WARNING: Use of undeclared Var r/atom at line 1 <cljs repl>
awesome-project.core=> 
make: *** [repl] Error 130
swannodette commented 4 years ago

One thing is that I think -c -r should just always work, if you had to compile it anyway the REPL should now about it - this is fixed now upstream and Krell master depends on latest ClojureScript with this fix. Still looking into why :analyze-path doesn't seem work.

swannodette commented 4 years ago

:analyze-path works fine but it needs to be in build.edn. It's a bit confusing but in general the compiler config is really all supported compiler / repl options. -ro is really about configuring the REPL environment - the thing that will actually talk to some specific JS environment.