Fork me on GitHub
#cljs-dev
<
2018-11-10
>
martinklepsch00:11:25

@anmonteiro awesome, thanks a bunch!

martinklepsch00:11:25

I found add-implicit-options which seems to rename some of the libraries related keys needed for this (in addition to get-upstream-deps which Antonio suggested)

(ana/analyze-file state file (cljs.closure/add-implicit-options {}))
react can still not be found despite the returned options listing it. I found the lines below which seem to indicate that there's more processing needed but it also seems that this requires a full compiler environment (compared to just analysis) https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/closure.clj#L2944-L2946 Am I missing something or is this the way to go?

martinklepsch23:11:08

Still somewhat stuck here... I think the js-dependency-index thing is probably not needed since only the :options part of the overall compiler opts map is passed to analyze-file... But not sure what else is needed... For context in case it got lost in scrollback: I'm trying to use analyze-file on some files that require react and somehow I can't figure out how to correctly pass the information about where the react lib can be found to analyze-file.

martinklepsch14:11:11

Wrote up problem statement and some notes here (code with minimal deps as well): https://gist.github.com/martinklepsch/9f885feb061ec3f03f365e22d0d9bf5b If anyone could take a look and perhaps point me in the right direction that would be super lovely. (People familiar with :js-dependency-index might be particularly able to help)

martinklepsch14:11:07

I think I found the issue! 😅

thheller14:11:50

state (ana/empty-state) this already accesses the compiler-env so should be done inside the binding

thheller14:11:57

not sure how relevant that is though

thheller14:11:09

wait nvm. confused it with empty-env

martinklepsch14:11:19

yeah passing state to analyze-file shadowed the compiler env

martinklepsch14:11:27

that was the issue and the reason my contains? returned the correct value

thheller14:11:29

but yeah you are setting up an empty state but then use a different binding

thheller14:11:29

(defn- analyze-file [file]
  (let [state (cljs.env/default-compiler-env opts)
        opts  (cljs.closure/add-implicit-options {})]                  ; also calls `get-upstream-deps`
    (binding [cljs.env/*compiler* state 
              an/*analyze-deps* true] ; (probably default)
      (println "REACT FOUND?" (contains? (:js-dependency-index @cljs.env/*compiler*) "react"))
      (ana/no-warn
        (cljs.closure/validate-opts opts)
        (ana/analyze-file state file opts)))
    state))

martinklepsch14:11:10

Well the binding isn't ever used due to the with-compiler-env thing in ana.api/analyze-file

martinklepsch14:11:35

solution is as basic as this:

(defn- analyze-file [file]
  (let [opts  (cljs.closure/add-implicit-options {})
        state (cljs.env/default-compiler-env opts)]
    (ana/no-warn
     (cljs.closure/validate-opts opts)
     (ana/analyze-file state file opts))
    state))

thheller14:11:25

it will re-use the binding if already set

martinklepsch15:11:10

Maybe were misunderstanding each other but I think with-compiler-env ignores any pre-existing *compiler* binding

thheller15:11:50

yeah since you are passing state explicitely it doesn't re-use

thheller15:11:49

AFAICT you just had 2 different state instances and only one had the js-deps populated

martinklepsch15:11:22

yeah that's my understanding too