CommonJS require function in shell?

76 views
Skip to first unread message

jg

unread,
Feb 25, 2012, 2:59:38 AM2/25/12
to mozill...@googlegroups.com
Hi,

I would like to know the status of commonJS/require function in rhino (including shell). For instance, a few general node.js modules installed with npm are directly usable in Rhino, and using them from the Rhino shell is nice. As node is very active, staying close to node (commonJS-wise) is helps a lot. So running modules or script without using "-modules" or "-main" is much expected. Maybe this feature is already implemented, but do we have to wait for a 1.7R4 release (when btw?)?
In the mean time, I used Narwhal but it's not alive anymore, at least for Rhino and I jumped to using require.js scripts https://github.com/micmath/Rhino-Require I haven't seen mentionned here. Can't some evolutions be written in plain JS, kind of "polyfills" if it's the term?

Thanks,
Best regards,
jg

Hannes Wallnöfer

unread,
Feb 25, 2012, 3:56:41 AM2/25/12
to mozill...@googlegroups.com
It's not totally clear what your problem is with Rhino's
implementation of CommonJS require. Is it that there are command line
switches required to activate it? This will likely stay that way since
CommonJS modules is not part of any "official" spec and usually not
present in core JS runtimes.

I've made some improvements (I think) that I've made to
require-related command line switches since 1.7R3. You can read about
it here:

http://groups.google.com/group/mozilla-rhino/browse_frm/thread/ecbcfdcb28e01292/cb6c896ec2cef230

1.7R4 should be out within the next month or two and will contain
these changes. If you're interested in a fuller implementation of
CommonJS related features on top of Rhino you may also want to have a
look at RingoJS (http://ringojs.org).

Hannes

2012/2/25 jg <jgra...@gmail.com>:

jg

unread,
Feb 25, 2012, 12:19:00 PM2/25/12
to mozill...@googlegroups.com
Thank you Hannes. And thanks a lot for what you do for the Rhino community.

My first problem with require function is that it's not available in Shell (in 1.7R3 at least).
The rest was more about suggestions. Node/V8 seems the most active community, interoperability with other JS modules is much useful. Why can't using the classpath or defining a RHINO_PATH (like NODE_PATH) for pointing to modules be just enough for loading modules? (But I don' know the changes you did, so CLI oddities might already be solved!).
I know a bit about ringojs (I liked the addToClasspath runtime method!), but I prefer stay with plain rhino (but I don't know the main engine differences between the two). I've just seen on ringojs forums, questions from others about "node compatibility" or "common node". So interoperability among engines is in the air.

Looking forward to next release,
regards,
jg

Reply all
Reply to author
Forward
0 new messages