Fork me on GitHub
#cljs-dev
<
2023-05-18
>
mikerod17:05:04

How can I relate the org.clojure/google-closure-library version back to the actual closure-library source tag/sha? eg. https://mvnrepository.com/artifact/org.clojure/google-closure-library/0.0-20211011-0726fdeb I don’t see “0.0-20211011-0726fdeb” as a tag or something I can find in https://github.com/google/closure-library I looked at tags they do have that were similar in the date string part, but there was nothing for 20211101 either (some were close such as https://github.com/google/closure-library/tree/v20211107 )

mikerod17:05:45

I do see in mvn repo, the description: > The Google Closure Library is a collection of JavaScript code designed for use with the Google Closure JavaScript Compiler. This non-official distribution was prepared by the ClojureScript team at http://clojure.org/ I am curious where is this “prepared by the ClojureScript team” at?

mikerod17:05:25

Perhaps part of my answer would be to look https://github.com/clojure/clojurescript/commit/715cdc07dbb1d595af91ea12affb6faf0b615d4b and try to track back to the artifact updates there.

mikerod17:05:33

Oh, so I overlooked that the short hash is there

mikerod17:05:58

Doesn’t https://github.com/google/closure-library/commit/0726fdeb seem like a fairly arbitrary commit from the library - not something they tagged as a release etc?

p-himik17:05:32

Might be the latest version available at the time it was prepared as a jar, dunno.

p-himik17:05:28

Although that CLJS commit says "GCL snapshot is from December."

mikerod17:05:39

Interesting. I’m trying to understand this update process

mikerod17:05:08

Also, it’s notable that this is from 2021 - pretty old

mikerod17:05:20

Maybe I am not looking at latest cljs though

mikerod18:05:47

I recently had a tricky google closure issue to debug & was trying to track down the impl and realized it was weird to find the cljs version being used - and then I came to realize it seemed like the cljs version is pretty old. The code that I was interested in, in particular, has changed quite in “modern closure” versions.

p-himik18:05:03

Not sure how relevant it is, but FWIW I believe shadow-cljs uses one of the latest GCL versions, maybe with some tweaks, and things work just fine, with very rare exceptions.

mikerod18:05:00

Yeah, I thought shadow may be trying to stay more in sync. I have been considering trying it out to see if I like the experience more. I’ve been more of a traditionalist (minimalist?) up to this point and worried about something like shadow that is doing things different than core.

mikerod18:05:25

I appreciate the feedback

thheller18:05:45

the closure library didn't use to have "releases" and even nowadays its more like "whatever HEAD was on date X"

thheller18:05:24

I think CLJS master was updated to the closure lib version shadow already uses, or might be in some branch. it is pending though.

thheller18:05:43

nothing much relevant changes in the closure lib, mostly bugfixes in code we don't use 😛

thheller18:05:53

unless you are somehow using goog.ui and stuff

mikerod19:05:53

Interesting. The latest cljs master and 1.11 tag I see seems to be on a 2021 closure version

mikerod19:05:27

I thought at one point you mentioned the “debug loader” going away from closure? I thought that may have a pretty big impact on cljs repl none optimizations?

mikerod19:05:36

I was wanting to track that past conversation but have lost it

mikerod19:05:27

I noticed when testing in jsdom recently that the :none optimization style cljs currently uses doesn’t work in jsdom at all due to the dynamic document.write(“<script>…”) usages

thheller19:05:36

yes, there was a commit suggesting they were to remove it. nothing has happened there yet though.

mikerod19:05:17

Ah ok, thanks for the info.

dnolen19:05:03

hrm I guess some Node packages now use the module key over the main key to identify the entrypoint?

borkdude19:05:41

oh you mean that some dependencies use that key instead of the officially documented one?

thheller19:05:25

lots of packages ship with both, using module for newer esm and usually main for the transpiled commonjs variants

thheller19:05:45

but there are some that only use module with no fallbacks

borkdude19:05:51

I see no docs on "module" but I do see this: https://nodejs.org/api/packages.html#exports

thheller19:05:36

not a lot of packages use exports yet. there are also some differences in how webpack and node handle that, so thats a bit annoying

borkdude19:05:50

> Prior to the introduction of support for ES modules in Node.js, it was a common pattern for package authors to include both CommonJS and ES module JavaScript sources in their package, with package.json "main" specifying the CommonJS entry point and package.json "module" specifying the ES module entry point. This enabled Node.js to run the CommonJS entry point while build tools such as bundlers used the ES module entry point, since Node.js ignored (and still ignores) the top-level "module" field.

