cljs-dev

2023-05-18T17:51:04.623359Z

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 )

2023-05-18T17:51:45.434469Z

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?

p-himik 2023-05-18T17:53:09.148639Z

The 0726fdeb part looks like a short Git hash. https://github.com/google/closure-library/commit/0726fdeb

2023-05-18T17:53:25.808549Z

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.

2023-05-18T17:53:33.448679Z

Oh, so I overlooked that the short hash is there

2023-05-18T17:55:58.786449Z

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-himik 2023-05-18T17:57:32.063819Z

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

p-himik 2023-05-18T17:58:28.151149Z

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

2023-05-18T17:58:39.921679Z

Interesting. I’m trying to understand this update process

2023-05-18T17:59:08.572189Z

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

2023-05-18T17:59:20.454189Z

Maybe I am not looking at latest cljs though

2023-05-18T17:59:39.335019Z

https://github.com/google/closure-library/commit/0726fdeb I think so

2023-05-18T18:00:47.548109Z

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-himik 2023-05-18T18:01:03.839369Z

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.

2023-05-18T18:02:00.755329Z

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.

2023-05-18T18:02:25.719109Z

I appreciate the feedback

thheller 2023-05-18T18:51:45.276039Z

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

thheller 2023-05-18T18:52:24.371899Z

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

thheller 2023-05-18T18:52:43.774749Z

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

thheller 2023-05-18T18:52:53.707279Z

unless you are somehow using goog.ui and stuff

2023-05-18T19:02:53.194319Z

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

2023-05-18T19:03:27.249939Z

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?

2023-05-18T19:03:36.545279Z

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

2023-05-18T19:04:27.011909Z

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

thheller 2023-05-18T19:04:36.124259Z

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

2023-05-18T19:56:17.752089Z

Ah ok, thanks for the info.

dnolen 2023-05-18T19:17:03.045949Z

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

borkdude 2023-05-18T19:24:28.123199Z

these are the package.json docs: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#main

borkdude 2023-05-18T19:26:41.163889Z

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

thheller 2023-05-18T19:32:25.903249Z

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

thheller 2023-05-18T19:32:45.072969Z

but there are some that only use module with no fallbacks

borkdude 2023-05-18T19:34:51.901209Z

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

thheller 2023-05-18T19:35:36.637499Z

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

borkdude 2023-05-18T19:35:50.532139Z

> 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.

dnolen 2023-05-18T19:35:51.918279Z

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

borkdude 2023-05-18T19:36:22.921949Z

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

borkdude 2023-05-18T19:37:15.428739Z

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

dnolen 2023-05-18T19:40:37.755949Z

right but we look at that stuff for resolution

dnolen 2023-05-18T19:40:58.248449Z

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

dnolen 2023-05-18T19:41:08.527269Z

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

thheller 2023-05-18T19:41:24.353769Z

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

thheller 2023-05-18T19:41:39.439579Z

pretty big mess overall

borkdude 2023-05-18T19:42:25.439299Z

and to make it more complicated:

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

thheller 2023-05-18T19:49:13.487389Z

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

thheller 2023-05-18T19:50:14.912059Z

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"

dnolen 2023-05-18T19:56:45.723779Z

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

thheller 2023-05-18T19:57:05.386289Z

indeed

2023-05-18T20:01:13.234389Z

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

2023-05-18T20:01:59.764859Z

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.

2023-05-18T20:02:34.759579Z

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.

dnolen 2023-05-18T20:02:43.098039Z

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

dnolen 2023-05-18T20:02:53.164939Z

+ tests to show what it’s supposed to do

2023-05-18T20:02:55.965129Z

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

dnolen 2023-05-18T20:04:10.211759Z

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

dnolen 2023-05-18T20:04:20.837739Z

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

2023-05-18T20:05:06.381759Z

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

dnolen 2023-05-18T20:05:56.066499Z

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

💯 1
borkdude 2023-05-18T20:22:09.921489Z

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()?

🤔 1
dnolen 2023-05-18T22:49:50.951059Z

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

dnolen 2023-05-18T22:50:17.994699Z

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

dnolen 2023-05-18T23:05:16.917129Z

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

👍 1
2023-05-19T00:11:22.577339Z

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).

dnolen 2023-05-19T02:13:46.502989Z

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

dnolen 2023-05-19T02:14:21.892659Z

so this maintains that expectation

2023-05-19T02:28:09.195929Z

Makes sense to me

dnolen 2023-05-18T19:41:37.021139Z

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

thheller 2023-05-18T19:43:01.078979Z

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

thheller 2023-05-18T19:44:51.487029Z

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)

dnolen 2023-05-18T19:45:03.655039Z

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

dnolen 2023-05-18T19:45:11.293729Z

but some of these tests set lang in

dnolen 2023-05-18T19:45:24.260499Z

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

thheller 2023-05-18T19:45:55.396409Z

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

thheller 2023-05-18T19:46:04.672019Z

and the compiler figures it out anyways when compiling

dnolen 2023-05-18T20:01:24.692019Z

yeah that’s what I’m doing now

dnolen 2023-05-18T20:01:27.860589Z

thanks!

dnolen 2023-05-18T19:43:01.218909Z

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