Fork me on GitHub
#cljs-dev
<
2020-06-02
>
bhauman00:06:34

well I tried to use webpack conditional eliding as a way to solve the cljs-ajax problem of trying to support node and it just didn’t work. I got conditional eliding to work with a constant value, but there was no route to make this work AFAIK. And its kind-of a shame because a macro could make quick work of this, but we have to introduce something to let the macro know the target env.

bhauman13:06:14

OK I found a way to do a conditional node require:

(cond
  (exists? goog/global.XMLHttpRequest)
  goog/global.XMLHttpRequest
  (exists? goog/global.require)
  (goog/global.require "xmlhttprequest")
  :else nil)

thheller13:06:10

require is not a global, it is not bound to the global in node.

thheller13:06:44

node wraps every file it loads in

function(module, exports, require) {
    // code
}

thheller13:06:21

this is were require is coming from, it is different for each file. so if you capture it somewhere and bind it to global you are going to inherit the semantics of that initial file.

bhauman13:06:46

but there is a global require right

thheller13:06:54

no there is not

bhauman13:06:24

node is a runtime

bhauman13:06:35

its not compiled

bhauman13:06:45

I’m doing this for node

bhauman13:06:23

OK i got you but if I inherit the require for the global this

thheller13:06:39

this is the exports passed into the function above for node commonjs modules

bhauman13:06:40

well I can make this work as well

bhauman13:06:07

(let [x require] (x “yada”))

bhauman13:06:41

its gotta not be optimized out

thheller13:06:50

yes, you can get creative and hide the require so webpack doesn't see it

bhauman13:06:51

by advanced

thheller13:06:31

note that is all really just temporary. libraries are going to have to come up with a different way of doing this.

thheller13:06:22

with ESM conditional requires will no longer be possible and thats definitely the direction everything is going. at least for now.

dnolen13:06:49

another reason I'm hesitant to do anything in ClojureScript itself about it - all this stuff seems too transient

thheller13:06:54

not that the solutions they intend for this (eg. import maps) are exactly pretty either ...

thheller13:06:57

webpack5 is also going to be much stricter about all of this. so thats gonna be interesting to watch too.

thheller13:06:19

they've been talking about "breaking changes" for over a year now

☠️ 4
bhauman13:06:40

and the JS eco-system ruptures

😱 4
thheller13:06:23

well ultimately I think its a good thing they are doing this. they created the problem in the first place and have to fix it some day 🙂

thheller13:06:50

but there are also many other new and interesting webpack alternatives coming up so we'll see what the impact of those are

souenzzo17:06:18

can I PR this guide to use ["npx" "[email protected]" ... ? I think that we can push this "habit" in cljs community of use pinned versions for avoid breaking changes, https://github.com/clojure/clojurescript-site/blob/master/content/reference/compiler-options.adoc#bundle-cmd

didibus19:06:36

Not sure where to report ClojureScript bugs? Is it on http://ask.clojure.org like for Clojure ? Any case, with 1.10.773 I get this error if I am using both :target :bundle and :install-deps true :

{:clojure.main/message
 "Execution error (IllegalArgumentException) at cljs.closure/compute-upstream-npm-deps$fn (closure.clj:2440).\ncontains? not supported on type: java.lang.Boolean\n",
 :clojure.main/triage
 {:clojure.error/class java.lang.IllegalArgumentException,
  :clojure.error/line 2440,
  :clojure.error/cause
  "contains? not supported on type: java.lang.Boolean",
  :clojure.error/symbol cljs.closure/compute-upstream-npm-deps$fn,
  :clojure.error/source "closure.clj",
  :clojure.error/phase :execution}

[...]

[cljs.closure$compute_upstream_npm_deps invoke "closure.clj" 2430]
   [cljs.closure$maybe_install_node_deps_BANG_
    invokeStatic
    "closure.clj"
    2587]
   [cljs.closure$maybe_install_node_deps_BANG_
    invoke
    "closure.clj"
    2585]

dnolen19:06:55

@didibus that one should have been fixed for Figwheel, report it JIRA provide minimal repro inline in the ticket

didibus19:06:48

Ok, will do. I'll try and make a minimal repro.

Alex Miller (Clojure team)19:06:46

@dnolen lots of people don't have jira access, they should report on http://ask.clojure.org

dnolen19:06:46

ah k didn't know that was the recommendation now

Alex Miller (Clojure team)19:06:18

we have a limited number of jira users on the cloud system (many thanks to Atlassian for providing it for free) so we are limiting jira accounts just to those doing development (ie providing patches) and trying to use http://ask.clojure.org for problem reporting and voting

richiardiandrea05:06:26

Genuine question, have you ever considered switching to ClubHouse (which is Clojure product)?

Alex Miller (Clojure team)19:06:59

apologies if I have not properly relayed all this to you in the past

dnolen21:06:29

ok I think we may need to update a couple of pointers on the website too