This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-05
Channels
- # aws (1)
- # beginners (57)
- # boot (3)
- # cider (6)
- # clara (49)
- # cljs-dev (47)
- # cljsjs (23)
- # clojure (144)
- # clojure-dev (2)
- # clojure-finland (1)
- # clojure-germany (1)
- # clojure-sg (1)
- # clojure-spec (25)
- # clojure-uk (245)
- # clojurescript (39)
- # core-async (3)
- # cursive (6)
- # datomic (117)
- # emacs (3)
- # fulcro (6)
- # hoplon (10)
- # jobs (7)
- # juxt (5)
- # leiningen (11)
- # om (27)
- # pedestal (4)
- # perun (2)
- # re-frame (22)
- # reagent (35)
- # ring-swagger (11)
- # shadow-cljs (333)
- # spacemacs (10)
- # specter (10)
- # sql (20)
- # vim (8)
@mhuebert I finished the proper resource loading and that definitely works. can’t quite work out why it complains about those missing vars
Macro loading can be weird. I think even self host macros can be in .clj files, as long as no java code is called
;; when compiling a macros namespace that requires itself, we need
;; to resolve calls to `my-ns.core/foo` to `my-ns.core$macros/foo`
;; to avoid undeclared variable warnings - António Monteiro
ah.. I see. when shadow is running the analyzer, compiling macros for self-host, is it taking the I see, :clj
path? haven’t looked if the 2nd pass is running in clojure or clojurescriptbootstrap.clj
runs in clj-mode, so that reader conditional expr is ignored.
re FIXME: actually load it all, not just core
- loading analyzer caches on init - not sure I understand the intention exactly, but FWIW I think loading/decoding ana caches is something better done at the time the relevant source files are required vs. all at once. (because this can also be slow, these ana caches can be huge.) so for example, the ana cache for cljs.spec.alpha would be downloaded and loaded at the same time as cljs.spec.alpha is required by source code evaluated by the self-host compiler (even if cljs.spec.alpha is already in the app build)
run the bootstrap build from master, it should log quite a bit about whats happening
the analyzer data looks correct to me but I have no idea what cljs.js/patch-alias-map
does and cljs calls it all over the place
yeah I understand what’s happening & have it running locally, have been toying with cljs.analyzer
it is a work in progress, not perfect 🙂. but you can click the left-brackets to collapse
what I meant is that instead of a no-op, load
should load the ‘missing’ analyzer data only when a namespace is required
so the load function, for namespaces that are already loaded, returns only the cache
and then sets the namespace as ‘fully’ loaded, so the next time it runs, it is ignored
I’ve played with these settings back and forth. in a reasonably sized project this stuff really matters
;; FIXME: this should probably do something async
;; otherwise it will block the entire time 60 or so files
;; are eval'd or transit parsed
ok. i am setting up another project with shadow-cljs. a few of us are using maria at clojurebridge this weekend so it needs to be as stable as possible 🙂
could these warnings/resolutions be related to clojure.core/cljs.core aliasing? (probably not, more likely related to self-require..)
🙂 i spent half the afternoon fighting with webpack trying to get sass and postcss autoprefixing to play together
webpack would be a delight. I have this legacy system some designer built that uses compass
from like 100 years ago
new cljs.core.Symbol("cljs.core$macros","seq","cljs.core$macros/seq",-1873195024,null)
which should probably be cljs.core/seq
that then contained new cljs.core.Symbol("demo.macro$macros","seq","demo.macro$macros/seq",-1873195024,null)
https://github.com/reagent-project/reagent/blob/master/examples/simple/src/simpleexample/core.cljs
only one issue, reagent doesn’t declare that it uses clojure.string
. gotta get that fixed.
spinning up a demo project, getting
[:browser] Build failure:
The required namespace "cljs.env.macros" is not available, it was required by "cljs/js$macros.cljc".
code evaled in the browser probably will not be able to access those JS dependencies
i’ve put mine here, https://github.com/mhuebert/shadow-eval.git
here is my cljs-live entry for maria.user:
{:name maria.user
:entry #{maria.user}
:provided #{maria.frames.live-frame}
:entry/no-follow #{maria.eval
cljs-live.eval
cljs.js
cljs.compiler
maria.editors.code
maria.repl-specials
cljs.core.match
maria.views.repl-specials
maria.live.analyze
maria.live.source-lookups}
:entry/exclude #{cljs.pprint}}
basically the :bootstrap-options :entries
just controls which namespaces are allowed to be used by self-host eval
and that can’t use self-host itself it seems … would probably make my head explode if that worked 😛
yeah. so the :entry/no-follow
excludes a thing, and does not look at its transitive deps at all (it does not specifically exclude all of its transitive deps, because they could be used elsewhere), there are some namespaces (like all those listed above) that I just found to be problematic with self-host
so I can probably add a :bootstrap-options {:exclude #{cljs.js other syms}
to control that
eg. (def ^:dynamic *create-element* js/React.createElement)
in re-view-hiccup.hiccup
i ended up doing that because cljs compiler things have been changing so frequently, and the :foreign-libs was so unpredictable
^^ an option to expose js deps as globals would be super helpful i think, i was trying to figure out how to make all my libraries possible to compile with shadow-cljs and also cljsbuild et al
now, if i run (require '[re-view.core :as v :refer [defview]])
it says :invalid-refer, but if I run (require-macros ...)
first, it loads
since the shadow-eval.core
namespace already uses re-view.core
it doesn’t properly load the analyzer data for it
hmm. so currently we set cljs/*loaded*
(or whatever) with the names of preloaded namespaces, so boot/load
isn’t called at all for them
but if we don’t put all of those into *loaded*
, but instead just keep that knowledge to ourselves, then when we see them for the first time in boot/load
we return the cache + blank js
it just stops too early in cases where the JS is loaded but the analyzer data is not
i think cljs.js will call the load fn if we don’t put all the app namespaces into *loaded*
[
:div "Error: " "#error {:message \"Could not eval [test]\", :data {:tag :cljs/analysis-error}, :cause #error {:message \"Cannot read property 'findInternedVar' of null at line 1 \", :data {:file nil, :line 1, :column 1, :tag :cljs/analysis-error}, :cause #object[TypeError TypeError: Cannot read property 'findInternedVar' of null]}}"
]
but no load is ever calledok. i made a quick example https://github.com/thheller/shadow-cljs/compare/master...mhuebert:patch-1
here is a much cleaner view: https://gist.github.com/mhuebert/4eaf8eef3f704f7905545e3530c3e519/revisions
it should never load the :js
for a pre-loaded ns, but otherwise the compiler doesn’t need to know they exist until they are required
right now there will be a problem if you use 2 modules and shadow.bootstrap
ends up in the second module
the first will blindly call shadow.bootstrap.set_loaded
without having declared a proper dependency on it
did you see the gist above? the demo totally worked without doing any extra loading in the beginning, just making sure not to load :js
for the pre-loads
boot/load
should be called for clojure.string
, analyzer data loaded but no js evaled
you didn’t take out this check https://gist.github.com/mhuebert/4eaf8eef3f704f7905545e3530c3e519/revisions#diff-4ebb24b82089d1f69766f74ec1eed471R88
the only reason i am focusing on this is because i used to have cljs-live behave like this and load everything up-front, and with a project that goes beyond tiny example, it can be really slow
analyzer data is now checked against the actual compiler state not the loaded-ref
(or *loaded*
)
https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/bootstrap.cljs#L148
you can have multiple compiler states in an app, perform namespace surgery on namespaces, reset them, etc. so checking the compiler state for whether or not to load an analysis cache makes perfect sense
I’d have to do quite a refactor if I had to ‘move’ maria’s compiler state, it is referenced from so many places
these are all in syntax quoted forms where i would expect them to resolve to cljs.core
this is the macro being called, in the cells.cell$macros
namespace:
(defmacro cell
"Returns an anonymous cell. ..."
([expr]
`(~'cells.cell/cell nil ~expr))
([key expr]
`(let ~lib-bindings
(~'cells.cell/cell* ~(cell-name key) (fn [~'self] ~expr)))))
well i wrote the cells lib, friends wrote the shapes library and collaborated on that intro doc 🙂
just pushed a bit of cleanup, both boot/init
and boot/load
now take the compiler-state as their first argument
if code was written on paper, i would be preparing for a festive burning of the cljs-live repo 😉
eg. the reason that you can do (require [maria.eval :as e])
and inspect the compiler state is because I’m able to exclude cljs.js
. I could attempt to reorganize the whole app around dividing lines based on which namespaces happen to not freak out in self-host, but that could get rather tedious
there are quite a few macro namespaces, for instance, which will never work in self-host (or not unless the authors make a serious effort), but namespaces that use those macros can nevertheless be used in self-host without problem (provided we can exclude those problematic ones)
eg. you can have a namespace which uses core.async
, and run those functions (compiled) in self-host no problem, because macroexpansion already happened, despite core.async
not working in self-host. (mfikes has a fork that does, but many libs don’t use it)
you can use the functions of cljs.core.async
but not actually do anything without go
right. you can’t use the macro, but you can use a function that was defined using go
, because it has already been expanded/compiled.
(maybe some day this will become obselete: https://github.com/mfikes/andare)
ok, I’ll add :exlude
taking a set of namespace symbols for macros that won’t be included