cljs-dev

dnolen 2025-01-13T11:05:14.662349Z

ok @thheller point yesterday was really good concerning the type problem that cljs.host would introduce. i.e. cljs.host.String etc. would be strange, or if the type resolved to String even though it seemed to come from cljs.host.String

dnolen 2025-01-13T11:09:14.494389Z

This has me feeling that pretending that there is a namespace is just not a good idea. All the options so far feel like complecting :require - now I'm wondering if we shouldn't just split the feature apart - i.e. :require-global

dnolen 2025-01-13T11:11:25.355079Z

@borkdude also pointed out that global packages are always available in Clojure - it seems to me in ClojureScript they are not by design (otherwise js/ wouldn't be a thing).

borkdude 2025-01-13T11:13:09.815559Z

@dnolen I agree, but I think having a single-segment special thing isn't bad. Since it's special and not something users would create. So personally I'd drop that column as a concern and still look at any of the other candidates, like (:require [js$crypto]) or (:require [global:crypto])

borkdude 2025-01-13T11:14:12.628789Z

I mean compared to (:require-global) that seems reasonable?

borkdude 2025-01-13T11:15:33.065079Z

Not strongly opposed to :require-global though

dnolen 2025-01-13T11:16:21.351109Z

adding new parsing to :require really isn't that awesome and more likely to lead to regrets. :require-global is pretty conservative.

borkdude 2025-01-13T11:16:33.421559Z

Would it look like

(ns foo (:require-global [console :refer [log]]))
?

dnolen 2025-01-13T11:17:00.844309Z

it would be more like :refer-clojure

dnolen 2025-01-13T11:17:15.832609Z

(:require-global :refer [console] :rename {...})

borkdude 2025-01-13T11:18:12.323519Z

and then console/log instead of js/console.log right

dnolen 2025-01-13T11:18:28.622619Z

it's just global browser stuff, I don't know about needing nested access etc.

dnolen 2025-01-13T11:19:08.848729Z

console/log unfortunately is a separate conversation, which I don't want to focus on at the moment there are conscerns there that @thheller raised.

dnolen 2025-01-13T11:19:26.489889Z

(.log console ...) for now as before

borkdude 2025-01-13T11:20:42.642289Z

(.log console) or (.log js/console) doesn't really make much of a difference tbh

borkdude 2025-01-13T11:22:26.427769Z

What's the problem statement again? Perhaps good to add that to the Excel sheet :)

dnolen 2025-01-13T11:24:11.268219Z

It's not about convenience anyways. And I'm not going to add that.

dnolen 2025-01-13T11:24:47.947309Z

There's tons of obvious benefits - externs validation, renames, REPL support (docs etc.)

dnolen 2025-01-13T11:27:53.904829Z

splitting it out into a separate thing that only implies a single global namespace (no qualifiers via $ or :) greatly simplifies the scope of the feature.

borkdude 2025-01-13T11:34:44.397889Z

What JIRA issue is this again?

dnolen 2025-01-13T11:51:49.665399Z

I'm not totally against more generalized (:require-global [...]) but the scope of impact seems small? The examples in CLJS-3233 are neat, but to be honest not that common. People are loading most libraries from CLJS, GCL, or NPM - I would think in most cases anything that's global is really just that - global browser API stuff, not a nested lib structure.

dnolen 2025-01-13T11:54:05.324739Z

one use case I do have in mind is the one developer just putting together a blog post with some interactive examples. You just drop some libs via script tags and you want to use ClojureScript with those libs.

dnolen 2025-01-13T11:54:30.505569Z

I feel like most of these libs are lightweight and the simpler (:require-global ...) is sufficient

borkdude 2025-01-13T12:15:24.703589Z

> one use case I do have in mind is the one developer just putting together a blog post with some interactive examples. You just drop some libs via script tags and you want to use ClojureScript with those libs. this is exactly how people use #scittle (CLJS interpreter that you include in a script tag + other libraries in script tags that are defined as globals, e.g. React) someone recently showed interest in having the CLJS-3233 feature in scittle to make working with that more convenient Here's the issue about that: https://github.com/babashka/scittle/issues/95

☝️ 1
dnolen 2025-01-13T12:44:08.164129Z

thanks will take a look

borkdude 2025-01-13T12:54:36.620739Z

To summarize the issue: Before people always have to write something like this:

(js/React.whatever ...)
while with "official" CLJS they can write when using an NPM lib:
(:require ["react" :as react])
for compatibility between them it would be nice if people could write:
(:require [#?(:scittle "js$React" :cljs "react") :as react])
I guess :require-global would also work in this setting. Am I summarizing it right @chris358? I guess this would be useful for normal CLJS in itself as well for letting people switch more easily between global and npm libs

thheller 2025-01-15T09:00:10.709539Z

seems like that could be easily fixed by scittle if it looked for some kind of config somewhere?

<script type="application/x-scittle-config">{:resolve {"react" {:global "React"}}}</script>
or so

πŸ‘ 1
borkdude 2025-01-15T09:47:32.818619Z

Yep that’s an option too

Chris McCormick 2025-01-15T05:50:23.404069Z

Sorry for the slow reply (traveling). Yes, I think that's a good summary, thanks @borkdude. The fundamental use-case for me is being able to re-use code when using libraries in interpreted mode (Scittle or cljs with script tags pulling libraries in) and compiled mode (shadow-cljs with npm installed modules that get compiled in the usual way). I am using Scittle to quickly try out ideas and MVP things, and then later move to shadow-cljs to get smaller artifact with better performance once I know it's worth investing more dev time. To give a concrete example, it would be great to be able to pull in my https://github.com/chr15m/cljs-dopeloop/blob/main/src/dopeloop/render.cljs library into Scittle apps (currently only using it in shadow-cljs). What makes this tricky is these JS deps in the library, which makes it incompatible with Scittle:

["virtual-audio-graph" :refer [bufferSource gain] :as vag]
    ["virtual-audio-graph$default" :as createVirtualAudioGraph]
    ["wav-encoder" :as wav-encoder]
I know these deps can work in Scittle if I refer to the globals after pulling the libraries in via script tag from CDN, but that would mean two versions of render.cljs - one which uses cljs requires above, and one which uses script tag and global js/ referencing.

Chris McCormick 2025-01-15T05:53:21.789569Z

Looking at your reader conditionals above I now realize I can probably hack something to create aliases in scittle mode anyway, so maybe I'll give that a try, thanks.

p-himik 2025-01-13T13:00:27.919959Z

Would it make sense to rely on something like :foreign-libs instead? Or maybe to extend :foreign-libs. So that the actual code is not conditioned upon where the functionality comes from.

πŸ€” 1
souenzzo 2025-01-13T13:06:14.495729Z

if reagent have a :foreign-libs configuration And I'm using reagent clojurescript will be able to import :foreign-libs directly from reagent jar? replicate the configuration in the project is not a good thing.

p-himik 2025-01-13T13:07:48.680119Z

It shouldn't work that way - jars shouldn't dictate where an app's dependency comes from. Only what the dependency is.

2025-01-13T14:58:54.025519Z

scittle can't do the official method?

borkdude 2025-01-13T15:10:50.859559Z

@nbtheduke What is the "official method"?

2025-01-13T15:11:19.305009Z

you said "while with official CLJS they can use ..." as if scittle can't do that

borkdude 2025-01-13T15:13:00.360479Z

@nbtheduke What I meant is that there is no way to use js/React as globally defined from the ns form. That would benefit scittle as well.

πŸ‘ 1