This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-06
Channels
- # aws (11)
- # beginners (51)
- # cider (61)
- # cljsrn (37)
- # clojure (51)
- # clojure-spec (5)
- # clojure-uk (6)
- # clojurescript (35)
- # core-async (29)
- # cursive (3)
- # datomic (4)
- # defnpodcast (3)
- # editors (10)
- # emacs (3)
- # fulcro (2)
- # lein-figwheel (9)
- # leiningen (3)
- # mount (3)
- # off-topic (59)
- # parinfer (6)
- # portkey (4)
- # re-frame (6)
- # shadow-cljs (136)
- # spacemacs (1)
- # specter (1)
- # tools-deps (10)
Is there a way to set the initial namespace when running shadow-cljs clj-repl
? I'd like to set it to user
instead of shadow.user
as I have some helper functions defined there.
is this something shadow-cljs might support, since it has a finite number of supported :compiler-options
Can you think of a reason that an app would work when building release with :pseudo-names true
, but then throw an exception when released without that option?
Turned out to be an externs issue causing a naming conflict.
http://Sentry.io doesnt seem to handle indexed sourcemaps in their parser
it’s a bummer that we can’t let another tool make the map at the end. wouldn’t want to miss out on the compiler’s optimizations just for sake of sourcemaps
wonder why sentry doesnt support index map. seems pretty common and https://github.com/mozilla/source-map supports it as well
@mjmeintjes yes externs. with :pseudo-names
you get long variable names that are less likely to clash, so it sometimes fixes things.
The weird thing is that I've been releasing and compiling without externs for a couple of months, but then just randomly today it started crashing. Probably just lucky/unlucky with name conflicts.
hehe yeah I had this happen before. works one day but then breaks suddenly. Closure picks variable names sort of incrementally so it starts with a,b,c,d,...
and then picks aa,ab,ac,...
and so on. if you have enough vars you eventually get to ga
which google analytics already uses and clashes
some function called static function which is just a simple ES6 module export.
// a.js
module.exports = {
setString: xxx
}
If a is an export of module b, and I require like this
(:require ["b" :refer [a]])
I can use setString
with following code:
(def a-set-string (aget a "setString"))
(a-set-string xxx)
but this won't work
(a.setString xxx)
is this an expected behavior?ah you mean a.setString
working sometimes? well ... blame weird choices in the CLJS compiler. it only works for locals not ns aliases
eg. (:require [clojure.string :as foo])
then foo
is not a variable and you can only use (foo/upper-case ...)
not (.upper-case foo)
for JS :as
must create a variable since some CommonJS uses module.exports = function() ...
which would not be callable otherwise
basically you should NEVER use a.setString
in any circumstance. the only exception to this is anything in the js/
namespace (eg. (js/console.log "foo")
) IMHO.
pretty sure that no official docs ever mention that a.setString
is even possible or allowed
I am writing some tests to explore how the cljs compiler works, Given
...
:test {:target :node-test
:output-to "out/node-tests.js"
:ns-regexp "-test$"
:autorun true}
:bootstrapped-assets-for-test {:target :bootstrap
:output-dir "out/bootstrap"
:entries [eval-and-parse.botstrapped-libs]
:exclude #{cljs.js}}
....
and...
(ns eval-and-parse.core-test
(:require
[cljs.js :as cljs]
[cljs.env :as env]
[shadow.cljs.bootstrap.browser :as boot]
[cljs.test :refer-macros [deftest is testing run-tests async]]))
(deftest library-gets-loaded-and-accesible-on-bootstrap-mode
(async done
(let [c-state (cljs/empty-state)]
(boot/init c-state
{:path "/bootstrap"
:load-on-init '#{eval-and-parse.bootstrapped-libs}}
(fn []
;; --------------- tests
(done))))))
I am getting ...
SHADOW import error ... ... ... .shadow-cljs/builds/test/dev/out/cljs-runtime/shadow.module.main.append.js
........shadow-cljs/builds/test/dev/out/cljs-runtime/goog.net.xmlhttp.js:175
return new XMLHttpRequest();
Is this because of the env where the tests are running? ie: :target :node-test
not sure what your question is going to be but :entries [eval-and-parse.botstrapped-libs]
seems to be missing an o
c-state
should be a comiler env. not an analyzer env. eg. (cljs.env/default-compiler-env)
dunno if you saw https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html
Now i am setting up tests to fill in my conceptual blanks and get a whole picture of compilation
so i am getting that message with test profile
{:target :node-test
:output-to "out/node-tests.js"
:ns-regexp "-test$"
:autorun true}
it should be pretty simple to write a shadow.cljs.bootstrap.node
that works the same
(ns eval-and-parse.core-test
(:require
[cljs.js :as cljs]
[cljs.env :as env]
[shadow.cljs.bootstrap.browser :as boot]
[cljs.test :refer-macros [deftest is testing run-tests async]]))
you are requiring shadow.cljs.bootstrap.browser
which clearly has "browser" in the name
the :bootstrap
target basically just pre-compiles files so they can be loaded at runtime
the other option is to no precompile anything and just making the sources accessible directly
:bootstrap
then creates a index.transit.json
containing all the information for the compiled files
info about cljs.core
you would find in (get-in @c-state [:cljs.analyzer/namespaces 'cljs.core])
I have a little viz of the compiler env and i can see things being added etc... makes sense ... one thing... when i do
(:require .....
["an-npm-lib" :as an-npm-lib]
...)
where does that go in the cljs.env/*compiler*
ok, so you use your dependecy resolution mechanism to look that up? Sorry, i am sure some of these questions are a bit stupid... 🙂
https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/analyzer.cljc#L2566
https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/build/resolve.clj#L402
this is the starting point. so if you have a browser build with :entries [foo.bar]
it get called with (resolve-entries state [foo.bar])
but most of the resolve magic is in that file. shadow.build.npm
has the npm
specific stuff
all of this works very very differently in CLJS though so none of this applies if you are looking into self-hosted stuff
can i access it like when i do this?
(->> "
(do
(ns my.somns (:require [clojure.string :as string]))
(def g 90)
(ns my.r (:require [clojure.string :as string]))
(def lo 90)
)
"
cljs.tools.reader/read-string
(cljs.analyzer/analyze user-env)
cljs.compiler/emit-str
)
but shadow-cljs is a build tool for building files. so some of the more dynamic stuff like evaling strings works differently as well
this might provide some hints https://github.com/thheller/shadow-cljs/blob/master/src/repl/shadow/cljs/repl_test.clj
thanks!! I will look at both little by little so i can see the different approches and learn from that.
one last question... at the browser console
module$node_modules$codemirror$addon$edit$closebrackets
is that how shadow
builds a look up for the bootstrapped libs?
that is the ns alias created for the node_modules/codemirror/addon/edit/closebrackets.js
file yes
in shadow-cljs everything is treated as a resource. each resource can provide one or more namespace and and can require zero or more
(ns foo.bar (:require ["react" :as r]))
basically gets rewritten to (ns foo.bar (:require [module$node_modules$react... :as r]))
> in shadow-cljs everything is treated as a resource At some point (it is sunday...) ( .. and as a beginner on the compiler bits ...) i would love to hear your view on the deps.edn/requiring from github and codeq etc... thanks for the help. have a great rest of sunday!
not possible to use shadow-cljs
as a git dep for example since it has some java code that needs to be compiled first
thinking about this stuff is a gigantic rabbit hole ... It is interesting to think about but I do no have enough time to do anything about it 🙂
I just setup shadow-cljs for my project, and I was wondering something. I've got om-next as a dependency and I think that's using a cljsjs packaged react. Then I've installed React with npm as it was needed as a dependency for another react-library. Do I know use two versions of React or does shadow-cljs somehow make om-next use the npm installed React?
@pontus.colliander you are using the npm version, when you use a cljsjs dependency with shadow, you are actually loading this file: https://github.com/thheller/shadow-cljsjs/blob/master/src/main/cljsjs/react.cljs
these are the common ones because people already rely on cljsjs, but you can just create your cljsjs.my-package
and make a shim like the one in the link I send before