Fork me on GitHub
#clojurescript
<
2019-01-31
>
stathissideris15:01:12

I’m trying to run https://github.com/Olical/cljs-test-runner with jsdom pre-loaded so that the code that references window etc can be loaded. I tried passing these options to the compiler

{:verbose       true
 :optimizations :none
 :npm-deps      {:jsdom "13.2.0"}
 :install-deps  true}

stathissideris15:01:32

but then I need a preload to require jsdom, right?

thheller15:01:45

adding :npm-deps by itself does not include it in a build yes

stathissideris15:01:50

thanks. Alright, so my options now are:

{:verbose       true
 :preloads      [test.preload]
 :optimizations :none
 :npm-deps      {:jsdom "13.2.0"}
 :install-deps  true}
and preload.cljs is:
(ns test.preload
  (:require [jsdom :as dom]))
(js/console.log jsdom)
but I get:
Compiling /Users/sideris/devel/work/gt/taz/dev/test/preload.cljs to cljs-test-runner-out/test/preload.js
#error {
 :cause No such namespace: jsdom, could not locate jsdom.cljs, jsdom.cljc, or JavaScript source providing "jsdom" in file /Users/sideris/devel/work/gt/taz/dev/test/preload.cljs
...

borkdude15:01:02

is this node? probably you need to do:

(def jsdom (js/require "jsdom"))

stathissideris15:01:47

@borkdude yes it’s node. It worked! the documentation mentions that :require works, but clearly that’s not the case

thheller15:01:52

:npm-deps is alpha with a lot of edge cases. so it is supposed to work via ns require but doesn't for some reason

thheller15:01:03

(works fine in shadow-cljs of course ;)

lilactown15:01:18

I’m taking a second stab at thinking about how to do conditional-ish load of a namespace (in this case, clojure.datafy)

lilactown15:01:16

I’m thinking of having some kind of indirection, where normally my library doesn’t use clojure.datafy, but by requiring a namespace it replaces the implementation with dataficationy things

lilactown15:01:00

ex:

;; my-lib.core
(defn datafy [x] x)

(defn nav [_ _ x] x)

;; ...uses datafy/nav

lilactown15:01:56

trying to think of the best way to do the indirection though. using an atom feels weird. multimethods don’t seem right

thheller15:01:42

not sure what your point is? the clojure.datafy namespace is tiny why is that something you want to eliminate?

lilactown15:01:41

@thheller maybe it’s not as important as I think, but I’m trying to support versions less than what’s in master right now

lilactown15:01:53

I don’t have a good sense of how often people upgrade their CLJS version

thheller15:01:12

ah backwards compatibility.

thheller15:01:29

people don't upgrade unless they are forced to 😉

lilactown15:01:13

well I could force them in order to use my cool awesome library!! 😛 but that sounds like hubris

thheller16:01:20

I think its fine for libs to say you require cljs 1.10.516+ or so

thheller16:01:34

otherwise we'd be stuck with IE6 forever 😉

lilactown16:01:44

@john yeah I remember that. I’m wary of it, seems like something that at the very least I would not want to troubleshoot if it broke peoples builds or whatever

lilactown16:01:34

I suppose. There’s just a relatively small surface area of my lib that actually uses datafy/nav, so it seems like something that would be easy enough to just elide if not there 😞

john16:01:13

and exist? may not work with 3rd party libs, depending on load order. datafy should exist prior to all 3rd party libs though, if at all.

thheller16:01:41

imho you should not implement datafy/nav at all in regular namespaces

thheller16:01:57

unless you are going to use it in your regular program

thheller16:01:10

if you only implement it because some tool may use it during development you are doing it wrong (IMHO)

lilactown16:01:43

in this case, I’m writing the tool for use during development 😄

lilactown16:01:01

but 💯 agreed

thheller16:01:28

yeah, I abuse the more dynamic nature of CLJ all the time. unfortunately not possible in CLJS or rather JS I should say 😞

stathissideris16:01:57

for posterity, this is my preload now:

(ns test.preload)
(def jsdom (js/require "jsdom"))
(js/console.log (.-JSDOM jsdom))
(set! js/window (new (.-JSDOM jsdom)))
(js/console.log js/window)

stathissideris16:01:14

test suite still fails, but for a new reason 😄 Error: React module should be required before createClass

Alex Miller (Clojure team)16:01:36

if you use the metadata protocol support to implement the datafy/nav protocols, it will have no dependencies on the datafy namespace

Alex Miller (Clojure team)16:01:48

it’s just metadata with a map of symbols to functions

Alex Miller (Clojure team)16:01:23

people without datafy are none the wiser, but people with datafy get the impl

lilactown16:01:47

I’m calling the datafy/nav fns

Alex Miller (Clojure team)16:01:28

oh, well that’s different :)

rboyd17:01:36

what would be a good modern javascript book to brush up on changes if you weren't paying attention to it over the past 4-5 years?

rboyd17:01:07

(if you had to leave the warm embrace of cljs for a time)

bherrmann17:01:07

You could just work through this page, https://babeljs.io/docs/en/learn

👍 5