The bit about require.paths is very carefully worded to permit it to
be object identical to a global require paths array. The spec is
clear that any modification has to be done in-place with the given
object, using methods like splice, since re-assignment may have no
effect. This is what we do in Narwhal. I can readily see why it
would not be desirable to have require.paths exist at all in some
cases though, which we also leave as an option. We might have to
revisit the idea of require.paths someday, but I think we're fine for
now. We might want to move "require" properties into the "system"
module, for example.
Kris Kowal
>
>
> Thoughts? What are other implementors doing with require.paths? If you're using a global require, how are you keeping track of relative module filenames?
Hippo has a require per module, but the require.paths is dont-delete, read-only meaning all instances share the same array of paths that you can only change with push/pop etc.
The spec is
clear that any modification has to be done in-place with the given
object, using methods like splice, since re-assignment may have no
effect.
> Thoughts? What are other implementors doing with require.paths? If you're using a global require, how are you keeping track of relative module filenames?
I resolve the identifier "module" against the top-level scope in the scope chain of the current require() invocation, then if it's an object, retrieve the property "id" from it; that gives me the absolute ID of the module. If this fails for whatever reason (identifier does not resolve to an object, object has no property of that name) then require() with relative ID fails.
It can't fail for a module also loaded with require() though as it'll make sure there's a readonly-dontdelete "module" object with a likewise readonly-dontdelete "id" property.
Attila.
>Hippo has a require per module, but the require.paths is dont-delete, read-only meaning all instances share the same array of paths that you can only change with push/pop etc.
>
> Thoughts? What are other implementors doing with require.paths? If you're using a global require, how are you keeping track of relative module filenames?
--
You received this message because you are subscribed to the Google Groups "CommonJS" group.
To post to this group, send email to comm...@googlegroups.com.
To unsubscribe from this group, send email to commonjs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/commonjs?hl=en.