Fork me on GitHub
#clojurescript
<
2017-10-20
>
ag00:10:24

how can I require all namespaces that match a regex? (all-ns) isn't a thing in clojurescript, right?

ag00:10:28

you'd ask why? it seems honzabrecka/karma-reporter's run-all-tests doesn't work like clojure.test/run-all-test - the former requires test ns' be required explicitly. That's tedious.

vemv00:10:50

cljs doesn't allow much dynamism when it comes to requires

vemv00:10:23

doo has the same tediousness

vemv00:10:39

so it wouldn't surprise me if we cannot escape from it 🙂

ag00:10:03

but somehow cljs.test/run-all-tests correctly finds all the tests?

ag00:10:16

without having them to be required

vemv00:10:32

good observation I once tried to create a macro for this, but doo didn't accept it (gave me some opaque error)

vemv00:10:34

correction: doo has (doo.runner/doo-all-tests). and it also can run karma (I do!)

vemv00:10:38

the problem I mentioned was for doo-tests not for doo-all-tests

ag00:10:06

I'm not using doo explicitly - I'd like to try using karma-reporter directly (which doo does anyway). I'd like to have karma server running in background and a separate task to run the tests

vemv00:10:36

interesting!

ag00:10:45

wow... it seems doo uses cljs.analyzer

ag00:10:38

I've been trying to make sense of our testing setup. But it's been painful, (partly because we use boot) Ideally I want: 1) Karma server running chrome-headless in a container 2) watch task that would poke Karma to run the tests whenever the code changes 3) Since Karma already running browser, theoretically there has to be a way to get a repl

ag00:10:09

right now it's too slow; it is a pain to get it running on CI; you still need a repl to write the tests, but using clojure.test/run-tests in browser repl is kinda wanky

vemv00:10:09

As for requires, you can explore the macro path. Ultimately you always can write a little program which builds and writes my_test_runner.cljs with all the boilerplate

vemv00:10:15

As for need for repl, I switch between chrome and chrome-headless which doo makes easy. I leave these doo tests running in auto mode; that's my L part of the 'REPL' experience

vemv00:10:02

occasionally I need to inspect the DOM, in those cases I (<! (timeout 100000000000)) in the middle of a test

vemv00:10:44

the (timeout 100000000000) could be changed for something more sophisticated, my setup isn't quite refined yet. But overall happy with it

ag00:10:14

maybe I should just use doo directly, without using boot-cljs-test

yury.solovyov10:10:36

is there a crypto api wrappers for CLJS ?

metametadata11:10:15

@vemv @ag I always thought that doo-all-tests also needs the ns-es already required

cemerick12:10:41

hi 👋 Having a spot of trouble with a JS module under advanced compilation. I feel like I've solved this exact problem before, but it's eluding me atm

cemerick12:10:46

I'm using https://www.npmjs.com/package/viz.js successfully in figwheel REPLs, but its module usage isn't being recognized/adapted when minified into a single JS file

cemerick12:10:48

it's a little wonky to my eye, and specifying a :module-type in a deps.cljs file doesn't help: if (typeof module === "object" && module.exports) { module.exports = Viz; } else { global.Viz = Viz; }

cemerick12:10:10

ofc, I can reach in and grab the Viz object and everything's fine, but if there's a better way, do tell 🙂

pesterhazy13:10:07

@cemerick you mean using js/window.Viz? That's the normal (classic) way of using JS dependencies

pesterhazy13:10:51

what's your concern with that?

cemerick14:10:44

@pesterhazy well, I'm testing under node using doo, so it'd actually be js/module.exports.Viz, but that isn't going to fly for the same code in the REPL

thheller14:10:11

@cemerick (:require ["viz.js" :as viz]) may or may not work with figwheel

pesterhazy14:10:34

won't js/goog.global.Viz work in both cituations?

thheller14:10:31

(js/require "viz.js") should always work when on node only?

cemerick14:10:05

I have this in my deps.cljs, so (:require vizjs) and js/Viz works nicely in the REPL: {:file "viz.js/viz-lite.js" :provides ["vizjs"]}

cemerick14:10:01

@pesterhazy I'll give goog.global.Viz a try

cemerick14:10:57

though I have a number of npm deps with entries in deps.cljs that do get transformed as I'd expect...though they're all es6 style, it seems

thheller14:10:18

--- node_modules/viz.js/viz.js:47
Object literal contains illegal duplicate key "stackAlloc", disallowed in strict mode
--- node_modules/viz.js/viz.js:47
Object literal contains illegal duplicate key "stackSave", disallowed in strict mode
--- node_modules/viz.js/viz.js:47
Object literal contains illegal duplicate key "stackRestore", disallowed in strict mode
--- node_modules/viz.js/viz.js:47
Object literal contains illegal duplicate key "establishStackSpace", disallowed in strict mode
--- node_modules/viz.js/viz.js:47
Object literal contains illegal duplicate key "setThrew", disallowed in strict mode

