cljs-dev

ClojureScript compiler & std lib dev, https://clojurescript.org/community/dev
bhauman 2020-06-02T00:38:34.080300Z

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.

bhauman 2020-06-02T13:00:14.081400Z

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)

thheller 2020-06-02T13:03:10.082200Z

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

thheller 2020-06-02T13:07:44.082900Z

node wraps every file it loads in

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

thheller 2020-06-02T13:08:21.083900Z

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.

bhauman 2020-06-02T13:09:46.085Z

but there is a global require right

bhauman 2020-06-02T13:09:54.085300Z

on this

thheller 2020-06-02T13:09:54.085400Z

no there is not

bhauman 2020-06-02T13:10:24.086Z

node is a runtime

bhauman 2020-06-02T13:10:35.086400Z

its not compiled

bhauman 2020-06-02T13:10:45.086700Z

I’m doing this for node

bhauman 2020-06-02T13:11:23.087300Z

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

bhauman 2020-06-02T13:11:34.087700Z

ok

thheller 2020-06-02T13:11:39.088Z

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

bhauman 2020-06-02T13:11:40.088100Z

well I can make this work as well

bhauman 2020-06-02T13:12:07.088600Z

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

bhauman 2020-06-02T13:12:41.089200Z

its gotta not be optimized out

thheller 2020-06-02T13:12:50.089600Z

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

bhauman 2020-06-02T13:12:51.089700Z

by advanced

bhauman 2020-06-02T13:16:58.090800Z

@thheller thanks!

thheller 2020-06-02T13:17:31.091600Z

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

thheller 2020-06-02T13:18:22.092800Z

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

dnolen 2020-06-02T13:20:49.094400Z

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

thheller 2020-06-02T13:20:54.094600Z

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

thheller 2020-06-02T13:24:57.095700Z

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

thheller 2020-06-02T13:25:19.096100Z

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

☠️ 1
dnolen 2020-06-02T13:27:22.096500Z

oh goody

bhauman 2020-06-02T13:27:40.096800Z

and the JS eco-system ruptures

😱 1
thheller 2020-06-02T13:50:23.098300Z

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 🙂

thheller 2020-06-02T13:50:50.098900Z

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

souenzzo 2020-06-02T17:24:18.101Z

can I PR this guide to use ["npx" "webpack@4.43.0" ... ? 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

dnolen 2020-06-02T18:44:36.101400Z

go for it

2020-06-02T19:06:36.102800Z

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]

alexmiller 2020-06-02T19:13:15.103Z

> Is it on http://ask.clojure.org like for Clojure ? yes

dnolen 2020-06-02T19:23:55.104Z

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

alexmiller 2020-06-02T19:24:46.104400Z

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

dnolen 2020-06-02T19:25:46.104800Z

ah k didn't know that was the recommendation now

alexmiller 2020-06-02T19:29:10.105300Z

and https://clojure.org/dev/dev

alexmiller 2020-06-02T19:30:18.106500Z

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

alexmiller 2020-06-02T19:30:59.107Z

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

2020-06-02T19:35:48.107100Z

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

dnolen 2020-06-02T21:43:29.109100Z

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

alexmiller 2020-06-02T22:03:45.109300Z

feel free to steal from http://clojure.org :)