cljdoc

Sam Ritchie 2023-06-27T00:16:01.406849Z

hmm, I have a failure on the new emmy-viewers library… https://app.circleci.com/pipelines/github/cljdoc/builder/43146/workflows/ed8f3794-9711-4a1d-aa4d-6c0982163702/jobs/59521 it’s not finding an npm dependency used transitively, but I’m sure that it’s declared correctly in the deps.cljs file for emmy.

1
✅ 1
Sam Ritchie 2023-06-27T12:28:25.771359Z

hmm, https://cljdoc.org/builds/69371 I tried to push a new tag to specify clj only and the build is still failing on that one bit: https://github.com/mentat-collective/emmy-viewers/blob/cljdoc-v0.1.0/doc/cljdoc.edn

Sam Ritchie 2023-06-27T12:28:46.340149Z

maybe the v is the problem there

Sam Ritchie 2023-06-27T12:29:12.052509Z

but I feel like this has worked before?

lread 2023-06-27T12:36:29.681019Z

@sritchie09, the cljdoc-<version> rebuild tag is currently for https://github.com/cljdoc/cljdoc/blob/master/doc/userguide/for-library-authors.adoc#overriding-articles-revision, not for API analysis.

Sam Ritchie 2023-06-27T12:38:30.430869Z

got it

lread 2023-06-27T12:39:52.989079Z

If I remember correctly, we didn't want to deal with the case of the jar sources possibly being out of synch with the git sources.

👍 1
lread 2023-06-27T13:14:50.525059Z

I'm trying to ramp up on how a cljs library can/should require an npm dep. It seems the topic is a bit complex? https://github.com/clojure/clojurescript-site/issues/224?

Sam Ritchie 2023-06-27T14:22:23.114869Z

@lee each of the dependencies packages its own deps.cljs file; that’s how emmy learns about them, and emmy-viewers learns about them the same way

Sam Ritchie 2023-06-27T14:22:30.631629Z

(vs emmy packaging a package.json)

👍 1
lread 2023-06-27T15:00:36.980419Z

Ok @sritchie09, to help my learning here, I'm going to do something simple. From a new empty directory, I'll create a deps.edn:

{:deps {org.clojure/clojurescript {:mvn/version "1.11.60"}
        org.mentat/emmy {:mvn/version "0.31.0"}}}
Then I'll fire up a cljs repl session and require the emmy.value ns
> clj -M -m cljs.main --repl-env node
ClojureScript 1.11.60
cljs.user=> (require '[emmy.value :as v])
But I get the following error:
Unexpected error (ExceptionInfo) compiling at (REPL:1).
No such namespace: complex.js, could not locate complex/js.cljs, complex/js.cljc, or JavaScript source providing "complex.js" in file file:/home/lee/.m2/repository/org/mentat/emmy/0.31.0/emmy-0.31.0.jar!/emmy/value.cljc
But, if I look in the emmy jar, I do see a /deps.cljs with:
{:npm-deps
 {"complex.js" "^2.1.1"
  "fraction.js" "^4.2.0"
  "odex" "3.0.0-rc.4"}}
So I am probably not yet understanding how deps.cljs :npm-deps works. Should the above work?

Sam Ritchie 2023-06-27T17:55:14.171119Z

Good question, I have been in shadow land so long that I’m not sure if there are any preparatory commands to run to get that to work

Sam Ritchie 2023-06-27T17:55:32.370449Z

I have avoided as much JS knowledge as possible, to my obvious detriment

lread 2023-06-27T18:04:50.367069Z

I've not found clear docs on what works when/why/how. There is https://widdindustries.com/blog/cljs-npm-libraries, but maybe it is old when measured in JavaScript time?

lread 2023-06-27T18:07:12.318169Z

I am working on static analysis for cljdoc, I can't remember if you generate any of emmy APIs at load time, if not it might be an easier way to go.

Sam Ritchie 2023-06-27T18:07:29.002309Z

So I guess it needs :npm-deps true somewhere

Sam Ritchie 2023-06-27T18:07:57.366939Z

lread 2023-06-27T18:12:08.503879Z

Oh! Interesting. I'll toy with that to learn more. Apparently, https://clojurescript.org/reference/compiler-options#npm-deps.

lread 2023-06-27T18:14:44.123949Z

That happened like 4.5 years ago, but it might be something the ragtag cljdoc team did not notice.

Sam Ritchie 2023-06-27T18:15:34.333489Z

Haha it’s a clue anyway :)

Sam Ritchie 2023-06-27T18:19:15.127099Z

Thanks for looking into this!! I can go clojure only too in the meantime

lread 2023-06-27T18:48:39.778169Z

Hmm.... I'm not having luck with :npm-deps true nor :install-deps true.... but maybe I don't have the right incantation.

lread 2023-06-27T18:53:15.835969Z

Maybe we should ask for help in #clojurescript

lread 2023-06-27T19:01:45.943509Z

