On Thursday, August 7, 2014 8:22:05 AM UTC+10, Dylan Butman wrote:
> I'm working on getting server rendering running with Nashorn. I've been
> successful with :optimization :simple, following
> https://github.com/DomKM/omelette (i stripped out the minimal server
> rendering example here
> https://github.com/pleasetrythisathome/om-server-rendering.
>
> I'm trying to evaluate the require dependencies/files in Nashorn so that I
> can then call an arbitrary function within a namespace (in this case,
> render-to-string).
>
> Mike Thompson's example of :optimization :none testing was helpful
> (specifically his PhantomJs runner file
> https://github.com/mike-thompson-day8/cljsbuild-none-test-seed/blob/master/test/bin/runner-none.js),
> but since he's using PhantomJs rather than Nashorn I'm a little stuck on my
> issue.
>
> (let [js (doto (.getEngineByName (ScriptEngineManager.) "nashorn")
> (.eval (-> "public/out/goog/base.js"
> io/resource
> io/reader))
> (.eval (-> "public/out/goog/deps.js"
> io/resource
> io/reader))
> ;; React requires either "window" or "global" to be defined.
> (.eval "var global = this;")
> ;; parse the compiled js file
> (.eval (-> "public/main.js"
> io/resource
> io/reader))
> (.eval "for(var namespace in goog.dependencies_.nameToPath)
> goog.require(namespace);")
> )
> core (.eval js "main.core")])
>
> errors saying that "main" is not defined.
>
> replacing the goog.require line with a simpler "goog.require("\main.core\")"
> produces the same error
>
> any thoughts?
I don't know anything about Nashorn, but I'll have a guess ...
This loop is obviously critical:
for(var namespace in goog.dependencies_.nameToPath)
goog.require(namespace)
It triggers many calls to
goog.global.CLOSURE_IMPORT_SCRIPT
But I don't see that you have monkey-patched this function for the Nashorn
context. For example, see how it was done for phantomjs:
goog.global.CLOSURE_IMPORT_SCRIPT = function(path) {
page.injectJs(googBasedir + path);
return true;
};
https://github.com/mike-thompson-day8/cljsbuild-none-test-seed/blob/master/test/bin/runner-none.js#L186-L189
--
Mike
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.