- I'm trying to figure out how to analyze a file that depends on
react(via CLJSJS) - Previously cljdoc.org would analyze with
*analyze-deps*set tofalse - With
1.10.439this no longer works. (Dynamic vars can't be resolved, see old description below) - With
*analyze-deps*set totrueI need to properly supply the foreign lib information but I can't figure out how.
When calling cljs.analyzer.api/analyze-file with the state-as-first-arg arity it calls cljs.env/with-compiler-env which shadowed my own binding described in Current Approach section. I was unaware that analyzer.api/empty-state is actually just a compiler env as well so creating the right compiler env and passing it to analyze-file solved all issues:
(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))Supplying :js-dependency-index via cljs.env/default-compiler-env like this:
(binding [cljs.env/*compiler* (cljs.env/default-compiler-env
(cljs.closure/add-implicit-options {}))]I think it's not possible to pass this via analyze-file's third opts arg since that is only the :options part of the compiler env. Unfortunately analyze-deps still throws when doing the check below. The check succeeds right after the binding form (see repro.clj):
(println "REACT FOUND?" (contains? (:js-dependency-index @cljs.env/*compiler*) "react"))??? Is something modifying the compiler env after the binding? I grepped for swap! calls but couldn't find anything that seemed relevant.
cljs.closure/add-implicit-optionsis called in the compiler itself and properly discovers the foreign lib information on the classpath (viacljs.closure/get-upstream-deps). Tried passing the return value asoptstoanalyze-file. Wasn't enough but helpful to better understand stuff.
The error typically looks like this, but also occurs with other dynamic vars:
Unable to resolve var: *instrument-enabled* in this context
Working with 1.10.339:
clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.339"}}}' repro.clj spec.cljc
Failing with 1.10.439:
clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.439"}}}' repro.clj spec.cljc
- It seems to be irrelevant whether the file is a
.cljcor.cljsfile. - In most (maybe all) cases the exception was thrown from inside a macro
ℹ️ the issue was that
[an/*analyze-deps* false]— with that flag set totrueeverything works as expected.