Fork me on GitHub
#cljdoc
<
2023-06-27
>
Sam Ritchie00:06:01

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.

thinking-face 2
2
Sam Ritchie00:06:11

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

lread02:06:13

I can take a look sometime my-tomorrow @U017QJZ9M7W

🙏 2
lread02:06:54

@U017QJZ9M7W 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 Ritchie02:06:59

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

Sam Ritchie02:06:11

Vanilla that is

lread03:06:05

k, tx, will dig more tomorrow

Sam Ritchie12:06:25

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 Ritchie12:06:46

maybe the v is the problem there

Sam Ritchie12:06:12

but I feel like this has worked before?

lread12:06:52

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.

👍 2
lread13:06:50

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 Ritchie14:06:23

@UE21H2HHD 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 Ritchie14:06:30

(vs emmy packaging a package.json)

👍 2
lread15:06:36

Ok @U017QJZ9M7W, 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 Ritchie17:06:14

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 Ritchie17:06:32

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

lread18:06:50

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?

lread18:06:12

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 Ritchie18:06:29

So I guess it needs :npm-deps true somewhere

lread18:06:08

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

lread18:06:44

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

Sam Ritchie18:06:34

Haha it’s a clue anyway :)

Sam Ritchie18:06:15

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

lread18:06:39

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

lread18:06:15

Maybe we should ask for help in #C03S1L9DN

lread19:06:45

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"
  }
}

lread19:06:40

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 Ritchie19:06:55

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

lread19:06:13

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.

lread20:06:45

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.

lread21:06:05

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.

lread21:06:52

So, @U017QJZ9M7W 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.

Sam Ritchie21:06:27

Thank you for all the work here @UE21H2HHD , 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 Ritchie21:06:38

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

lread21:06:45

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.

lread22:06:19

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

lread14:06:28

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

lread14:06:10

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 Ritchie14:06:58

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 Ritchie14:06:11

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

lread14:06:08

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.

lread14:06:56

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.

lread14:06:06

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

Sam Ritchie14:06:37

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 Ritchie14:06:43

I will move those out

Sam Ritchie14:06:04

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

👍 2
lread14:06:21

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 Ritchie14:06:56

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

lread15:06:35

For you @U017QJZ9M7W? Always a pleasure!

❤️ 2
lread15:06:27

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.

lread00:06:23

Ok, @U017QJZ9M7W, 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.

👍 2
Sam Ritchie00:06:06

Thank you, will do!

👍 2
Sam Ritchie14:06:29

@UE21H2HHD 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

lread14:06:42

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.

🎉 2
lread14:06:40

@U017QJZ9M7W 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 Ritchie14:06:08

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

👍 2