Live data from Hacker News

ClojureScript Is Not An Island: Integrating Node Modules

clojurescript.org

11–20 of 43 posts

Re: ClojureScript Is Not An Island: Integrating Node Modules

#11
post #10

How does Clojurescript lookup for a module you declare? For example, in https://github.com/omcljs/om/blob/c68e668a73cc534ecfdc71d631... (couldn't think of any Clojurescript library), you have `[om.dom`, `[cljsjs.react`, `[goog.dom`. Where does the compiler look for these things? How does it knows one is a local module and the other an external package? I need to know this so I can implement it in https://github.com/f…

This is quite a large question to answer.

From viewpoint of compiler, there is no much distinction between local and external packages. Clojure (and so ClojureScript compiler) is built on to of JVM and uses Maven dependencies so that is where most of the dependencies come from. From viewpoint of compiler, all files are in JVM classpath (or in directories specified in Cljs compiler options).

Om declares it's dependencies in project.clj file: https://github.com/omcljs/om/blob/master/project.clj#L13

- om.dom, based on the name, compiler will look for om/dom.cljs/cljc files in classpath, and in this case the file is local to the project

- cljsjs.react is foreign-library (https://clojurescript.org/reference/packaging-foreign-deps) provided by external cljsjs/react package. Compiler indexes all these foreign-libraries at start, so when it encounters require to one of them knows what to do

- goog.dom is Closure module provided by Google Closure library (https://github.com/google/closure-library), which is dependency of ClojureScript. Compiler will look for goog/dom.js file if no .cljs or .cljc by the name is found.

Re: ClojureScript Is Not An Island: Integrating Node Modules

#13
Scary, any newbie will read this and run away.

Is passing through the complexity, pain and all the caveats one can encounter from this really worth it for using Clojurescript? Serious question, now that with have ES6+ and today babel/webpack are solid tools.

I mean from all the modules mess, I didn't get what's the correct way to do javascript interop right now.

Re: ClojureScript Is Not An Island: Integrating Node Modules

#15

The thing I like about Clojurescript is the ability to escape the node/NPM ecosystem entirely. It's feature, not a bug, that I don't want to interoperate with node/NPM.

As someone looking to get into CLJS, where do I find "native" CLJS libraries in case I wish to avoid using NPM?

Re: ClojureScript Is Not An Island: Integrating Node Modules

#16
post #15

The thing I like about Clojurescript is the ability to escape the node/NPM ecosystem entirely. It's feature, not a bug, that I don't want to interoperate with node/NPM.

As someone looking to get into CLJS, where do I find "native" CLJS libraries in case I wish to avoid using NPM?

Native CLJS libraries are regular JARs that you add to your classpath. Most people publish them to Clojars[1] (which also has Clojure libs). Maven Central may also have some.

[1] http://clojars.org

Re: ClojureScript Is Not An Island: Integrating Node Modules

#17

Scary, any newbie will read this and run away. Is passing through the complexity, pain and all the caveats one can encounter from this really worth it for using Clojurescript? Serious question, now that with have ES6+ and today babel/webpack are solid tools. I mean from all the modules mess, I didn't get what's the correct way to do javascript interop right now.

I fail to see how Closure Complier is any more complicated, more painful, and has any more caveats than Babel/Webpack. With Closure Compiler at 8 years old and building some of the most sophisticated JS properties on the web (GDocs anyone?) it seems pretty "solid" to me. Perhaps it not clear from the post but that's a big part of why this works, we're not doing the heavy lifting.

Re: ClojureScript Is Not An Island: Integrating Node Modules

#18
post #15

The thing I like about Clojurescript is the ability to escape the node/NPM ecosystem entirely. It's feature, not a bug, that I don't want to interoperate with node/NPM.

As someone looking to get into CLJS, where do I find "native" CLJS libraries in case I wish to avoid using NPM?

Clojure Toolbox (https://www.clojure-toolbox.com/) lists libraries for both Clojure and ClojureScript.

Re: ClojureScript Is Not An Island: Integrating Node Modules

#19

Scary, any newbie will read this and run away. Is passing through the complexity, pain and all the caveats one can encounter from this really worth it for using Clojurescript? Serious question, now that with have ES6+ and today babel/webpack are solid tools. I mean from all the modules mess, I didn't get what's the correct way to do javascript interop right now.

I fail to see how Closure Complier is any more complicated, more painful, and has any more caveats than Babel/Webpack. With Closure Compiler at 8 years old and building some of the most sophisticated JS properties on the web (GDocs anyone?) it seems pretty "solid" to me. Perhaps it not clear from the post but that's a big part of why this works, we're not doing the heavy lifting.

Its not about closure, is all the Clojurescript interop issues/gotchas, what's the correct way to do interop today in Clojurescript?

Re: ClojureScript Is Not An Island: Integrating Node Modules

#20

This feature is really, really a long time coming. Myself and other ClojureScript core contributors are happy to answer any questions people may have.

This is huge. Very excited for this! Is there support for private NPM repos? NPM looks for the registry URL and auth token in ~/.npmrc and uses that to authenticate.
Post reply on HN