Improving shell commonjs module support

45 views
Skip to first unread message

Hannes Wallnöfer

unread,
Dec 21, 2011, 5:02:51 PM12/21/11
to mozilla-rhino
It has become increasingly clear that the current command line options
to support commonjs modules in rhino shell are not really optimal. The
greatest problem is the fact that the main module has to be specified
with the special -main option, making it difficult to pass arguments
to the script (you have to repeat the exact same script name a second
time in order to do that). Other problems include limited support for
require() in non-module scripts (relative module ids don't work) and
no way to activate commonjs module support without using the -modules
or -main switch.

I've pushed a change to github master that I hope will fix these problems:

https://github.com/mozilla/rhino/commit/5ce561e1be528d55485c49a2858fbb41d1ad4d6c

Here's what's changed:

1) The -main option to define the main module has been removed. If
commonjs module support is enabled and a script is passed on the
command line it is the main module. If more than one scripts are
defined (using the -f option) the last one is used as main module.

2) There's now a -require command line option to enable commonjs
modules without having to using any of the other module related
options like -modules. Those other options imply the -require switch,
so it's only needed if you don't want to define a module search path.

3) Relative module ids are now supported in non-module command line
scripts, shell input and code provided through the -e option. For
ordinary scripts, relative ids are resolved relative to the script's
file name or URL. For shell and -e option, relative ids are resoved
relative to the current working directory.

Let me know what you think of these changes.

Hannes

Tim Schaub

unread,
Dec 21, 2011, 8:03:07 PM12/21/11
to mozill...@googlegroups.com
These sound like great changes to me. Thanks for the continued work
on Rhino. Looking forward to the next release!

Tim

2011/12/21 Hannes Wallnöfer <han...@gmail.com>:

Vassilis

unread,
Dec 22, 2011, 4:17:23 AM12/22/11
to mozilla-rhino

I would also like to thank you for your work and for keeping rhino
going.I think these are some nice enhancements for the shell.
Vassilis
On Dec 22, 12:02 am, Hannes Wallnöfer <hann...@gmail.com> wrote:
> It has become increasingly clear that the current command line options
> to support commonjs modules in rhino shell are not really optimal. The
> greatest problem is the fact that the main module has to be specified
> with the special -main option, making it difficult to pass arguments
> to the script (you have to repeat the exact same script name a second
> time in order to do that). Other problems include limited support for
> require() in non-module scripts (relative module ids don't work) and
> no way to activate commonjs module support without using the -modules
> or -main switch.
>
> I've pushed a change to github master that I hope will fix these problems:
>
> https://github.com/mozilla/rhino/commit/5ce561e1be528d55485c49a2858fb...
Reply all
Reply to author
Forward
0 new messages