How does Ringo in AppengineJS resolve relative path reference in Javascript code?

5 views
Skip to first unread message

Giacecco

unread,
Jul 31, 2010, 7:48:44 AM7/31/10
to appenginejs
I've noticed some time ago, but never investigated further, the way we
can "require" other javascript code using relative paths that work
simultaneously:

1) starting from where the referrer is, e.g. require("foo") can mean
foo.js in the same folder as the referrer javascript file is, and

2) starting from [application path]/packages/appengine/lib, e.g.
require("google/appengine/ext/db") means [application path]/packages/
appengine/lib/google/appengine/ext/db.js

I can't understand how (2) works. I expected some setting to be hidden
somewhere but can't find it. How does it work?

G.

George Moschovitis

unread,
Jul 31, 2010, 8:35:18 AM7/31/10
to appen...@googlegroups.com
Hannes can better answer this question but let me try.

the lib directory (have a look at package.json) of all packages is added to the search path
the module-path defined in app.yaml or web.xml is also added to the search path

for relative requires you have to do:

require("./foo");

instead of

require("foo");

hope this helps,
-g.

Giacecco

unread,
Jul 31, 2010, 11:17:53 AM7/31/10
to appenginejs
At the moment, require("foo") works exactly like require("./foo") in
my code, that is in the src folder of the application. Is that a bug
then?

G.

On Jul 31, 1:35 pm, George Moschovitis <george.moschovi...@gmail.com>
wrote:

George Moschovitis

unread,
Jul 31, 2010, 11:57:16 AM7/31/10
to appen...@googlegroups.com
On Sat, Jul 31, 2010 at 6:17 PM, Giacecco <giac...@giacec.co> wrote:
At the moment, require("foo") works exactly like require("./foo") in
my code, that is in the src folder of the application. Is that a bug
then?

no, if both files are in the src folder, require("foo") and require("./foo") are equivalent to the mechanism I described ;-)

-g.
Reply all
Reply to author
Forward
0 new messages