But... install-deps true does generate package.json, package-lock.json and node_modules.

❯ clj -M --main cljs.main -co '{:install-deps true}' -re node -r
ClojureScript 1.11.60
cljs.user=> (require '[emmy.value :as v])
WARNING: abs already refers to: #'clojure.core/abs in namespace: clojure.math.numeric-tower, being replaced by: #'clojure.math.numeric-tower/abs
Execution error (Error) at (<cljs repl>:1).
Cannot find module 'complex.js'
Require stack:
- /tmp/out361420216702976617719667604306161/emmy/value.js
- /home/lee/proj/oss/-verify/cljs-npm-deps/[stdin]
❯ ls
deps.edn node_modules  package.json  package-lock.json
❯ cat package.json 
{
  "dependencies": {
    "@cljs-oss/module-deps": "^1.1.1",
    "complex.js": "^2.1.1",
    "fraction.js": "^4.2.0",
    "odex": "^3.0.0-rc.4"
  }
}

lread 2023-06-27T19:08:40.831069Z

Side thought: I wonder if some cljs libs these days require shadow-cljs.... (don't work with vanilla ClojureScript) and maybe should be analyzed with shadow-cljs... if that's possible...

Sam Ritchie 2023-06-27T19:11:55.862229Z

I hope that’s not the case with this one… it is weird that Emmy works fine

lread 2023-06-27T19:45:13.646479Z

Hmmm.... yeah, but my simple tests above were with emmy. This implies that emmy does not work with vanilla ClojureScript (or we just don't know how to get it to work with vanilla ClojureScript). But why does cljdoc cljs analysis pass for emmy? Dunno yet, that is cljdoc code I'm not familiar with yet.

lread 2023-06-27T20:39:45.554009Z

Right, so https://github.com/cljdoc/cljdoc-analyzer/blob/2983ed108d9a44ab1c26cd0f4a0d85425893bb62/modules/metagetta/src/cljdoc_analyzer/metagetta/clojurescript.clj#L104-L128. This must be what makes emmy pass cljs API analysis. But for whatever reason, the trick does not work for emmy-viewers->emmy.

lread 2023-06-27T21:11:05.954509Z

Ok, so yup, only immediate lib sources get the faked out js deps. So any js dep from emmy-viewers is faked out, but js deps from emmy are not.... and when emmy-viewers loads emmy, we get the no such namespace error on for example fraction.js/bigfraction.js.

lread 2023-06-27T21:14:52.972229Z

So, @sritchie09 I shall raise an issue but an interesting discovery is that cljdoc cljs API analysis does not imply that a lib will work with vanilla ClojureScript. I think.

lread 2023-06-27T21:42:22.810899Z

issue raised: https://github.com/cljdoc/cljdoc-analyzer/issues/84

Sam Ritchie 2023-06-27T21:55:27.283779Z

Thank you for all the work here @lee , especially as I was distracted by family instead of helping - I’m glad that this failure makes sense and we’ve got a path forward

Sam Ritchie 2023-06-27T21:55:38.675289Z

I’ve also got some work to do with testing vanilla cljs

lread 2023-06-27T21:57:45.264839Z

I can't say I understand all the workings, but yeah, I think I have something to explore anyway! I'm gonna try, for my own education, emmy-viewers in a shadow-cljs repl.

lread 2023-06-27T22:04:19.785039Z

Ok, cool, (as you already know), shadow-cljs handles all these deps.cljs automagically.

Sam Ritchie 2023-06-27T00:17:11.169819Z

any ideas on how to resolve this one? Or why I’m not seeing it on the main Emmy build?

lread 2023-06-27T02:21:13.865319Z

I can take a look sometime my-tomorrow @sritchie09

🙏 1
lread 2023-06-27T02:39:54.970779Z

@sritchie09 a naive question from I guy who does not know: is :npm-depsin deps.cljs a https://shadow-cljs.github.io/docs/UsersGuide.html#publish-deps-cljs?

Sam Ritchie 2023-06-27T02:50:59.597849Z

I think it’s a clojurescript thing too these days…

Sam Ritchie 2023-06-27T02:51:11.375619Z

Vanilla that is

lread 2023-06-27T03:09:05.796439Z

k, tx, will dig more tomorrow

Sam Ritchie 2023-06-29T14:27:29.052679Z

@lee tasks complete: https://github.com/mentat-collective/emmy-viewers/pull/56 I want to get a couple more PRs in today, then I’ll cut a release

lread 2023-06-29T14:38:42.917249Z

Coolio. I just double checked that I did not steer you wrong by: 1. cloning emmy-viewers, 2. then rm -rf ~/.m2/repository/org/mentat 3. then from emmy-viewers dir, clojure -T:build install, 4. then from cljdoc-analyzer dir:

❯ clojure -M -m cljdoc-analyzer.cljdoc-main '{:project "org.mentat/emmy-viewers", :version "0.1.0", 
  :jarpath "/home/lee/.m2/repository/org/mentat/emmy-viewers/0.1.0/emmy-viewers-0.1.0.jar",
  :pompath "/home/lee/.m2/repository/org/mentat/emmy-viewers/0.1.0/emmy-viewers-0.1.0.pom",
  :languages nil, :repos {"clojars" {:url ""}, "central" {:url ""}}}'
API analysis worked fine. All indicators point to extreme success.

🎉 1
lread 2023-06-29T14:40:40.581979Z

@sritchie09 unless you truly only want your clj API analyzed, you'll probably want to turf this: https://github.com/mentat-collective/emmy-viewers/blob/main/doc/cljdoc.edn

Sam Ritchie 2023-06-29T14:41:08.242859Z

Oh yeah I forgot, that was a workaround I had tried

👍 1
lread 2023-06-28T14:14:28.114679Z

@sritchie09 I've hacked past (but have not yet pushed changes) to handle the JavaScript requires issue. But, of course, there is always the next issue! Cljs analysis is now failing with:

No such namespace: nextjournal.clojure-mode, could not locate nextjournal/clojure_mode.cljs, nextjournal/clojure_mode.cljc, or JavaScript source providing "nextjournal.clojure-mode" (Please check that namespaces with dashes use underscores in the ClojureScript file name) in file file:/home/lee/.m2/repository/io/github/nextjournal/clerk/0.14.919/clerk-0.14.919.jar!/nextjournal/clerk/render/code.cljs
If I delete the /demo dir from the emmy-viewers jar I get past this, but...

lread 2023-06-28T14:16:10.068249Z

My next error is:

No such namespace: lambdaisland.deep-diff2.diff-impl, could not locate lambdaisland/deep_diff2/diff_impl.cljs, lambdaisland/deep_diff2/diff_impl.cljc, or JavaScript source providing "lambdaisland.deep-diff2.diff-impl" (Please check that namespaces with dashes use underscores in the ClojureScript file name) in file file:/home/lee/.m2/repository/djblue/portal/0.42.1/portal-0.42.1.jar!/portal/ui/viewer/diff.cljs

Sam Ritchie 2023-06-28T14:16:58.411029Z

Oh interesting… okay yeah I think I have a bunch of “provided” dependencies that only come into play if you pull in a special dependency of clerk

Sam Ritchie 2023-06-28T14:17:11.366069Z

I need to do some class path hygiene and think about what I’m actually shipping I think

lread 2023-06-28T14:22:08.481349Z

Hmm... I do see deep-diff2 as a provided dep of https://repo.clojars.org/djblue/portal/0.42.1/portal-0.42.1.pom. But, I think provided deps only apply to a library, not its dependencies.

lread 2023-06-28T14:23:56.356759Z

I'll muck around a bit more and contrive emmy-viewers pom and jar. I'd like to see emmy-viewers analyzing, at least locally, on my dev box.

lread 2023-06-28T14:26:06.036369Z

Also: not sure if you want that /demo dir in your jar. Maybe your users need it?

Sam Ritchie 2023-06-28T14:30:37.707279Z

I have been migrating code out of those final two namespaces, but you’re right that they don’t need to be in the jar, just on the class path for a couple of the demos that can’t use the proper API yet

Sam Ritchie 2023-06-28T14:30:43.237239Z

I will move those out

Sam Ritchie 2023-06-28T14:37:04.392479Z

Yeah but I can remove them from there and only add them in for the GitHub pages build

👍 1
lread 2023-06-28T14:59:21.594689Z

Ok, I have emmy-viewers docs building locally. Summary of hacks: 1. have cljdoc-analyzer fake out JavaScript requires found on classpath (I'll clean this up and push probably sometime today) 2. emmy-viewers jar a. delete /demo dir b. edit /emmy/viewer/sci.cljs to comment out references to demo namespace 3. emmy-viewers pom, added provided deps:

<dependency>
  <groupId>lambdaisland</groupId>
  <artifactId>deep-diff2</artifactId>
  <version>2.8.190</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>hickory</groupId>
  <artifactId>hickory</artifactId>
  <version>0.7.1</version>
  <scope>provided</scope>
</dependency>

Sam Ritchie 2023-06-28T14:59:56.467339Z

Amazing! I can take care of 2 and 3. Thank you @lee !

lread 2023-06-28T15:00:35.607449Z

For you @sritchie09? Always a pleasure!

❤️ 1
lread 2023-06-28T15:02:27.423159Z

I'll letcha know when I've pushed item 1. When the dust settles, I'll likely add emmy-viewers to our cljdoc analyzer integration test suite.

lread 2023-06-29T00:03:23.373269Z

Ok, @sritchie09, fix for item 1 is live. Lemme know when you address items 2 and 3 (and a release), and then I'll add emmy-viewers to the cljdoc-analyzer integration test suite.

👍 1
Sam Ritchie 2023-06-29T00:59:06.143159Z

Thank you, will do!

👍 1