IMHO, a path is a bad way to represent this.
My vote:
-1 to something that resolves a path
+.5 to something like getResource() which may follow a similar to the
kind of rules that we have in require already and returns a stream as
defined in the IO/* we chose.
+.5 to something that resolves an absolute url relative to the module. A
url is more reasonable to represent something on the filesystem, in a
package database (there's already one for jars, and that could easily
inspire one that applies to zips), or in the various locations. The only
thing an implementation needs to do is support creating those urls, and
support extracting data from those urls in whatever generic method we give.
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]
I think the original idea was something like:
module.resource(id).open(…);
where id conforms to our notions of relative and top level
identifiers. The resource, in this case would have to be in the
module library paths.
Tom has also been asking for package relative resources. Presently,
we do not maintain a reference between modules and the package that
contains them, but that is likely change, I think, as there are other
package-relative features seemingly in the works.
Ihab had an idea of using something like # or ! as a package relative
root for another feature we've been discussing offlist, but the intent
was for that to be like a top-level identifier that's restricted to
the current package as a self-defence mechanism for packages for
downloaded modules mixed with less suspicious packages. That needs
further thought.
require("#./only-my-modules");
But perhaps an identifier prefix would be good for package root
relative resource identifiers, e.g.,
module.resource("@media/icons/logo-512.png")
.open("rb")
.copy(system.stdout);
Kris Kowal
In Narwhal, they are. The only difference between relative and
top-level in Narwhal, with regard to module path searching, is that a
relative identifier gets converted to a top-level identifier by
resolving it against the top-level identifier of the calling module.
I presume that your implementation resolves the identifier against the
calling module's canonical path instead of its top-level identifier.
This is an area that the specification does not yet address, but it is
likely to be important if we standardize packaging. I think it's
important that we keep paths and identifiers decoupled in the interest
of maintaining the possibility of non-path-like module storage
systems.
Kris Kowal
None of the tests in the suite address behaviors of modules in
different library paths because library paths are not a feature
required by the specification. So, this is definitely a grey area.
We may want to make some extensions to the standard, for loaders that
have certain things in common, like packages and load paths. These
would not be mandatory or applicable to all CommonJS module system
implementation, but would give us some additional consistency among
our file-system based implementations and alternately database backed
or all http based implementations.
Kris Kowal
+1
Why exactly does it have to be non-modifiable? sure if its over http
you can't. But if its local file I don't see we should restrict
permissions like that.
I think normative text should say that the object returned by
.resource(id) must have an "open" property that will return a stream
for read when applied with no arguments. It may be a good idea to
include other methods analogous to the file system Path object like
mtime (which I'm going to call lastModified in the next revision in
adherence to the resolution on literate names over unix names). It
would not be necessary to restrict the objects further.
With this specification, it would be sufficient for an implementation
to return a Path object, or something more restrictive in sandboxed
systems.
Kris Kowal