librelist archives

« back to archive

Rhino require, anyone?

Rhino require, anyone?

From:
Michael Mathews
Date:
2011-05-07 @ 21:49
I just updated my project to allow developers to require nodejs modules 
(even those installed via npm) into a rhino script.

https://github.com/micmath/Rhino-Require

Not surprisingly, for those modules that are built into node itself, this 
won't work in rhino, but I've started a "shim file" to fake the node 
built-in modules that I personally needed for jsdoc:

https://github.com/micmath/jsdoc/blob/jsdoc%2Brhinode/lib/rhino-shim.js

Using these techniques I've been able to prototype a version of jsdoc that
uses nodejs modules and runs equally well under node or rhino.

-- 
Michael Mathews

Re: [nug] Rhino require, anyone?

From:
Tom Yandell
Date:
2011-05-07 @ 23:06
Very cool. Seen this?

https://github.com/lhofhansl/RhiNodeII

I thought Rhino was supposed to be slow?

https://github.com/lhofhansl/RhiNodeII/wiki/Benchmarks

I wonder how difficult it would be to make it run with Mug?

https://github.com/timcameronryan/mug

Tom

On 7 May 2011 22:49, Michael Mathews <micmath@gmail.com> wrote:

> I just updated my project to allow developers to require nodejs modules
> (even those installed via npm) into a rhino script.
>
>     https://github.com/micmath/Rhino-Require
>
> Not surprisingly, for those modules that are built into node itself, this
> won't work in rhino, but I've started a "shim file" to fake the node
> built-in modules that I personally needed for jsdoc:
>
>
> https://github.com/micmath/jsdoc/blob/jsdoc%2Brhinode/lib/rhino-shim.js
>
> Using these techniques I've been able to prototype a version of jsdoc that
> uses nodejs modules and runs equally well under node or rhino.
>
> --
> Michael Mathews
>

Re: [nug] Rhino require, anyone?

From:
Michael Mathews
Date:
2011-05-08 @ 08:05
On Sunday, 8 May 2011 at 00:06, Tom Yandell wrote:
Very cool. Seen this?
> 
> https://github.com/lhofhansl/RhiNodeII
> 

I really genuinely thought I was being so original when I named my branch 
"rhinode". Oh well.

Trust me when I say I don't want to write Java to run node modules. I want
to write node to run node modules. The RhiNodeII seems to be embracing the
Rhinode a bit too closely if you ask me.

> 
> I thought Rhino was supposed to be slow?
> 
> https://github.com/lhofhansl/RhiNodeII/wiki/Benchmarks

1) Those benchmarks were run against an old version of node. 2) timing 
millions of loops probably does not represent a typical use case. In my 
experience I'm more likely to start up rhino, run a little code and exit. 
What is slow about rhino is the starting up bit. Even if rhino (which uses
quite mature Java) takes only 10 ms to complete a task, if it takes 2000 
ms to start up, you can't exactly call it faster than node which might 
complete the task in 20 ms but starts up in 50 ms.

I've been running jsdoc's unit test suite in both rhino and node whenever 
I make a change to the code. I haven't timed it but I know what I 
experience: the node results seems to instantly "blink" onto the terminal,
whilst I can literally count seconds before the rhino results appear.

> 
> I wonder how difficult it would be to make it run with Mug?
> 
> https://github.com/timcameronryan/mug
> 
Rhino already has a JavaScript => Java Class compiler -- I've never used 
it. Not sure what the Clojure bit gives you, but the goal of the project 
seems to be that it will make better java classes than rhino?

http://www.mozilla.org/rhino/jsc.html

> 
> Tom
> 
> On 7 May 2011 22:49, Michael Mathews <micmath@gmail.com> wrote:
> > I just updated my project to allow developers to require nodejs 
modules (even those installed via npm) into a rhino script.
> > 
> > https://github.com/micmath/Rhino-Require 
> > 
> > Not surprisingly, for those modules that are built into node itself, 
this won't work in rhino, but I've started a "shim file" to fake the node 
built-in modules that I personally needed for jsdoc: 
> > 
> > https://github.com/micmath/jsdoc/blob/jsdoc%2Brhinode/lib/rhino-shim.js 
> > 
> > Using these techniques I've been able to prototype a version of jsdoc 
that uses nodejs modules and runs equally well under node or rhino.
> > 
> > -- 
> > Michael Mathews
> > 
> 

Re: [nug] Rhino require, anyone?

From:
Michael Mathews
Date:
2011-05-08 @ 13:51
I've had an email off of the creator of the RingoJS framework, who noticed
my Rhino-Require project, and pointed out that they also have a commonjs 
module loader, and that when rhino 1.7r3 finally gets released there will 
be a commonjs module loader built into the rhino distribution itself, so 
that's pretty interesting news.

Also I stumbled across this today as well:

https://github.com/rbackhouse/zazl/blob/master/org.dojotoolkit.server.util.js/jsutil/commonjs/loader.js

Described here:

http://rbackhouse.blogspot.com/2011/03/writing-your-own-commonjs-module-loader.html

-- 
Michael Mathews
On Sunday, 8 May 2011 at 09:05, Michael Mathews wrote: 
> On Sunday, 8 May 2011 at 00:06, Tom Yandell wrote:
> > Very cool. Seen this?
> > 
> > https://github.com/lhofhansl/RhiNodeII
> > 
> 
> I really genuinely thought I was being so original when I named my 
branch "rhinode". Oh well.
> 
> Trust me when I say I don't want to write Java to run node modules. I 
want to write node to run node modules. The RhiNodeII seems to be 
embracing the Rhinode a bit too closely if you ask me.
> 
> > I thought Rhino was supposed to be slow?
> > 
> > https://github.com/lhofhansl/RhiNodeII/wiki/Benchmarks
> 
> 1) Those benchmarks were run against an old version of node. 2) timing 
millions of loops probably does not represent a typical use case. In my 
experience I'm more likely to start up rhino, run a little code and exit. 
What is slow about rhino is the starting up bit. Even if rhino (which uses
quite mature Java) takes only 10 ms to complete a task, if it takes 2000 
ms to start up, you can't exactly call it faster than node which might 
complete the task in 20 ms but starts up in 50 ms.
> 
> I've been running jsdoc's unit test suite in both rhino and node 
whenever I make a change to the code. I haven't timed it but I know what I
experience: the node results seems to instantly "blink" onto the terminal,
whilst I can literally count seconds before the rhino results appear.
> 
> > 
> > I wonder how difficult it would be to make it run with Mug?
> > 
> > https://github.com/timcameronryan/mug
> > 
> Rhino already has a JavaScript => Java Class compiler -- I've never used
it. Not sure what the Clojure bit gives you, but the goal of the project 
seems to be that it will make better java classes than rhino?
> 
> http://www.mozilla.org/rhino/jsc.html
> 
> > Tom
> > 
> > On 7 May 2011 22:49, Michael Mathews <micmath@gmail.com> wrote:
> > > I just updated my project to allow developers to require nodejs 
modules (even those installed via npm) into a rhino script.
> > > 
> > > https://github.com/micmath/Rhino-Require 
> > > 
> > > Not surprisingly, for those modules that are built into node itself,
this won't work in rhino, but I've started a "shim file" to fake the node 
built-in modules that I personally needed for jsdoc: 
> > > 
> > > https://github.com/micmath/jsdoc/blob/jsdoc%2Brhinode/lib/rhino-shim.js 
> > > 
> > > Using these techniques I've been able to prototype a version of 
jsdoc that uses nodejs modules and runs equally well under node or rhino.
> > > 
> > > -- 
> > > Michael Mathews
> > > 
> > 
>