thheller14:10:30

might not be compatible with the import

cemerick14:10:17

@pesterhazy goog.global.Viz doesn't work. goog.global is the same as this in the single-file testing case, so it's actually no different than js/Viz

cemerick14:10:30

@thheller so are you thinking that that's what's tripping up the module transform. I don't have any strict mode on atm BTW

thheller14:10:29

it seems to be enabled by default, not sure you can disable it

cemerick14:10:47

it seems there are many strict modes 😉

cemerick14:10:01

I don't see those warnings FWIW

cemerick14:10:50

I guess I'll just add a trap and fall back when necessary

pesterhazy14:10:28

lein-cljsbuild's {:compiler {:closure-defines {my.ns.myvar "asdf"}}} a la https://www.martinklepsch.org/posts/parameterizing-clojurescript-builds.html just doesn't seem to work for me

pesterhazy14:10:44

@martinklepsch ^^ is there a trick to it? does it work with simple optimizations?

martinklepsch14:10:58

@pesterhazy not sure about simple

pesterhazy15:10:22

@martinklepsch advanced also doesn't seem to work for me

roman01la15:10:32

@pesterhazy have you tried my.ns.myvar as a string? "my.ns.myvar"

roman01la15:10:38

this usually works for me

pesterhazy15:10:19

I found the problem

pesterhazy15:10:51

my actual variable was called my.ns/app-url - this needs to be mangled into "my.ns.app_url"

metametadata15:10:49

I found working with :external-config is much saner than using goog defines

pesterhazy15:10:38

@metametadata interesting - could you elaborate?

metametadata15:10:50

yeah, I'm googling 🙂

metametadata15:10:18

I first saw it in @darwin's libs

metametadata15:10:47

Anyways. From my project.clj:

:compiler {... :external-config {:myapp {:debug? false}}}
then in code:
(ns app.config
  "Compilation time app configuration."
  (:require [cljs.env :as env]
            [schema.core :as s]))

(s/defschema Env
  {:debug? s/Bool})

(s/defn ^:always-validate -config :- Env
  []
  (when (some? env/*compiler*)
    (get-in @env/*compiler* [:options :external-config :myapp])))

(defmacro if-debug
  "Emits expression based on the value of debug flag in project's compiler options."
  ([then]
   `(if-debug ~then nil))
  ([then else]
   (if (:debug? (-config))
     then
     else)))

(defmacro when-debug
  [& body]
  `(if-debug (do [email protected])))
And then usage:
(defn main
  []
  (app-config/when-debug
    (.warn js/console "App debug mode is ON.")
    (s/set-fn-validation! true)) 

   ,,,)

pesterhazy15:10:34

Interesting! that looks like CLJS compiler internals. Is "external-config" a public API?

metametadata15:10:02

AFAIU yes, e.g. figwheel validator allows it

pesterhazy15:10:43

I'll check it out, thanks @metametadata

pesterhazy15:10:46

@martinklepsch I think mentioning the name mangling problems would be a useful addition to your blog post (also simple optimizations work fine, as well as advanced)

thheller15:10:23

@pesterhazy the compiler mangles for you but you have to pass in the correct symbol

thheller15:10:44

it should work if you pass in my.ns/app-url (as a symbol not a string)

martinklepsch15:10:45

**Note:** Sometimes for debugging you may want to pass the the Closure
define as a string. If you decide to do so make sure it matches the
string in the `goog.define` call in your emitted Javascript
(i.e. account for name mangling).
like this?

pesterhazy15:10:25

I just tried again and it looks like @thheller is right - the names are mangled correctly if you pass a symbol

pesterhazy15:10:05

@martinklepsch I think that's very clear, yes!

pesterhazy15:10:22

s/the the/the/ though

pesterhazy15:10:22

my debugging was flawed because lein cljsbuild sometimes doesn't rebuild even though I ran lein clean just before that

ajs20:10:44

For years I have had the habit of removing all build artifacts like out/* as well as the main compiled JavaScript file by deleting at the shell before compiling an optimized build. I just never found any other way to ensure a proper build.

martinklepsch15:10:13

thanks for the feedback, post has been updated 👍

yedi19:10:07

does anyone have tips for debugging null pointer exceptions when running lein cljsbuild

ajs20:10:51

println:)

yedi20:10:56

apparently all i had to do was lein clean FML

ajs20:10:44

For years I have had the habit of removing all build artifacts like out/* as well as the main compiled JavaScript file by deleting at the shell before compiling an optimized build. I just never found any other way to ensure a proper build.

madstap23:10:24

Are there any complete docs as to what I can put in deps.cljs? It's being kinda difficult to google.

madstap23:10:22

If I put {:npm-deps {,,,}, :install-deps true} in there, will all the builds in :lein-cljsbuild have that merged in?