dnolen19:05:51

@U04V15CAJ yes I think this is one of those things that magically works even though you’re not supposed to it that way?

borkdude19:05:22

(this text came from Dual CommonJS/ES module packages in the link above)

borkdude19:05:15

so it seems that top level module fields isn't an npm thing but a tooling convention (webpack etc?)

dnolen19:05:37

right but we look at that stuff for resolution

dnolen19:05:58

one question would be whether considering module for Node would cause problems - I’m thinking it might

dnolen19:05:08

so maybe we need to check that nothing else is available etc.

thheller19:05:24

node also has "type":"module" which also makes it behave differently

thheller19:05:39

pretty big mess overall

borkdude19:05:25

and to make it more complicated:

// package.json
{
  "exports": {
    "import": "./index-module.js",
    "require": "./index-require.cjs"
  },
  "type": "module"
} 

thheller19:05:13

thats not even the fun part, gets real fun with wildcards and other nested things

thheller19:05:14

I have attempted to implement it several times now and always get fed up. no one even bothered to define a proper standard, so every tool does something slightly different. I'm now waiting till things settle and there is one "winner"

dnolen19:05:45

So many bad ideas let’s just put ‘‘em all in!

mikerod20:05:13

I am running into several libs lately that are using “package exports”.

mikerod20:05:59

And I’ve had issues in CLJS with a :bundle target in that CLJS doesn’t understand “package exports” indexing. So I have to do a :require to the “real module file” that CLJS does find. Then I have to configure webpack to ignore it’s “package exports” built-in resolution.

mikerod20:05:34

Example: recent versions of react-select. I have to do this in webpack:

resolve: {
    alias: {
      "react-select/creatable/dist/react-select-creatable.cjs":
      path.resolve(__dirname,
                   "node_modules/react-select/creatable/dist/react-select-creatable.cjs.js")
    }
  }
so I can use a :require that CLJS allows.

dnolen20:05:43

we could add that, the code is a bit ugly - would be good refactor the resolution stuff a bit so it more understandable

dnolen20:05:53

+ tests to show what it’s supposed to do

mikerod20:05:55

If I don’t do this, webpack v5+ will not allow me to access this file. It “enforces” package exports.

dnolen20:05:10

well I might start on this refactor tweak because I need this for work anyhow

dnolen20:05:20

perhaps one result is that this code will be easier to adjust in a sensible way

mikerod20:05:06

That sounds like it could be pretty nice. I was reading the current impl recently a bit.

dnolen20:05:56

I think lifting it to a helper namespace and breaking everything apart is a good start - w/ some comments

💯 2
borkdude20:05:09

Why does CLJS have to parse package.json btw? Shouldn't node/JS tooling just to the right thing when you emit a require() or import()?

2
dnolen22:05:50

It used be like that that - if you did something wrong fails at runtime of course

dnolen22:05:17

When I did the bundle support stuff might as well validate reusing that work

dnolen23:05:16

Oh but also you have to know to emit JS require - and that means you have to know which node modules exist

👍 2
mikerod00:05:22

I had this thought at one point too. “Could cljs just assume anything it didn’t know in a :require should be a JS require?” But I could see how that’d be leading to bad runtime errors. Eg a typo in a require (maybe intended as a cljs ns) would lead to a weird later failure from a bundler that may be misleading. I didn’t know if there was other reasons for cljs to check JS dep referenced existed though (for a target like bundle).

dnolen02:05:46

the main thing is that semantics of the ns form is that we check early whether a namespace exists or not

dnolen02:05:21

so this maintains that expectation

mikerod02:05:09

Makes sense to me

dnolen19:05:37

@thheller for the latest Closure Lib you defaulted to :ecmascript-2017?

thheller19:05:01

the default shadow-cljs uses for most things is :ecmascript-2020

thheller19:05:51

only exception is the :react-native target since the hermes engine (now the default I guess) only supports es5 (no const support used in goog.* stuff)

dnolen19:05:03

I see, CLJS took a PR that defaults :es-next

dnolen19:05:11

but some of these tests set lang in

dnolen19:05:24

but GCL itself appears to be :es-2017 at a minimum

thheller19:05:55

lang-in is always set to the highest (so :es-next) in shadow, there doesn't seem to be a downside to setting it too high

thheller19:05:04

and the compiler figures it out anyways when compiling

dnolen20:05:24

yeah that’s what I’m doing now

dnolen19:05:01

oh I see just these tests are setting it rather than choosing the new default