Fork me on GitHub
#cljdoc
<
2019-03-01
>
joelsanchez09:03:33

hi 👋 I'm requiring a namespace from an npm module loaded with shadow-cljs, what do I have to do to make it work with cljdoc?

martinklepsch09:03:00

Hi Joel! 👋 I think unless we switch the underlying analyzer to shadow's implementation there's nothing easy we can do here

martinklepsch09:03:07

If this is a library I would recommend to use plain CLJS because otherwise all consumers will be required to use shadow-cljs as well (might be ok but certainly a smaller user-pool)

joelsanchez09:03:49

it's not a library, the cljs files can be used by child projects but it's not their main usecase. in this case the cljs is the backoffice of an ecommerce site, and this dependency is only going to be used to build sites /extend the software

joelsanchez09:03:08

but, can the cljs be ignored? so that my clj sources are analyzed and the documentation is picked up

joelsanchez09:03:19

don't care that much about the cljs part, it's not documented anyway

joelsanchez09:03:25

also can it stop using the dev profile?

martinklepsch09:03:42

@U5LPUJ7AP there's no concept of profiles in cljdoc's analyzer. We look at a projects pom file (http://repo.clojars.org/ventas-core/ventas-core/0.0.13/ventas-core-0.0.13.pom) and try to include some additional dependencies that a project might need. Eg. some namespace might need core.async but it's expected that the user provides it. Often these kinds of dependencies can be found in the pom with <scope>test</scope> etc

joelsanchez09:03:14

ah sorry. so can the cljs files be ignored?

martinklepsch09:03:19

selecting platforms isn't supported for users at this stage but I can hardcode it for you if you want

joelsanchez09:03:33

well, sure 🙂

martinklepsch09:03:34

(have done so for other projects, would be no problem)

martinklepsch09:03:05

"ventas-core/ventas-core" is correct?

joelsanchez09:03:20

no, just ventas-core

joelsanchez09:03:46

I should have called it joelsanchez/ventas-core but I haven't. so...

martinklepsch09:03:48

ok (that's the same)

martinklepsch09:03:27

Maven has group and artifact IDs. In Clojure when you have a project ID that doesn't contain a / it implies that they're both the same

joelsanchez09:03:41

learning every day... 😛

martinklepsch10:03:57

didn't know this for a long time either (and it's not really all that useful to know hahaha)

thheller10:03:29

@martinklepsch this should work fine if you respect deps.cljs and install the dependencies listed there

martinklepsch10:03:34

yeah, I guess that's the issue then

thheller10:03:55

this might work?

thheller11:03:30

the problem is that CLJS needs to index the node_modules directory to understand that "react-color" is a npm dependency.

thheller11:03:16

I'm not sure if there is a setting to just make it ignore any string deps? I think :target :nodejs does something to that extent? I'm not actually sure how any of this works in default CLJS anymore

thheller11:03:54

since you only analyze and not actually compile it would be fine to just ignore the string deps and treat them as a plain JS object

thheller11:03:29

you could probably add something that doesn't actually require installing the deps

thheller11:03:17

I should have some time tomorrow, maybe I can figure something out that cljdoc parses these properly

martinklepsch11:03:44

that would be super nice 🙂 otherwise I might get to it eventually 🙂

joelsanchez11:03:40

thank you both @U05224H0W @martinklepsch for your help and for your outstanding projects

thheller11:03:31

@martinklepsch can you point me to the code that does the analysis? the function that starts it all?

martinklepsch11:03:32

That namespace has a -main. What you'll need to do to play with that is: 1. Unpack the contents of the dependency's jar into a directory 2. Add it as a dependency to the local deps.edn then you should be able to run something like clj -m codox.main clojurescript jar-contents-dir

martinklepsch11:03:54

It's a little fiddly, let me try to push a commit with some inline docs/pointers for this

thheller11:03:03

its fine. already saw what I needed 😉

borkdude09:03:09

(a bit off topic, but related: is shadow-cljs basically a different dialect of CLJS? what if you write a lib in that, can normal CLJS not consume it? feel free to respond on a thread)

martinklepsch09:03:36

Yeah, I think that's pretty much correct /cc @U05224H0W

thheller10:03:58

no that is incorrect. shadow-cljs is a build tool for clojurescript. the language stays the same with one little exception: https://dev.clojure.org/jira/browse/CLJS-2376 this is already implemented

borkdude10:03:03

And this is the exception Joel runs into I guess?

thheller10:03:26

reading ...

thheller10:03:14

nope that is completely standard. I'm guessing that the npm dependencies just aren't installed?

martinklepsch10:03:09

Sorry for the confusion here @U05224H0W and thanks for chiming in

joelsanchez11:03:06

node_modules is gitignored so they won't be installed by default

joelsanchez11:03:17

there is a package.json with react-color and the other deps though

borkdude11:03:38

I guess cljdoc would have to install them?

joelsanchez11:03:17

sorry, git is irrelevant, but node_modules is not inside resources and not in the artifact at all

martinklepsch11:03:18

Thomas gave some more context on that in the other thread

thheller16:03:34

finally finished writing that blog post I've been thinking about for a while ... maybe it clears up some of the confusion: https://code.thheller.com/blog/shadow-cljs/2019/03/01/what-shadow-cljs-is-and-isnt.html

borkdude17:03:37

One thing I didn’t get is that you’re referring above to CLJS-2376 which introduces this string syntax in require, and that shadow-cljs already implements this. But CLJS-2376 is not yet in CLJS master it seems, so the language is in that aspect still different?

thheller17:03:45

CLJS-2376 introduces :default not the string requires. string requires have been implemented for a while

thheller19:03:44

@martinklepsch I made some adjustments to the codox stuff so that string requires work without actually having to install npm dependencies. https://gist.github.com/thheller/5bc57a7571cf83fd12190ab7165cdb46

thheller19:03:16

the main difference is that the compiler state is only created once in read-namespaces instead of re-creating it all the time

thheller19:03:29

as that re-analyzes all the deps all the time

thheller19:03:40

problem is that it won't fix (:require [react-color ...]) since its a symbol

thheller19:03:07

another strategy could be reading all deps.cljs files for :npm-deps and creating the fake :js-module-index entry for each (maybe package.json too)

thheller19:03:23

then the symbol would work too