arichiardi / replumb

ClojureScript plumbing for your self-hosted REPLs.
http://clojurescript.io
Eclipse Public License 1.0
210 stars 16 forks source link

Cannot use google closure libs #186

Closed viebel closed 8 years ago

viebel commented 8 years ago

read-eval-call fails to import google closure libs.

I've tried this syntax:

(ns my.ns (:require [goog.string :as gstring])) (gstring/capitalize "abc") 
(defn no-op [file-url src-cb]
  (src-cb ""))

(def repl-opts-noop (merge (replumb/options :browser
                                             []
                                             no-op)
                            {:warning-as-error false
                             :context :statement
                             :verbose false}))

(replumb/read-eval-call repl-opts-noop identity "(ns my.ns (:require [goog.string :as gstring])) (gstring/capitalize \"abc\") ")
;=> #error {:message "No such namespace: goog.string, could not locate goog/string.cljs, goog/string.cljc, or Closure namespace \"goog.string\"", :data {:tag :cljs/analysis-error}}}
arichiardi commented 8 years ago

It does import them and you can use them in ClojureScript/JavaScript, but as I told you already once on Slack, require is different. You need to provide the source file and IO. You cannot pass "" and no-op as load-file. It is actually a ClojureScript core requirement. Closing this.

viebel commented 8 years ago

same bug with fetch-file! as provided here io.cljs

viebel commented 8 years ago

Could you please provide a code example that works fine with goog libs?

arichiardi commented 8 years ago

I am pretty confident this is not a bug because we have tests against it. So a couple of things (sorry not enough time at the moment) to do:

For the last task, if you use boot you can use lambda-x/boot-pack-source project on GitHub.

arichiardi commented 8 years ago

Example in the test:

https://github.com/Lambda-X/replumb/blob/master/test/cljs/replumb/require_test.cljs#L271

With options:

https://github.com/Lambda-X/replumb/blob/master/test/browser/replumb/test_env.cljs#L7

viebel commented 8 years ago

Thanks for the reference. It works fine now. Except that I have to manually import some goog libs inside the code of my project e.g.

[goog.string.format]
 [goog.date.Interval]
 [goog.date.UtcDateTime]

What is the best way to import all the goog libs?

arichiardi commented 8 years ago

I am glad you solved! If you use boot, you can check https://github.com/Lambda-X/boot-pack-source

An example usage is here

viebel commented 8 years ago

I'm not familiar with boot. I use leiningen. What should I do though?

arichiardi commented 8 years ago

Switch to boot! :smile: I have not had the need to develop a lein plugin as clojurescript.io is using boot but I guess an alternative solution would be to copy the files you need (it can be a lot) on the server under your src-paths folder. I was doing that before coming up with the boot task. Again, this is ClojureScript core and there is nothing we can do about it. Planck does the same, bundling the required files in the executable.