Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't init clojurescript in clojure-only project #3

Closed
mishadoff opened this issue Feb 23, 2018 · 6 comments
Closed

Can't init clojurescript in clojure-only project #3

mishadoff opened this issue Feb 23, 2018 · 6 comments

Comments

@mishadoff
Copy link

I have a plain clojure project (no clojurescript), when I use debux and require core namespace in REPL i get exception

CompilerException java.io.FileNotFoundException: Could not locate cljs/analyzer/api__init.class or cljs/analyzer/api.clj on classpath., compiling:(debux/common/util.cljc)

Probably this caused by init of [cljs.analyzer.api :as ana] which is not in classpath.
Is there a way to disable clojurescript and make it work for clojure only?

P.S. Adding clojurescript deps looks like short term fix, but would be good to avoid unnecessary deps

@philoskim
Copy link
Owner

philoskim commented Feb 23, 2018

Thanks for your pointing out this error. This problem will be solved in the next version of debux.

My solution is simple.

The following part of debux/project.clj

:dependencies [[org.clojure/clojure "1.8.0" :scope "provided"]
               [org.clojure/clojurescript "1.9.854" :scope "provided"]]

will be changed to the following.

:dependencies [[org.clojure/clojure "1.8.0"]
               [org.clojure/clojurescript "1.9.854"]]

That is, the default cversion of clojure and clojurescript will be provided by debux, not you. So you don't need to include clojurescript dependency in your project.clj.

@mishadoff
Copy link
Author

mishadoff commented Feb 23, 2018

Wouldn't be better to require clojure script related namespaces with reader macro? So that we don't bring unnecessary deps in classpath?

#?(:cljs (:require [cljs.analyzer.api :as ana]))

@philoskim
Copy link
Owner

philoskim commented Feb 23, 2018

Debux library has over 90% of macro related codes by the nature of this library and I had a lot of trial and error experience on the macro programming.

In my knowledge and practice, your suggestion doesn't work, because the macro expansions in ClojureScript are carried out before compile time by Clojure, not by ClojureScript. So every code executed during macro-expansion time has to be located in #?(:clj ...), not in #?(:cljs ...).

At first, I thought which code should be changed to meet your requirement. After long review, I conclude that the shared codes between Clojure and ClojureScript has to be dupicated too much to meet your requirement and it is not desirable. So I decided to discard code rewriting and change the project.clj as above. It's not clean solution but simple one from a viewpoint of implementation. So I chose it.

If I am wrong, please let me know about it.

@philoskim
Copy link
Owner

philoskim commented Mar 28, 2018

Now debux has a new production version debux-stubs (https://github.com/philoskim/debux#two-libraries) library and the explaination about it is here (https://github.com/philoskim/debux#two-libraries). If you use this library in production, no unnecessary dependencies will be added to the classpath. Thanks a lot for the suggestion!

@onetom
Copy link

onetom commented Mar 11, 2020

I've also just looked into this issue, because the load time of debux is quite substantial (~1s on a beefy 8core i9). My suspicion is that it's caused by the requirement to load the cljs analyser.

To get rid of ClojureScript dependency, the cleanest way would be to fork the library and remove any cljs related code. This of course introduces extra maintenance burden, but given how little this library changes lately; it might worth the effort.

What do you think @philoskim ? Am I missing something, or it worth giving it a try to gut cljs from it?

@philoskim
Copy link
Owner

philoskim commented Mar 12, 2020

@onetom

I measured the load time of debux in the Clojure REPL several times like this.

(ns examples.lab)

(time (use 'debux.core))

The results are as follows.

"Elapsed time: 0.400357 msecs"
"Elapsed time: 0.328361 msecs"
"Elapsed time: 0.328984 msecs"
"Elapsed time: 0.35696 msecs"

The CPU of my notebook is the Intel i7-6500U dual cores.

I think that the load time is relatively small, compared to the entire development time.
So now I don't consider separating debux into the Clojure and ClojureScript versions.

Sorry to say that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants